Skip to content

Commit 92cfa77

Browse files
committed
chore: wip, fix tests
1 parent 535ea10 commit 92cfa77

36 files changed

+12570
-3622
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
node_modules
33
lib
4+
dist

README.md

+26-108
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,39 @@
1-
# react-json-tree
1+
# react-vite-component-template
22

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**.
44

5-
![](https://img.shields.io/npm/v/react-json-tree.svg)
5+
Check my post about this repository [here](https://victorlillo.dev/blog/react-typescript-vite-component-library).
66

7-
### Usage
7+
## Features
88

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**.
1310

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.
2312

24-
<JSONTree data={json} />;
25-
```
13+
- 🌳 **Tree shaking**, for not distributing dead-code.
2614

27-
#### Result:
15+
- 📚 **Storybook** for live viewing the components.
2816

29-
![](https://i.ibb.co/0KSYRJg/example-result.png)
17+
- 🎨 **PostCSS** for processing our CSS.
3018

31-
Check out [examples](examples) directory for more details.
19+
- 🖌️ **CSS Modules** in development, compiled CSS for production builds.
3220

33-
### Theming
21+
- 🧪 Testing with **Vitest** and **React Testing Library**.
3422

35-
Style with CSS. @todo base styles
23+
- ✅ Code quality tools with **ESLint**, **Prettier** and **Stylelint**.
3624

37-
<div>
38-
<JSONTree data={data} />
39-
</div>;
40-
```
25+
## 🤖 Scripts
4126

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-
![](http://cl.ly/image/1J1a0b0T0K3c/screenshot%202015-10-07%20at%203.44.31%20PM.png)
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**. |

eslint.config.js

+28-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1-
import eslintJs from './.config/eslint.js.config.base.mjs';
2-
import eslintTsReact from './.config/eslint.ts.react.config.base.mjs';
3-
import eslintTsReactJest from './.config/eslint.ts.react.jest.config.base.mjs';
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
import eslintConfigPrettier from 'eslint-config-prettier'
7+
import storybook from 'eslint-plugin-storybook'
48

5-
export default [
6-
...eslintJs,
7-
...eslintTsReact(import.meta.dirname),
8-
...eslintTsReactJest(import.meta.dirname),
9+
export default tseslint.config(
10+
{ ignores: ['dist', '.storybook'] },
911
{
10-
ignores: ['examples', 'lib'],
12+
extends: [js.configs.recommended, ...tseslint.configs.recommended, eslintConfigPrettier],
13+
files: ['**/*.{ts,tsx}'],
14+
languageOptions: {
15+
ecmaVersion: 2020,
16+
globals: globals.browser,
17+
},
18+
plugins: {
19+
'react-hooks': reactHooks,
20+
'react-refresh': reactRefresh,
21+
},
22+
rules: {
23+
...reactHooks.configs.recommended.rules,
24+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
25+
},
1126
},
12-
];
27+
{
28+
files: ['**/*.stories.@(ts|tsx|js|jsx|mjs|cjs)'],
29+
extends: [...storybook.configs['flat/recommended']],
30+
}
31+
)

0 commit comments

Comments
 (0)