-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.tsx
270 lines (249 loc) · 9.35 KB
/
demo.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import { createRoot } from 'react-dom/client'
import styled from '@emotion/styled'
import * as React from 'react'
import {
Row,
Col,
Box,
Alert,
Button,
DateTimeField,
DropdownMenu,
EditingForm,
FormSubmitHandler,
Icon,
InputField,
Message,
Modal,
Section,
SelectField,
SelectOnChangeHandler,
Toast,
useDeviceSize,
useFormState,
whenDomReady,
Yup,
} from './src/all.js'
import './test/setup-select.js'
import 'bootstrap/dist/css/bootstrap.css'
import 'flatpickr/dist/flatpickr.css'
interface FormData {
[key: string]: string | boolean | Date | { name: string }[]
}
const StyledCheckbox = styled(InputField)({
border: 0,
'.form-check-input, &.form-check-input': {
height: 16,
width: 16,
'&:checked': {
backgroundColor: 'gray',
borderColor: 'red',
},
},
})
export default function Demo() {
const [isExpanded, setExpanded] = React.useState(false)
const [defaultValue, setDefaultValue] = React.useState({
name: 'test',
nested: [{ name: 'b' }],
cbv: true,
bc: 'a',
rbv: 'c',
simpleDate: new Date(),
from: new Date('2022-10-21'),
to: new Date('2022-11-02'),
} satisfies FormData)
const displaySize = useDeviceSize()
const onSubmit: FormSubmitHandler<FormData> = async (values, fc) => {
console.log(values) // eslint-disable-line no-console
await new Promise((r) => setTimeout(r, 2000))
setDefaultValue({...defaultValue, name: values.name + `-${fc.formState.submitCount}` })
//throw 'uh oh'
//fc.setFormError(new Error('a save error occured'))
}
const logSelectChange: SelectOnChangeHandler = (v) => {
console.log(v)
}
return (
<div className="container mt-5">
<Message
message="hello"
hint="This is a test of the MessageBox"
prefixIcon={<Icon icon="clock" />}
/>
<Alert height="33px" danger onDismiss={() => {}} message="this is test" />
<h6>Display size = {displaySize}</h6>
<Box gap="large">
<Button
icon="clock"
tooltip="Click to show a Toast Message"
onClick={() =>
Toast.show({
title: 'cool title!',
message: 'hello',
autohide: false,
placement: 'topRight',
})
}
>
Show Toast
</Button>
<Button
onClick={() =>
Toast.show({
message: (
<>
hello it is <b>time</b>
</>
),
autohide: false,
})
}
>
<Icon icon="clock" />
Show Toast without title
</Button>
</Box>
<h6 className="mt-4">Form test</h6>
<EditingForm
name="Demo Form"
className="row"
defaultValues={defaultValue}
validationSchema={Yup.object().shape({
name: Yup.string().required(),
simpleDate: Yup.date().required(),
from: Yup.date().required(),
})}
validateOnMount
onSubmit={onSubmit}
>
<InputField sm={10} data-testid="name" name="name" label="Name" />
<StyledCheckbox
sm={2}
type="checkbox"
data-testid="cbv"
name="cbv"
label="CheckBox field"
/>
<Box>
<StyledCheckbox
sm={2}
type="checkbox"
id="custom-checkbox"
data-testid="cbv2"
name="cbv2"
/>
<label htmlFor="custom-checkbox">Custom and cool!</label>
</Box>
<Col size={12}>
<Row>
<InputField sm={3} type="radio" name="rbv" value="a" label="A" order={{ md: 4 }} />
<InputField sm={3} type="radio" name="rbv" value="b" label="B" order={{ md: 3 }} />
<InputField sm={3} type="radio" name="rbv" value="c" label="C" order={{ md: 2 }} />
<InputField sm={3} type="radio" name="rbv" value="d" label="D" order={{ md: 1 }} />
</Row>
</Col>
<SelectField
size={3}
onChange={logSelectChange}
placeholder="Select an option..."
label="Options"
options={[
{ label: 'A', value: 'a' },
{ label: 'B', value: 'b' },
{ label: 'C', value: 'c' },
]}
name="nested[0].name"
/>
<SelectField
placeholder="Select without a label"
isMulti wrapDisplayedLabels
options={[
{ label: 'A long choice', value: 'a' },
{ label: 'B a longer choice that is not selected', value: 'b' },
{ label: 'C an even longer choice than the previous one', value: 'c' },
{ label: 'D A long choice', value: 'd' },
{ label: 'E a longer choice that is not selected', value: 'e' },
{ label: 'F an even longer choice than the previous one', value: 'f' },
{ label: 'G A long choice', value: 'g' },
{ label: 'H a longer choice that is not selected', value: 'h' },
{ label: 'I an even longer choice than the previous one', value: 'i' },
]}
name="bc"
/>
<DateTimeField name="simpleDate" label="Simple Date" />
<DateTimeField name="dates" rangeNames={['from', 'to']} label="Date Range" />
<FormValidDisplay />
</EditingForm>
<h6 className="mt-4">Dropdown test</h6>
<div className="row">
<DropdownMenu alignEnd label="Pick Option" activeIndex={1}>
<div className="dropdown-item">one</div>
<div className="dropdown-item">two</div>
<hr className="dropdown-divider" />
<div className="dropdown-item">three</div>
</DropdownMenu>
</div>
<h6 className="mt-4">Section test</h6>
<Box direction="column" style={{ minHeight: '300px' }}>
<h4>hi</h4>
<Section
id="section-test"
onToggle={() => setExpanded(!isExpanded)}
isExpanded={isExpanded}
className="mb-4"
heading="This is a section"
footer={<Box justify="end">This is footer</Box>}
>
<div style={{ border: '1px solid blue', margin: 20 }}>
<h5>Hello World</h5>
<button
onClick={(ev) => {
ev.currentTarget.parentElement!.style!.height = '200px'
}}
>
make bigger
</button>
</div>
</Section>
</Box>
<ModalExamples />
</div>
)
}
const ModalExamples = () => {
const [show1, setShow1] = React.useState<boolean>(false)
const [show2, setShow2] = React.useState<boolean>(false)
const [show3, setShow3] = React.useState<boolean>(false)
return (
<Box direction="column" width="20%" gap="large">
<h3>Modal Example</h3>
<Button onClick={() => setShow1(true)}>With close btn and no header</Button>
<Modal center show={show1} onHide={() => setShow1(false)}>
<Modal.Body>test</Modal.Body>
</Modal>
<Button onClick={() => setShow2(true)}>No close button</Button>
<Modal center show={show2} closeBtn={false} onHide={() => setShow2(false)}>
<Modal.Body>test</Modal.Body>
</Modal>
<Button onClick={() => setShow3(true)}>With header</Button>
<Modal center show={show3} onHide={() => setShow3(false)}>
<Modal.Header>A Header</Modal.Header>
<Modal.Body>Body Text</Modal.Body>
</Modal>
</Box>
)
}
const FormValidDisplay: React.FC = () => {
const { isValid } = useFormState()
return <h3> {isValid ? 'Valid' : 'Invalid'} </h3>
}
whenDomReady(() => {
const el = document.getElementById('app')
const root = createRoot(el!)
root.render(
<React.StrictMode>
<Demo />
</React.StrictMode>
)
})