Skip to content

Commit d817f34

Browse files
committed
feat: add online theme editing feature.
1 parent a0831f7 commit d817f34

File tree

2 files changed

+88
-5
lines changed

2 files changed

+88
-5
lines changed

core/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,88 @@ export default function Demo() {
131131
}
132132
```
133133

134+
Online custom style example, please check in the [documentation website](https://uiwjs.github.io/react-json-view/)
135+
136+
```tsx mdx:preview
137+
import React, { useState, useRef } from 'react';
138+
import Colorful from '@uiw/react-color-colorful';
139+
import JsonView from '@uiw/react-json-view';
140+
141+
const object = {
142+
avatar: 'https://i.imgur.com/MK3eW3As.jpg',
143+
string: 'Lorem ipsum dolor sit amet',
144+
integer: 42,
145+
float: 114.514,
146+
bigint: 10086n,
147+
null: null,
148+
undefined,
149+
timer: 0,
150+
date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'),
151+
array: [19, 100.86, 'test', NaN, Infinity],
152+
nestedArray: [
153+
[1, 2],
154+
[3, 4],
155+
],
156+
object: {
157+
'first-child': true,
158+
'second-child': false,
159+
'last-child': null,
160+
},
161+
string_number: '1234',
162+
}
163+
const customTheme = {
164+
'--w-rjv-color': '#9cdcfe',
165+
'--w-rjv-background-color': '#1e1e1e',
166+
'--w-rjv-border-left': '1px solid #323232',
167+
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
168+
'--w-rjv-info-color': '#656565',
169+
170+
'--w-rjv-curlybraces-color': '#d4d4d4',
171+
'--w-rjv-brackets-color': '#d4d4d4',
172+
173+
'--w-rjv-type-string-color': '#ce9178',
174+
'--w-rjv-type-int-color': '#268bd2',
175+
'--w-rjv-type-float-color': '#859900',
176+
'--w-rjv-type-bigint-color': '#268bd2',
177+
'--w-rjv-type-boolean-color': '#559bd4',
178+
'--w-rjv-type-date-color': '#586e75',
179+
'--w-rjv-type-null-color': '#d33682',
180+
'--w-rjv-type-nan-color': '#859900',
181+
'--w-rjv-type-undefined-color': '#586e75',
182+
};
183+
184+
export default function Demo() {
185+
const [cssvar, setCssvar] = useState('--w-rjv-background-color');
186+
const [hex, setHex] = useState("#1e1e1e");
187+
const [theme, setTheme] = useState(customTheme);
188+
const onChange = ({ hexa }) => {
189+
const value = cssvar === '--w-rjv-border-left' ? `1px solid ${hexa}` : hexa;
190+
setHex(hexa);
191+
setTheme({ ...theme, [cssvar]: value });
192+
};
193+
return (
194+
<React.Fragment>
195+
<div style={{ display: 'flex', gap: '1rem' }}>
196+
<JsonView value={object} keyName="root" style={{ flex: 1, ...theme }} />
197+
<div>
198+
<Colorful color={hex} onChange={onChange} />
199+
<div style={{ display: 'flex', gap: '0.4rem', flexWrap: 'wrap' }}>
200+
{Object.keys(customTheme).map((varname, idx) => {
201+
const click = () => setCssvar(varname);
202+
const active = cssvar === varname ? '#a8a8a8' : '';
203+
return <button key={idx} style={{ background: active }} onClick={click}>{varname}</button>
204+
})}
205+
</div>
206+
</div>
207+
</div>
208+
Copy the theme configuration below into your project.
209+
<pre>
210+
{JSON.stringify(theme, null, 2)}
211+
</pre>
212+
</React.Fragment>
213+
)
214+
}
215+
```
134216
## Render
135217

136218
```tsx mdx:preview

www/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
"map": "source-map-explorer build/static/js/*.js --html build/website-result.html"
99
},
1010
"dependencies": {
11-
"@wcj/dark-mode": "^1.0.13",
1211
"@uiw/react-back-to-top": "1.2.3",
12+
"@uiw/react-color-colorful": "^1.3.1",
1313
"@uiw/react-github-corners": "^1.5.15",
14-
"@uiw/react-markdown-preview": "^4.1.0",
1514
"@uiw/react-json-view": "^0.0.1",
16-
"styled-components": "^6.0.0-rc.3",
17-
"react-code-preview-layout": "^3.0.1",
15+
"@uiw/react-markdown-preview": "^4.1.0",
16+
"@wcj/dark-mode": "^1.0.13",
1817
"react": "^18.2.0",
19-
"react-dom": "^18.2.0"
18+
"react-code-preview-layout": "^3.0.1",
19+
"react-dom": "^18.2.0",
20+
"styled-components": "^6.0.0-rc.3"
2021
},
2122
"devDependencies": {
2223
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",

0 commit comments

Comments
 (0)