Skip to content

Commit d721a63

Browse files
authored
Allow customization of string wrapping char (#19)
* feat: add valueWrap prop
1 parent a1b7735 commit d721a63

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

examples/src/App.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ const App = () => (
101101
</div>
102102
<br />
103103

104+
<h3>No quotations around string values</h3>
105+
<div style={{ background: "#222" }}>
106+
<JSONTree valueWrap={""} data={data} />
107+
</div>
108+
<br />
109+
104110
<h3>Theming Example</h3>
105111
<p>
106112
Styles are managed with css variables, override the default values to

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gtk-grafana/react-json-tree",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "React JSON Viewer Component, Extracted from redux-devtools",
55
"keywords": [
66
"react",

src/JSONNode.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function JSONNode({
1616
value,
1717
valueRenderer,
1818
isCustomNode,
19+
valueWrap,
1920
...rest
2021
}: Props) {
2122
const nodeType = isCustomNode(value) ? "Custom" : objType(value);
@@ -35,6 +36,7 @@ export default function JSONNode({
3536
...simpleNodeProps,
3637
data: value,
3738
isCustomNode,
39+
valueWrap,
3840
};
3941

4042
switch (nodeType) {
@@ -54,7 +56,7 @@ export default function JSONNode({
5456
<JSONValueNode
5557
{...simpleNodeProps}
5658
key={key}
57-
valueGetter={(raw: string) => `"${raw}"`}
59+
valueGetter={(raw: string) => `${valueWrap}${raw}${valueWrap}`}
5860
/>
5961
);
6062
case "Number":

src/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function JSONTree({
5555
isCustomNode = noCustomNode,
5656
collectionLimit = 50,
5757
sortObjectKeys = false,
58+
valueWrap = '"',
5859
}: JSONTreeProps) {
5960
return (
6061
<ul
@@ -76,6 +77,7 @@ export function JSONTree({
7677
postprocessValue={postprocessValue}
7778
collectionLimit={collectionLimit}
7879
sortObjectKeys={sortObjectKeys}
80+
valueWrap={valueWrap}
7981
/>
8082
</ul>
8183
);

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface CommonExternalProps {
5656
isCustomNode: IsCustomNode;
5757
collectionLimit: number;
5858
sortObjectKeys: SortObjectKeys;
59+
valueWrap: string;
5960
}
6061

6162
export interface CommonInternalProps extends CommonExternalProps {

0 commit comments

Comments
 (0)