@codeleap/web 3.25.0 → 3.25.2
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 +1 -2
- package/src/components/ActionIcon/index.tsx +52 -51
- package/src/components/ActionIcon/styles.ts +5 -1
- package/src/components/ActivityIndicator/index.tsx +55 -34
- package/src/components/ActivityIndicator/styles.ts +6 -0
- package/src/components/Badge/index.tsx +80 -43
- package/src/components/Badge/styles.ts +11 -1
- package/src/components/Button/index.tsx +89 -46
- package/src/components/Button/styles.ts +5 -0
- package/src/components/Checkbox/index.tsx +97 -83
- package/src/components/Checkbox/styles.ts +5 -1
- package/src/components/Collapse/index.tsx +83 -41
- package/src/components/Collapse/styles.ts +6 -3
- package/src/components/ColorPicker/index.tsx +48 -95
- package/src/components/ColorPicker/styles.ts +11 -11
- package/src/components/ColorPicker/types.ts +12 -26
- package/src/components/CropPicker/index.tsx +104 -100
- package/src/components/CropPicker/styles.ts +7 -0
- package/src/components/CropPicker/types.ts +17 -8
- package/src/{lib/hooks/useCropPicker.ts → components/CropPicker/useCropPicker.tsx} +15 -68
- package/src/components/CropPicker/utils.ts +51 -0
- package/src/components/DatePicker/{components → defaultComponents}/Header.tsx +17 -9
- package/src/components/DatePicker/{components → defaultComponents}/OuterInput.tsx +7 -6
- package/src/components/DatePicker/index.tsx +124 -110
- package/src/components/DatePicker/styles.ts +12 -1
- package/src/components/DatePicker/types.ts +33 -16
- package/src/components/Drawer/index.tsx +125 -133
- package/src/components/Drawer/styles.ts +5 -0
- package/src/components/Dropzone/index.tsx +63 -87
- package/src/components/Dropzone/styles.ts +6 -0
- package/src/components/Dropzone/types.ts +37 -29
- package/src/components/EmptyPlaceholder/index.tsx +83 -63
- package/src/components/EmptyPlaceholder/styles.ts +5 -0
- package/src/components/FileInput.tsx +91 -0
- package/src/components/Grid/index.tsx +41 -40
- package/src/components/Grid/styles.ts +9 -2
- package/src/components/Grid/types.ts +12 -10
- package/src/components/Icon/index.tsx +47 -45
- package/src/components/Icon/styles.ts +8 -0
- package/src/components/InputBase/index.tsx +42 -71
- package/src/components/InputBase/styles.ts +47 -37
- package/src/components/InputBase/types.ts +7 -19
- package/src/components/InputBase/utils.ts +23 -3
- package/src/components/List/ListLayout.tsx +37 -20
- package/src/components/List/PaginationIndicator.tsx +102 -0
- package/src/components/List/index.tsx +41 -36
- package/src/components/List/styles.ts +11 -5
- package/src/components/List/types.ts +20 -30
- package/src/components/List/useInfiniteScroll.ts +159 -0
- package/src/components/LoadingOverlay/index.tsx +33 -31
- package/src/components/LoadingOverlay/styles.ts +8 -3
- package/src/components/Modal/index.tsx +160 -98
- package/src/components/Modal/styles.ts +5 -0
- package/src/components/NumberIncrement/index.tsx +98 -67
- package/src/components/NumberIncrement/styles.ts +5 -0
- package/src/components/Overlay/index.tsx +35 -37
- package/src/components/Overlay/styles.ts +5 -3
- package/src/components/Pager/index.tsx +81 -65
- package/src/components/Pager/styles.ts +9 -3
- package/src/components/Progress/Bar/index.tsx +50 -45
- package/src/components/Progress/Bar/styles.tsx +7 -0
- package/src/components/Progress/Bar/types.tsx +30 -0
- package/src/components/Progress/Circle/index.tsx +48 -45
- package/src/components/Progress/Circle/styles.ts +8 -1
- package/src/components/Progress/Circle/types.ts +22 -10
- package/src/components/RadioInput/index.tsx +124 -78
- package/src/components/RadioInput/styles.ts +6 -0
- package/src/components/Scroll/index.tsx +32 -0
- package/src/components/Scroll/styles.ts +8 -0
- package/src/components/SearchInput/index.tsx +10 -10
- package/src/components/SectionFilters/index.tsx +36 -47
- package/src/components/SectionFilters/styles.ts +5 -1
- package/src/components/SectionFilters/types.ts +13 -14
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +84 -0
- package/src/components/SegmentedControl/index.tsx +89 -111
- package/src/components/SegmentedControl/styles.ts +21 -7
- package/src/components/Select/index.tsx +58 -92
- package/src/components/Select/styles.ts +36 -19
- package/src/components/Select/types.ts +13 -17
- package/src/components/Slider/index.tsx +93 -85
- package/src/components/Slider/styles.ts +6 -13
- package/src/components/Switch/index.tsx +74 -63
- package/src/components/Switch/styles.ts +6 -1
- package/src/components/Tag/index.tsx +44 -39
- package/src/components/Tag/styles.ts +9 -1
- package/src/components/Tag/types.ts +10 -10
- package/src/components/Text/index.tsx +48 -37
- package/src/components/Text/styles.ts +8 -0
- package/src/components/Text/types.ts +8 -8
- package/src/components/TextEditor/index.tsx +28 -49
- package/src/components/TextEditor/styles.ts +8 -1
- package/src/components/TextEditor/types.ts +6 -11
- package/src/components/TextInput/index.tsx +96 -58
- package/src/components/TextInput/mask.tsx +50 -2
- package/src/components/TextInput/styles.ts +8 -3
- package/src/components/Tooltip/index.tsx +84 -61
- package/src/components/Tooltip/styles.ts +10 -3
- package/src/components/Touchable/index.tsx +86 -43
- package/src/components/Touchable/styles.ts +6 -0
- package/src/components/View/index.tsx +50 -36
- package/src/components/View/styles.ts +6 -0
- package/src/components/View/types.ts +15 -14
- package/src/components/components.ts +3 -2
- package/src/components/defaultStyles.ts +79 -0
- package/src/index.ts +0 -1
- package/src/lib/hooks/index.ts +0 -5
- package/src/lib/hooks/useBreakpointMatch.ts +7 -8
- package/src/lib/hooks/useMediaQuery.ts +3 -4
- package/src/lib/hooks/usePagination.ts +63 -79
- package/src/lib/index.ts +0 -1
- package/src/lib/utils/index.ts +0 -1
- package/src/lib/utils/test.ts +2 -2
- package/src/components/ActionIcon/types.ts +0 -15
- package/src/components/ActivityIndicator/types.ts +0 -12
- package/src/components/Badge/types.ts +0 -28
- package/src/components/Button/types.ts +0 -25
- package/src/components/Checkbox/types.ts +0 -15
- package/src/components/Collapse/types.ts +0 -11
- package/src/components/Drawer/types.ts +0 -23
- package/src/components/EmptyPlaceholder/types.ts +0 -32
- package/src/components/FileInput/index.tsx +0 -72
- package/src/components/FileInput/types.ts +0 -14
- package/src/components/Icon/types.ts +0 -15
- package/src/components/LoadingOverlay/types.ts +0 -16
- package/src/components/Modal/types.ts +0 -55
- package/src/components/NumberIncrement/types.ts +0 -29
- package/src/components/Overlay/types.ts +0 -13
- package/src/components/Pager/types.ts +0 -35
- package/src/components/PaginationButtons/index.tsx +0 -173
- package/src/components/PaginationButtons/styles.ts +0 -7
- package/src/components/PaginationButtons/types.ts +0 -26
- package/src/components/PaginationIndicator/index.tsx +0 -69
- package/src/components/PaginationIndicator/styles.ts +0 -3
- package/src/components/PaginationIndicator/types.ts +0 -18
- package/src/components/Progress/Bar/styles.ts +0 -10
- package/src/components/Progress/Bar/types.ts +0 -26
- package/src/components/RadioInput/types.ts +0 -29
- package/src/components/SegmentedControl/types.ts +0 -44
- package/src/components/Slider/types.ts +0 -29
- package/src/components/Switch/types.ts +0 -13
- package/src/components/TextInput/types.ts +0 -85
- package/src/components/Tooltip/types.ts +0 -46
- package/src/components/Touchable/types.ts +0 -22
- package/src/lib/WebStyleRegistry.ts +0 -51
- package/src/lib/hooks/useFileInput.ts +0 -15
- package/src/lib/hooks/useInfiniteScroll.ts +0 -77
- package/src/lib/hooks/useRefresh.ts +0 -87
- package/src/lib/hooks/useStylesFor.ts +0 -13
- package/src/lib/utils/cache.ts +0 -9
- /package/src/components/DatePicker/{components → defaultComponents}/index.tsx +0 -0
|
@@ -1,31 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx, CSSObject } from '@emotion/react'
|
|
3
|
+
import {
|
|
4
|
+
AnyFunction,
|
|
5
|
+
ComponentVariants,
|
|
6
|
+
IconPlaceholder,
|
|
7
|
+
TypeGuards,
|
|
8
|
+
onMount,
|
|
9
|
+
onUpdate,
|
|
10
|
+
useDefaultComponentStyle,
|
|
11
|
+
useNestedStylesByKey,
|
|
12
|
+
StylesOf,
|
|
13
|
+
PropsOf,
|
|
14
|
+
useIsomorphicEffect,
|
|
15
|
+
} from '@codeleap/common'
|
|
16
|
+
|
|
2
17
|
import React, { useId, useRef } from 'react'
|
|
3
18
|
import ReactDOM from 'react-dom'
|
|
4
19
|
import { v4 } from 'uuid'
|
|
5
20
|
import { View } from '../View'
|
|
6
21
|
import { Text } from '../Text'
|
|
7
|
-
import { Overlay } from '../Overlay'
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
22
|
+
import { Overlay, OverlayProps } from '../Overlay'
|
|
23
|
+
import { ModalComposition, ModalPresets } from './styles'
|
|
24
|
+
import { ActionIcon, ActionIconProps } from '../ActionIcon'
|
|
25
|
+
import { Scroll } from '../Scroll'
|
|
26
|
+
import { ComponentCommonProps } from '../../types'
|
|
27
|
+
import { Touchable, TouchableProps } from '../Touchable'
|
|
10
28
|
import { modalScrollLock, ModalStore } from '../../lib/tools/modal'
|
|
11
|
-
import { ModalHeaderProps, ModalProps } from './types'
|
|
12
|
-
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
13
|
-
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
14
|
-
import { AnyRecord, AppIcon, IJSX, StyledComponentProps, useNestedStylesByKey } from '@codeleap/styles'
|
|
15
29
|
|
|
16
30
|
export * from './styles'
|
|
17
|
-
|
|
31
|
+
|
|
32
|
+
export type ModalProps =
|
|
33
|
+
{
|
|
34
|
+
visible?: boolean
|
|
35
|
+
children?: React.ReactNode
|
|
36
|
+
title?: React.ReactNode | string
|
|
37
|
+
description?: React.ReactNode | string
|
|
38
|
+
renderModalBody?: (props: ModalBodyProps) => React.ReactElement
|
|
39
|
+
toggle?: AnyFunction
|
|
40
|
+
styles?: StylesOf<ModalComposition>
|
|
41
|
+
style?: React.CSSProperties
|
|
42
|
+
accessible?: boolean
|
|
43
|
+
showClose?: boolean
|
|
44
|
+
closable?: boolean
|
|
45
|
+
dismissOnBackdrop?: boolean
|
|
46
|
+
scroll?: boolean
|
|
47
|
+
header?: React.ReactElement
|
|
48
|
+
footer?: React.ReactNode
|
|
49
|
+
withOverlay?: boolean
|
|
50
|
+
closeIconName?: IconPlaceholder
|
|
51
|
+
keepMounted?: boolean
|
|
52
|
+
renderHeader?: (props: ModalHeaderProps) => React.ReactElement
|
|
53
|
+
debugName?: string
|
|
54
|
+
closeButtonProps?: Partial<ActionIconProps>
|
|
55
|
+
closeOnEscape?: boolean
|
|
56
|
+
onClose?: () => void
|
|
57
|
+
overlayProps?: Partial<OverlayProps>
|
|
58
|
+
zIndex?: number
|
|
59
|
+
withScrollContainer?: boolean
|
|
60
|
+
scrollLock?: boolean
|
|
61
|
+
backdropProps?: Partial<TouchableProps>
|
|
62
|
+
alterHistory?: boolean
|
|
63
|
+
modalId?: string
|
|
64
|
+
autoIndex?: boolean
|
|
65
|
+
} & ComponentVariants<typeof ModalPresets> & ComponentCommonProps
|
|
18
66
|
|
|
19
67
|
function focusModal(event: FocusEvent, id: string) {
|
|
20
|
-
event
|
|
68
|
+
event.preventDefault()
|
|
21
69
|
const modal = document.getElementById(id)
|
|
22
70
|
if (modal) modal.focus()
|
|
23
71
|
}
|
|
24
72
|
|
|
73
|
+
type ModalBodyProps = {
|
|
74
|
+
id: string
|
|
75
|
+
variantStyles: PropsOf<ModalComposition>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type ModalHeaderProps = Partial<Omit<ModalProps, 'children'>> & {
|
|
79
|
+
id: string
|
|
80
|
+
variantStyles: PropsOf<ModalComposition>
|
|
81
|
+
onPressClose: () => void
|
|
82
|
+
}
|
|
83
|
+
|
|
25
84
|
const ModalDefaultHeader = (props: ModalHeaderProps) => {
|
|
26
85
|
const {
|
|
27
86
|
id,
|
|
28
|
-
|
|
87
|
+
variantStyles,
|
|
29
88
|
title,
|
|
30
89
|
showClose,
|
|
31
90
|
closable,
|
|
@@ -36,7 +95,7 @@ const ModalDefaultHeader = (props: ModalHeaderProps) => {
|
|
|
36
95
|
debugName,
|
|
37
96
|
} = props
|
|
38
97
|
|
|
39
|
-
const closeButtonStyles = useNestedStylesByKey('closeButton',
|
|
98
|
+
const closeButtonStyles = useNestedStylesByKey('closeButton', variantStyles)
|
|
40
99
|
|
|
41
100
|
const showCloseButton = showClose && closable
|
|
42
101
|
|
|
@@ -48,67 +107,98 @@ const ModalDefaultHeader = (props: ModalHeaderProps) => {
|
|
|
48
107
|
<View
|
|
49
108
|
id={`${id}-header`}
|
|
50
109
|
component='header'
|
|
51
|
-
|
|
110
|
+
css={variantStyles.header}
|
|
52
111
|
className='modal-header header'
|
|
53
112
|
>
|
|
54
|
-
<View id={`${id}-title`}
|
|
113
|
+
<View id={`${id}-title`} css={variantStyles.titleWrapper}>
|
|
55
114
|
{TypeGuards.isString(title) ? (
|
|
56
|
-
<Text debugName={debugName} text={title}
|
|
57
|
-
) :
|
|
115
|
+
<Text debugName={debugName} text={title} css={variantStyles.title} />
|
|
116
|
+
) : (
|
|
117
|
+
title
|
|
118
|
+
)}
|
|
58
119
|
|
|
59
|
-
{showCloseButton
|
|
120
|
+
{showCloseButton && (
|
|
60
121
|
<ActionIcon
|
|
61
122
|
debugName={debugName}
|
|
62
|
-
icon={closeIconName as
|
|
123
|
+
icon={closeIconName as IconPlaceholder}
|
|
63
124
|
onPress={onPressClose}
|
|
64
125
|
{...closeButtonProps}
|
|
65
|
-
|
|
126
|
+
styles={closeButtonStyles}
|
|
66
127
|
/>
|
|
67
|
-
)
|
|
128
|
+
)}
|
|
68
129
|
</View>
|
|
69
130
|
|
|
70
131
|
{TypeGuards.isString(description) ? (
|
|
71
|
-
<Text debugName={debugName} text={description} style={
|
|
72
|
-
) :
|
|
132
|
+
<Text debugName={debugName} text={description} style={variantStyles.description} />
|
|
133
|
+
) : (
|
|
134
|
+
description
|
|
135
|
+
)}
|
|
73
136
|
</View>
|
|
74
137
|
)
|
|
75
138
|
}
|
|
76
139
|
|
|
77
|
-
|
|
140
|
+
const defaultProps: Partial<ModalProps> = {
|
|
141
|
+
title: '',
|
|
142
|
+
closeIconName: 'x' as IconPlaceholder,
|
|
143
|
+
closable: true,
|
|
144
|
+
withOverlay: true,
|
|
145
|
+
showClose: true,
|
|
146
|
+
scroll: false,
|
|
147
|
+
closeOnEscape: true,
|
|
148
|
+
renderHeader: ModalDefaultHeader,
|
|
149
|
+
keepMounted: true,
|
|
150
|
+
dismissOnBackdrop: true,
|
|
151
|
+
zIndex: null,
|
|
152
|
+
description: null,
|
|
153
|
+
withScrollContainer: false,
|
|
154
|
+
scrollLock: false,
|
|
155
|
+
autoIndex: false,
|
|
156
|
+
alterHistory: false,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const ModalContent = (
|
|
160
|
+
modalProps: ModalProps & { id: string },
|
|
161
|
+
) => {
|
|
78
162
|
const {
|
|
79
163
|
children,
|
|
80
164
|
visible,
|
|
81
165
|
title,
|
|
82
166
|
toggle,
|
|
167
|
+
variants = [],
|
|
168
|
+
styles,
|
|
83
169
|
footer,
|
|
84
|
-
style,
|
|
170
|
+
style = {},
|
|
85
171
|
renderHeader: ModalHeader,
|
|
86
172
|
closable,
|
|
87
173
|
withOverlay,
|
|
88
174
|
showClose,
|
|
175
|
+
responsiveVariants = {},
|
|
89
176
|
closeIconName,
|
|
90
177
|
scroll,
|
|
91
178
|
renderModalBody,
|
|
92
179
|
closeOnEscape,
|
|
93
180
|
onClose,
|
|
94
|
-
overlayProps,
|
|
181
|
+
overlayProps = {},
|
|
95
182
|
dismissOnBackdrop,
|
|
96
183
|
zIndex,
|
|
97
184
|
withScrollContainer,
|
|
98
185
|
debugName,
|
|
99
|
-
backdropProps,
|
|
186
|
+
backdropProps = {},
|
|
100
187
|
alterHistory,
|
|
101
188
|
id: modalId,
|
|
102
189
|
autoIndex,
|
|
103
190
|
...props
|
|
104
191
|
} = modalProps
|
|
105
192
|
|
|
106
|
-
const styles = useStylesFor(Modal.styleRegistryName, style)
|
|
107
|
-
|
|
108
193
|
const index = ModalStore(store => (store.indexes?.[modalId] ?? 0))
|
|
109
194
|
|
|
110
195
|
const id = useId()
|
|
111
196
|
const modalRef = useRef(null)
|
|
197
|
+
const variantStyles = useDefaultComponentStyle<'u:Modal', typeof ModalPresets>('u:Modal', {
|
|
198
|
+
responsiveVariants,
|
|
199
|
+
variants,
|
|
200
|
+
styles,
|
|
201
|
+
})
|
|
112
202
|
|
|
113
203
|
const toggleAndReturn = () => {
|
|
114
204
|
toggle?.()
|
|
@@ -128,7 +218,7 @@ export const ModalContent = (modalProps: ModalProps & { id: string }) => {
|
|
|
128
218
|
}
|
|
129
219
|
}
|
|
130
220
|
|
|
131
|
-
const handleTabKeyPress = (e: React.KeyboardEvent<HTMLDivElement>, { firstElement, lastElement }: Record<'firstElement' |
|
|
221
|
+
const handleTabKeyPress = (e: React.KeyboardEvent<HTMLDivElement>, { firstElement, lastElement }: Record<'firstElement' |'lastElement', HTMLDivElement>) => {
|
|
132
222
|
if (e.key === 'Tab' || e?.keyCode === 9) {
|
|
133
223
|
if (e.shiftKey && document.activeElement === firstElement) {
|
|
134
224
|
e.preventDefault()
|
|
@@ -166,9 +256,11 @@ export const ModalContent = (modalProps: ModalProps & { id: string }) => {
|
|
|
166
256
|
if (modal) modal.focus()
|
|
167
257
|
}, [id])
|
|
168
258
|
|
|
169
|
-
const close = (closable && dismissOnBackdrop) ? toggleAndReturn : () =>
|
|
259
|
+
const close = (closable && dismissOnBackdrop) ? toggleAndReturn : () => { }
|
|
170
260
|
|
|
171
|
-
const ModalBody = renderModalBody || View
|
|
261
|
+
const ModalBody = renderModalBody || (scroll ? Scroll : View)
|
|
262
|
+
|
|
263
|
+
const ModalArea = withScrollContainer ? Scroll : View
|
|
172
264
|
|
|
173
265
|
const _zIndex = React.useMemo(() => {
|
|
174
266
|
return TypeGuards.isNumber(zIndex) ? { zIndex } : {}
|
|
@@ -178,34 +270,43 @@ export const ModalContent = (modalProps: ModalProps & { id: string }) => {
|
|
|
178
270
|
<View
|
|
179
271
|
ref={modalRef}
|
|
180
272
|
aria-hidden={!visible}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
visible
|
|
184
|
-
|
|
273
|
+
css={[
|
|
274
|
+
variantStyles.wrapper,
|
|
275
|
+
visible
|
|
276
|
+
? variantStyles['wrapper:visible']
|
|
277
|
+
: variantStyles['wrapper:hidden'],
|
|
278
|
+
autoIndex ? { zIndex: index } : {},
|
|
185
279
|
_zIndex,
|
|
186
280
|
]}
|
|
187
281
|
>
|
|
188
282
|
<Overlay
|
|
189
283
|
debugName={debugName}
|
|
190
284
|
visible={withOverlay ? visible : false}
|
|
191
|
-
{
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
285
|
+
css={[
|
|
286
|
+
variantStyles.backdrop,
|
|
287
|
+
visible
|
|
288
|
+
? variantStyles['backdrop:visible']
|
|
289
|
+
: variantStyles['backdrop:hidden'],
|
|
195
290
|
]}
|
|
291
|
+
{...overlayProps}
|
|
196
292
|
/>
|
|
197
293
|
|
|
198
|
-
<
|
|
294
|
+
<ModalArea css={variantStyles.innerWrapper}>
|
|
199
295
|
<Touchable
|
|
296
|
+
css={variantStyles.backdropPressable}
|
|
200
297
|
onPress={close}
|
|
201
298
|
debounce={1000}
|
|
202
|
-
debugName='modal backdrop'
|
|
203
299
|
{...backdropProps}
|
|
204
|
-
style={styles.backdropPressable}
|
|
205
300
|
/>
|
|
206
|
-
|
|
207
301
|
<View
|
|
208
302
|
component='section'
|
|
303
|
+
css={[
|
|
304
|
+
variantStyles.box,
|
|
305
|
+
visible
|
|
306
|
+
? variantStyles['box:visible']
|
|
307
|
+
: variantStyles['box:hidden'],
|
|
308
|
+
style,
|
|
309
|
+
]}
|
|
209
310
|
className='content'
|
|
210
311
|
tabIndex={0}
|
|
211
312
|
id={id}
|
|
@@ -214,35 +315,35 @@ export const ModalContent = (modalProps: ModalProps & { id: string }) => {
|
|
|
214
315
|
aria-describedby={`${id}-title`}
|
|
215
316
|
aria-label='Close the modal by pressing Escape key'
|
|
216
317
|
{...props}
|
|
217
|
-
style={[
|
|
218
|
-
styles.box,
|
|
219
|
-
visible ? styles['box:visible'] : styles['box:hidden'],
|
|
220
|
-
]}
|
|
221
318
|
>
|
|
222
319
|
<ModalHeader
|
|
223
320
|
{...modalProps}
|
|
224
|
-
|
|
321
|
+
variantStyles={variantStyles}
|
|
225
322
|
id={id}
|
|
226
323
|
onPressClose={toggleAndReturn}
|
|
227
324
|
debugName={debugName}
|
|
228
325
|
/>
|
|
229
326
|
|
|
230
|
-
<ModalBody
|
|
327
|
+
<ModalBody
|
|
328
|
+
css={variantStyles.body}
|
|
329
|
+
variantStyles={variantStyles}
|
|
330
|
+
id={id}
|
|
331
|
+
>
|
|
231
332
|
{children}
|
|
232
333
|
</ModalBody>
|
|
233
334
|
|
|
234
|
-
{footer
|
|
235
|
-
<View component='footer'
|
|
335
|
+
{footer && (
|
|
336
|
+
<View component='footer' css={variantStyles.footer}>
|
|
236
337
|
{footer}
|
|
237
338
|
</View>
|
|
238
|
-
)
|
|
339
|
+
)}
|
|
239
340
|
</View>
|
|
240
|
-
</
|
|
341
|
+
</ModalArea>
|
|
241
342
|
</View>
|
|
242
343
|
)
|
|
243
344
|
}
|
|
244
345
|
|
|
245
|
-
export const Modal = (props
|
|
346
|
+
export const Modal = (props) => {
|
|
246
347
|
const allProps = {
|
|
247
348
|
...Modal.defaultProps,
|
|
248
349
|
...props,
|
|
@@ -279,7 +380,7 @@ export const Modal = (props: ModalProps) => {
|
|
|
279
380
|
}
|
|
280
381
|
|
|
281
382
|
if (scrollLock) modalScrollLock(visible, modalId.current)
|
|
282
|
-
|
|
383
|
+
|
|
283
384
|
if (autoIndex) {
|
|
284
385
|
setTimeout(() => {
|
|
285
386
|
setIndex(visible, modalId.current)
|
|
@@ -291,7 +392,9 @@ export const Modal = (props: ModalProps) => {
|
|
|
291
392
|
}
|
|
292
393
|
}, [visible])
|
|
293
394
|
|
|
294
|
-
const content = <ModalContent {...
|
|
395
|
+
const content = <ModalContent {...props} visible={visible} toggle={toggle} id={modalId.current} />
|
|
396
|
+
|
|
397
|
+
// if (renderStatus === 'unmounted') return null
|
|
295
398
|
|
|
296
399
|
if (typeof window === 'undefined') return content
|
|
297
400
|
|
|
@@ -299,48 +402,7 @@ export const Modal = (props: ModalProps) => {
|
|
|
299
402
|
content,
|
|
300
403
|
document.body,
|
|
301
404
|
)
|
|
302
|
-
}
|
|
303
405
|
|
|
304
|
-
Modal.styleRegistryName = 'Modal'
|
|
305
|
-
|
|
306
|
-
Modal.elements = [
|
|
307
|
-
'wrapper',
|
|
308
|
-
'box',
|
|
309
|
-
'backdrop',
|
|
310
|
-
'body',
|
|
311
|
-
'footer',
|
|
312
|
-
'header',
|
|
313
|
-
'title',
|
|
314
|
-
'innerWrapper',
|
|
315
|
-
'backdropPressable',
|
|
316
|
-
'description',
|
|
317
|
-
'titleWrapper',
|
|
318
|
-
`closeButton`,
|
|
319
|
-
]
|
|
320
|
-
|
|
321
|
-
Modal.rootElement = 'wrapper'
|
|
322
|
-
|
|
323
|
-
Modal.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
324
|
-
return Modal as (props: StyledComponentProps<ModalProps, typeof styles>) => IJSX
|
|
325
406
|
}
|
|
326
407
|
|
|
327
|
-
Modal.defaultProps =
|
|
328
|
-
title: '',
|
|
329
|
-
closeIconName: 'x' as AppIcon,
|
|
330
|
-
closable: true,
|
|
331
|
-
withOverlay: true,
|
|
332
|
-
showClose: true,
|
|
333
|
-
scroll: false,
|
|
334
|
-
closeOnEscape: true,
|
|
335
|
-
renderHeader: ModalDefaultHeader,
|
|
336
|
-
keepMounted: true,
|
|
337
|
-
dismissOnBackdrop: true,
|
|
338
|
-
zIndex: null,
|
|
339
|
-
description: null,
|
|
340
|
-
withScrollContainer: false,
|
|
341
|
-
scrollLock: false,
|
|
342
|
-
autoIndex: false,
|
|
343
|
-
alterHistory: false,
|
|
344
|
-
} as Partial<ModalProps>
|
|
345
|
-
|
|
346
|
-
WebStyleRegistry.registerComponent(Modal)
|
|
408
|
+
Modal.defaultProps = defaultProps
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
1
2
|
import { ActionIconComposition } from '../ActionIcon'
|
|
2
3
|
|
|
3
4
|
export type AnimatableParts = 'box' | 'backdrop' | 'wrapper'
|
|
@@ -18,3 +19,7 @@ export type ModalComposition =
|
|
|
18
19
|
| ModalParts
|
|
19
20
|
| `${AnimatableParts}:visible`
|
|
20
21
|
| `${AnimatableParts}:hidden`
|
|
22
|
+
|
|
23
|
+
const createModalStyle = createDefaultVariantFactory<ModalComposition>()
|
|
24
|
+
|
|
25
|
+
export const ModalPresets = includePresets((style) => createModalStyle(() => ({ body: style })))
|
|
@@ -1,45 +1,90 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx, CSSObject } from '@emotion/react'
|
|
1
3
|
import * as React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
+
import {
|
|
5
|
+
ComponentVariants,
|
|
6
|
+
yup,
|
|
7
|
+
useDefaultComponentStyle,
|
|
8
|
+
StylesOf,
|
|
9
|
+
PropsOf,
|
|
10
|
+
TypeGuards,
|
|
11
|
+
onUpdate,
|
|
12
|
+
useState,
|
|
13
|
+
useRef,
|
|
14
|
+
useValidate,
|
|
15
|
+
FormTypes,
|
|
16
|
+
IconPlaceholder,
|
|
17
|
+
} from '@codeleap/common'
|
|
18
|
+
import { View } from '../View'
|
|
19
|
+
import { NumberIncrementPresets, NumberIncrementComposition } from './styles'
|
|
20
|
+
import { InputBase, InputBaseProps, selectInputBaseProps } from '../InputBase'
|
|
4
21
|
import { Text } from '../Text'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
22
|
+
import {
|
|
23
|
+
PatternFormat,
|
|
24
|
+
PatternFormatProps as PFProps,
|
|
25
|
+
NumericFormat,
|
|
26
|
+
NumericFormatProps as NFProps,
|
|
27
|
+
NumberFormatBase,
|
|
28
|
+
} from 'react-number-format'
|
|
29
|
+
import { FormatInputValueFunction } from 'react-number-format/types/types'
|
|
10
30
|
|
|
11
|
-
export * from './types'
|
|
12
31
|
export * from './styles'
|
|
13
32
|
|
|
33
|
+
export type NumberIncrementProps = Pick<
|
|
34
|
+
InputBaseProps,
|
|
35
|
+
'debugName' | 'disabled' | 'label'
|
|
36
|
+
> & {
|
|
37
|
+
styles?: StylesOf<NumberIncrementComposition>
|
|
38
|
+
value: number
|
|
39
|
+
onValueChange: (value: number) => void
|
|
40
|
+
onChangeText?: (value: number) => void
|
|
41
|
+
validate?: FormTypes.ValidatorWithoutForm<string> | yup.SchemaOf<string>
|
|
42
|
+
style?: PropsOf<typeof View>['style']
|
|
43
|
+
max?: number
|
|
44
|
+
min?: number
|
|
45
|
+
step?: number
|
|
46
|
+
editable?: boolean
|
|
47
|
+
prefix?: NFProps['prefix']
|
|
48
|
+
suffix?: NFProps['suffix']
|
|
49
|
+
separator?: NFProps['thousandSeparator']
|
|
50
|
+
format?: PFProps['format']
|
|
51
|
+
mask?: PFProps['mask']
|
|
52
|
+
hasSeparator?: boolean
|
|
53
|
+
_error?: string
|
|
54
|
+
formatter?: FormatInputValueFunction
|
|
55
|
+
placeholder?: string
|
|
56
|
+
} & ComponentVariants<typeof NumberIncrementPresets>
|
|
57
|
+
|
|
14
58
|
export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
15
59
|
const {
|
|
16
60
|
inputBaseProps,
|
|
17
|
-
others
|
|
18
|
-
} = selectInputBaseProps(
|
|
61
|
+
others,
|
|
62
|
+
} = selectInputBaseProps(props)
|
|
19
63
|
|
|
20
64
|
const {
|
|
21
|
-
|
|
65
|
+
responsiveVariants = {},
|
|
66
|
+
variants = [],
|
|
67
|
+
style = {},
|
|
68
|
+
styles = {},
|
|
22
69
|
value,
|
|
23
70
|
disabled,
|
|
24
71
|
onValueChange,
|
|
25
72
|
onChangeText,
|
|
26
|
-
max,
|
|
27
|
-
min,
|
|
28
|
-
step,
|
|
29
|
-
editable,
|
|
30
|
-
hasSeparator,
|
|
31
|
-
format,
|
|
32
|
-
mask,
|
|
73
|
+
max = 1000000000,
|
|
74
|
+
min = 0,
|
|
75
|
+
step = 1,
|
|
76
|
+
editable = true,
|
|
77
|
+
hasSeparator = false,
|
|
78
|
+
format = null,
|
|
79
|
+
mask = undefined,
|
|
33
80
|
suffix,
|
|
34
|
-
separator,
|
|
81
|
+
separator = null,
|
|
35
82
|
prefix,
|
|
36
83
|
validate,
|
|
37
84
|
_error,
|
|
38
|
-
formatter,
|
|
85
|
+
formatter = null,
|
|
39
86
|
placeholder,
|
|
40
|
-
} =
|
|
41
|
-
|
|
42
|
-
const styles = useStylesFor(NumberIncrement.styleRegistryName, style)
|
|
87
|
+
} = others
|
|
43
88
|
|
|
44
89
|
const [isFocused, setIsFocused] = useState(false)
|
|
45
90
|
|
|
@@ -65,6 +110,16 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
65
110
|
return false
|
|
66
111
|
}, [value])
|
|
67
112
|
|
|
113
|
+
const variantStyles = useDefaultComponentStyle<'u:NumberIncrement', typeof NumberIncrementPresets>(
|
|
114
|
+
'u:NumberIncrement',
|
|
115
|
+
{
|
|
116
|
+
responsiveVariants,
|
|
117
|
+
variants,
|
|
118
|
+
styles,
|
|
119
|
+
rootElement: 'wrapper',
|
|
120
|
+
},
|
|
121
|
+
)
|
|
122
|
+
|
|
68
123
|
const onChange = (newValue: number) => {
|
|
69
124
|
if (onValueChange) onValueChange?.(newValue)
|
|
70
125
|
if (onChangeText) onChangeText?.(newValue)
|
|
@@ -88,19 +143,19 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
88
143
|
|
|
89
144
|
const inputTextStyle = React.useMemo(() => {
|
|
90
145
|
return [
|
|
91
|
-
|
|
92
|
-
isFocused
|
|
93
|
-
hasError
|
|
94
|
-
disabled
|
|
95
|
-
]
|
|
146
|
+
variantStyles.input,
|
|
147
|
+
isFocused && variantStyles['input:focus'],
|
|
148
|
+
hasError && variantStyles['input:error'],
|
|
149
|
+
disabled && variantStyles['input:disabled'],
|
|
150
|
+
]
|
|
96
151
|
}, [disabled, isFocused, hasError])
|
|
97
152
|
|
|
98
153
|
const placeholderStyles = [
|
|
99
|
-
|
|
100
|
-
isFocused
|
|
101
|
-
hasError
|
|
102
|
-
disabled
|
|
103
|
-
]
|
|
154
|
+
variantStyles.placeholder,
|
|
155
|
+
isFocused && variantStyles['placeholder:focus'],
|
|
156
|
+
hasError && variantStyles['placeholder:error'],
|
|
157
|
+
disabled && variantStyles['placeholder:disabled'],
|
|
158
|
+
]
|
|
104
159
|
|
|
105
160
|
const handleBlur = React.useCallback(() => {
|
|
106
161
|
if (TypeGuards.isNumber(max) && (value >= max)) {
|
|
@@ -169,27 +224,28 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
169
224
|
<InputBase
|
|
170
225
|
{...inputBaseProps}
|
|
171
226
|
error={hasError ? errorMessage : null}
|
|
172
|
-
|
|
173
|
-
...
|
|
174
|
-
innerWrapper:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
227
|
+
styles={{
|
|
228
|
+
...variantStyles,
|
|
229
|
+
innerWrapper: [
|
|
230
|
+
variantStyles.innerWrapper,
|
|
231
|
+
editable && variantStyles['innerWrapper:cursor'],
|
|
232
|
+
],
|
|
178
233
|
}}
|
|
179
234
|
rightIcon={{
|
|
180
|
-
name: 'plus' as
|
|
235
|
+
name: 'plus' as IconPlaceholder,
|
|
181
236
|
disabled: disabled || incrementDisabled,
|
|
182
237
|
onPress: () => handleChange('increment'),
|
|
183
238
|
component: 'button',
|
|
184
239
|
...inputBaseProps.rightIcon,
|
|
185
240
|
}}
|
|
186
241
|
leftIcon={{
|
|
187
|
-
name: 'minus' as
|
|
242
|
+
name: 'minus' as IconPlaceholder,
|
|
188
243
|
disabled: disabled || decrementDisabled,
|
|
189
244
|
onPress: () => handleChange('decrement'),
|
|
190
245
|
component: 'button',
|
|
191
246
|
...inputBaseProps.leftIcon,
|
|
192
247
|
}}
|
|
248
|
+
style={style}
|
|
193
249
|
disabled={disabled}
|
|
194
250
|
focused={isFocused}
|
|
195
251
|
innerWrapperProps={{
|
|
@@ -205,13 +261,10 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
205
261
|
<Input
|
|
206
262
|
displayType='input'
|
|
207
263
|
css={[
|
|
208
|
-
// @ts-expect-error
|
|
209
264
|
...inputTextStyle,
|
|
210
|
-
// @ts-expect-error
|
|
211
265
|
{
|
|
212
266
|
'&::placeholder': placeholderStyles,
|
|
213
267
|
},
|
|
214
|
-
// @ts-expect-error
|
|
215
268
|
{
|
|
216
269
|
'&:focus': [
|
|
217
270
|
{
|
|
@@ -236,29 +289,7 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
236
289
|
placeholder={placeholder}
|
|
237
290
|
getInputRef={innerInputRef}
|
|
238
291
|
/>
|
|
239
|
-
) : <Text text={String(value)}
|
|
292
|
+
) : <Text text={String(value)} css={inputTextStyle} />}
|
|
240
293
|
</InputBase>
|
|
241
294
|
)
|
|
242
295
|
}
|
|
243
|
-
|
|
244
|
-
NumberIncrement.styleRegistryName = 'NumberIncrement'
|
|
245
|
-
NumberIncrement.elements = [...InputBase.elements, 'input', 'placeholder']
|
|
246
|
-
NumberIncrement.rootElement = 'wrapper'
|
|
247
|
-
|
|
248
|
-
NumberIncrement.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
249
|
-
return NumberIncrement as (props: StyledComponentProps<NumberIncrementProps, typeof styles>) => IJSX
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
NumberIncrement.defaultProps = {
|
|
253
|
-
max: 1000000000,
|
|
254
|
-
min: 0,
|
|
255
|
-
step: 1,
|
|
256
|
-
editable: true,
|
|
257
|
-
hasSeparator: false,
|
|
258
|
-
mask: undefined,
|
|
259
|
-
separator: null,
|
|
260
|
-
format: null,
|
|
261
|
-
formatter: null,
|
|
262
|
-
} as Partial<NumberIncrementProps>
|
|
263
|
-
|
|
264
|
-
WebStyleRegistry.registerComponent(NumberIncrement)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
1
2
|
import { InputBaseParts } from '../InputBase'
|
|
2
3
|
|
|
3
4
|
export type NumberIncrementParts = InputBaseParts | 'input' | 'placeholder'
|
|
@@ -8,3 +9,7 @@ export type NumberIncrementComposition =
|
|
|
8
9
|
| NumberIncrementParts
|
|
9
10
|
| `${NumberIncrementParts}:${NumberIncrementStates}`
|
|
10
11
|
| `innerWrapper:cursor`
|
|
12
|
+
|
|
13
|
+
const createNumberIncrementStyle = createDefaultVariantFactory<NumberIncrementComposition>()
|
|
14
|
+
|
|
15
|
+
export const NumberIncrementPresets = includePresets((styles) => createNumberIncrementStyle(() => ({ wrapper: styles })))
|