@storybook/components 5.2.1 → 5.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/html.js +1 -1
- package/dist/typography/DocumentFormatting.js +2 -1
- package/dist/typography/DocumentWrapper.js +2 -2
- package/package.json +11 -5
- package/src/ActionBar/ActionBar.stories.tsx +0 -41
- package/src/ActionBar/ActionBar.tsx +0 -75
- package/src/Badge/Badge.stories.tsx +0 -11
- package/src/Badge/Badge.tsx +0 -68
- package/src/Button/Button.stories.tsx +0 -53
- package/src/Button/Button.tsx +0 -256
- package/src/ScrollArea/ScrollArea.stories.tsx +0 -85
- package/src/ScrollArea/ScrollArea.tsx +0 -62
- package/src/ScrollArea/ScrollAreaStyles.tsx +0 -166
- package/src/addon-panel/addon-panel.tsx +0 -33
- package/src/bar/bar.tsx +0 -93
- package/src/bar/button.ts +0 -89
- package/src/bar/separator.tsx +0 -39
- package/src/blocks/BlockBackgroundStyles.tsx +0 -9
- package/src/blocks/ColorPalette.stories.tsx +0 -29
- package/src/blocks/ColorPalette.tsx +0 -168
- package/src/blocks/Description.stories.tsx +0 -15
- package/src/blocks/Description.tsx +0 -18
- package/src/blocks/DocsPage.stories.tsx +0 -67
- package/src/blocks/DocsPage.tsx +0 -81
- package/src/blocks/DocsPageExampleCaption.md +0 -93
- package/src/blocks/DocsPageExampleCaption.mdx +0 -93
- package/src/blocks/EmptyBlock.stories.tsx +0 -9
- package/src/blocks/EmptyBlock.tsx +0 -23
- package/src/blocks/IFrame.tsx +0 -60
- package/src/blocks/IconGallery.stories.tsx +0 -32
- package/src/blocks/IconGallery.tsx +0 -72
- package/src/blocks/Preview.stories.tsx +0 -96
- package/src/blocks/Preview.tsx +0 -162
- package/src/blocks/PropsTable/PropDef.ts +0 -7
- package/src/blocks/PropsTable/PropRow.stories.tsx +0 -113
- package/src/blocks/PropsTable/PropRow.tsx +0 -102
- package/src/blocks/PropsTable/PropsTable.stories.tsx +0 -14
- package/src/blocks/PropsTable/PropsTable.tsx +0 -169
- package/src/blocks/Source.stories.tsx +0 -36
- package/src/blocks/Source.tsx +0 -72
- package/src/blocks/Story.stories.tsx +0 -25
- package/src/blocks/Story.tsx +0 -115
- package/src/blocks/Toolbar.tsx +0 -85
- package/src/blocks/Typeset.stories.tsx +0 -16
- package/src/blocks/Typeset.tsx +0 -68
- package/src/blocks/ZoomContext.tsx +0 -5
- package/src/blocks/index.ts +0 -10
- package/src/brand/StorybookIcon.stories.tsx +0 -6
- package/src/brand/StorybookIcon.tsx +0 -26
- package/src/brand/StorybookLogo.stories.tsx +0 -10
- package/src/brand/StorybookLogo.tsx +0 -33
- package/src/form/field/field.tsx +0 -42
- package/src/form/form.stories.tsx +0 -133
- package/src/form/index.tsx +0 -18
- package/src/form/input/input.tsx +0 -178
- package/src/html.tsx +0 -12
- package/src/icon/icon.stories.tsx +0 -77
- package/src/icon/icon.tsx +0 -22
- package/src/icon/icons.tsx +0 -310
- package/src/icon/svg.tsx +0 -24
- package/src/index.ts +0 -37
- package/src/placeholder/placeholder.stories.tsx +0 -24
- package/src/placeholder/placeholder.tsx +0 -25
- package/src/spaced/Spaced.stories.tsx +0 -72
- package/src/spaced/Spaced.tsx +0 -69
- package/src/syntaxhighlighter/formatter.test.js +0 -90
- package/src/syntaxhighlighter/formatter.ts +0 -26
- package/src/syntaxhighlighter/syntaxhighlighter.stories.tsx +0 -136
- package/src/syntaxhighlighter/syntaxhighlighter.tsx +0 -165
- package/src/tabs/tabs.stories.tsx +0 -207
- package/src/tabs/tabs.tsx +0 -252
- package/src/tooltip/ListItem.stories.tsx +0 -35
- package/src/tooltip/ListItem.tsx +0 -245
- package/src/tooltip/Tooltip.stories.tsx +0 -42
- package/src/tooltip/Tooltip.tsx +0 -146
- package/src/tooltip/TooltipLinkList.stories.tsx +0 -52
- package/src/tooltip/TooltipLinkList.tsx +0 -49
- package/src/tooltip/TooltipMessage.stories.tsx +0 -37
- package/src/tooltip/TooltipMessage.tsx +0 -67
- package/src/tooltip/TooltipNote.stories.tsx +0 -15
- package/src/tooltip/TooltipNote.tsx +0 -25
- package/src/tooltip/WithTooltip.stories.tsx +0 -85
- package/src/tooltip/WithTooltip.tsx +0 -159
- package/src/typings.d.ts +0 -4
- package/src/typography/DocumentFormatting.tsx +0 -355
- package/src/typography/DocumentFormattingSample.md +0 -127
- package/src/typography/DocumentWrapper.stories.tsx +0 -190
- package/src/typography/DocumentWrapper.tsx +0 -441
- package/src/typography/link/link.stories.tsx +0 -67
- package/src/typography/link/link.test.tsx +0 -108
- package/src/typography/link/link.tsx +0 -223
- package/src/typography/typography.stories.tsx +0 -111
- package/src/typography/withReset.tsx +0 -12
- package/tsconfig.json +0 -18
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { styled } from '@storybook/theming';
|
|
3
|
-
import { ResetWrapper } from '../typography/DocumentFormatting';
|
|
4
|
-
|
|
5
|
-
import { getBlockBackgroundStyle } from './BlockBackgroundStyles';
|
|
6
|
-
|
|
7
|
-
const ItemLabel = styled.div<{}>(({ theme }) => ({
|
|
8
|
-
fontFamily: theme.typography.fonts.base,
|
|
9
|
-
fontSize: theme.typography.size.s2,
|
|
10
|
-
marginLeft: 10,
|
|
11
|
-
lineHeight: 1.2,
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
const ItemSpecimen = styled.div<{}>(({ theme }) => ({
|
|
15
|
-
...getBlockBackgroundStyle(theme),
|
|
16
|
-
overflow: 'hidden',
|
|
17
|
-
height: 40,
|
|
18
|
-
width: 40,
|
|
19
|
-
display: 'flex',
|
|
20
|
-
alignItems: 'center',
|
|
21
|
-
justifyContent: 'center',
|
|
22
|
-
flex: 'none',
|
|
23
|
-
|
|
24
|
-
'> img, > svg': {
|
|
25
|
-
width: 20,
|
|
26
|
-
height: 20,
|
|
27
|
-
},
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
const Item = styled.div({
|
|
31
|
-
display: 'inline-flex',
|
|
32
|
-
flexDirection: 'row',
|
|
33
|
-
alignItems: 'center',
|
|
34
|
-
flex: '0 1 calc(20% - 10px)',
|
|
35
|
-
minWidth: 120,
|
|
36
|
-
|
|
37
|
-
margin: '0px 10px 30px 0',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const List = styled.div({
|
|
41
|
-
display: 'flex',
|
|
42
|
-
flexFlow: 'row wrap',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
interface IconItemProps {
|
|
46
|
-
name: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* An individual icon with a caption and an example (passed as `children`).
|
|
51
|
-
*/
|
|
52
|
-
export const IconItem: React.FunctionComponent<IconItemProps> = ({ name, children }) => {
|
|
53
|
-
return (
|
|
54
|
-
<Item>
|
|
55
|
-
<ItemSpecimen>{children}</ItemSpecimen>
|
|
56
|
-
<ItemLabel>{name}</ItemLabel>
|
|
57
|
-
</Item>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Show a grid of icons, as specified by `IconItem`.
|
|
63
|
-
*/
|
|
64
|
-
export const IconGallery: React.FunctionComponent = ({ children, ...props }) => {
|
|
65
|
-
return (
|
|
66
|
-
<ResetWrapper>
|
|
67
|
-
<List {...props} className="docblock-icongallery">
|
|
68
|
-
{children}
|
|
69
|
-
</List>
|
|
70
|
-
</ResetWrapper>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { Preview } from './Preview';
|
|
4
|
-
|
|
5
|
-
import { Story } from './Story';
|
|
6
|
-
import { Button } from '../Button/Button';
|
|
7
|
-
import * as sourceStories from './Source.stories';
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
title: 'Docs|Preview',
|
|
11
|
-
component: Preview,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const codeCollapsed = () => (
|
|
15
|
-
<Preview isExpanded={false} withSource={sourceStories.jsx().props}>
|
|
16
|
-
<Button secondary>Button 1</Button>
|
|
17
|
-
</Preview>
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
export const codeExpanded = () => (
|
|
21
|
-
<Preview isExpanded withSource={sourceStories.jsx().props}>
|
|
22
|
-
<Button secondary>Button 1</Button>
|
|
23
|
-
</Preview>
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
export const codeError = () => (
|
|
27
|
-
<Preview isExpanded withSource={sourceStories.sourceUnavailable().props}>
|
|
28
|
-
<Button secondary>Button 1</Button>
|
|
29
|
-
</Preview>
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
export const single = () => (
|
|
33
|
-
<Preview>
|
|
34
|
-
<Button secondary>Button 1</Button>
|
|
35
|
-
</Preview>
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
export const row = () => (
|
|
39
|
-
<Preview>
|
|
40
|
-
<Button secondary>Button 1</Button>
|
|
41
|
-
<Button secondary>Button 2</Button>
|
|
42
|
-
<Button secondary>Button 3</Button>
|
|
43
|
-
<Button secondary>Button 4</Button>
|
|
44
|
-
<Button secondary>Button 5</Button>
|
|
45
|
-
<Button secondary>Button 6</Button>
|
|
46
|
-
<Button secondary>Button 7</Button>
|
|
47
|
-
</Preview>
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
export const column = () => (
|
|
51
|
-
<Preview isColumn>
|
|
52
|
-
<Button secondary>Button 1</Button>
|
|
53
|
-
<Button secondary>Button 2</Button>
|
|
54
|
-
<Button secondary>Button 3</Button>
|
|
55
|
-
</Preview>
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
export const gridWith3Columns = () => (
|
|
59
|
-
<Preview columns={3}>
|
|
60
|
-
<Button secondary>Button 1</Button>
|
|
61
|
-
<Button secondary>Button 2</Button>
|
|
62
|
-
<Button secondary>Button 3</Button>
|
|
63
|
-
<Button secondary>Button 4</Button>
|
|
64
|
-
<Button secondary>Button 5</Button>
|
|
65
|
-
<Button secondary>Button 6</Button>
|
|
66
|
-
<Button secondary>Button 7 long long long long long title</Button>
|
|
67
|
-
<Button secondary>Button 8</Button>
|
|
68
|
-
<Button secondary>Button 9</Button>
|
|
69
|
-
<Button secondary>Button 10</Button>
|
|
70
|
-
<Button secondary>Button 11</Button>
|
|
71
|
-
<Button secondary>Button 12</Button>
|
|
72
|
-
<Button secondary>Button 13</Button>
|
|
73
|
-
<Button secondary>Button 14</Button>
|
|
74
|
-
<Button secondary>Button 15</Button>
|
|
75
|
-
<Button secondary>Button 16</Button>
|
|
76
|
-
<Button secondary>Button 17</Button>
|
|
77
|
-
<Button secondary>Button 18</Button>
|
|
78
|
-
<Button secondary>Button 19</Button>
|
|
79
|
-
<Button secondary>Button 20</Button>
|
|
80
|
-
</Preview>
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const buttonFn = () => <Button secondary>Hello Button</Button>;
|
|
84
|
-
|
|
85
|
-
export const withToolbar = () => (
|
|
86
|
-
<Preview withToolbar>
|
|
87
|
-
<Story inline storyFn={buttonFn} title="with toolbar" />
|
|
88
|
-
</Preview>
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
export const withToolbarMulti = () => (
|
|
92
|
-
<Preview withToolbar>
|
|
93
|
-
<Story inline storyFn={buttonFn} title="story1" />
|
|
94
|
-
<Story inline storyFn={buttonFn} title="story2" />
|
|
95
|
-
</Preview>
|
|
96
|
-
);
|
package/src/blocks/Preview.tsx
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { styled } from '@storybook/theming';
|
|
3
|
-
import { darken } from 'polished';
|
|
4
|
-
import { logger } from '@storybook/client-logger';
|
|
5
|
-
|
|
6
|
-
import { getBlockBackgroundStyle } from './BlockBackgroundStyles';
|
|
7
|
-
import { Source, SourceProps } from './Source';
|
|
8
|
-
import { ActionBar, ActionItem } from '../ActionBar/ActionBar';
|
|
9
|
-
import { Toolbar } from './Toolbar';
|
|
10
|
-
import { ZoomContext } from './ZoomContext';
|
|
11
|
-
|
|
12
|
-
export interface PreviewProps {
|
|
13
|
-
isColumn?: boolean;
|
|
14
|
-
columns?: number;
|
|
15
|
-
withSource?: SourceProps;
|
|
16
|
-
isExpanded?: boolean;
|
|
17
|
-
withToolbar?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const ChildrenContainer = styled.div<PreviewProps>(({ isColumn, columns }) => ({
|
|
21
|
-
display: 'flex',
|
|
22
|
-
flexWrap: 'wrap',
|
|
23
|
-
flexDirection: isColumn ? 'column' : 'row',
|
|
24
|
-
marginTop: -20,
|
|
25
|
-
|
|
26
|
-
'> *': {
|
|
27
|
-
flex: columns ? `1 1 calc(100%/${columns} - 20px)` : `1 1 0%`,
|
|
28
|
-
marginRight: 20,
|
|
29
|
-
marginTop: 20,
|
|
30
|
-
},
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
const StyledSource = styled(Source)<{}>(({ theme }) => ({
|
|
34
|
-
margin: 0,
|
|
35
|
-
borderTopLeftRadius: 0,
|
|
36
|
-
borderTopRightRadius: 0,
|
|
37
|
-
borderBottomLeftRadius: theme.appBorderRadius,
|
|
38
|
-
borderBottomRightRadius: theme.appBorderRadius,
|
|
39
|
-
border: 'none',
|
|
40
|
-
|
|
41
|
-
background:
|
|
42
|
-
theme.base === 'light' ? 'rgba(0, 0, 0, 0.85)' : darken(0.05, theme.background.content),
|
|
43
|
-
color: theme.color.lightest,
|
|
44
|
-
button: {
|
|
45
|
-
background:
|
|
46
|
-
theme.base === 'light' ? 'rgba(0, 0, 0, 0.85)' : darken(0.05, theme.background.content),
|
|
47
|
-
},
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
const PreviewWrapper = styled.div<PreviewProps>(
|
|
51
|
-
({ theme, withSource, isExpanded }) => ({
|
|
52
|
-
...getBlockBackgroundStyle(theme),
|
|
53
|
-
padding: '30px 20px',
|
|
54
|
-
position: 'relative',
|
|
55
|
-
overflow: 'hidden',
|
|
56
|
-
borderBottomLeftRadius: withSource && isExpanded && 0,
|
|
57
|
-
borderBottomRightRadius: withSource && isExpanded && 0,
|
|
58
|
-
borderBottomWidth: isExpanded && 0,
|
|
59
|
-
}),
|
|
60
|
-
({ withToolbar }) => withToolbar && { paddingTop: 64 }
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const PreviewContainer = styled.div({
|
|
64
|
-
margin: '25px 0 40px',
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
interface SourceItem {
|
|
68
|
-
source?: React.ReactElement;
|
|
69
|
-
actionItem: ActionItem;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const getSource = (
|
|
73
|
-
withSource: SourceProps,
|
|
74
|
-
expanded: boolean,
|
|
75
|
-
setExpanded: Function
|
|
76
|
-
): SourceItem => {
|
|
77
|
-
switch (true) {
|
|
78
|
-
case !!(withSource && withSource.error): {
|
|
79
|
-
return {
|
|
80
|
-
source: null,
|
|
81
|
-
actionItem: {
|
|
82
|
-
title: 'No code available',
|
|
83
|
-
disabled: true,
|
|
84
|
-
onClick: () => setExpanded(false),
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
case expanded: {
|
|
89
|
-
return {
|
|
90
|
-
source: <StyledSource {...withSource} dark />,
|
|
91
|
-
actionItem: { title: 'Hide code', onClick: () => setExpanded(false) },
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
default: {
|
|
95
|
-
return {
|
|
96
|
-
source: null,
|
|
97
|
-
actionItem: { title: 'Show code', onClick: () => setExpanded(true) },
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
function getStoryId(children: React.ReactNode) {
|
|
103
|
-
if (React.Children.count(children) === 1) {
|
|
104
|
-
const elt = children as React.ReactElement;
|
|
105
|
-
if (elt.props) {
|
|
106
|
-
return elt.props.id;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* A preview component for showing one or more component `Story`
|
|
114
|
-
* items. The preview also shows the source for the component
|
|
115
|
-
* as a drop-down.
|
|
116
|
-
*/
|
|
117
|
-
const Preview: React.FunctionComponent<PreviewProps> = ({
|
|
118
|
-
isColumn,
|
|
119
|
-
columns,
|
|
120
|
-
children,
|
|
121
|
-
withSource,
|
|
122
|
-
withToolbar = false,
|
|
123
|
-
isExpanded = false,
|
|
124
|
-
...props
|
|
125
|
-
}) => {
|
|
126
|
-
const [expanded, setExpanded] = React.useState(isExpanded);
|
|
127
|
-
const { source, actionItem } = getSource(withSource, expanded, setExpanded);
|
|
128
|
-
const [scale, setScale] = React.useState(1);
|
|
129
|
-
|
|
130
|
-
if (withToolbar && Array.isArray(children)) {
|
|
131
|
-
logger.warn('Cannot use toolbar with multiple preview children, disabling');
|
|
132
|
-
}
|
|
133
|
-
const showToolbar = withToolbar && !Array.isArray(children);
|
|
134
|
-
return (
|
|
135
|
-
<PreviewContainer {...props}>
|
|
136
|
-
<PreviewWrapper {...{ withSource, withToolbar: showToolbar }}>
|
|
137
|
-
{showToolbar && (
|
|
138
|
-
<Toolbar
|
|
139
|
-
border
|
|
140
|
-
zoom={z => setScale(scale * z)}
|
|
141
|
-
resetZoom={() => setScale(1)}
|
|
142
|
-
storyId={getStoryId(children)}
|
|
143
|
-
baseUrl="./iframe.html"
|
|
144
|
-
/>
|
|
145
|
-
)}
|
|
146
|
-
<ZoomContext.Provider value={{ scale }}>
|
|
147
|
-
<ChildrenContainer isColumn={isColumn} columns={columns}>
|
|
148
|
-
{Array.isArray(children) ? (
|
|
149
|
-
children.map((child, i) => <div key={i.toString()}>{child}</div>)
|
|
150
|
-
) : (
|
|
151
|
-
<div>{children}</div>
|
|
152
|
-
)}
|
|
153
|
-
</ChildrenContainer>
|
|
154
|
-
</ZoomContext.Provider>
|
|
155
|
-
{withSource && <ActionBar actionItems={[actionItem]} />}
|
|
156
|
-
</PreviewWrapper>
|
|
157
|
-
{withSource && source}
|
|
158
|
-
</PreviewContainer>
|
|
159
|
-
);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export { Preview };
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { PropRow } from './PropRow';
|
|
3
|
-
import { Table } from './PropsTable';
|
|
4
|
-
import { ResetWrapper } from '../../typography/DocumentFormatting';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
component: PropRow,
|
|
8
|
-
title: 'Docs|PropRow',
|
|
9
|
-
excludeStories: /.*Def$/,
|
|
10
|
-
decorators: [
|
|
11
|
-
getStory => (
|
|
12
|
-
<ResetWrapper>
|
|
13
|
-
<Table>
|
|
14
|
-
<tbody>{getStory()}</tbody>
|
|
15
|
-
</Table>
|
|
16
|
-
</ResetWrapper>
|
|
17
|
-
),
|
|
18
|
-
],
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const stringDef = {
|
|
22
|
-
name: 'someString',
|
|
23
|
-
type: { name: 'string' },
|
|
24
|
-
required: true,
|
|
25
|
-
description: 'someString description',
|
|
26
|
-
defaultValue: 'fixme',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const longNameDef = {
|
|
30
|
-
...stringDef,
|
|
31
|
-
name: 'reallyLongStringThatTakesUpSpace',
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const longDescDef = {
|
|
35
|
-
...stringDef,
|
|
36
|
-
description: 'really long description that takes up a lot of space. sometimes this happens.',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const numberDef = {
|
|
40
|
-
name: 'someNumber',
|
|
41
|
-
type: { name: 'number' },
|
|
42
|
-
required: false,
|
|
43
|
-
description: 'someNumber description',
|
|
44
|
-
defaultValue: 0,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const objectDef = {
|
|
48
|
-
name: 'someObject',
|
|
49
|
-
type: { name: 'objectOf', value: { name: 'number' } },
|
|
50
|
-
required: false,
|
|
51
|
-
description: 'A simple `objectOf` propType.',
|
|
52
|
-
defaultValue: { value: '{ key: 1 }', computed: false },
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const arrayDef = {
|
|
56
|
-
name: 'someOArray',
|
|
57
|
-
type: { name: 'arrayOf', value: { name: 'number' } },
|
|
58
|
-
required: false,
|
|
59
|
-
description: 'array of a certain type',
|
|
60
|
-
defaultValue: { value: '[1, 2, 3]', computed: false },
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const complexDef = {
|
|
64
|
-
name: 'someComplex',
|
|
65
|
-
type: {
|
|
66
|
-
name: 'objectOf',
|
|
67
|
-
value: {
|
|
68
|
-
name: 'shape',
|
|
69
|
-
value: {
|
|
70
|
-
id: {
|
|
71
|
-
name: 'number',
|
|
72
|
-
description:
|
|
73
|
-
"Just an internal propType for a shape.\n It's also required, and as you can see it supports multi-line comments!",
|
|
74
|
-
required: true,
|
|
75
|
-
},
|
|
76
|
-
func: {
|
|
77
|
-
name: 'func',
|
|
78
|
-
description: 'A simple non-required function',
|
|
79
|
-
required: false,
|
|
80
|
-
},
|
|
81
|
-
arr: {
|
|
82
|
-
name: 'arrayOf',
|
|
83
|
-
value: {
|
|
84
|
-
name: 'shape',
|
|
85
|
-
value: {
|
|
86
|
-
index: {
|
|
87
|
-
name: 'number',
|
|
88
|
-
description: '5-level deep propType definition and still works.',
|
|
89
|
-
required: true,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
description: 'An `arrayOf` shape',
|
|
94
|
-
required: false,
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
required: false,
|
|
100
|
-
description: 'A very complex `objectOf` propType.',
|
|
101
|
-
defaultValue: {
|
|
102
|
-
value: '{\n thing: {\n id: 2,\n func: () => {},\n arr: [],\n },\n}',
|
|
103
|
-
computed: false,
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const string = () => <PropRow row={stringDef} />;
|
|
108
|
-
export const longName = () => <PropRow row={longNameDef} />;
|
|
109
|
-
export const longDesc = () => <PropRow row={longDescDef} />;
|
|
110
|
-
export const number = () => <PropRow row={numberDef} />;
|
|
111
|
-
export const objectOf = () => <PropRow row={objectDef} />;
|
|
112
|
-
export const arrayOf = () => <PropRow row={arrayDef} />;
|
|
113
|
-
export const complex = () => <PropRow row={complexDef} />;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { styled } from '@storybook/theming';
|
|
3
|
-
import { transparentize } from 'polished';
|
|
4
|
-
import { PropDef } from './PropDef';
|
|
5
|
-
|
|
6
|
-
enum PropType {
|
|
7
|
-
SHAPE = 'shape',
|
|
8
|
-
UNION = 'union',
|
|
9
|
-
ARRAYOF = 'arrayOf',
|
|
10
|
-
OBJECTOF = 'objectOf',
|
|
11
|
-
ENUM = 'enum',
|
|
12
|
-
INSTANCEOF = 'instanceOf',
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface PrettyPropTypeProps {
|
|
16
|
-
type: any;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface PrettyPropValProps {
|
|
20
|
-
value: any;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface PropRowProps {
|
|
24
|
-
row: PropDef;
|
|
25
|
-
// FIXME: row options
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const Name = styled.span({ fontWeight: 'bold' });
|
|
29
|
-
|
|
30
|
-
const Required = styled.span<{}>(({ theme }) => ({
|
|
31
|
-
color: theme.color.negative,
|
|
32
|
-
fontFamily: theme.typography.fonts.mono,
|
|
33
|
-
cursor: 'help',
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
const StyledPropDef = styled.div<{}>(({ theme }) => ({
|
|
37
|
-
color:
|
|
38
|
-
theme.base === 'light'
|
|
39
|
-
? transparentize(0.4, theme.color.defaultText)
|
|
40
|
-
: transparentize(0.6, theme.color.defaultText),
|
|
41
|
-
fontFamily: theme.typography.fonts.mono,
|
|
42
|
-
fontSize: `${theme.typography.size.code}%`,
|
|
43
|
-
}));
|
|
44
|
-
|
|
45
|
-
const prettyPrint = (type: any): string => {
|
|
46
|
-
if (!type || !type.name) {
|
|
47
|
-
return '';
|
|
48
|
-
}
|
|
49
|
-
let fields = '';
|
|
50
|
-
switch (type.name) {
|
|
51
|
-
case PropType.SHAPE:
|
|
52
|
-
fields = Object.keys(type.value)
|
|
53
|
-
.map((key: string) => `${key}: ${prettyPrint(type.value[key])}`)
|
|
54
|
-
.join(', ');
|
|
55
|
-
return `{ ${fields} }`;
|
|
56
|
-
case PropType.UNION:
|
|
57
|
-
return Array.isArray(type.value)
|
|
58
|
-
? `Union<${type.value.map(prettyPrint).join(' | ')}>`
|
|
59
|
-
: JSON.stringify(type.value);
|
|
60
|
-
case PropType.ARRAYOF:
|
|
61
|
-
return `[ ${prettyPrint(type.value)} ]`;
|
|
62
|
-
case PropType.OBJECTOF:
|
|
63
|
-
return `objectOf(${prettyPrint(type.value)})`;
|
|
64
|
-
case PropType.ENUM:
|
|
65
|
-
if (type.computed) {
|
|
66
|
-
return JSON.stringify(type);
|
|
67
|
-
}
|
|
68
|
-
return Array.isArray(type.value)
|
|
69
|
-
? type.value.map((v: any) => v && v.value && v.value.toString()).join(' | ')
|
|
70
|
-
: JSON.stringify(type);
|
|
71
|
-
case PropType.INSTANCEOF:
|
|
72
|
-
return `instanceOf(${JSON.stringify(type.value)})`;
|
|
73
|
-
default:
|
|
74
|
-
return type.name;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const PrettyPropType: React.FunctionComponent<PrettyPropTypeProps> = ({ type }) => (
|
|
79
|
-
<span>{prettyPrint(type)}</span>
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
export const PrettyPropVal: React.FunctionComponent<PrettyPropValProps> = ({ value }) => (
|
|
83
|
-
<span>{JSON.stringify(value)}</span>
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
export const PropRow: React.FunctionComponent<PropRowProps> = ({
|
|
87
|
-
row: { name, type, required, description, defaultValue },
|
|
88
|
-
}) => (
|
|
89
|
-
<tr>
|
|
90
|
-
<td>
|
|
91
|
-
<Name>{name}</Name>
|
|
92
|
-
{required ? <Required title="Required">*</Required> : null}
|
|
93
|
-
</td>
|
|
94
|
-
<td>
|
|
95
|
-
<div>{description}</div>
|
|
96
|
-
<StyledPropDef>
|
|
97
|
-
<PrettyPropType type={type} />
|
|
98
|
-
</StyledPropDef>
|
|
99
|
-
</td>
|
|
100
|
-
<td>{defaultValue === undefined ? '-' : <PrettyPropVal value={defaultValue} />}</td>
|
|
101
|
-
</tr>
|
|
102
|
-
);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { PropsTable, PropsTableError } from './PropsTable';
|
|
3
|
-
import { stringDef, numberDef } from './PropRow.stories';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
component: PropsTable,
|
|
7
|
-
title: 'Docs|PropTable',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const normal = () => <PropsTable rows={[stringDef, numberDef]} />;
|
|
11
|
-
|
|
12
|
-
export const error = () => <PropsTable error={PropsTableError.NO_COMPONENT} />;
|
|
13
|
-
|
|
14
|
-
export const empty = () => <PropsTable rows={[]} />;
|