Skip to content

Commit e41b038

Browse files
author
Adrian Florescu
committed
feat(virtualtree): added virtual tree demo styles and added support for typescript story
1 parent 9e53296 commit e41b038

File tree

7 files changed

+122
-46
lines changed

7 files changed

+122
-46
lines changed

.storybook/config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { configure } from '@storybook/react';
2+
23
import { configureActions } from '@storybook/addon-actions';
34
configureActions()
5+
6+
const req = require.context('../stories', true, /\.stories\.tsx$/);
47
function loadStories() {
5-
require('../stories/index.js');
6-
// You can require as many stories as you need.
8+
req.keys().forEach(req);
79
}
10+
811
configure(loadStories, module);

.storybook/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require("path");
33
module.exports = async ({ config, mode }) => {
44
config.module.rules.push({
55
test: /\.tsx?$/,
6-
include: path.resolve(__dirname, "../src"),
6+
include: [path.resolve(__dirname, "../src"), path.resolve(__dirname, "../stories")],
77
use: [
88
require.resolve("awesome-typescript-loader"),
99
require.resolve("react-docgen-typescript-loader"),

package-lock.json

Lines changed: 13 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,8 @@
8383
"commitizen": {
8484
"path": "./node_modules/cz-conventional-changelog"
8585
}
86+
},
87+
"dependencies": {
88+
"@types/storybook__addon-info": "^4.1.2"
8689
}
8790
}

stories/index.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

stories/my.stories.tsx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import * as React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
4+
// Addons
5+
import { withInfo } from "@storybook/addon-info";
6+
import { action } from '@storybook/addon-actions';
7+
8+
9+
// Components
10+
import VirtualTree from '../src/components/VirtualTree/VirtualTree'
11+
import { data as originalNodes } from '../src/components/VirtualTree/data/customData';
12+
13+
14+
const VirtualTreeStories = storiesOf("VirtualTree", module).addDecorator(withInfo);
15+
16+
const buttonStyle = {
17+
border: 0,
18+
fontSize: '14px',
19+
marginRight: '10px',
20+
height: '24px',
21+
width: '24px',
22+
lineHeight: '24px',
23+
background: '#E7D3AF',
24+
borderRadius: '50%',
25+
fontFamily: 'PT Mono, monospace'
26+
}
27+
28+
VirtualTreeStories.add(
29+
"VirtualTree",
30+
() => (
31+
<VirtualTree nodes={originalNodes} allExpanded={false}>
32+
{({ style, node, index, selectNode, expandOrCollapse }) => {
33+
return (
34+
<div style={style}>
35+
<div
36+
style={{
37+
overflow: 'auto',
38+
borderBottom: '1px solid #fff',
39+
fontFamily: 'sans-serif',
40+
fontSize: '15px',
41+
color: '#775E32',
42+
}}
43+
>
44+
<p
45+
style={{
46+
padding: '10px 0',
47+
paddingLeft: node.nesting * 20 + 'px',
48+
background: '#FFF1F1',
49+
margin: '0',
50+
display: 'block',
51+
lineHeight: '24px'
52+
53+
}}
54+
>
55+
{node.hasChildren ? (
56+
<button
57+
style={buttonStyle}
58+
onClick={(e) => {
59+
e.stopPropagation();
60+
action('a')('Row clicked')
61+
expandOrCollapse(node.path);
62+
}}
63+
>
64+
{node.expanded ? '-' : '+'}
65+
</button>
66+
) : (
67+
<button style={{...buttonStyle, background: '#fff'}}>-</button>
68+
)}
69+
<label htmlFor={node.path}>
70+
Path: {node.path} / i: {node.i} / Name: {node.name}
71+
</label>
72+
</p>
73+
</div>
74+
</div>
75+
)
76+
}}
77+
</VirtualTree>
78+
)
79+
)

tsconfig.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
{
22
"compilerOptions": {
3+
"outDir": "build/lib",
4+
"module": "commonjs",
35
"target": "es5",
4-
"module": "commonjs", //still get umd output by using libraryTarget: "umd" in webpack.config.js
5-
"declaration": true,
6-
"outDir": "./dist",
6+
"lib": ["es5", "es6", "es7", "es2017", "dom"],
7+
"sourceMap": true,
8+
"allowJs": false,
79
"jsx": "react",
10+
"moduleResolution": "node",
11+
"rootDirs": ["src", "stories"],
12+
"baseUrl": "src",
13+
"forceConsistentCasingInFileNames": true,
14+
"noImplicitReturns": true,
15+
"noImplicitThis": true,
16+
"noImplicitAny": true,
17+
"strictNullChecks": true,
18+
"suppressImplicitAnyIndexErrors": true,
19+
"noUnusedLocals": true,
20+
"declaration": true,
21+
"allowSyntheticDefaultImports": true,
22+
"experimentalDecorators": true,
23+
"emitDecoratorMetadata": true
824
},
9-
"exclude": [
10-
"node_modules",
11-
"dist"
12-
]
25+
"include": ["src/**/*"],
26+
"exclude": ["node_modules", "dist", "scripts"]
1327
}

0 commit comments

Comments
 (0)