@codeleap/web 3.25.0 → 3.25.3
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 +57 -91
- 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,5 +1,7 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
1
3
|
import React, { useRef, forwardRef, useImperativeHandle } from 'react'
|
|
2
|
-
import { FormTypes, useValidate, useState, TypeGuards, onUpdate, useEffect } from '@codeleap/common'
|
|
4
|
+
import { FormTypes, useValidate, useState, TypeGuards, onUpdate, IconPlaceholder, useEffect } from '@codeleap/common'
|
|
3
5
|
import _Select, { components, MenuListProps, MenuProps, MultiValueProps, NoticeProps } from 'react-select'
|
|
4
6
|
import Async from 'react-select/async'
|
|
5
7
|
import { useSelectStyles } from './styles'
|
|
@@ -11,25 +13,15 @@ import { View } from '../View'
|
|
|
11
13
|
import { ActivityIndicator } from '../ActivityIndicator'
|
|
12
14
|
import { CSSInterpolation } from '@emotion/css'
|
|
13
15
|
import { Icon } from '../Icon'
|
|
14
|
-
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
15
|
-
import { AnyRecord, AppIcon, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
|
|
16
16
|
|
|
17
17
|
export * from './styles'
|
|
18
18
|
export * from './types'
|
|
19
19
|
|
|
20
20
|
const DefaultOption = (props: TCustomOption & { component: (props: TCustomOption) => JSX.Element }) => {
|
|
21
|
-
const {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
selectedIcon,
|
|
26
|
-
component = null,
|
|
27
|
-
itemProps = {} as TCustomOption['itemProps'],
|
|
28
|
-
isFocused,
|
|
29
|
-
debugName,
|
|
30
|
-
} = props
|
|
31
|
-
|
|
32
|
-
const styles = optionsStyles({ isSelected, isFocused, baseStyles: (itemProps?.style ?? {}) })
|
|
21
|
+
const { isSelected, optionsStyles, label, selectedIcon, component = null, itemProps = {} as TCustomOption['itemProps'], isFocused, debugName } = props
|
|
22
|
+
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
const styles = optionsStyles({ isSelected, isFocused, baseStyles: (props?.data?.itemProps?.style ?? itemProps?.style ?? {}) })
|
|
33
25
|
|
|
34
26
|
let _Component = null
|
|
35
27
|
|
|
@@ -41,7 +33,8 @@ const DefaultOption = (props: TCustomOption & { component: (props: TCustomOption
|
|
|
41
33
|
rightIcon={isSelected && selectedIcon}
|
|
42
34
|
debugName={debugName}
|
|
43
35
|
{...itemProps}
|
|
44
|
-
|
|
36
|
+
{...props?.data?.itemProps}
|
|
37
|
+
styles={styles}
|
|
45
38
|
/>
|
|
46
39
|
)
|
|
47
40
|
} else {
|
|
@@ -50,13 +43,14 @@ const DefaultOption = (props: TCustomOption & { component: (props: TCustomOption
|
|
|
50
43
|
|
|
51
44
|
return (
|
|
52
45
|
<components.Option {...props}>
|
|
53
|
-
<_Component {...props}
|
|
46
|
+
<_Component {...props} styles={styles} />
|
|
54
47
|
</components.Option>
|
|
55
48
|
)
|
|
56
49
|
}
|
|
57
50
|
|
|
58
51
|
const CustomMenu = (props: MenuProps & { Footer: () => JSX.Element }) => {
|
|
59
52
|
const { Footer, children } = props
|
|
53
|
+
|
|
60
54
|
return <React.Fragment>
|
|
61
55
|
<components.Menu {...props}>
|
|
62
56
|
{children}
|
|
@@ -67,6 +61,7 @@ const CustomMenu = (props: MenuProps & { Footer: () => JSX.Element }) => {
|
|
|
67
61
|
|
|
68
62
|
const CustomMenuList = (props: MenuListProps & { defaultStyles: { wrapper: React.CSSProperties } }) => {
|
|
69
63
|
const { children, defaultStyles } = props
|
|
64
|
+
|
|
70
65
|
return (
|
|
71
66
|
<components.MenuList {...props}>
|
|
72
67
|
<View style={defaultStyles.wrapper}>
|
|
@@ -77,13 +72,13 @@ const CustomMenuList = (props: MenuListProps & { defaultStyles: { wrapper: React
|
|
|
77
72
|
}
|
|
78
73
|
|
|
79
74
|
const DefaultPlaceholder = (props: PlaceholderProps) => {
|
|
80
|
-
const { text: TextPlaceholder, defaultStyles, icon: _IconPlaceholder,
|
|
75
|
+
const { text: TextPlaceholder, defaultStyles, icon: _IconPlaceholder, debugName } = props
|
|
81
76
|
|
|
82
77
|
const _Text = () => {
|
|
83
78
|
if (TypeGuards.isNil(TextPlaceholder)) return null
|
|
84
79
|
|
|
85
80
|
if (TypeGuards.isString(TextPlaceholder)) {
|
|
86
|
-
return <Text debugName={debugName} text={TextPlaceholder}
|
|
81
|
+
return <Text debugName={debugName} text={TextPlaceholder} css={[defaultStyles.text]} />
|
|
87
82
|
} else if (React.isValidElement(TextPlaceholder)) {
|
|
88
83
|
return TextPlaceholder as JSX.Element
|
|
89
84
|
} else if (TypeGuards.isFunction(TextPlaceholder)) {
|
|
@@ -92,14 +87,10 @@ const DefaultPlaceholder = (props: PlaceholderProps) => {
|
|
|
92
87
|
}
|
|
93
88
|
|
|
94
89
|
const _Image = () => {
|
|
95
|
-
if (TypeGuards.isNil(_IconPlaceholder)
|
|
96
|
-
|
|
97
|
-
if (TypeGuards.isString(image)) {
|
|
98
|
-
return <img src={image} css={defaultStyles.icon} />
|
|
99
|
-
}
|
|
90
|
+
if (TypeGuards.isNil(_IconPlaceholder)) return null
|
|
100
91
|
|
|
101
92
|
if (TypeGuards.isString(_IconPlaceholder)) {
|
|
102
|
-
return <Icon debugName={debugName} name={_IconPlaceholder as
|
|
93
|
+
return <Icon debugName={debugName} name={_IconPlaceholder as IconPlaceholder} forceStyle={defaultStyles.icon as React.CSSProperties} />
|
|
103
94
|
} else if (React.isValidElement(_IconPlaceholder)) {
|
|
104
95
|
// @ts-ignore
|
|
105
96
|
return <View style={defaultStyles.icon}>
|
|
@@ -122,7 +113,7 @@ const LoadingIndicator = (props: LoadingIndicatorProps) => {
|
|
|
122
113
|
const { defaultStyles, debugName } = props
|
|
123
114
|
|
|
124
115
|
return (
|
|
125
|
-
<View
|
|
116
|
+
<View css={[defaultStyles.wrapper]}>
|
|
126
117
|
<ActivityIndicator debugName={debugName} />
|
|
127
118
|
</View>
|
|
128
119
|
)
|
|
@@ -154,15 +145,37 @@ const CustomMultiValue = (props: MultiValueProps & { defaultStyles: { text: CSSI
|
|
|
154
145
|
// @ts-ignore
|
|
155
146
|
const text = getMultiValue(selectProps?.value, separator, { searchable })
|
|
156
147
|
|
|
157
|
-
return <Text text={text}
|
|
148
|
+
return <Text text={text} css={[defaultStyles.text]} />
|
|
158
149
|
}
|
|
159
150
|
|
|
160
151
|
const defaultFormatPlaceholderNoItems = (props: PlaceholderProps & { text: string }) => {
|
|
161
152
|
return props.text + `"${props.selectProps.inputValue}"`
|
|
162
153
|
}
|
|
163
154
|
|
|
155
|
+
const defaultProps: Partial<SelectProps> = {
|
|
156
|
+
PlaceholderComponent: DefaultPlaceholder,
|
|
157
|
+
PlaceholderNoItemsComponent: DefaultPlaceholder,
|
|
158
|
+
LoadingIndicatorComponent: LoadingIndicator,
|
|
159
|
+
noItemsText: 'No results for ',
|
|
160
|
+
noItemsIcon: 'placeholderNoItems-select',
|
|
161
|
+
placeholderText: 'Search items',
|
|
162
|
+
placeholderIcon: 'placeholder-select',
|
|
163
|
+
showDropdownIcon: true,
|
|
164
|
+
placeholder: 'Select',
|
|
165
|
+
clearable: false,
|
|
166
|
+
formatPlaceholderNoItems: defaultFormatPlaceholderNoItems,
|
|
167
|
+
selectedIcon: 'check',
|
|
168
|
+
searchable: false,
|
|
169
|
+
separatorMultiValue: ', ',
|
|
170
|
+
itemProps: {} as ButtonProps,
|
|
171
|
+
loadingIndicatorSize: 20,
|
|
172
|
+
options: [],
|
|
173
|
+
loadInitialValue: false,
|
|
174
|
+
loadingMessage: 'loading...',
|
|
175
|
+
}
|
|
176
|
+
|
|
164
177
|
export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
165
|
-
|
|
178
|
+
<T extends string | number = string, Multi extends boolean = false>
|
|
166
179
|
(props: SelectProps<T, Multi>, inputRef: React.ForwardedRef<HTMLInputElement>) => {
|
|
167
180
|
|
|
168
181
|
type Option = FormTypes.Option<T>
|
|
@@ -176,8 +189,9 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
176
189
|
})
|
|
177
190
|
|
|
178
191
|
const {
|
|
192
|
+
variants,
|
|
179
193
|
validate,
|
|
180
|
-
|
|
194
|
+
styles,
|
|
181
195
|
debugName,
|
|
182
196
|
onValueChange,
|
|
183
197
|
options,
|
|
@@ -195,10 +209,8 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
195
209
|
LoadingIndicatorComponent,
|
|
196
210
|
noItemsText,
|
|
197
211
|
noItemsIcon,
|
|
198
|
-
noItemsImage,
|
|
199
212
|
placeholderText,
|
|
200
213
|
placeholderIcon,
|
|
201
|
-
placeholderImage,
|
|
202
214
|
showDropdownIcon,
|
|
203
215
|
placeholder,
|
|
204
216
|
clearable,
|
|
@@ -253,14 +265,13 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
253
265
|
|
|
254
266
|
const {
|
|
255
267
|
reactSelectStyles,
|
|
256
|
-
|
|
268
|
+
variantStyles,
|
|
257
269
|
optionsStyles,
|
|
258
270
|
placeholderStyles,
|
|
259
271
|
loadingStyles,
|
|
260
272
|
inputMultiValueStyles,
|
|
261
273
|
menuWrapperStyles,
|
|
262
|
-
|
|
263
|
-
} = useSelectStyles({ ...props, styleRegistryName: Select.styleRegistryName }, {
|
|
274
|
+
} = useSelectStyles(props, {
|
|
264
275
|
error: !!hasError,
|
|
265
276
|
focused: isFocused,
|
|
266
277
|
disabled: isDisabled,
|
|
@@ -335,7 +346,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
335
346
|
focused: isFocused,
|
|
336
347
|
error: !!hasError,
|
|
337
348
|
disabled: isDisabled,
|
|
338
|
-
|
|
349
|
+
variantStyles,
|
|
339
350
|
debugName: debugName,
|
|
340
351
|
}
|
|
341
352
|
|
|
@@ -343,17 +354,16 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
343
354
|
const hasInputValue = !!props.selectProps.inputValue
|
|
344
355
|
const styles = placeholderStyles[hasInputValue ? 'noItems' : 'empty']
|
|
345
356
|
const icon = hasInputValue ? noItemsIcon : placeholderIcon
|
|
346
|
-
const image = hasInputValue ? noItemsImage : placeholderImage
|
|
347
357
|
|
|
348
358
|
const placeholderProps = {
|
|
349
359
|
...props,
|
|
350
360
|
...componentProps,
|
|
351
361
|
icon,
|
|
352
|
-
image,
|
|
353
362
|
defaultStyles: styles,
|
|
354
363
|
}
|
|
355
364
|
|
|
356
365
|
if (!hasInputValue) {
|
|
366
|
+
|
|
357
367
|
return <PlaceholderComponent {...placeholderProps} text={placeholderText} />
|
|
358
368
|
} else {
|
|
359
369
|
const _Text = TypeGuards.isString(noItemsText) ? formatPlaceholderNoItems({ ...placeholderProps, text: noItemsText }) : noItemsText
|
|
@@ -389,12 +399,12 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
389
399
|
debugName={debugName}
|
|
390
400
|
error={hasError ? errorMessage : null}
|
|
391
401
|
focused={isFocused}
|
|
392
|
-
|
|
393
|
-
...
|
|
394
|
-
innerWrapper:
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
402
|
+
styles={{
|
|
403
|
+
...variantStyles,
|
|
404
|
+
innerWrapper: [
|
|
405
|
+
variantStyles.innerWrapper,
|
|
406
|
+
searchable && variantStyles['innerWrapper:searchable'],
|
|
407
|
+
],
|
|
398
408
|
}}
|
|
399
409
|
innerWrapperProps={{
|
|
400
410
|
...(inputBaseProps.innerWrapperProps || {}),
|
|
@@ -410,6 +420,8 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
410
420
|
tabSelectsValue={false}
|
|
411
421
|
tabIndex={0}
|
|
412
422
|
backspaceRemovesValue={true}
|
|
423
|
+
// escapeRemoves={true}
|
|
424
|
+
// deleteRemoves={true}
|
|
413
425
|
{...otherProps}
|
|
414
426
|
{..._props}
|
|
415
427
|
onKeyDown={isFocused ? handleKeyDown : null}
|
|
@@ -467,52 +479,6 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
467
479
|
/>
|
|
468
480
|
</InputBase>
|
|
469
481
|
)
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
Select.styleRegistryName = 'Select'
|
|
473
|
-
|
|
474
|
-
Select.elements = [
|
|
475
|
-
...InputBase.elements,
|
|
476
|
-
'item',
|
|
477
|
-
'listPortal',
|
|
478
|
-
'listHeader',
|
|
479
|
-
'listWrapper',
|
|
480
|
-
'list',
|
|
481
|
-
'inputContainer',
|
|
482
|
-
'input',
|
|
483
|
-
'placeholder',
|
|
484
|
-
'value',
|
|
485
|
-
'valueMultiple',
|
|
486
|
-
'valueWrapper',
|
|
487
|
-
'clearIcon',
|
|
488
|
-
'dropdownIcon',
|
|
489
|
-
]
|
|
490
|
-
|
|
491
|
-
Select.rootElement = 'wrapper'
|
|
492
|
-
|
|
493
|
-
Select.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
494
|
-
return Select as (props: StyledComponentProps<SelectProps, typeof styles>) => IJSX
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
Select.defaultProps = {
|
|
498
|
-
PlaceholderComponent: DefaultPlaceholder,
|
|
499
|
-
PlaceholderNoItemsComponent: DefaultPlaceholder,
|
|
500
|
-
LoadingIndicatorComponent: LoadingIndicator,
|
|
501
|
-
noItemsText: 'No results for ',
|
|
502
|
-
placeholderText: 'Search items',
|
|
503
|
-
placeholderIcon: 'search',
|
|
504
|
-
showDropdownIcon: true,
|
|
505
|
-
placeholder: 'Select',
|
|
506
|
-
clearable: false,
|
|
507
|
-
formatPlaceholderNoItems: defaultFormatPlaceholderNoItems,
|
|
508
|
-
selectedIcon: 'check',
|
|
509
|
-
searchable: false,
|
|
510
|
-
separatorMultiValue: ', ',
|
|
511
|
-
itemProps: {} as ButtonProps,
|
|
512
|
-
loadingIndicatorSize: 20,
|
|
513
|
-
options: [],
|
|
514
|
-
loadInitialValue: false,
|
|
515
|
-
loadingMessage: 'loading...',
|
|
516
|
-
} as Partial<SelectProps>
|
|
482
|
+
})
|
|
517
483
|
|
|
518
|
-
|
|
484
|
+
Select.defaultProps = defaultProps
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { capitalize, FormTypes } from '@codeleap/common'
|
|
2
|
-
import { useNestedStylesByKey } from '@codeleap/styles'
|
|
1
|
+
import { capitalize, createDefaultVariantFactory, FormTypes, getNestedStylesByKey, includePresets, useDefaultComponentStyle } from '@codeleap/common'
|
|
3
2
|
import { CSSInterpolation } from '@emotion/css'
|
|
4
3
|
import { CSSObjectWithLabel, GroupBase, StylesConfig } from 'react-select'
|
|
5
4
|
import { ButtonParts as _ButtonParts } from '../Button'
|
|
6
5
|
import { InputBaseParts } from '../InputBase'
|
|
7
|
-
import { SelectProps
|
|
8
|
-
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
6
|
+
import { SelectProps } from './types'
|
|
9
7
|
|
|
10
8
|
type ButtonParts = _ButtonParts
|
|
11
9
|
|
|
@@ -45,38 +43,57 @@ export type SelectState = 'error' | 'focus' | 'disabled'
|
|
|
45
43
|
|
|
46
44
|
export type SelectComposition = SelectParts | `${SelectParts}:${SelectState}` | SelectStatefulParts
|
|
47
45
|
|
|
46
|
+
const createSelectStyle = createDefaultVariantFactory<SelectComposition>()
|
|
47
|
+
|
|
48
|
+
export const SelectPresets = includePresets((styles) => createSelectStyle(() => ({ wrapper: styles })))
|
|
49
|
+
|
|
48
50
|
export type ComponentState = {
|
|
49
51
|
error?: boolean
|
|
50
52
|
focused?: boolean
|
|
51
53
|
disabled?: boolean
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
export type OptionState = {
|
|
56
|
+
export type OptionState = {
|
|
55
57
|
isSelected: boolean
|
|
56
58
|
isFocused: boolean
|
|
57
|
-
baseStyles: SelectProps['itemProps']['
|
|
59
|
+
baseStyles: SelectProps['itemProps']['styles']
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
export function useSelectStyles<T, Multi extends boolean>(props:
|
|
61
|
-
const {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
export function useSelectStyles<T, Multi extends boolean>(props: SelectProps<T, Multi>, state: ComponentState) {
|
|
63
|
+
const {
|
|
64
|
+
responsiveVariants = {},
|
|
65
|
+
variants,
|
|
66
|
+
styles,
|
|
67
|
+
} = props
|
|
68
|
+
|
|
69
|
+
const {
|
|
70
|
+
error,
|
|
71
|
+
focused,
|
|
72
|
+
disabled,
|
|
73
|
+
} = state
|
|
74
|
+
|
|
75
|
+
const variantStyles = useDefaultComponentStyle<'u:Select', typeof SelectPresets>(
|
|
76
|
+
'u:Select',
|
|
77
|
+
{
|
|
78
|
+
responsiveVariants,
|
|
79
|
+
variants,
|
|
80
|
+
styles,
|
|
81
|
+
},
|
|
82
|
+
)
|
|
66
83
|
|
|
67
84
|
const stylesKey = (key: SelectParts | SelectStatefulParts, _styles: CSSObjectWithLabel = {}) => ({
|
|
68
85
|
..._styles,
|
|
69
|
-
...
|
|
70
|
-
...(focused ?
|
|
71
|
-
...(disabled ?
|
|
72
|
-
...(error ?
|
|
86
|
+
...variantStyles[key],
|
|
87
|
+
...(focused ? variantStyles[key + ':focus'] : {}),
|
|
88
|
+
...(disabled ? variantStyles[key + ':disabled'] : {}),
|
|
89
|
+
...(error ? variantStyles[key + ':error'] : {}),
|
|
73
90
|
})
|
|
74
91
|
|
|
75
|
-
const optionNestedStyles =
|
|
92
|
+
const optionNestedStyles = getNestedStylesByKey('item', variantStyles)
|
|
76
93
|
|
|
77
94
|
const optionStyleKey = (
|
|
78
95
|
key: ButtonParts | `${ButtonParts}:${ItemState}`,
|
|
79
|
-
state: OptionState
|
|
96
|
+
state: OptionState
|
|
80
97
|
) => {
|
|
81
98
|
return {
|
|
82
99
|
...stylesKey(`item${capitalize(key)}` as any),
|
|
@@ -152,7 +169,7 @@ export function useSelectStyles<T, Multi extends boolean>(props: UseSelectStyles
|
|
|
152
169
|
}
|
|
153
170
|
|
|
154
171
|
return {
|
|
155
|
-
|
|
172
|
+
variantStyles,
|
|
156
173
|
reactSelectStyles,
|
|
157
174
|
optionsStyles,
|
|
158
175
|
placeholderStyles,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { FormTypes, yup } from '@codeleap/common'
|
|
1
|
+
import { ComponentVariants, FormTypes, PropsOf, StylesOf, yup } from '@codeleap/common'
|
|
2
2
|
import { CSSInterpolation } from '@emotion/css'
|
|
3
|
+
import { CSSObject } from '@emotion/react'
|
|
3
4
|
import { MutableRefObject } from 'react'
|
|
4
5
|
import { GroupBase, NoticeProps, OptionProps, Props } from 'react-select'
|
|
5
6
|
import { AsyncProps } from 'react-select/async'
|
|
6
7
|
import { ComponentCommonProps } from '../../types'
|
|
7
|
-
import { ButtonProps } from '../Button'
|
|
8
|
+
import { Button, ButtonProps } from '../Button'
|
|
8
9
|
import { InputBaseProps } from '../InputBase'
|
|
9
|
-
import { SelectComposition, OptionState } from './styles'
|
|
10
|
-
import { StyledProp } from '@codeleap/styles'
|
|
10
|
+
import { SelectPresets, SelectComposition, OptionState } from './styles'
|
|
11
11
|
|
|
12
12
|
type SelectValue<T, Multi extends boolean> = Multi extends true ? T[] : T
|
|
13
13
|
|
|
@@ -26,20 +26,20 @@ type DynamicSelectProps<T, Multi extends boolean> =
|
|
|
26
26
|
Props<FormTypes.Option<T>, Multi, GroupBase<FormTypes.Option<T>>>
|
|
27
27
|
>)
|
|
28
28
|
|
|
29
|
-
export type ReactSelectProps<T, Multi extends boolean = false> = Omit<InputBaseProps, '
|
|
30
|
-
options: FormTypes.Options<T>
|
|
29
|
+
export type ReactSelectProps<T, Multi extends boolean = false> = Omit<InputBaseProps, 'styles' | 'variants'> &{
|
|
30
|
+
options: FormTypes.Options<T> & { itemProps?: PropsOf<typeof Button> }
|
|
31
31
|
value: SelectValue<T, Multi>
|
|
32
32
|
onValueChange?: (value: SelectValue<T, Multi>) => void
|
|
33
33
|
multiple?: Multi
|
|
34
34
|
validate?: FormTypes.ValidatorWithoutForm<SelectValue<T, Multi>> | yup.SchemaOf<SelectValue<T, Multi>>
|
|
35
|
-
|
|
35
|
+
styles?: StylesOf<SelectComposition>
|
|
36
36
|
} & DynamicSelectProps<T, Multi>
|
|
37
37
|
|
|
38
38
|
export type ComponentPartProps = {
|
|
39
39
|
focused: boolean
|
|
40
40
|
error: boolean
|
|
41
41
|
disabled: boolean
|
|
42
|
-
|
|
42
|
+
variantStyles: Record<SelectComposition, React.CSSProperties>
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export type TCustomOption = OptionProps & ComponentPartProps & ComponentCommonProps & {
|
|
@@ -47,6 +47,7 @@ export type TCustomOption = OptionProps & ComponentPartProps & ComponentCommonPr
|
|
|
47
47
|
selectedIcon?: string
|
|
48
48
|
itemProps?: ButtonProps
|
|
49
49
|
styles?: OptionState['baseStyles']
|
|
50
|
+
data: OptionProps['data'] & { itemProps?: PropsOf<typeof Button>}
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
type SelectPlaceholderElement = string | ((props: PlaceholderProps) => JSX.Element) | JSX.Element
|
|
@@ -59,7 +60,6 @@ export type PlaceholderProps = NoticeProps & ComponentPartProps & {
|
|
|
59
60
|
icon: CSSInterpolation
|
|
60
61
|
}
|
|
61
62
|
icon: SelectPlaceholderElement
|
|
62
|
-
image: HTMLImageElement['src']
|
|
63
63
|
} & ComponentCommonProps
|
|
64
64
|
|
|
65
65
|
export type LoadingIndicatorProps = NoticeProps & {
|
|
@@ -72,6 +72,7 @@ export type SelectProps<T = any, Multi extends boolean = false> = React.PropsWit
|
|
|
72
72
|
debugName?: string
|
|
73
73
|
clearable?: boolean
|
|
74
74
|
closeOnSelect?: boolean
|
|
75
|
+
css?: CSSObject
|
|
75
76
|
focused?: boolean
|
|
76
77
|
_error?: string
|
|
77
78
|
renderItem?: (props: TCustomOption) => JSX.Element
|
|
@@ -81,10 +82,8 @@ export type SelectProps<T = any, Multi extends boolean = false> = React.PropsWit
|
|
|
81
82
|
LoadingIndicatorComponent?: (props: LoadingIndicatorProps) => JSX.Element
|
|
82
83
|
noItemsText?: SelectPlaceholderElement
|
|
83
84
|
noItemsIcon?: SelectPlaceholderElement
|
|
84
|
-
noItemsImage?: PlaceholderProps['image']
|
|
85
85
|
placeholderText?: SelectPlaceholderElement
|
|
86
86
|
placeholderIcon?: SelectPlaceholderElement
|
|
87
|
-
placeholderImage?: PlaceholderProps['image']
|
|
88
87
|
showDropdownIcon?: boolean
|
|
89
88
|
formatPlaceholderNoItems?: (props: PlaceholderProps & { text: string }) => string
|
|
90
89
|
selectedIcon?: string
|
|
@@ -98,15 +97,12 @@ export type SelectProps<T = any, Multi extends boolean = false> = React.PropsWit
|
|
|
98
97
|
limit?: number
|
|
99
98
|
loadInitialValue?: boolean
|
|
100
99
|
loadingMessage?: string
|
|
101
|
-
selectedOption?: { label: FormTypes.Label; value: T } | SelectValue<T, Multi>
|
|
100
|
+
selectedOption?: { label: FormTypes.Label; value: T; } | SelectValue<T, Multi>
|
|
102
101
|
selectRef?: MutableRefObject<any>
|
|
103
|
-
setSelectedOption?: (value: { label: FormTypes.Label; value: T } | SelectValue<T, Multi>) => void
|
|
102
|
+
setSelectedOption?: (value: { label: FormTypes.Label; value: T; } | SelectValue<T, Multi>) => void
|
|
104
103
|
} & Omit<
|
|
105
104
|
ReactSelectProps<T, Multi>,
|
|
106
105
|
'isSearchable' | 'isClearable' | 'isDisabled' | 'loadingMessage' | 'filterOption' |
|
|
107
106
|
'isLoading' | 'menuPortalTarget' | 'closeMenuOnSelect' | 'isMulti'>
|
|
107
|
+
& ComponentVariants<typeof SelectPresets>
|
|
108
108
|
>
|
|
109
|
-
|
|
110
|
-
export type UseSelectStylesProps = SelectProps & {
|
|
111
|
-
styleRegistryName: string
|
|
112
|
-
}
|