This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Importer.stories.tsx
172 lines (155 loc) · 4.52 KB
/
Importer.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
import React, { useState } from 'react';
import { Story, Meta } from '@storybook/react';
import { ImporterProps } from './ImporterProps';
import { Importer, ImporterField } from './Importer';
import { deDE } from '../locale';
export default {
title: 'Importer',
component: Importer,
parameters: {
actions: { argTypesRegex: '^on.*|dataHandler' }
}
} as Meta;
type SampleImporterProps = ImporterProps<{ fieldA: string }>;
export const Main: Story<SampleImporterProps> = (args: SampleImporterProps) => {
return (
<Importer {...args}>
<ImporterField name="fieldA" label="Field A" />
<ImporterField name="fieldB" label="Field B" optional />
</Importer>
);
};
export const LocaleDE: Story<SampleImporterProps> = (
args: SampleImporterProps
) => {
return (
<Importer {...args} locale={deDE}>
<ImporterField name="fieldA" label="Field A" />
<ImporterField name="fieldB" label="Field B" optional />
</Importer>
);
};
export const Timesheet: Story<SampleImporterProps> = (
args: SampleImporterProps
) => {
return (
<Importer {...args}>
<ImporterField name="date" label="Date" />
<ImporterField name="clientName" label="Client" />
<ImporterField name="projectName" label="Project" />
<ImporterField name="projectCode" label="Project Code" optional />
<ImporterField name="taskName" label="Task" />
<ImporterField name="notes" label="Notes" optional />
</Importer>
);
};
export const CustomDelimiterConfig: Story<SampleImporterProps> = (
args: SampleImporterProps
) => {
return (
<Importer {...args}>
<ImporterField name="fieldA" label="Field A" />
<ImporterField name="fieldB" label="Field B" />
</Importer>
);
};
CustomDelimiterConfig.args = {
delimiter: '!' // use a truly unusual delimiter that PapaParse would not guess normally
};
export const InsideScrolledPage: Story<SampleImporterProps> = (
args: SampleImporterProps
) => {
return (
<div>
Scroll below
<div style={{ paddingTop: '120vh' }}></div>
<Importer {...args}>
<ImporterField name="fieldA" label="Field A" />
<ImporterField name="fieldB" label="Field B" optional />
</Importer>
</div>
);
};
export const CustomWidth: Story<SampleImporterProps> = (
args: SampleImporterProps
) => {
return (
<div style={{ width: '20rem' }}>
<Importer {...args}>
<ImporterField name="fieldA" label="Field A" />
<ImporterField name="fieldB" label="Field B" optional />
</Importer>
</div>
);
};
CustomWidth.args = {
displayColumnPageSize: 2, // fewer columns for e.g. a narrower display
displayFieldRowSize: 3 // fewer columns for e.g. a narrower display
};
export const RenderProp: Story<SampleImporterProps> = (
args: SampleImporterProps
) => {
return (
<Importer {...args}>
{({ preview }) => {
return (
<>
<ImporterField name="coreFieldA" label="Field A" />
<ImporterField name="coreFieldB" label="Field B" />
{preview &&
preview.columns.map(({ header, index }) =>
header ? (
<ImporterField
key={index}
name={`uploaded_${header}`}
label={`Field ${header}`}
/>
) : null
)}
</>
);
}}
</Importer>
);
};
const PresetSelector: React.FC<{
children: (fieldContent: React.ReactNode) => React.ReactElement;
}> = ({ children }) => {
const [selection, setSelection] = useState('Person');
return (
<div>
<div style={{ marginBottom: '1rem' }}>
<select
style={{ fontSize: '150%' }}
value={selection}
onChange={(event) => setSelection(event.target.value)}
>
<option>Person</option>
<option>Car</option>
</select>
</div>
{children(
selection === 'Person' ? (
<>
<ImporterField name="person_name" label="Preset A: Person Name" />
<ImporterField name="person_age" label="Preset A: Person Age" />
</>
) : (
<>
<ImporterField name="car_make" label="Preset B: Car Make" />
<ImporterField name="car_model" label="Preset B: Car Model" />
</>
)
)}
</div>
);
};
export const ChooseFieldPresets: Story<SampleImporterProps> = (
args: SampleImporterProps
) => {
return (
<PresetSelector>
{(fields) => <Importer {...args}>{fields}</Importer>}
</PresetSelector>
);
};