Skip to content

Commit 7dd18d7

Browse files
committed
refactor: refactor components.value props.
1 parent b854a00 commit 7dd18d7

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

core/README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export default function Demo() {
249249
displayDataTypes={false}
250250
style={{
251251
'--w-rjv-background-color': '#ffffff',
252-
'--w-rjv-border-left': '0',
252+
'--w-rjv-border-left-width': '0',
253253
}}
254254
components={{
255255
braces: () => <span />,
@@ -266,6 +266,45 @@ export default function Demo() {
266266
}
267267
```
268268

269+
**Preview Picture**
270+
271+
```tsx mdx:preview
272+
import React from 'react';
273+
import JsonView from '@uiw/react-json-view';
274+
275+
const object = {
276+
avatar: 'https://i.imgur.com/MK3eW3As.jpg',
277+
string: 'Lorem ipsum dolor sit amet',
278+
integer: 42,
279+
}
280+
281+
function value({ type, children, ...props }) {
282+
if (type === 'string' && /\.(jpg)$/.test(children)) {
283+
return (
284+
<span {...props}>
285+
<img src={children} height="36" />
286+
</span>
287+
);
288+
}
289+
}
290+
291+
export default function Demo() {
292+
return (
293+
<JsonView
294+
value={object}
295+
keyName="root"
296+
// quotes=""
297+
displayObjectSize={false}
298+
displayDataTypes={false}
299+
style={{
300+
'--w-rjv-background-color': '#ffffff',
301+
}}
302+
components={{ value }}
303+
/>
304+
)
305+
}
306+
```
307+
269308
## Modify Icon Style
270309

271310
Use built-in default icons.
@@ -433,7 +472,7 @@ Here is the size benchmark (using [bundlephobia.com](https://bundlephobia.com))
433472
| react-json-tree-viewer | [![](https://img.shields.io/bundlephobia/min/react-json-tree-viewer?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![](https://img.shields.io/bundlephobia/minzip/react-json-tree-viewer?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![](https://badgen.net/bundlephobia/dependency-count/react-json-tree-viewer?color=red&label=&t=123)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![GitHub last commit](https://img.shields.io/github/last-commit/nsisodiya/react-json-viewer?style=flat&label=last)](https://github.com/nsisodiya/react-json-viewer/commits) |
434473
| react-domify | [![](https://img.shields.io/bundlephobia/min/react-domify?color=red&label=)](https://bundlephobia.com/result?p=react-domify) | [![](https://img.shields.io/bundlephobia/minzip/react-domify?color=red&label=)](https://bundlephobia.com/result?p=react-domify) | [![](https://badgen.net/bundlephobia/dependency-count/react-domify?color=red&label=)](https://bundlephobia.com/result?p=react-domify) | [![GitHub last commit](https://img.shields.io/github/last-commit/JedWatson/react-domify?style=flat&label=last)](https://github.com/JedWatson/react-domify/commits) |
435474
| react18-json-view | [![](https://img.shields.io/bundlephobia/min/react18-json-view?color=red&label=)](https://bundlephobia.com/result?p=react18-json-view) | [![](https://img.shields.io/bundlephobia/minzip/react18-json-view?color=red&label=)](https://bundlephobia.com/result?p=react18-json-view) | [![](https://badgen.net/bundlephobia/dependency-count/react18-json-view?color=red&label=)](https://bundlephobia.com/result?p=react18-json-view) | [![GitHub last commit](https://img.shields.io/github/last-commit/YYsuni/react18-json-view?style=flat&label=last)](https://github.com/YYsuni/react18-json-view/commits) |
436-
| @textea/json-viewer | [![](https://img.shields.io/bundlephobia/min/@textea/json-viewer?color=red&label=)](https://bundlephobia.com/result?p=@textea/json-viewer) | [![](https://img.shields.io/bundlephobia/minzip/@textea/json-viewer?color=red&label=)](https://bundlephobia.com/result?p=@textea/json-viewer) | [![](https://badgen.net/bundlephobia/dependency-count/%40textea%2Fjson-viewer?color=red&label=&t=vvv12213)](https://bundlephobia.com/result?p=@textea/json-viewer) | [![GitHub last commit](https://img.shields.io/github/last-commit/uiwjs/json-viewer?style=flat&label=last)](https://github.com/uiwjs/json-viewer/commits) |
475+
| @textea/json-viewer | [![](https://img.shields.io/bundlephobia/min/@textea/json-viewer?color=red&label=)](https://bundlephobia.com/result?p=@textea/json-viewer) | [![](https://img.shields.io/bundlephobia/minzip/@textea/json-viewer?color=red&label=)](https://bundlephobia.com/result?p=@textea/json-viewer) | [![](https://badgen.net/bundlephobia/dependency-count/%40textea%2Fjson-viewer?color=red&label=&t=vvv12213)](https://bundlephobia.com/result?p=@textea/json-viewer) | [![GitHub last commit](https://img.shields.io/github/last-commit/TexteaInc/json-viewer?style=flat&label=last)](https://github.com/TexteaInc/json-viewer/commits) |
437476

438477
## Development
439478

core/src/node.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export function RooNode<T extends object>(props: RooNodeProps<T>) {
166166
{tools}
167167
</Line>
168168
{expand && (
169-
<Line style={{ borderLeft: '1px solid var(--w-rjv-line-color, #ebebeb)', marginLeft: 6 }}>
169+
<Line style={{ borderLeft: 'var(--w-rjv-border-left-width, 1px) solid var(--w-rjv-line-color, #ebebeb)', marginLeft: 6 }}>
170170
{nameKeys.length > 0 &&
171171
nameKeys.map((key, idx) => {
172172
const item = value[key];

core/src/value.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ export function ValueView<T = object>(props: ValueViewProps<T>) {
119119
}
120120

121121
if (content && typeof content === 'string') {
122-
const valueView = renderValue ? (
123-
renderValue({
124-
className: 'w-rjv-value',
125-
style: { color, ...style },
126-
type,
127-
children: content,
128-
})
129-
) : (
122+
const reView = renderValue && renderValue({
123+
className: 'w-rjv-value',
124+
style: { color, ...style },
125+
type,
126+
content,
127+
children: (value as string),
128+
});
129+
const valueView = reView ? reView : (
130130
<Label color={color} style={style} className="w-rjv-value">
131131
{content}
132132
</Label>

0 commit comments

Comments
 (0)