Skip to content

Commit adf2b10

Browse files
committed
docs: update README
1 parent 624e32e commit adf2b10

File tree

1 file changed

+45
-93
lines changed

1 file changed

+45
-93
lines changed

README.md

Lines changed: 45 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,54 @@
66
[![codecov](https://codecov.io/gh/TexteaInc/json-viewer/branch/main/graph/badge.svg?token=r32mzVhrRl)](https://codecov.io/gh/TexteaInc/json-viewer)
77
[![Netlify Status](https://api.netlify.com/api/v1/badges/4fab3ed5-7084-449d-9fc9-12df09108301/deploy-status)](https://viewer.textea.io)
88

9-
This is a React component for JSON viewer, but not only a JSON viewer.
9+
`@textea/json-viewer` is a React component that can be used to view and display any kind of data, not just JSON.
1010

1111
~~Json Viewer?~~
1212
**ANY Data Viewer**
1313

14-
> This is v2 branch with fancy features like 100% TypeScript, lightly code and customizable component support.
15-
>
16-
> If you are looking for v1 version based on [mac-s-g/react-json-view](https://github.com/mac-s-g/react-json-view),
17-
> Please see [v1.x](https://github.com/TexteaInc/json-viewer/tree/v1.x).
18-
1914
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/textea-json-viewer-v2-afaey9?file=pages%2Findex.js)
2015

21-
## Usage
16+
## Features 🚀
2217

23-
`@textea/json-viewer` is using [Material-UI](https://mui.com/) as the base component library, so you need to install it and its peer dependencies first.
18+
- 🦾 100% TypeScript
19+
- 🎨 Customizable: Key, value, editable, copy, select... Anything you can think of!
20+
- 🌈 Theme support: light or dark, or use [Base16](https://github.com/chriskempson/base16) themes.
21+
- ⚛️ SSR Ready
22+
- 📋 Copy to Clipboard
23+
- 🔍 Inspect anything: `Object`, `Array`, primitive types, and even `Map` and `Set`.
24+
- 📊 Metadata preview: Total items, length of string...
25+
- ✏️ Editor: Comes with an editor for basic types, which you can also customize to fit your use case.
2426

25-
### NPM
27+
## Installation
2628

27-
```shell
29+
`@textea/json-viewer` is using [Material-UI](https://mui.com/) as the base component library, so you need to install it and its peer dependencies first.
30+
31+
```sh
2832
npm install @textea/json-viewer @mui/material @emotion/react @emotion/styled
2933
```
3034

31-
### Yarn
35+
### CDN
3236

33-
```shell
34-
yarn add @textea/json-viewer
37+
```html
38+
<!DOCTYPE html>
39+
<html lang="en">
40+
<body>
41+
<div id="json-viewer"></div>
42+
<script src="https://cdn.jsdelivr.net/npm/@textea/json-viewer@3"></script>
43+
<script>
44+
new JsonViewer({
45+
value: {
46+
/* ... */
47+
}
48+
}).render('#json-viewer')
49+
</script>
50+
</body>
51+
</html>
3552
```
3653

37-
### PNPM
38-
39-
```shell
40-
pnpm add @textea/json-viewer
41-
```
54+
## Usage
4255

43-
### Basic Example
56+
Here is a basic example:
4457

4558
```jsx
4659
import { JsonViewer } from '@textea/json-viewer'
@@ -51,98 +64,37 @@ const object = {
5164
const Component = () => <JsonViewer value={object} />
5265
```
5366

54-
### Customizable data type
67+
### Customization
68+
69+
You can define custom data types to handle data that is not supported out of the box. Here is an example of how to display an image:
5570

5671
```jsx
5772
import { JsonViewer, defineDataType } from '@textea/json-viewer'
5873

5974
const object = {
60-
// what if I want to inspect a image?
6175
image: 'https://i.imgur.com/1bX5QH6.jpg'
6276
// ... other values
6377
}
64-
const Component = () => (
65-
<JsonViewer
66-
value={object}
67-
// just define it
68-
valueTypes={[
69-
defineDataType({
70-
is: (value) => typeof value === 'string' && value.startsWith('https://i.imgur.com'),
71-
Component: (props) => <Image height={50} width={50} src={props.value} alt={props.value} />
72-
})
73-
]}
74-
/>
75-
)
78+
79+
// Let's define a data type for image
80+
const imageDataType = defineDataType({
81+
is: (value) => typeof value === 'string' && value.startsWith('https://i.imgur.com'),
82+
Component: (props) => <Image height={50} width={50} src={props.value} alt={props.value} />
83+
})
84+
85+
const Component = () => <JsonViewer value={object} valueTypes={[imageDataType]} />
7686
```
7787

7888
![Avatar Preview](public/avatar-preview.png)
7989

8090
[see the full code](docs/pages/full/index.tsx)
8191

82-
### Base 16 Theme Support
83-
84-
```tsx
85-
export const ocean: NamedColorspace = {
86-
scheme: 'Ocean',
87-
author: 'Chris Kempson (http://chriskempson.com)',
88-
base00: '#2b303b',
89-
base01: '#343d46',
90-
base02: '#4f5b66',
91-
base03: '#65737e',
92-
base04: '#a7adba',
93-
base05: '#c0c5ce',
94-
base06: '#dfe1e8',
95-
base07: '#eff1f5',
96-
base08: '#bf616a',
97-
base09: '#d08770',
98-
base0A: '#ebcb8b',
99-
base0B: '#a3be8c',
100-
base0C: '#96b5b4',
101-
base0D: '#8fa1b3',
102-
base0E: '#b48ead',
103-
base0F: '#ab7967'
104-
}
92+
## Theme
10593

106-
const Component = () => <JsonViewer value={object} theme={ocean} />
107-
```
94+
Please refer to [Styling and Theming](https://viewer.textea.io/how-to/styling)
10895

10996
![Ocean Theme Preview](public/ocean-theme.png)
11097

111-
### Browser
112-
113-
```html
114-
<!DOCTYPE html>
115-
<html lang="en">
116-
<body>
117-
<div id="json-viewer"></div>
118-
<script src="https://cdn.jsdelivr.net/npm/@textea/json-viewer"></script>
119-
<script>
120-
new JsonViewer({
121-
value: {
122-
/* ... */
123-
}
124-
}).render()
125-
</script>
126-
</body>
127-
</html>
128-
```
129-
130-
## Features
131-
132-
- [x] 100% TypeScript
133-
- [x] Customizable
134-
- [x] `keyRenderer` for customize key renderer
135-
- [x] `valueTypes` for customize any value types you want
136-
- [x] `light | dark | base16` Theme support
137-
- [ ] custom metadata
138-
- [x] Support `Next.js` SSR
139-
- [x] `onChange` props allow users to edit value
140-
- [x] Inspect `object`, `Array`, primitive type, even `Map` and `Set` by default.
141-
- [x] Metadata preview, like total items, length of string...
142-
- [x] `Copy to Clipboard` on Click
143-
- [ ] Editor for basic types
144-
- [ ] Fully Test Coverage
145-
14698
## Contributors
14799

148100
<a href="https://github.com/TexteaInc/json-viewer/graphs/contributors"><img src="https://opencollective.com/json-viewer/contributors.svg?width=890&button=false" /></a>

0 commit comments

Comments
 (0)