-
Notifications
You must be signed in to change notification settings - Fork 20
/
00-Uncontrolled.stories.tsx
174 lines (154 loc) · 5.12 KB
/
00-Uncontrolled.stories.tsx
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { StoryFn } from '@storybook/react';
import { StoryColumnType } from './resources/types';
import { FilterSortPaginationStoryComponent } from './00-Uncontrolled/00-FilterSortPagination';
import { CustomLabelsStoryComponent } from './00-Uncontrolled/01-CustomLabels';
import { CustomCellStyleStoryComponent } from './00-Uncontrolled/02-CustomCellStyle';
import { CustomRowStyleStoryComponent } from './00-Uncontrolled/03-CustomRowStyle';
import { CustomTableHeaderPropsStoryComponent } from './00-Uncontrolled/04-CustomTableHeaderProps';
import { RowOnClickStoryComponent } from './00-Uncontrolled/05-RowOnClick';
import { MutatingTableStateStoryComponent } from './00-Uncontrolled/06-MutatingTableState';
import { ComposedTableStoryComponent } from './00-Uncontrolled/07-ComposedTable';
import { NestedObjectComponent } from './00-Uncontrolled/08-NestedObject';
export default {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/react/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'Uncontrolled'
};
// Filter, sort, pagination, checkbox.
const FilterSortPaginationTemplate: StoryFn<
typeof FilterSortPaginationStoryComponent
> = FilterSortPaginationStoryComponent;
export const FilterSortPagination = FilterSortPaginationTemplate.bind({});
FilterSortPagination.storyName = 'Filter, sort, pagination, checkbox';
FilterSortPagination.parameters = {
docs: {
source: 'helloworld'
}
};
// Custom labels.
const CustomLabelsStoryComponentTemplate: StoryFn<
typeof CustomLabelsStoryComponent
> = CustomLabelsStoryComponent;
export const CustomLabels = CustomLabelsStoryComponentTemplate.bind({});
CustomLabels.storyName = 'Custom labels';
CustomLabels.argTypes = {
filterPlaceholder: {
name: 'Filter placeholder',
type: 'string'
},
afterSelect: {
name: 'Text after pagination options',
type: 'string'
},
beforeSelect: {
name: 'Text before pagination options',
type: 'string'
},
firstPage: {
name: 'First page label',
type: 'string'
},
lastPage: {
name: 'Last page label',
type: 'string'
},
nextPage: {
name: 'Next page label',
type: 'string'
},
prevPage: {
name: 'Previous page label',
type: 'string'
}
};
CustomLabels.args = {
filterPlaceholder: 'Filter text...',
beforeSelect: 'Number of rows shown',
firstPage: '<<',
lastPage: '>>',
nextPage: '>',
prevPage: '<'
};
// Custom cell style.
const CustomCellStyleStoryComponentTemplate: StoryFn<
typeof CustomCellStyleStoryComponent
> = CustomCellStyleStoryComponent;
export const CustomCellStyle = CustomCellStyleStoryComponentTemplate.bind({});
CustomCellStyle.storyName = 'Custom cell style';
CustomCellStyle.argTypes = {
scoreCellColumnColor: {
name: 'Score cell column color if score is lower than 50',
type: 'string',
controls: {
type: 'color'
}
}
};
CustomCellStyle.args = {
scoreCellColumnColor: '#cf8a8a'
};
// Custom table row style.
const CustomRowStyleStoryComponentTemplate: StoryFn<
typeof CustomRowStyleStoryComponent
> = CustomRowStyleStoryComponent;
export const CustomRowStyleProps = CustomRowStyleStoryComponentTemplate.bind(
{}
);
CustomRowStyleProps.storyName = 'Custom row props depending depending on score';
CustomRowStyleProps.args = {
rowProps: (row: StoryColumnType) => ({
style: { background: `rgba(128, 0, 0, ${row.score / 200})` }
})
};
// Custom table header props.
const CustomTableHeaderPropsStoryComponentTemplate: StoryFn<
typeof CustomTableHeaderPropsStoryComponent
> = CustomTableHeaderPropsStoryComponent;
export const CustomTableHeaderProps =
CustomTableHeaderPropsStoryComponentTemplate.bind({});
CustomTableHeaderProps.storyName = 'Custom "score" table header classname';
CustomTableHeaderProps.argTypes = {
thClassName: {
name: '"Score" table header classname',
type: 'string'
}
};
CustomTableHeaderProps.args = {
thClassName: '#hello-world'
};
// Custom row on click.
const RowOnClickTemplate: StoryFn<typeof RowOnClickStoryComponent> =
RowOnClickStoryComponent;
export const RowOnClick = RowOnClickTemplate.bind({});
RowOnClick.storyName = 'Adding row on click event';
RowOnClick.argTypes = {
rowOnClickText: {
name: 'Text shown when row is clicked',
type: 'string'
}
};
RowOnClick.args = {
rowOnClickText: 'Hello, world'
};
// Control table from outside.
const MutatingTableStateStoryComponentTemplate: StoryFn<
typeof MutatingTableStateStoryComponent
> = MutatingTableStateStoryComponent;
export const MutatingTableState = MutatingTableStateStoryComponentTemplate.bind(
{}
);
MutatingTableState.storyName = "Mutating uncontrolled table's state";
// Composed table.
const ComposedTableStoryComponentTemplate: StoryFn<
typeof ComposedTableStoryComponent
> = ComposedTableStoryComponent;
export const ComposedTable = ComposedTableStoryComponentTemplate.bind({});
ComposedTable.storyName = 'Composed table';
// Nested object.
const NestedObjectComponentTemplate: StoryFn<
typeof NestedObjectComponent
> = NestedObjectComponent;
export const NestedObjectTable = NestedObjectComponentTemplate.bind({});
NestedObjectTable.storyName = 'Nested object table';