@chem-po/react-web 0.0.51 → 0.0.53
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/package.json +4 -5
- package/src/components/auth/SignIn.tsx +0 -43
- package/src/components/auth/index.ts +0 -1
- package/src/components/box/CollapseHorizontal.tsx +0 -19
- package/src/components/box/ContentBox.tsx +0 -17
- package/src/components/box/ExpandOnMount.tsx +0 -48
- package/src/components/box/Expandable.tsx +0 -96
- package/src/components/box/FullSizeContainer.tsx +0 -50
- package/src/components/box/MobileFrame/index.tsx +0 -146
- package/src/components/box/MobileFrame/styles.css +0 -35
- package/src/components/box/index.ts +0 -6
- package/src/components/button/DeleteButton.tsx +0 -178
- package/src/components/button/Toggle.tsx +0 -88
- package/src/components/button/ViewButton.tsx +0 -30
- package/src/components/button/index.ts +0 -3
- package/src/components/feed/FeedContentPane.tsx +0 -111
- package/src/components/feed/MediaFeed.tsx +0 -200
- package/src/components/feed/MediaFeedBackground.tsx +0 -127
- package/src/components/feed/MediaFeedRefresh.tsx +0 -78
- package/src/components/feed/MediaFeedSwipeUp.tsx +0 -35
- package/src/components/feed/constants.ts +0 -11
- package/src/components/feed/context.tsx +0 -19
- package/src/components/feed/hooks.ts +0 -290
- package/src/components/feed/index.ts +0 -2
- package/src/components/feed/types.ts +0 -50
- package/src/components/form/Condition.tsx +0 -26
- package/src/components/form/Field.tsx +0 -39
- package/src/components/form/Form.tsx +0 -428
- package/src/components/form/FormFooter.tsx +0 -90
- package/src/components/form/UploadProgress/index.tsx +0 -38
- package/src/components/form/UploadProgress/styles.css +0 -23
- package/src/components/form/index.ts +0 -4
- package/src/components/form/input/Editable.tsx +0 -155
- package/src/components/form/input/InputSlider.tsx +0 -76
- package/src/components/form/input/OptionalTag.tsx +0 -33
- package/src/components/form/input/StandaloneInput.tsx +0 -41
- package/src/components/form/input/boolean/index.tsx +0 -53
- package/src/components/form/input/color/index.tsx +0 -126
- package/src/components/form/input/date/index.tsx +0 -122
- package/src/components/form/input/datetime/index.tsx +0 -93
- package/src/components/form/input/file.tsx +0 -379
- package/src/components/form/input/hooks/index.ts +0 -2
- package/src/components/form/input/hooks/useInputImperativeHandle.ts +0 -16
- package/src/components/form/input/hooks/useInputStyles.ts +0 -125
- package/src/components/form/input/index.ts +0 -2
- package/src/components/form/input/input.css +0 -44
- package/src/components/form/input/input.tsx +0 -134
- package/src/components/form/input/multipleSelect/index.tsx +0 -89
- package/src/components/form/input/number/index.tsx +0 -87
- package/src/components/form/input/number/styles.css +0 -8
- package/src/components/form/input/select/index.tsx +0 -109
- package/src/components/form/input/shared/InputContainer.tsx +0 -13
- package/src/components/form/input/socialMedia/index.tsx +0 -165
- package/src/components/form/input/text/index.tsx +0 -78
- package/src/components/form/input/text/textarea.tsx +0 -43
- package/src/components/form/input/time/index.tsx +0 -33
- package/src/components/form/input/type.ts +0 -0
- package/src/components/form/input/types.ts +0 -4
- package/src/components/form/view/file.tsx +0 -36
- package/src/components/form/view/index.tsx +0 -52
- package/src/components/form/view/multipleSelect.tsx +0 -51
- package/src/components/form/view/select.tsx +0 -50
- package/src/components/form/view/types.ts +0 -11
- package/src/components/index.ts +0 -14
- package/src/components/list/Body/InfiniteScrollGridBody.tsx +0 -177
- package/src/components/list/Body/InfiniteScrollListBody.tsx +0 -114
- package/src/components/list/Body/ListBody.tsx +0 -24
- package/src/components/list/Body/PagedGridBody.tsx +0 -104
- package/src/components/list/Body/PagedListBody.tsx +0 -92
- package/src/components/list/Body/hooks.ts +0 -84
- package/src/components/list/DataList.tsx +0 -33
- package/src/components/list/ListContainer.tsx +0 -21
- package/src/components/list/ListContent.tsx +0 -54
- package/src/components/list/ListCreate.tsx +0 -57
- package/src/components/list/ListFilters.tsx +0 -182
- package/src/components/list/ListFooter.tsx +0 -458
- package/src/components/list/ListHeader.tsx +0 -180
- package/src/components/list/ListItem/ListCell.tsx +0 -49
- package/src/components/list/ListItem/ListRow.tsx +0 -44
- package/src/components/list/ListItemView.tsx +0 -53
- package/src/components/list/ListSort.tsx +0 -84
- package/src/components/list/NoItems.tsx +0 -33
- package/src/components/list/constants.ts +0 -1
- package/src/components/list/index.ts +0 -4
- package/src/components/list/types.ts +0 -26
- package/src/components/list/utils.ts +0 -63
- package/src/components/loading/CircularProgress.tsx +0 -12
- package/src/components/loading/Loading.tsx +0 -160
- package/src/components/loading/LoadingImage.tsx +0 -128
- package/src/components/loading/LoadingSwitch.tsx +0 -78
- package/src/components/loading/index.ts +0 -4
- package/src/components/media/PlayButton.tsx +0 -95
- package/src/components/media/index.ts +0 -1
- package/src/components/modal/DefaultModal.tsx +0 -18
- package/src/components/modal/DesktopModal.tsx +0 -16
- package/src/components/modal/ForceMobile.tsx +0 -7
- package/src/components/modal/MobileModal.tsx +0 -89
- package/src/components/modal/index.ts +0 -3
- package/src/components/modal/type.ts +0 -7
- package/src/components/nav/NavBar.tsx +0 -102
- package/src/components/nav/index.ts +0 -1
- package/src/components/overlay/ImageViewOverlay.tsx +0 -88
- package/src/components/overlay/MobileOverlay.tsx +0 -23
- package/src/components/overlay/index.ts +0 -2
- package/src/components/text/GradientText/index.tsx +0 -17
- package/src/components/text/GradientText/styles.css +0 -5
- package/src/components/text/NumberTicker.tsx +0 -28
- package/src/components/text/index.ts +0 -1
- package/src/components/theme/colorMode/DarkModeToggle.tsx +0 -40
- package/src/components/theme/colorMode/index.ts +0 -1
- package/src/components/theme/index.ts +0 -1
- package/src/components/view/ErrorView.tsx +0 -14
- package/src/components/view/RedirectView.tsx +0 -43
- package/src/components/view/index.ts +0 -2
- package/src/contexts/index.ts +0 -2
- package/src/contexts/theme.ts +0 -316
- package/src/contexts/view.tsx +0 -26
- package/src/custom.d.ts +0 -4
- package/src/hooks/index.ts +0 -1
- package/src/hooks/ui/index.ts +0 -1
- package/src/hooks/ui/useBorderColor.ts +0 -4
- package/src/index.ts +0 -5
- package/src/store/index.ts +0 -1
- package/src/store/usePlayer.ts +0 -75
- package/src/store/useScreen.ts +0 -22
- package/src/types/forms.ts +0 -5
- package/src/types/index.ts +0 -1
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
import { CloseIcon, DeleteIcon, DragHandleIcon, EditIcon } from '@chakra-ui/icons'
|
|
2
|
-
import {
|
|
3
|
-
Box,
|
|
4
|
-
Button,
|
|
5
|
-
Flex,
|
|
6
|
-
IconButton,
|
|
7
|
-
Stack,
|
|
8
|
-
Text,
|
|
9
|
-
useColorModeValue,
|
|
10
|
-
VStack,
|
|
11
|
-
} from '@chakra-ui/react'
|
|
12
|
-
import { isField, isListField } from '@chem-po/core'
|
|
13
|
-
import {
|
|
14
|
-
ChempoFormProvider,
|
|
15
|
-
DataViewProps,
|
|
16
|
-
DataViewProvider,
|
|
17
|
-
Field,
|
|
18
|
-
FieldFormProps,
|
|
19
|
-
FieldMap,
|
|
20
|
-
FieldMapFormProps,
|
|
21
|
-
FormOnSubmit,
|
|
22
|
-
FormProps,
|
|
23
|
-
IFormElement,
|
|
24
|
-
ListField,
|
|
25
|
-
useDataView,
|
|
26
|
-
useFormSubmit,
|
|
27
|
-
UseFormSubmitProps,
|
|
28
|
-
useGetItemField,
|
|
29
|
-
} from '@chem-po/react'
|
|
30
|
-
import { DragDropContext, Draggable, Droppable, DropResult } from '@hello-pangea/dnd'
|
|
31
|
-
import React, { FC, useMemo, useState } from 'react'
|
|
32
|
-
import { useFieldArray, UseFieldArrayMove, useFormContext } from 'react-hook-form'
|
|
33
|
-
import { useBorderColor } from '../../hooks'
|
|
34
|
-
import { Expandable } from '../box'
|
|
35
|
-
import { ExpandOnMount } from '../box/ExpandOnMount'
|
|
36
|
-
import { DeleteButton } from '../button/DeleteButton'
|
|
37
|
-
import { Condition } from './Condition'
|
|
38
|
-
import { FieldComponent } from './Field'
|
|
39
|
-
import { FormFooter } from './FormFooter'
|
|
40
|
-
import { Editable } from './input/Editable'
|
|
41
|
-
import { FieldView } from './view'
|
|
42
|
-
|
|
43
|
-
const makeOnDragEndFunction = (move: UseFieldArrayMove) => (result: DropResult) => {
|
|
44
|
-
// dropped outside the list
|
|
45
|
-
if (!result.destination) {
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
move(result.source.index, result.destination.index)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const ListFieldInput: FC<{ field: ListField; name: string }> = ({ field, name }) => {
|
|
53
|
-
const emptyData = useMemo(() => {
|
|
54
|
-
if (isField(field.itemField)) return ''
|
|
55
|
-
if (isListField(field.itemField)) return []
|
|
56
|
-
return {}
|
|
57
|
-
}, [field])
|
|
58
|
-
const draggingBg = useColorModeValue('#efefef', '#2b2b2b')
|
|
59
|
-
const borderColor = useBorderColor()
|
|
60
|
-
const { control } = useFormContext()
|
|
61
|
-
const { fields, append, remove, move } = useFieldArray({
|
|
62
|
-
control,
|
|
63
|
-
name,
|
|
64
|
-
})
|
|
65
|
-
const onDragEnd = useMemo(() => makeOnDragEndFunction(move), [move])
|
|
66
|
-
return (
|
|
67
|
-
<Flex overflow="hidden" gap={2} flexFlow="column" w="100%" px={2} py={1}>
|
|
68
|
-
<Text lineHeight={1} opacity={0.7} fontSize="sm">
|
|
69
|
-
{field.placeholder}
|
|
70
|
-
</Text>
|
|
71
|
-
<DragDropContext onDragEnd={onDragEnd}>
|
|
72
|
-
<Droppable droppableId="droppable">
|
|
73
|
-
{(droppableProvided, { draggingFromThisWith }) => (
|
|
74
|
-
<Flex
|
|
75
|
-
ref={droppableProvided.innerRef}
|
|
76
|
-
flexFlow="column"
|
|
77
|
-
w="100%"
|
|
78
|
-
py={1}
|
|
79
|
-
borderRadius={4}
|
|
80
|
-
minH="30px"
|
|
81
|
-
align="flex"
|
|
82
|
-
{...droppableProvided.droppableProps}>
|
|
83
|
-
{fields.length ? (
|
|
84
|
-
fields.map((formField, idx) => (
|
|
85
|
-
<Draggable key={formField.id} draggableId={formField.id} index={idx}>
|
|
86
|
-
{({ dragHandleProps, draggableProps, innerRef }, { isDragging }) => (
|
|
87
|
-
<Flex
|
|
88
|
-
transition="all 300ms"
|
|
89
|
-
boxShadow={`2px 2px 4px #000000${isDragging ? '55' : '00'}`}
|
|
90
|
-
borderRadius={4}
|
|
91
|
-
pt={2}
|
|
92
|
-
px={2}
|
|
93
|
-
border={`1px solid ${borderColor}`}
|
|
94
|
-
bg={`${draggingBg}${isDragging ? 'ff' : '00'}`}
|
|
95
|
-
ref={innerRef}
|
|
96
|
-
w="100%"
|
|
97
|
-
{...draggableProps}>
|
|
98
|
-
<ExpandOnMount>
|
|
99
|
-
<Flex
|
|
100
|
-
opacity={draggingFromThisWith && !isDragging ? 0.5 : 1}
|
|
101
|
-
gap={1}
|
|
102
|
-
align="center"
|
|
103
|
-
w="100%">
|
|
104
|
-
<IconButton
|
|
105
|
-
aria-label="drag"
|
|
106
|
-
size="xs"
|
|
107
|
-
opacity={0.8}
|
|
108
|
-
variant="ghost"
|
|
109
|
-
icon={<DragHandleIcon />}
|
|
110
|
-
{...dragHandleProps}
|
|
111
|
-
/>
|
|
112
|
-
<Box minW="0" flex={1}>
|
|
113
|
-
<FormElement name={formField.id} field={field.itemField} />
|
|
114
|
-
</Box>
|
|
115
|
-
<IconButton
|
|
116
|
-
aria-label="delete"
|
|
117
|
-
size="xs"
|
|
118
|
-
bg="red.600"
|
|
119
|
-
color="white"
|
|
120
|
-
icon={<DeleteIcon filter="drop-shadow(1px 1px 3px #00000088)" />}
|
|
121
|
-
onClick={e => {
|
|
122
|
-
e.stopPropagation()
|
|
123
|
-
remove(idx)
|
|
124
|
-
}}
|
|
125
|
-
/>
|
|
126
|
-
</Flex>
|
|
127
|
-
</ExpandOnMount>
|
|
128
|
-
</Flex>
|
|
129
|
-
)}
|
|
130
|
-
</Draggable>
|
|
131
|
-
))
|
|
132
|
-
) : (
|
|
133
|
-
<Text fontSize="sm" opacity={0.7} py={1} px={2}>
|
|
134
|
-
No items
|
|
135
|
-
</Text>
|
|
136
|
-
)}
|
|
137
|
-
{droppableProvided.placeholder}
|
|
138
|
-
</Flex>
|
|
139
|
-
)}
|
|
140
|
-
</Droppable>
|
|
141
|
-
</DragDropContext>
|
|
142
|
-
<Flex>
|
|
143
|
-
<Button mr="auto" width="auto" size="xs" onClick={() => append(emptyData)}>
|
|
144
|
-
+ NEW
|
|
145
|
-
</Button>
|
|
146
|
-
</Flex>
|
|
147
|
-
</Flex>
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export const FormElement = ({
|
|
152
|
-
field,
|
|
153
|
-
name,
|
|
154
|
-
// validate,
|
|
155
|
-
}: {
|
|
156
|
-
field: IFormElement
|
|
157
|
-
name: string
|
|
158
|
-
// validate?: boolean
|
|
159
|
-
}) => {
|
|
160
|
-
const fields = useMemo<Array<{ name: string; field: IFormElement }>>(() => {
|
|
161
|
-
if (isField(field) || isListField(field)) return [{ name: 'value', field }]
|
|
162
|
-
|
|
163
|
-
return Object.entries((field as FieldMap).children).map(([childName, childField]) => ({
|
|
164
|
-
name: `${name ? `${name}.` : ''}${childName}`,
|
|
165
|
-
field: childField,
|
|
166
|
-
}))
|
|
167
|
-
}, [field, name])
|
|
168
|
-
return (
|
|
169
|
-
<VStack spacing={1} w="100%">
|
|
170
|
-
{fields.map(f => {
|
|
171
|
-
if (isListField(f.field)) {
|
|
172
|
-
const b = <ListFieldInput key={f.name} name={f.name} field={f.field} />
|
|
173
|
-
return f.field.condition ? (
|
|
174
|
-
<Condition path={name} condition={f.field.condition} key={f.name}>
|
|
175
|
-
{b}
|
|
176
|
-
</Condition>
|
|
177
|
-
) : (
|
|
178
|
-
b
|
|
179
|
-
)
|
|
180
|
-
}
|
|
181
|
-
if (isField(f.field)) {
|
|
182
|
-
const b = <FieldComponent key={f.name} name={f.name} field={f.field} />
|
|
183
|
-
return f.field.condition ? (
|
|
184
|
-
<Condition path={name} condition={f.field.condition} key={f.name}>
|
|
185
|
-
{b}
|
|
186
|
-
</Condition>
|
|
187
|
-
) : (
|
|
188
|
-
b
|
|
189
|
-
)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const b = <FormElement key={f.name} name={f.name} field={f.field} />
|
|
193
|
-
return f.field.condition ? (
|
|
194
|
-
<Condition path={name} condition={f.field.condition} key={f.name}>
|
|
195
|
-
{b}
|
|
196
|
-
</Condition>
|
|
197
|
-
) : (
|
|
198
|
-
b
|
|
199
|
-
)
|
|
200
|
-
})}
|
|
201
|
-
</VStack>
|
|
202
|
-
)
|
|
203
|
-
}
|
|
204
|
-
const ListFieldView = ({
|
|
205
|
-
field,
|
|
206
|
-
value,
|
|
207
|
-
path,
|
|
208
|
-
}: {
|
|
209
|
-
field: ListField
|
|
210
|
-
value: any[]
|
|
211
|
-
path: string
|
|
212
|
-
}) => {
|
|
213
|
-
const { placeholder } = field
|
|
214
|
-
const borderColor = useBorderColor()
|
|
215
|
-
const getItemField = useGetItemField(field)
|
|
216
|
-
return (
|
|
217
|
-
<Box w="100%" p={1}>
|
|
218
|
-
<Expandable
|
|
219
|
-
border={`1px solid ${borderColor}`}
|
|
220
|
-
borderRadius={4}
|
|
221
|
-
initExpanded
|
|
222
|
-
header={() => <Text py={1}>{placeholder}</Text>}>
|
|
223
|
-
<Flex flexFlow="column" bg="background.200" gap={2} px={2} py={1}>
|
|
224
|
-
{value?.length ? (
|
|
225
|
-
value.map((item, index) => (
|
|
226
|
-
<Box
|
|
227
|
-
bg="background.100"
|
|
228
|
-
key={`${path}.${index}`}
|
|
229
|
-
border={`1px solid ${borderColor}`}
|
|
230
|
-
borderRadius={3}>
|
|
231
|
-
<FormElementView
|
|
232
|
-
path={`${path}.${index}`}
|
|
233
|
-
field={getItemField(index)}
|
|
234
|
-
value={item}
|
|
235
|
-
/>
|
|
236
|
-
</Box>
|
|
237
|
-
))
|
|
238
|
-
) : (
|
|
239
|
-
<Text fontSize="sm" opacity={0.7} py={1} px={2}>
|
|
240
|
-
No items
|
|
241
|
-
</Text>
|
|
242
|
-
)}
|
|
243
|
-
</Flex>
|
|
244
|
-
</Expandable>
|
|
245
|
-
</Box>
|
|
246
|
-
)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const FormElementView = ({
|
|
250
|
-
field,
|
|
251
|
-
value,
|
|
252
|
-
path,
|
|
253
|
-
storagePath,
|
|
254
|
-
}: {
|
|
255
|
-
field: IFormElement
|
|
256
|
-
value: any
|
|
257
|
-
path: string
|
|
258
|
-
storagePath?: string
|
|
259
|
-
}) => {
|
|
260
|
-
const { updateField } = useDataView()
|
|
261
|
-
if (isField(field)) {
|
|
262
|
-
return updateField ? (
|
|
263
|
-
<Editable
|
|
264
|
-
storagePath={storagePath}
|
|
265
|
-
field={field}
|
|
266
|
-
value={value}
|
|
267
|
-
onSubmit={v => updateField(path, v)}
|
|
268
|
-
/>
|
|
269
|
-
) : (
|
|
270
|
-
<FieldView field={field} value={value} />
|
|
271
|
-
)
|
|
272
|
-
}
|
|
273
|
-
if (isListField(field)) {
|
|
274
|
-
return <ListFieldView path={path} field={field} value={value} />
|
|
275
|
-
}
|
|
276
|
-
return (
|
|
277
|
-
<DataView
|
|
278
|
-
storagePath={storagePath ? `${storagePath}.${path}` : undefined}
|
|
279
|
-
path={path}
|
|
280
|
-
field={field}
|
|
281
|
-
/>
|
|
282
|
-
)
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export const DataView = ({
|
|
286
|
-
field,
|
|
287
|
-
value,
|
|
288
|
-
onClose,
|
|
289
|
-
onDelete,
|
|
290
|
-
onSubmit,
|
|
291
|
-
itemName,
|
|
292
|
-
storagePath,
|
|
293
|
-
path = '',
|
|
294
|
-
}: DataViewProps & { path?: string }) => {
|
|
295
|
-
const { name: fieldName, children } = field
|
|
296
|
-
const [isEditing, setIsEditing] = useState(false)
|
|
297
|
-
return (
|
|
298
|
-
<DataViewProvider value={value} onSubmit={onSubmit}>
|
|
299
|
-
<Expandable
|
|
300
|
-
alwaysExpanded
|
|
301
|
-
header={() => (
|
|
302
|
-
<Flex align="center" px={2} w="100%">
|
|
303
|
-
<Text py={2} fontSize="lg" fontFamily="fonts.heading">
|
|
304
|
-
{fieldName}
|
|
305
|
-
</Text>
|
|
306
|
-
<Flex gap={2} align="center" ml="auto">
|
|
307
|
-
{onDelete ? <DeleteButton onDelete={onDelete} itemName={itemName ?? 'item'} /> : null}
|
|
308
|
-
{onSubmit ? (
|
|
309
|
-
<IconButton
|
|
310
|
-
size="sm"
|
|
311
|
-
borderRadius="full"
|
|
312
|
-
minW={0}
|
|
313
|
-
w={7}
|
|
314
|
-
h={7}
|
|
315
|
-
ml="auto"
|
|
316
|
-
aria-label="edit"
|
|
317
|
-
icon={<EditIcon />}
|
|
318
|
-
onClick={() => setIsEditing(true)}
|
|
319
|
-
/>
|
|
320
|
-
) : null}
|
|
321
|
-
{onClose ? (
|
|
322
|
-
<IconButton
|
|
323
|
-
size="sm"
|
|
324
|
-
borderRadius="full"
|
|
325
|
-
minW={0}
|
|
326
|
-
w={7}
|
|
327
|
-
h={7}
|
|
328
|
-
variant="ghost"
|
|
329
|
-
aria-label="close"
|
|
330
|
-
icon={<CloseIcon opacity={0.8} w={3} h={3} />}
|
|
331
|
-
onClick={onClose}
|
|
332
|
-
/>
|
|
333
|
-
) : null}
|
|
334
|
-
</Flex>
|
|
335
|
-
</Flex>
|
|
336
|
-
)}>
|
|
337
|
-
{isEditing && onSubmit ? (
|
|
338
|
-
<Form
|
|
339
|
-
storagePath={storagePath}
|
|
340
|
-
field={field}
|
|
341
|
-
value={value}
|
|
342
|
-
onSubmit={onSubmit}
|
|
343
|
-
onBack={() => setIsEditing(false)}
|
|
344
|
-
/>
|
|
345
|
-
) : (
|
|
346
|
-
<Flex flexFlow="column" px={4} py={2}>
|
|
347
|
-
{Object.entries(children).map(([key, childField]) => (
|
|
348
|
-
<FormElementView
|
|
349
|
-
storagePath={storagePath ? `${storagePath}/${key}` : undefined}
|
|
350
|
-
path={path ? `${path}.${key}` : key}
|
|
351
|
-
key={key}
|
|
352
|
-
field={childField}
|
|
353
|
-
value={value?.[key]}
|
|
354
|
-
/>
|
|
355
|
-
))}
|
|
356
|
-
</Flex>
|
|
357
|
-
)}
|
|
358
|
-
</Expandable>
|
|
359
|
-
</DataViewProvider>
|
|
360
|
-
)
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export const FieldMapForm = <F extends FieldMap>({
|
|
364
|
-
onSubmit: submit,
|
|
365
|
-
onBack,
|
|
366
|
-
field,
|
|
367
|
-
value,
|
|
368
|
-
buttonText = 'SUBMIT',
|
|
369
|
-
renderFooter,
|
|
370
|
-
storagePath,
|
|
371
|
-
}: FieldMapFormProps<F>) => {
|
|
372
|
-
const submitDataProps = useMemo<UseFormSubmitProps<F>>(
|
|
373
|
-
() => ({
|
|
374
|
-
field,
|
|
375
|
-
value,
|
|
376
|
-
submit,
|
|
377
|
-
storagePath,
|
|
378
|
-
}),
|
|
379
|
-
[field, value, submit, storagePath],
|
|
380
|
-
)
|
|
381
|
-
|
|
382
|
-
const { onSubmit, uploads } = useFormSubmit(submitDataProps)
|
|
383
|
-
|
|
384
|
-
return (
|
|
385
|
-
<Stack w="100%" spacing={3}>
|
|
386
|
-
<form>
|
|
387
|
-
<Box pt={1} px={2} w="100%">
|
|
388
|
-
<FormElement name="" field={field} />
|
|
389
|
-
</Box>
|
|
390
|
-
<FormFooter
|
|
391
|
-
uploads={uploads}
|
|
392
|
-
onSubmit={onSubmit}
|
|
393
|
-
renderFooter={renderFooter}
|
|
394
|
-
onBack={onBack}
|
|
395
|
-
buttonText={buttonText}
|
|
396
|
-
/>
|
|
397
|
-
</form>
|
|
398
|
-
</Stack>
|
|
399
|
-
)
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export const FieldForm = <F extends Field | ListField>({
|
|
403
|
-
onSubmit,
|
|
404
|
-
field,
|
|
405
|
-
value,
|
|
406
|
-
...props
|
|
407
|
-
}: FieldFormProps<F>) => {
|
|
408
|
-
const fieldMap = useMemo<FieldMap>(() => ({ children: { value: field } }), [field])
|
|
409
|
-
return (
|
|
410
|
-
<FieldMapForm
|
|
411
|
-
field={fieldMap}
|
|
412
|
-
value={{ value }}
|
|
413
|
-
onSubmit={data => onSubmit(data?.value)}
|
|
414
|
-
{...props}
|
|
415
|
-
/>
|
|
416
|
-
)
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
export const Form = <F extends IFormElement>({ field, onSubmit, ...props }: FormProps<F>) => {
|
|
420
|
-
const body =
|
|
421
|
-
isField(field) || isListField(field) ? (
|
|
422
|
-
<FieldForm field={field} onSubmit={onSubmit as FormOnSubmit<Field | ListField>} {...props} />
|
|
423
|
-
) : (
|
|
424
|
-
<FieldMapForm field={field} onSubmit={onSubmit as FormOnSubmit<FieldMap>} {...props} />
|
|
425
|
-
)
|
|
426
|
-
|
|
427
|
-
return <ChempoFormProvider>{body}</ChempoFormProvider>
|
|
428
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { Button, ButtonProps, Collapse, Flex, HStack, Progress, Text } from '@chakra-ui/react'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { FC, PropsWithChildren } from 'react'
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
FormProps,
|
|
8
|
-
IFormElement,
|
|
9
|
-
useBorderColor,
|
|
10
|
-
useChempoForm,
|
|
11
|
-
UseFormSubmit,
|
|
12
|
-
} from '@chem-po/react'
|
|
13
|
-
import { useFormState } from 'react-hook-form'
|
|
14
|
-
import { UploadProgress } from './UploadProgress'
|
|
15
|
-
|
|
16
|
-
const CancelButton = ({ onBack, children }: PropsWithChildren<{ onBack: () => void }>) => (
|
|
17
|
-
<Button
|
|
18
|
-
flex={1}
|
|
19
|
-
transition="all 500ms"
|
|
20
|
-
onClick={onBack}
|
|
21
|
-
variant="outline"
|
|
22
|
-
border="1px solid #cdcdcd"
|
|
23
|
-
color="#777"
|
|
24
|
-
ml="auto">
|
|
25
|
-
{children}
|
|
26
|
-
</Button>
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
export const SubmitButton: FC<
|
|
30
|
-
{ onSubmitClick: () => Promise<void>; submitting: boolean } & ButtonProps
|
|
31
|
-
> = ({ onSubmitClick, submitting, children, filter, opacity }) => (
|
|
32
|
-
<Button
|
|
33
|
-
isLoading={submitting}
|
|
34
|
-
filter={filter}
|
|
35
|
-
flex={1}
|
|
36
|
-
transition="all 500ms"
|
|
37
|
-
opacity={opacity}
|
|
38
|
-
onClick={() => {
|
|
39
|
-
onSubmitClick()
|
|
40
|
-
}}
|
|
41
|
-
ml="auto"
|
|
42
|
-
variant="solid">
|
|
43
|
-
{children}
|
|
44
|
-
</Button>
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
const FormErrorView = () => {
|
|
48
|
-
const { formError } = useChempoForm()
|
|
49
|
-
return (
|
|
50
|
-
<Collapse in={!!formError}>
|
|
51
|
-
<Text color="red">{formError ?? ''}</Text>
|
|
52
|
-
</Collapse>
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const FormFooter = <F extends IFormElement>({
|
|
57
|
-
renderFooter: RenderFooter,
|
|
58
|
-
...props
|
|
59
|
-
}: Pick<FormProps<F>, 'renderFooter' | 'onBack' | 'buttonText'> &
|
|
60
|
-
Pick<UseFormSubmit, 'uploads'> & {
|
|
61
|
-
onSubmit: () => Promise<void>
|
|
62
|
-
}) => {
|
|
63
|
-
const { uploads, onBack, buttonText, onSubmit } = props
|
|
64
|
-
const { isSubmitting: submitting, isValid: valid } = useFormState()
|
|
65
|
-
const borderColor = useBorderColor()
|
|
66
|
-
return (
|
|
67
|
-
<Flex w="100%" flexFlow="column">
|
|
68
|
-
<Collapse endingHeight={5} style={{ width: '100%' }} in={submitting}>
|
|
69
|
-
<Progress w="100%" h="5px" isIndeterminate />
|
|
70
|
-
</Collapse>
|
|
71
|
-
<UploadProgress uploads={uploads} />
|
|
72
|
-
<FormErrorView />
|
|
73
|
-
{RenderFooter ? (
|
|
74
|
-
<RenderFooter {...props} />
|
|
75
|
-
) : (
|
|
76
|
-
<HStack py={2} borderTop="1px solid" borderColor={borderColor} px={3} w="100%">
|
|
77
|
-
{onBack ? <CancelButton onBack={onBack}>Cancel</CancelButton> : null}
|
|
78
|
-
<SubmitButton
|
|
79
|
-
size="sm"
|
|
80
|
-
filter={`grayscale(${!valid ? 100 : 0}%)`}
|
|
81
|
-
opacity={!valid ? 0.5 : 1}
|
|
82
|
-
onSubmitClick={onSubmit}
|
|
83
|
-
submitting={submitting}>
|
|
84
|
-
{buttonText}
|
|
85
|
-
</SubmitButton>
|
|
86
|
-
</HStack>
|
|
87
|
-
)}
|
|
88
|
-
</Flex>
|
|
89
|
-
)
|
|
90
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Center, Flex, Progress, Text } from '@chakra-ui/react'
|
|
2
|
-
import { UploadsState } from '@chem-po/core'
|
|
3
|
-
import React, { useMemo } from 'react'
|
|
4
|
-
import { TransitionGroup } from 'react-transition-group'
|
|
5
|
-
import { ExpandOnMount } from '../../box'
|
|
6
|
-
import './styles.css'
|
|
7
|
-
|
|
8
|
-
export const UploadProgress = ({ uploads }: { uploads: UploadsState }) => {
|
|
9
|
-
const asArr = useMemo(() => Object.values(uploads), [uploads])
|
|
10
|
-
return (
|
|
11
|
-
<TransitionGroup component={Flex} width="100%" flexFlow="column">
|
|
12
|
-
{asArr.map(upload => (
|
|
13
|
-
<ExpandOnMount key={upload.label}>
|
|
14
|
-
<Center px={2} height="26px" position="relative" w="100%" flexDirection="column">
|
|
15
|
-
<Progress
|
|
16
|
-
borderRadius="full"
|
|
17
|
-
value={upload.percent * 100}
|
|
18
|
-
mx={2}
|
|
19
|
-
my={1}
|
|
20
|
-
size="md"
|
|
21
|
-
height="100%"
|
|
22
|
-
width="100%"
|
|
23
|
-
/>
|
|
24
|
-
<Text
|
|
25
|
-
fontFamily="fonts.heading"
|
|
26
|
-
textShadow="1px 1px 3px #000000aa"
|
|
27
|
-
color="white"
|
|
28
|
-
position="absolute"
|
|
29
|
-
fontSize="sm"
|
|
30
|
-
fontWeight={500}>
|
|
31
|
-
{upload.label.toUpperCase()}
|
|
32
|
-
</Text>
|
|
33
|
-
</Center>
|
|
34
|
-
</ExpandOnMount>
|
|
35
|
-
))}
|
|
36
|
-
</TransitionGroup>
|
|
37
|
-
)
|
|
38
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
.upload-enter {
|
|
2
|
-
opacity: 0;
|
|
3
|
-
height: 0;
|
|
4
|
-
overflow: hidden;
|
|
5
|
-
}
|
|
6
|
-
.upload-enter-active {
|
|
7
|
-
opacity: 1;
|
|
8
|
-
height: 26px;
|
|
9
|
-
overflow: hidden;
|
|
10
|
-
transition: opacity 300ms, height 300ms;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.upload-exit {
|
|
14
|
-
opacity: 1;
|
|
15
|
-
height: 26px;
|
|
16
|
-
overflow: hidden;
|
|
17
|
-
}
|
|
18
|
-
.upload-exit-active {
|
|
19
|
-
opacity: 0;
|
|
20
|
-
height: 0;
|
|
21
|
-
overflow: hidden;
|
|
22
|
-
transition: opacity 300ms, height 300ms;
|
|
23
|
-
}
|