@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.
Files changed (150) hide show
  1. package/package.json +1 -2
  2. package/src/components/ActionIcon/index.tsx +52 -51
  3. package/src/components/ActionIcon/styles.ts +5 -1
  4. package/src/components/ActivityIndicator/index.tsx +55 -34
  5. package/src/components/ActivityIndicator/styles.ts +6 -0
  6. package/src/components/Badge/index.tsx +80 -43
  7. package/src/components/Badge/styles.ts +11 -1
  8. package/src/components/Button/index.tsx +89 -46
  9. package/src/components/Button/styles.ts +5 -0
  10. package/src/components/Checkbox/index.tsx +97 -83
  11. package/src/components/Checkbox/styles.ts +5 -1
  12. package/src/components/Collapse/index.tsx +83 -41
  13. package/src/components/Collapse/styles.ts +6 -3
  14. package/src/components/ColorPicker/index.tsx +48 -95
  15. package/src/components/ColorPicker/styles.ts +11 -11
  16. package/src/components/ColorPicker/types.ts +12 -26
  17. package/src/components/CropPicker/index.tsx +104 -100
  18. package/src/components/CropPicker/styles.ts +7 -0
  19. package/src/components/CropPicker/types.ts +17 -8
  20. package/src/{lib/hooks/useCropPicker.ts → components/CropPicker/useCropPicker.tsx} +15 -68
  21. package/src/components/CropPicker/utils.ts +51 -0
  22. package/src/components/DatePicker/{components → defaultComponents}/Header.tsx +17 -9
  23. package/src/components/DatePicker/{components → defaultComponents}/OuterInput.tsx +7 -6
  24. package/src/components/DatePicker/index.tsx +124 -110
  25. package/src/components/DatePicker/styles.ts +12 -1
  26. package/src/components/DatePicker/types.ts +33 -16
  27. package/src/components/Drawer/index.tsx +125 -133
  28. package/src/components/Drawer/styles.ts +5 -0
  29. package/src/components/Dropzone/index.tsx +63 -87
  30. package/src/components/Dropzone/styles.ts +6 -0
  31. package/src/components/Dropzone/types.ts +37 -29
  32. package/src/components/EmptyPlaceholder/index.tsx +83 -63
  33. package/src/components/EmptyPlaceholder/styles.ts +5 -0
  34. package/src/components/FileInput.tsx +91 -0
  35. package/src/components/Grid/index.tsx +41 -40
  36. package/src/components/Grid/styles.ts +9 -2
  37. package/src/components/Grid/types.ts +12 -10
  38. package/src/components/Icon/index.tsx +47 -45
  39. package/src/components/Icon/styles.ts +8 -0
  40. package/src/components/InputBase/index.tsx +42 -71
  41. package/src/components/InputBase/styles.ts +47 -37
  42. package/src/components/InputBase/types.ts +7 -19
  43. package/src/components/InputBase/utils.ts +23 -3
  44. package/src/components/List/ListLayout.tsx +37 -20
  45. package/src/components/List/PaginationIndicator.tsx +102 -0
  46. package/src/components/List/index.tsx +41 -36
  47. package/src/components/List/styles.ts +11 -5
  48. package/src/components/List/types.ts +20 -30
  49. package/src/components/List/useInfiniteScroll.ts +159 -0
  50. package/src/components/LoadingOverlay/index.tsx +33 -31
  51. package/src/components/LoadingOverlay/styles.ts +8 -3
  52. package/src/components/Modal/index.tsx +160 -98
  53. package/src/components/Modal/styles.ts +5 -0
  54. package/src/components/NumberIncrement/index.tsx +98 -67
  55. package/src/components/NumberIncrement/styles.ts +5 -0
  56. package/src/components/Overlay/index.tsx +35 -37
  57. package/src/components/Overlay/styles.ts +5 -3
  58. package/src/components/Pager/index.tsx +81 -65
  59. package/src/components/Pager/styles.ts +9 -3
  60. package/src/components/Progress/Bar/index.tsx +50 -45
  61. package/src/components/Progress/Bar/styles.tsx +7 -0
  62. package/src/components/Progress/Bar/types.tsx +30 -0
  63. package/src/components/Progress/Circle/index.tsx +48 -45
  64. package/src/components/Progress/Circle/styles.ts +8 -1
  65. package/src/components/Progress/Circle/types.ts +22 -10
  66. package/src/components/RadioInput/index.tsx +124 -78
  67. package/src/components/RadioInput/styles.ts +6 -0
  68. package/src/components/Scroll/index.tsx +32 -0
  69. package/src/components/Scroll/styles.ts +8 -0
  70. package/src/components/SearchInput/index.tsx +10 -10
  71. package/src/components/SectionFilters/index.tsx +36 -47
  72. package/src/components/SectionFilters/styles.ts +5 -1
  73. package/src/components/SectionFilters/types.ts +13 -14
  74. package/src/components/SegmentedControl/SegmentedControlOption.tsx +84 -0
  75. package/src/components/SegmentedControl/index.tsx +89 -111
  76. package/src/components/SegmentedControl/styles.ts +21 -7
  77. package/src/components/Select/index.tsx +57 -91
  78. package/src/components/Select/styles.ts +36 -19
  79. package/src/components/Select/types.ts +13 -17
  80. package/src/components/Slider/index.tsx +93 -85
  81. package/src/components/Slider/styles.ts +6 -13
  82. package/src/components/Switch/index.tsx +74 -63
  83. package/src/components/Switch/styles.ts +6 -1
  84. package/src/components/Tag/index.tsx +44 -39
  85. package/src/components/Tag/styles.ts +9 -1
  86. package/src/components/Tag/types.ts +10 -10
  87. package/src/components/Text/index.tsx +48 -37
  88. package/src/components/Text/styles.ts +8 -0
  89. package/src/components/Text/types.ts +8 -8
  90. package/src/components/TextEditor/index.tsx +28 -49
  91. package/src/components/TextEditor/styles.ts +8 -1
  92. package/src/components/TextEditor/types.ts +6 -11
  93. package/src/components/TextInput/index.tsx +96 -58
  94. package/src/components/TextInput/mask.tsx +50 -2
  95. package/src/components/TextInput/styles.ts +8 -3
  96. package/src/components/Tooltip/index.tsx +84 -61
  97. package/src/components/Tooltip/styles.ts +10 -3
  98. package/src/components/Touchable/index.tsx +86 -43
  99. package/src/components/Touchable/styles.ts +6 -0
  100. package/src/components/View/index.tsx +50 -36
  101. package/src/components/View/styles.ts +6 -0
  102. package/src/components/View/types.ts +15 -14
  103. package/src/components/components.ts +3 -2
  104. package/src/components/defaultStyles.ts +79 -0
  105. package/src/index.ts +0 -1
  106. package/src/lib/hooks/index.ts +0 -5
  107. package/src/lib/hooks/useBreakpointMatch.ts +7 -8
  108. package/src/lib/hooks/useMediaQuery.ts +3 -4
  109. package/src/lib/hooks/usePagination.ts +63 -79
  110. package/src/lib/index.ts +0 -1
  111. package/src/lib/utils/index.ts +0 -1
  112. package/src/lib/utils/test.ts +2 -2
  113. package/src/components/ActionIcon/types.ts +0 -15
  114. package/src/components/ActivityIndicator/types.ts +0 -12
  115. package/src/components/Badge/types.ts +0 -28
  116. package/src/components/Button/types.ts +0 -25
  117. package/src/components/Checkbox/types.ts +0 -15
  118. package/src/components/Collapse/types.ts +0 -11
  119. package/src/components/Drawer/types.ts +0 -23
  120. package/src/components/EmptyPlaceholder/types.ts +0 -32
  121. package/src/components/FileInput/index.tsx +0 -72
  122. package/src/components/FileInput/types.ts +0 -14
  123. package/src/components/Icon/types.ts +0 -15
  124. package/src/components/LoadingOverlay/types.ts +0 -16
  125. package/src/components/Modal/types.ts +0 -55
  126. package/src/components/NumberIncrement/types.ts +0 -29
  127. package/src/components/Overlay/types.ts +0 -13
  128. package/src/components/Pager/types.ts +0 -35
  129. package/src/components/PaginationButtons/index.tsx +0 -173
  130. package/src/components/PaginationButtons/styles.ts +0 -7
  131. package/src/components/PaginationButtons/types.ts +0 -26
  132. package/src/components/PaginationIndicator/index.tsx +0 -69
  133. package/src/components/PaginationIndicator/styles.ts +0 -3
  134. package/src/components/PaginationIndicator/types.ts +0 -18
  135. package/src/components/Progress/Bar/styles.ts +0 -10
  136. package/src/components/Progress/Bar/types.ts +0 -26
  137. package/src/components/RadioInput/types.ts +0 -29
  138. package/src/components/SegmentedControl/types.ts +0 -44
  139. package/src/components/Slider/types.ts +0 -29
  140. package/src/components/Switch/types.ts +0 -13
  141. package/src/components/TextInput/types.ts +0 -85
  142. package/src/components/Tooltip/types.ts +0 -46
  143. package/src/components/Touchable/types.ts +0 -22
  144. package/src/lib/WebStyleRegistry.ts +0 -51
  145. package/src/lib/hooks/useFileInput.ts +0 -15
  146. package/src/lib/hooks/useInfiniteScroll.ts +0 -77
  147. package/src/lib/hooks/useRefresh.ts +0 -87
  148. package/src/lib/hooks/useStylesFor.ts +0 -13
  149. package/src/lib/utils/cache.ts +0 -9
  150. /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
