|
1 |
| -# react-json-tree |
| 1 | +# react-vite-component-template |
2 | 2 |
|
3 |
| -React JSON Viewer Component, Extracted from [redux-devtools](https://github.com/reduxjs/redux-devtools). Supports [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable) objects, such as [Immutable.js](https://facebook.github.io/immutable-js/). |
| 3 | +Template for building a **React component library**, with **Vite**, **TypeScript** and **Storybook**. |
4 | 4 |
|
5 |
| - |
| 5 | +Check my post about this repository [here](https://victorlillo.dev/blog/react-typescript-vite-component-library). |
6 | 6 |
|
7 |
| -### Usage |
| 7 | +## Features |
8 | 8 |
|
9 |
| -```jsx |
10 |
| -import { JSONTree } from 'react-json-tree'; |
11 |
| -// If you're using Immutable.js: `npm i --save immutable` |
12 |
| -import { Map } from 'immutable'; |
| 9 | +- ⚛️ **React** component library with **TypeScript**. |
13 | 10 |
|
14 |
| -// Inside a React component: |
15 |
| -const json = { |
16 |
| - array: [1, 2, 3], |
17 |
| - bool: true, |
18 |
| - object: { |
19 |
| - foo: 'bar', |
20 |
| - }, |
21 |
| - immutable: Map({ key: 'value' }), |
22 |
| -}; |
| 11 | +- 🏗️ **Vite** as development environment. |
23 | 12 |
|
24 |
| -<JSONTree data={json} />; |
25 |
| -``` |
| 13 | +- 🌳 **Tree shaking**, for not distributing dead-code. |
26 | 14 |
|
27 |
| -#### Result: |
| 15 | +- 📚 **Storybook** for live viewing the components. |
28 | 16 |
|
29 |
| - |
| 17 | +- 🎨 **PostCSS** for processing our CSS. |
30 | 18 |
|
31 |
| -Check out [examples](examples) directory for more details. |
| 19 | +- 🖌️ **CSS Modules** in development, compiled CSS for production builds. |
32 | 20 |
|
33 |
| -### Theming |
| 21 | +- 🧪 Testing with **Vitest** and **React Testing Library**. |
34 | 22 |
|
35 |
| -Style with CSS. @todo base styles |
| 23 | +- ✅ Code quality tools with **ESLint**, **Prettier** and **Stylelint**. |
36 | 24 |
|
37 |
| -<div> |
38 |
| - <JSONTree data={data} /> |
39 |
| -</div>; |
40 |
| -``` |
| 25 | +## 🤖 Scripts |
41 | 26 |
|
42 |
| -#### Advanced Customization |
43 |
| -
|
44 |
| -```jsx |
45 |
| -<div> |
46 |
| - <JSONTree |
47 |
| - data={data} |
48 |
| - /> |
49 |
| -</div> |
50 |
| -``` |
51 |
| - |
52 |
| -#### Customize Labels for Arrays, Objects, and Iterables |
53 |
| - |
54 |
| -You can pass `getItemString` to customize the way arrays, objects, and iterable nodes are displayed (optional). |
55 |
| - |
56 |
| -By default, it'll be: |
57 |
| - |
58 |
| -```jsx |
59 |
| -<JSONTree getItemString={(type, data, itemType, itemString, keyPath) |
60 |
| - => <span>{itemType} {itemString}</span>} |
61 |
| -``` |
62 |
| - |
63 |
| -But if you pass the following: |
64 |
| - |
65 |
| -```jsx |
66 |
| -const getItemString = (type, data, itemType, itemString, keyPath) |
67 |
| - => (<span> // {type}</span>); |
68 |
| -``` |
69 |
| -
|
70 |
| -Then the preview of child elements now look like this: |
71 |
| -
|
72 |
| - |
73 |
| -
|
74 |
| -#### Customize Rendering |
75 |
| -
|
76 |
| -You can pass the following properties to customize rendered labels and values: |
77 |
| -
|
78 |
| -```jsx |
79 |
| -<JSONTree |
80 |
| - labelRenderer={([key]) => <strong>{key}</strong>} |
81 |
| - valueRenderer={(raw) => <em>{raw}</em>} |
82 |
| -/> |
83 |
| -``` |
84 |
| -
|
85 |
| -In this example the label and value will be rendered with `<strong>` and `<em>` wrappers respectively. |
86 |
| -
|
87 |
| -For `labelRenderer`, you can provide a full path - [see this PR](https://github.com/chibicode/react-json-tree/pull/32). |
88 |
| -
|
89 |
| -Their full signatures are: |
90 |
| -
|
91 |
| -- `labelRenderer: function(keyPath, nodeType, expanded, expandable)` |
92 |
| -- `valueRenderer: function(valueAsString, value, ...keyPath)` |
93 |
| - |
94 |
| -#### More Options |
95 |
| - |
96 |
| -- `shouldExpandNodeInitially: function(keyPath, data, level)` - determines if node should be expanded when it first renders (root is expanded by default) |
97 |
| -- `hideRoot: boolean` - if `true`, the root node is hidden. |
98 |
| -- `sortObjectKeys: boolean | function(a, b)` - sorts object keys with compare function (optional). Isn't applied to iterable maps like `Immutable.Map`. |
99 |
| -- `postprocessValue: function(value)` - maps `value` to a new `value` |
100 |
| -- `isCustomNode: function(value)` - overrides the default object type detection and renders the value as a single value |
101 |
| -- `collectionLimit: number` - sets the number of nodes that will be rendered in a collection before rendering them in collapsed ranges |
102 |
| -- `keyPath: (string | number)[]` - overrides the initial key path for the root node (defaults to `[root]`) |
103 |
| - |
104 |
| -### Credits |
105 |
| - |
106 |
| -- All credits to [Dave Vedder](http: //www.eskimospy.com/) ([[email protected]](mailto:[email protected])), who wrote the original code as [JSONViewer](https://bitbucket.org/davevedder/react-json-viewer/). |
107 |
| -- Extracted from [redux-devtools](https: //github.com/gaearon/redux-devtools), which contained ES6 + inline style port of [JSONViewer](https://bitbucket.org/davevedder/react-json-viewer/) by [Daniele Zannotti](http://www.github.com/dzannotti) ([[email protected]](mailto:[email protected])) |
108 |
| -- [Iterable support](https://github.com/gaearon/redux-devtools/pull/79) thanks to [Daniel K](https://github.com/FredyC). |
109 |
| -- npm package created by [Shu Uesugi](http: //github.com/chibicode) ([[email protected]](mailto:[email protected])) per [this issue](https://github.com/gaearon/redux-devtools/issues/85). |
110 |
| -- Improved and maintained by [Alexander Kuznetsov](https://github.com/alexkuz). The repository was merged into [`redux-devtools` monorepo](https://github.com/reduxjs/redux-devtools) from [`alexkuz/react-json-tree`](https://github.com/alexkuz/react-json-tree). |
111 |
| - |
112 |
| -### Similar Libraries |
113 |
| - |
114 |
| -- [react-treeview](https://github.com/chenglou/react-treeview) |
115 |
| -- [react-json-inspector](https://github.com/Lapple/react-json-inspector) |
116 |
| -- [react-object-inspector](https://github.com/xyc/react-object-inspector) |
117 |
| -- [react-json-view](https://github.com/mac-s-g/react-json-view) |
118 |
| - |
119 |
| -### License |
120 |
| - |
121 |
| -MIT |
| 27 | +| Script | Function | |
| 28 | +| :---------------: | ---------------------------------------------------------------------------------- | |
| 29 | +| `build` | Build the `dist`, with types declarations, after checking types with TypeScript. | |
| 30 | +| `lint` | Lint the project with **Eslint**. | |
| 31 | +| `lint:fix` | Lint and fix the project with **Eslint**. | |
| 32 | +| `format` | Check the project format with **Prettier**. | |
| 33 | +| `format:fix` | Format the project code with **Prettier**. | |
| 34 | +| `stylelint` | Lint the styles code with **Stylelint**. | |
| 35 | +| `stylelint:fix` | Lint and fix the styles code with **Stylelint**. | |
| 36 | +| `storybook` | Start a Storybook development server. | |
| 37 | +| `build-storybook` | Build the Storybook `dist`. | |
| 38 | +| `test` | Run the tests with **Vitest** using `jsdom` and starts a **Vitest UI** dev server. | |
| 39 | +| `coverage` | Generate a coverage report, with **v8**. | |
0 commit comments