-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathDefault.tsx
More file actions
110 lines (96 loc) · 3.06 KB
/
Copy pathDefault.tsx
File metadata and controls
110 lines (96 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { Box, Button, Flex, InvertTheme } from '@stoplight/mosaic';
import { Story } from '@storybook/react';
import { JSONSchema4 } from 'json-schema';
import React from 'react';
import { JsonSchemaProps, JsonSchemaViewer } from '../components/JsonSchemaViewer';
const defaultSchema = require('../__fixtures__/default-schema.json');
const stressSchema = require('../__fixtures__/stress-schema.json');
const githubIssueSchema = require('../__fixtures__/real-world/github-issue.json');
const arrayOfComplexObjects = require('../__fixtures__/arrays/of-complex-objects.json');
const allOfComplexSchema = require('../__fixtures__/combiners/allOfs/complex.json');
export default {
component: JsonSchemaViewer,
argTypes: {},
};
const Template: Story<JsonSchemaProps> = ({ schema = defaultSchema as JSONSchema4, ...args }) => (
<JsonSchemaViewer schema={schema} {...args} />
);
export const Default = Template.bind({});
export const CustomRowAddon = Template.bind({});
CustomRowAddon.args = {
renderRowAddon: ({ nestingLevel }) => {
return nestingLevel == 1 ? (
<Flex h="full" alignItems="center">
<Button pl={1} mr={1} size="sm" appearance="minimal" icon="bullseye" />
<Button pl={1} mr={1} size="sm" appearance="minimal">
Expand All
</Button>
</Flex>
) : null;
},
};
export const Expansions = Template.bind({});
Expansions.args = {
schema: arrayOfComplexObjects as JSONSchema4,
renderRootTreeLines: true,
defaultExpandedDepth: 0,
};
export const ArrayOfObjects = Template.bind({});
ArrayOfObjects.args = { schema: arrayOfComplexObjects as JSONSchema4, renderRootTreeLines: true };
export const StressTest = Template.bind({});
StressTest.args = { schema: stressSchema as JSONSchema4, defaultExpandedDepth: 7 };
export const ErrorBoundary = Template.bind({});
ErrorBoundary.args = {
schema: {
'null (throws error)': null,
'object (recovers from error)': defaultSchema,
},
};
export const InvalidTypes = Template.bind({});
InvalidTypes.args = {
schema: {
type: 'object',
// @ts-ignore
properties: {
id: {
type: 'string',
},
address: {
type: [
// @ts-ignore
'null',
// @ts-ignore
{
type: 'object',
properties: {
taskId: {
type: 'string',
format: 'uuid',
},
},
},
],
},
},
},
};
InvalidTypes.storyName = 'Invalid types';
export const DarkMode: Story<JsonSchemaProps> = ({ schema = defaultSchema as JSONSchema4, ...args }) => (
<InvertTheme>
<Box bg="canvas">
<JsonSchemaViewer schema={schema} {...args} />
</Box>
</InvertTheme>
);
export const ExpandCollapseAll = Template.bind({});
ExpandCollapseAll.args = {
showExpandAll: true,
schema: githubIssueSchema as JSONSchema4,
};
ExpandCollapseAll.storyName = 'Expand/Collapse All';
export const CircularExpandCollapseAll = Template.bind({});
CircularExpandCollapseAll.args = {
showExpandAll: true,
maxRefDepth: 10,
schema: allOfComplexSchema as JSONSchema4,
};