- isSelected,
23
- optionsStyles,
24
- label,
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
- style={styles}
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} style={styles} />
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, image, debugName } = props
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} style={defaultStyles.text} />
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) && TypeGuards.isNil(image)) return null
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 AppIcon} forceStyle={defaultStyles.icon as React.CSSProperties} />
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 style={defaultStyles.wrapper}>
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} style={defaultStyles.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
- <T extends string | number = string, Multi extends boolean = false>
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
- style,
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
- styles,
268
+ variantStyles,
257
269
  optionsStyles,
258
270
  placeholderStyles,
259
271
  loadingStyles,
260
272
  inputMultiValueStyles,
261
273
  menuWrapperStyles,
262
- // @ts-expect-error @verify
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
- styles,
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
- style={{
393
- ...styles,
394
- innerWrapper: {
395
- ...styles.innerWrapper,
396
- ...(searchable ? styles['innerWrapper:searchable'] : {}),
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
- }) as StyledComponentWithProps<SelectProps>
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
- WebStyleRegistry.registerComponent(Select)
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, UseSelectStylesProps } from './types'
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']['style']
59
+ baseStyles: SelectProps['itemProps']['styles']
58
60
  }
59
61
 
60
- export function useSelectStyles<T, Multi extends boolean>(props: UseSelectStylesProps, state: ComponentState) {
61
- const { style } = props
62
-
63
- const { error, focused, disabled } = state
64
-
65
- const styles = useStylesFor(props?.styleRegistryName, style)
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
- ...styles[key],
70
- ...(focused ? styles[key + ':focus'] : {}),
71
- ...(disabled ? styles[key + ':disabled'] : {}),
72
- ...(error ? styles[key + ':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 = useNestedStylesByKey('item', styles)
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
- styles,
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, 'style'> & {
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
- style?: StyledProp<SelectComposition>
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
- styles: Record<SelectComposition, React.CSSProperties>
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
- }