@codeleap/web 3.24.3 → 3.25.0

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 +2 -1
  2. package/src/components/ActionIcon/index.tsx +51 -52
  3. package/src/components/ActionIcon/styles.ts +1 -5
  4. package/src/components/ActionIcon/types.ts +15 -0
  5. package/src/components/ActivityIndicator/index.tsx +34 -55
  6. package/src/components/ActivityIndicator/styles.ts +0 -6
  7. package/src/components/ActivityIndicator/types.ts +12 -0
  8. package/src/components/Badge/index.tsx +43 -80
  9. package/src/components/Badge/styles.ts +1 -11
  10. package/src/components/Badge/types.ts +28 -0
  11. package/src/components/Button/index.tsx +46 -89
  12. package/src/components/Button/styles.ts +0 -5
  13. package/src/components/Button/types.ts +25 -0
  14. package/src/components/Checkbox/index.tsx +83 -97
  15. package/src/components/Checkbox/styles.ts +1 -5
  16. package/src/components/Checkbox/types.ts +15 -0
  17. package/src/components/Collapse/index.tsx +41 -83
  18. package/src/components/Collapse/styles.ts +3 -6
  19. package/src/components/Collapse/types.ts +11 -0
  20. package/src/components/ColorPicker/index.tsx +95 -48
  21. package/src/components/ColorPicker/styles.ts +11 -11
  22. package/src/components/ColorPicker/types.ts +26 -12
  23. package/src/components/CropPicker/index.tsx +100 -104
  24. package/src/components/CropPicker/styles.ts +0 -7
  25. package/src/components/CropPicker/types.ts +8 -15
  26. package/src/components/DatePicker/{defaultComponents → components}/Header.tsx +9 -17
  27. package/src/components/DatePicker/{defaultComponents → components}/OuterInput.tsx +6 -7
  28. package/src/components/DatePicker/index.tsx +110 -124
  29. package/src/components/DatePicker/styles.ts +1 -12
  30. package/src/components/DatePicker/types.ts +16 -33
  31. package/src/components/Drawer/index.tsx +133 -125
  32. package/src/components/Drawer/styles.ts +0 -5
  33. package/src/components/Drawer/types.ts +23 -0
  34. package/src/components/Dropzone/index.tsx +87 -63
  35. package/src/components/Dropzone/styles.ts +0 -6
  36. package/src/components/Dropzone/types.ts +29 -37
  37. package/src/components/EmptyPlaceholder/index.tsx +63 -83
  38. package/src/components/EmptyPlaceholder/styles.ts +0 -5
  39. package/src/components/EmptyPlaceholder/types.ts +32 -0
  40. package/src/components/FileInput/index.tsx +72 -0
  41. package/src/components/FileInput/types.ts +14 -0
  42. package/src/components/Grid/index.tsx +40 -41
  43. package/src/components/Grid/styles.ts +2 -9
  44. package/src/components/Grid/types.ts +10 -12
  45. package/src/components/Icon/index.tsx +45 -47
  46. package/src/components/Icon/styles.ts +0 -8
  47. package/src/components/Icon/types.ts +15 -0
  48. package/src/components/InputBase/index.tsx +71 -42
  49. package/src/components/InputBase/styles.ts +37 -47
  50. package/src/components/InputBase/types.ts +19 -7
  51. package/src/components/InputBase/utils.ts +3 -23
  52. package/src/components/List/ListLayout.tsx +20 -37
  53. package/src/components/List/index.tsx +36 -41
  54. package/src/components/List/styles.ts +5 -11
  55. package/src/components/List/types.ts +30 -20
  56. package/src/components/LoadingOverlay/index.tsx +31 -33
  57. package/src/components/LoadingOverlay/styles.ts +3 -8
  58. package/src/components/LoadingOverlay/types.ts +16 -0
  59. package/src/components/Modal/index.tsx +98 -160
  60. package/src/components/Modal/styles.ts +0 -5
  61. package/src/components/Modal/types.ts +55 -0
  62. package/src/components/NumberIncrement/index.tsx +67 -98
  63. package/src/components/NumberIncrement/styles.ts +0 -5
  64. package/src/components/NumberIncrement/types.ts +29 -0
  65. package/src/components/Overlay/index.tsx +37 -35
  66. package/src/components/Overlay/styles.ts +3 -5
  67. package/src/components/Overlay/types.ts +13 -0
  68. package/src/components/Pager/index.tsx +65 -81
  69. package/src/components/Pager/styles.ts +3 -9
  70. package/src/components/Pager/types.ts +35 -0
  71. package/src/components/PaginationButtons/index.tsx +173 -0
  72. package/src/components/PaginationButtons/styles.ts +7 -0
  73. package/src/components/PaginationButtons/types.ts +26 -0
  74. package/src/components/PaginationIndicator/index.tsx +69 -0
  75. package/src/components/PaginationIndicator/styles.ts +3 -0
  76. package/src/components/PaginationIndicator/types.ts +18 -0
  77. package/src/components/Progress/Bar/index.tsx +45 -50
  78. package/src/components/Progress/Bar/styles.ts +10 -0
  79. package/src/components/Progress/Bar/types.ts +26 -0
  80. package/src/components/Progress/Circle/index.tsx +45 -48
  81. package/src/components/Progress/Circle/styles.ts +1 -8
  82. package/src/components/Progress/Circle/types.ts +10 -22
  83. package/src/components/RadioInput/index.tsx +78 -124
  84. package/src/components/RadioInput/styles.ts +0 -6
  85. package/src/components/RadioInput/types.ts +29 -0
  86. package/src/components/SearchInput/index.tsx +10 -10
  87. package/src/components/SectionFilters/index.tsx +47 -36
  88. package/src/components/SectionFilters/styles.ts +1 -5
  89. package/src/components/SectionFilters/types.ts +14 -13
  90. package/src/components/SegmentedControl/index.tsx +111 -89
  91. package/src/components/SegmentedControl/styles.ts +7 -21
  92. package/src/components/SegmentedControl/types.ts +44 -0
  93. package/src/components/Select/index.tsx +92 -56
  94. package/src/components/Select/styles.ts +19 -36
  95. package/src/components/Select/types.ts +15 -10
  96. package/src/components/Slider/index.tsx +85 -93
  97. package/src/components/Slider/styles.ts +13 -6
  98. package/src/components/Slider/types.ts +29 -0
  99. package/src/components/Switch/index.tsx +63 -74
  100. package/src/components/Switch/styles.ts +1 -6
  101. package/src/components/Switch/types.ts +13 -0
  102. package/src/components/Tag/index.tsx +39 -44
  103. package/src/components/Tag/styles.ts +1 -9
  104. package/src/components/Tag/types.ts +10 -10
  105. package/src/components/Text/index.tsx +37 -48
  106. package/src/components/Text/styles.ts +0 -8
  107. package/src/components/Text/types.ts +8 -8
  108. package/src/components/TextEditor/index.tsx +49 -28
  109. package/src/components/TextEditor/styles.ts +1 -8
  110. package/src/components/TextEditor/types.ts +11 -6
  111. package/src/components/TextInput/index.tsx +58 -96
  112. package/src/components/TextInput/mask.tsx +2 -50
  113. package/src/components/TextInput/styles.ts +3 -8
  114. package/src/components/TextInput/types.ts +85 -0
  115. package/src/components/Tooltip/index.tsx +61 -84
  116. package/src/components/Tooltip/styles.ts +3 -10
  117. package/src/components/Tooltip/types.ts +46 -0
  118. package/src/components/Touchable/index.tsx +43 -86
  119. package/src/components/Touchable/styles.ts +0 -6
  120. package/src/components/Touchable/types.ts +22 -0
  121. package/src/components/View/index.tsx +36 -50
  122. package/src/components/View/styles.ts +0 -6
  123. package/src/components/View/types.ts +14 -15
  124. package/src/components/components.ts +2 -3
  125. package/src/index.ts +1 -0
  126. package/src/lib/WebStyleRegistry.ts +51 -0
  127. package/src/lib/hooks/index.ts +5 -0
  128. package/src/lib/hooks/useBreakpointMatch.ts +8 -7
  129. package/src/{components/CropPicker/useCropPicker.tsx → lib/hooks/useCropPicker.ts} +66 -13
  130. package/src/lib/hooks/useFileInput.ts +15 -0
  131. package/src/lib/hooks/useInfiniteScroll.ts +77 -0
  132. package/src/lib/hooks/useMediaQuery.ts +4 -3
  133. package/src/lib/hooks/usePagination.ts +79 -63
  134. package/src/lib/hooks/useRefresh.ts +87 -0
  135. package/src/lib/hooks/useStylesFor.ts +13 -0
  136. package/src/lib/index.ts +1 -0
  137. package/src/lib/utils/cache.ts +9 -0
  138. package/src/lib/utils/index.ts +1 -0
  139. package/src/lib/utils/test.ts +2 -2
  140. package/src/components/CropPicker/utils.ts +0 -51
  141. package/src/components/FileInput.tsx +0 -91
  142. package/src/components/List/PaginationIndicator.tsx +0 -102
  143. package/src/components/List/useInfiniteScroll.ts +0 -159
  144. package/src/components/Progress/Bar/styles.tsx +0 -7
  145. package/src/components/Progress/Bar/types.tsx +0 -30
  146. package/src/components/Scroll/index.tsx +0 -32
  147. package/src/components/Scroll/styles.ts +0 -8
  148. package/src/components/SegmentedControl/SegmentedControlOption.tsx +0 -84
  149. package/src/components/defaultStyles.ts +0 -79
  150. /package/src/components/DatePicker/{defaultComponents → components}/index.tsx +0 -0
@@ -1,32 +1,20 @@
1
- import { ComponentVariants, IconPlaceholder, PropsOf, StylesOf } from '@codeleap/common'
2
- import {
3
- IconProps,
4
- ProgressCircleComposition,
5
- ProgressCirclePresets,
6
- View,
7
- TextProps as _TextProps,
8
- } from '../../components'
1
+ import { PropsOf } from '@codeleap/common'
2
+ import { IconProps, ProgressCircleComposition, ViewProps, TextProps } from '../../components'
9
3
  import { ProgressPropsRoot } from '..'
10
4
  import { CircularProgressbarWithChildren, buildStyles } from 'react-circular-progressbar'
11
- import { ElementType } from 'react'
5
+ import { AppIcon, StyledProp } from '@codeleap/styles'
12
6
 
13
- type TextProps = _TextProps<ElementType>
14
-
15
- export type ProgressCircleProps = Omit<
16
- PropsOf<typeof View>,
17
- 'styles' | 'variants' | 'children'
18
- > &
19
- ComponentVariants<typeof ProgressCirclePresets> &
20
- ProgressPropsRoot & {
21
- styles?: StylesOf<ProgressCircleComposition>
7
+ export type ProgressCircleProps =
8
+ Omit<ViewProps, 'style'> &
9
+ Omit<ProgressPropsRoot, 'style'> &
10
+ {
11
+ style?: StyledProp<ProgressCircleComposition>
22
12
  circleProps?: PropsOf<typeof CircularProgressbarWithChildren>
23
13
  circleStyles?: Parameters<typeof buildStyles>[0]
24
14
  children?: React.ReactNode
25
15
  size?: number
26
-
27
- text?: TextProps['text'] | JSX.Element
16
+ text?: string | JSX.Element
28
17
  textProps?: Partial<TextProps>
29
-
30
- icon?: IconPlaceholder
18
+ icon?: AppIcon
31
19
  iconProps?: Partial<IconProps>
32
20
  }
@@ -1,47 +1,19 @@
1
- /** @jsx jsx */
2
- import { jsx } from '@emotion/react'
3
-
4
- import React, { ReactNode } from 'react'
1
+ import React from 'react'
5
2
  import { Text } from '../Text'
6
3
  import { Touchable } from '../Touchable'
7
- import {
8
- ComponentVariants,
9
- FormTypes,
10
- StylesOf,
11
- TypeGuards,
12
- useDefaultComponentStyle,
13
- } from '@codeleap/common'
4
+ import { TypeGuards } from '@codeleap/common'
14
5
  import { View } from '../View'
15
- import { RadioInputComposition, RadioInputPresets } from './styles'
16
- import { InputBase, InputBaseProps, selectInputBaseProps } from '../InputBase'
6
+ import { InputBase, selectInputBaseProps } from '../InputBase'
7
+ import { RadioOptionProps, RadioInputProps } from './types'
8
+ import { AnyRecord, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
9
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
10
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
11
+ import { RadioInputComposition } from './styles'
17
12
 
18
13
  export * from './styles'
14
+ export * from './types'
19
15
 
20
- type WrapperProps = InputBaseProps
21
-
22
- type RadioOption<T> = FormTypes.Options<T>[number] & {
23
- disabled?: boolean
24
- }
25
-
26
- export type RadioGroupProps<T extends string|number> = WrapperProps & {
27
- options: RadioOption<T>[]
28
- value: T
29
- onValueChange(value: T): void
30
- label: ReactNode
31
- styles?: StylesOf<RadioInputComposition>
32
- } & ComponentVariants<typeof RadioInputPresets>
33
-
34
- type OptionProps<T extends string|number> = {
35
- item: RadioOption<T>
36
- selected: boolean
37
- onSelect(): void
38
- styles?: StylesOf<RadioInputComposition>
39
- debugName?: string
40
- disabled?: boolean
41
- separator?: boolean
42
- }
43
-
44
- const Option = <T extends string|number>(props: OptionProps<T>) => {
16
+ const Option = <T extends string | number>(props: RadioOptionProps<T>) => {
45
17
  const {
46
18
  debugName,
47
19
  item,
@@ -52,107 +24,89 @@ const Option = <T extends string|number>(props: OptionProps<T>) => {
52
24
  separator = false,
53
25
  } = props
54
26
 
55
- const isDisabled = disabled || item.disabled
56
-
57
- const getStyle = (key) => {
58
- if (isDisabled && selected) {
59
- return styles[`${key}:selectedDisabled`]
60
- }
61
- if (isDisabled) {
62
- return styles[`${key}:disabled`]
63
- }
64
- if (selected) {
65
- return styles[`${key}:selected`]
66
- }
67
- return styles[key]
68
- }
27
+ const isDisabled = disabled || item?.disabled
69
28
 
70
- const label = TypeGuards.isString(item.label) ? <Text
71
- css={[
72
- styles.optionLabel,
73
- getStyle('optionLabel'),
74
- ]}
75
- text={item.label}
76
- /> : item.label
77
-
78
- return <React.Fragment>
79
- <Touchable
80
- debugName={`${debugName} option ${item.value}`}
81
- css={[
82
- styles.optionWrapper,
83
- getStyle('optionWrapper'),
84
- ]}
85
- onPress={onSelect}
86
- disabled={isDisabled}
87
- >
88
- <View
89
- css={[
90
- styles.optionIndicator,
91
- getStyle('optionIndicator'),
92
- ]}
29
+ const getStyle = (key: RadioInputComposition) => {
30
+ let style = null
31
+
32
+ if (isDisabled && selected) style = styles[`${key}:selectedDisabled`]
33
+ else if (isDisabled) style = styles[`${key}:disabled`]
34
+ else if (selected) style = styles[`${key}:selected`]
93
35
 
36
+ return mergeStyles([styles[key], style])
37
+ }
38
+
39
+ return (
40
+ <React.Fragment>
41
+ <Touchable
42
+ debugName={`${debugName} option ${item.value}`}
43
+ style={getStyle('optionWrapper')}
44
+ onPress={onSelect}
45
+ disabled={isDisabled}
94
46
  >
95
- <View
96
- css={[
97
- styles.optionIndicatorInner,
98
- getStyle('optionIndicatorInner'),
99
- ]}
100
- />
101
- </View>
102
- {label}
47
+ <View style={getStyle('optionIndicator')}>
48
+ <View style={getStyle('optionIndicatorInner')} />
49
+ </View>
103
50
 
104
- </Touchable>
105
- {separator && <View style={styles.optionSeparator} />}
106
- </React.Fragment>
51
+ {TypeGuards.isString(item.label) ? <Text style={getStyle('optionLabel')} text={item.label} /> : item.label}
52
+ </Touchable>
53
+
54
+ {separator ? <View style={styles.optionSeparator} /> : null}
55
+ </React.Fragment>
56
+ )
107
57
  }
108
58
 
109
- export const RadioGroup = <T extends string|number>(
110
- props: RadioGroupProps<T>,
111
- ) => {
59
+ export const RadioInput = <T extends string | number>(props: RadioInputProps<T>) => {
112
60
  const {
113
61
  inputBaseProps,
114
- others,
115
- } = selectInputBaseProps(props)
62
+ others: radioInputProps,
63
+ } = selectInputBaseProps({
64
+ ...RadioInput.defaultProps,
65
+ ...props,
66
+ })
116
67
 
117
68
  const {
118
69
  options,
119
70
  value,
120
71
  onValueChange,
121
- responsiveVariants = {},
122
- variants = [],
123
- styles,
72
+ style,
124
73
  disabled,
125
74
  debugName,
126
- } = others
75
+ } = radioInputProps
127
76
 
128
- const variantStyles = useDefaultComponentStyle<'u:RadioInput', typeof RadioInputPresets>('u:RadioInput', {
129
- responsiveVariants,
130
- variants,
131
- styles,
132
- })
77
+ const styles = useStylesFor(RadioInput.styleRegistryName, style)
78
+
79
+ return (
80
+ <InputBase
81
+ {...inputBaseProps}
82
+ disabled={disabled}
83
+ style={styles}
84
+ debugName={debugName}
85
+ >
86
+ {options?.map((item, idx) => (
87
+ <Option
88
+ debugName={debugName}
89
+ item={item}
90
+ key={idx}
91
+ disabled={disabled}
92
+ styles={styles}
93
+ selected={value === item?.value}
94
+ onSelect={() => onValueChange(item?.value)}
95
+ separator={idx < options?.length - 1}
96
+ />
97
+ ))}
98
+ </InputBase>
99
+ )
100
+ }
133
101
 
134
- return <InputBase
135
- {...inputBaseProps}
136
- disabled={disabled}
137
- styles={{
138
- ...variantStyles,
139
- innerWrapper: [
140
- variantStyles.innerWrapper,
141
- ],
142
- }}
143
- debugName={debugName}
144
- >
145
- {options?.map((item, idx) => (
146
- <Option
147
- debugName={debugName}
148
- item={item}
149
- key={idx}
150
- disabled={disabled}
151
- styles={variantStyles}
152
- selected={value === item.value}
153
- onSelect={() => onValueChange(item.value)}
154
- separator={idx < options.length - 1}
155
- />
156
- ))}
157
- </InputBase>
102
+ RadioInput.styleRegistryName = 'RadioInput'
103
+ RadioInput.elements = [...InputBase.elements, 'option']
104
+ RadioInput.rootElement = 'wrapper'
105
+
106
+ RadioInput.withVariantTypes = <S extends AnyRecord, T extends string | number>(styles: S) => {
107
+ return RadioInput as (props: StyledComponentProps<RadioInputProps<T>, typeof styles>) => IJSX
158
108
  }
109
+
110
+ RadioInput.defaultProps = {} as Partial<RadioInputProps<string | number>>
111
+
112
+ WebStyleRegistry.registerComponent(RadioInput)
@@ -1,4 +1,3 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { IconLessInputBaseParts } from '../InputBase'
3
2
 
4
3
  type OptionParts = 'wrapper' | 'label' | 'indicator' | 'indicatorInner' | 'separator'
@@ -7,8 +6,3 @@ type OptionStates = 'selected' | 'disabled' | 'selectedDisabled'
7
6
  type OptionComposition = `${OptionParts}:${OptionStates}` | OptionParts
8
7
 
9
8
  export type RadioInputComposition = IconLessInputBaseParts | `${IconLessInputBaseParts}:disabled` | `option${Capitalize<OptionComposition>}`
10
-
11
- const createRadioStyle =
12
- createDefaultVariantFactory<RadioInputComposition>()
13
-
14
- export const RadioInputPresets = includePresets(style => createRadioStyle(() => ({ wrapper: style })))
@@ -0,0 +1,29 @@
1
+ import { FormTypes, StylesOf } from '@codeleap/common'
2
+ import { InputBaseProps } from '../InputBase'
3
+ import { ReactNode } from 'react'
4
+ import { StyledProp } from '@codeleap/styles'
5
+ import { RadioInputComposition } from './styles'
6
+
7
+ type WrapperProps = InputBaseProps
8
+
9
+ type RadioOption<T> = FormTypes.Options<T>[number] & {
10
+ disabled?: boolean
11
+ }
12
+
13
+ export type RadioInputProps<T extends string|number> = Omit<WrapperProps, 'style'> & {
14
+ options: RadioOption<T>[]
15
+ value: T
16
+ onValueChange(value: T): void
17
+ label: ReactNode
18
+ style?: StyledProp<RadioInputComposition>
19
+ }
20
+
21
+ export type RadioOptionProps<T extends string|number> = {
22
+ item: RadioOption<T>
23
+ selected: boolean
24
+ onSelect(): void
25
+ styles?: StylesOf<RadioInputComposition>
26
+ debugName?: string
27
+ disabled?: boolean
28
+ separator?: boolean
29
+ }
@@ -1,14 +1,14 @@
1
- import { AnyFunction, IconPlaceholder, TypeGuards } from '@codeleap/common'
2
1
  import React, { useState } from 'react'
3
2
  import { TextInput, TextInputProps } from '../TextInput'
4
- import { ComponentWithDefaultProps } from '../../types/utility'
3
+ import { AnyFunction, TypeGuards } from '@codeleap/common'
4
+ import { AppIcon } from '@codeleap/styles'
5
5
 
6
6
  export type SearchInputProps = {
7
7
  placeholder: string
8
8
  clearable?: boolean
9
9
  debugName: string
10
- clearIcon?: IconPlaceholder
11
- searchIcon?: IconPlaceholder
10
+ clearIcon?: AppIcon
11
+ searchIcon?: AppIcon
12
12
  debounce?: number
13
13
  onSearchChange: (search: string) => void
14
14
  onTypingChange?: (isTyping: boolean) => void
@@ -17,7 +17,7 @@ export type SearchInputProps = {
17
17
  defaultValue?: string
18
18
  } & Partial<TextInputProps>
19
19
 
20
- export const SearchInput: ComponentWithDefaultProps<SearchInputProps> = (props) => {
20
+ export const SearchInput = (props: SearchInputProps) => {
21
21
  const {
22
22
  debugName,
23
23
  onSearchChange,
@@ -30,7 +30,7 @@ export const SearchInput: ComponentWithDefaultProps<SearchInputProps> = (props)
30
30
  debounce,
31
31
  value,
32
32
  onValueChange,
33
- defaultValue = '',
33
+ defaultValue,
34
34
  ...rest
35
35
  } = {
36
36
  ...SearchInput.defaultProps,
@@ -44,7 +44,6 @@ export const SearchInput: ComponentWithDefaultProps<SearchInputProps> = (props)
44
44
 
45
45
  const handleChangeSearch = (value: string) => {
46
46
  setSearch(value)
47
-
48
47
  if (TypeGuards.isNil(debounce)) {
49
48
  onSearchChange?.(value)
50
49
  } else {
@@ -92,6 +91,7 @@ export const SearchInput: ComponentWithDefaultProps<SearchInputProps> = (props)
92
91
  SearchInput.defaultProps = {
93
92
  debounce: null,
94
93
  clearable: true,
95
- clearIcon: 'x' as IconPlaceholder,
96
- searchIcon: 'search' as IconPlaceholder,
97
- }
94
+ clearIcon: 'x' as AppIcon,
95
+ searchIcon: 'search' as AppIcon,
96
+ defaultValue: '',
97
+ } as Partial<SearchInputProps>
@@ -1,18 +1,19 @@
1
1
  /* eslint-disable max-len */
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars */
3
3
  import React from 'react'
4
- import { TypeGuards, getNestedStylesByKey, useCallback, useDefaultComponentStyle, useMemo, useConditionalState } from '@codeleap/common'
5
- import { SectionFilterPresets } from './styles'
6
- import { ItemOptionProps, ItemProps, OnPressOptionProps, OptionProps, SectionFiltersProps, SectionFilterFooterProps, onSelectItemProps } from './types'
4
+ import { TypeGuards, useCallback, useMemo, useConditionalState } from '@codeleap/common'
5
+ import { ItemOptionProps, ItemProps, OnPressOptionProps, OptionProps, SectionFiltersProps, SectionFilterFooterProps } from './types'
7
6
  import { View } from '../View'
8
7
  import { Text } from '../Text'
9
8
  import { Button } from '../Button'
9
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
10
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
11
+ import { AnyRecord, IJSX, StyledComponentProps, useCompositionStyles } from '@codeleap/styles'
10
12
 
11
13
  export * from './styles'
12
14
  export * from './types'
13
15
 
14
16
  const ItemOption = (props: OptionProps) => {
15
-
16
17
  const {
17
18
  option,
18
19
  item,
@@ -49,24 +50,21 @@ const ItemOption = (props: OptionProps) => {
49
50
  return (
50
51
  <Button
51
52
  debugName='Item option'
52
- text={option?.label}
53
+ text={String(option?.label)}
53
54
  onPress={onPress}
54
55
  selected={isItemSelected}
55
- styles={styles}
56
56
  {...buttonProps}
57
+ style={styles}
57
58
  />
58
59
  )
59
60
  }
60
61
 
61
62
  export const SectionFilters = (props: SectionFiltersProps) => {
62
-
63
63
  const {
64
64
  data,
65
65
  onSelectItem,
66
66
  renderFooterComponent,
67
- responsiveVariants,
68
- variants,
69
- styles,
67
+ style,
70
68
  applyFilterButtonProps,
71
69
  clearFilterButtonProps,
72
70
  applyButtonText,
@@ -77,19 +75,9 @@ export const SectionFilters = (props: SectionFiltersProps) => {
77
75
  ...props,
78
76
  }
79
77
 
80
- const variantStyles = useDefaultComponentStyle<'u:SectionFilters', typeof SectionFilterPresets>(
81
- 'u:SectionFilters',
82
- {
83
- responsiveVariants,
84
- variants,
85
- styles,
86
- rootElement: 'wrapper',
87
- },
88
- )
78
+ const styles = useStylesFor(SectionFilters.styleRegistryName, style)
89
79
 
90
- const applyButtonStyles = getNestedStylesByKey('applyButton', variantStyles)
91
- const clearButtonStyles = getNestedStylesByKey('clearButton', variantStyles)
92
- const itemOptionButtonStyles = getNestedStylesByKey('itemOptionButton', variantStyles)
80
+ const compositionStyles = useCompositionStyles(['itemOptionButton', 'clearButton', 'applyButton'], styles)
93
81
 
94
82
  const [_selectedItems, _setSelectedItems] = useConditionalState(props?.selectedItems, props?.setSelectedItems, { initialValue: {}})
95
83
  const [_draft, _setDraft] = useConditionalState(props?.draftItems, props?.setDraftItems, { initialValue: {}})
@@ -98,7 +86,6 @@ export const SectionFilters = (props: SectionFiltersProps) => {
98
86
  const shouldDisableActions = Object.keys(_draft)?.length === 0 && Object.keys(_selectedItems)?.length === 0
99
87
 
100
88
  const onPressOption = useCallback((params: OnPressOptionProps) => {
101
-
102
89
  const { item, option, canSelectMultiple, hasMultipleOptions } = params
103
90
 
104
91
  _setDraft((state) => {
@@ -142,7 +129,6 @@ export const SectionFilters = (props: SectionFiltersProps) => {
142
129
  }, [_draft, onSelectItem])
143
130
 
144
131
  const renderItem = useCallback((item: ItemProps) => {
145
-
146
132
  const {
147
133
  showDescriptionLabel = true,
148
134
  } = item
@@ -153,7 +139,6 @@ export const SectionFilters = (props: SectionFiltersProps) => {
153
139
  const description = TypeGuards.isString(item?.descriptionLabel) ? item?.descriptionLabel : item?.label
154
140
 
155
141
  const Option = ({ option }: { option: ItemOptionProps}) => {
156
-
157
142
  if (TypeGuards.isNil(item?.id)) {
158
143
  return null
159
144
  }
@@ -163,7 +148,7 @@ export const SectionFilters = (props: SectionFiltersProps) => {
163
148
  option={option}
164
149
  item={item}
165
150
  selectedItems={_draft}
166
- styles={itemOptionButtonStyles}
151
+ styles={{ ...compositionStyles?.itemOptionButton }}
167
152
  onPress={() => onPressOption({ option, item, canSelectMultiple, hasMultipleOptions })}
168
153
  canSelectMultiple={canSelectMultiple}
169
154
  />
@@ -171,9 +156,9 @@ export const SectionFilters = (props: SectionFiltersProps) => {
171
156
  }
172
157
 
173
158
  return (
174
- <View style={variantStyles.optionWrapper}>
175
- {showDescriptionLabel ? <Text style={variantStyles.label} text={description} /> : null}
176
- <View style={variantStyles.optionInnerWrapper}>
159
+ <View style={styles.optionWrapper}>
160
+ {showDescriptionLabel && description ? <Text style={styles.label} text={`${description}`} /> : null}
161
+ <View style={styles.optionInnerWrapper}>
177
162
  {hasMultipleOptions ? (
178
163
  item?.options?.map?.((option) => <Option option={option} />)
179
164
  ) : (
@@ -188,26 +173,26 @@ export const SectionFilters = (props: SectionFiltersProps) => {
188
173
  </View>
189
174
  )
190
175
 
191
- }, [_draft, variantStyles, itemOptionButtonStyles])
176
+ }, [_draft, styles, compositionStyles?.itemOptionButton])
192
177
 
193
178
  const DefaultFooter = ({ onApply, onClear, shouldDisableActions }: SectionFilterFooterProps) => {
194
179
  return (
195
- <View style={variantStyles.footerWrapper}>
180
+ <View style={styles.footerWrapper}>
196
181
  <Button
197
- styles={applyButtonStyles}
198
182
  text={applyButtonText}
199
183
  debugName={`Section Filters Footer - Apply items`}
200
184
  onPress={onApply}
201
185
  disabled={shouldDisableActions}
202
186
  {...applyFilterButtonProps}
187
+ style={compositionStyles?.applyButton}
203
188
  />
204
189
  <Button
205
- styles={clearButtonStyles}
206
190
  text={clearButtonText}
207
191
  debugName={`Section Filters Footer - Apply items`}
208
192
  onPress={onClear}
209
193
  disabled={shouldDisableActions}
210
194
  {...clearFilterButtonProps}
195
+ style={compositionStyles?.clearButton}
211
196
  />
212
197
  </View>
213
198
  )
@@ -226,10 +211,14 @@ export const SectionFilters = (props: SectionFiltersProps) => {
226
211
 
227
212
  const Footer = renderFooterComponent || DefaultFooter
228
213
 
214
+ if (!data?.length) {
215
+ return null
216
+ }
217
+
229
218
  return (
230
- <View style={variantStyles.wrapper}>
231
- <View style={variantStyles.innerWrapper}>
232
- {isEmpty ? null : data.map((item) => renderItem(item))}
219
+ <View style={styles.wrapper}>
220
+ <View style={styles.innerWrapper}>
221
+ {isEmpty ? null : data?.map((item) => renderItem(item))}
233
222
  </View>
234
223
 
235
224
  <Footer
@@ -241,8 +230,30 @@ export const SectionFilters = (props: SectionFiltersProps) => {
241
230
  )
242
231
  }
243
232
 
233
+ SectionFilters.styleRegistryName = 'SectionFilters'
234
+
235
+ SectionFilters.elements = [
236
+ 'wrapper',
237
+ 'innerWrapper',
238
+ 'label',
239
+ 'optionWrapper',
240
+ 'optionInnerWrapper',
241
+ 'itemOptionButton',
242
+ 'footerWrapper',
243
+ 'applyButton',
244
+ 'clearButton',
245
+ ]
246
+
247
+ SectionFilters.rootElement = 'wrapper'
248
+
249
+ SectionFilters.withVariantTypes = <S extends AnyRecord>(styles: S) => {
250
+ return SectionFilters as (props: StyledComponentProps<SectionFiltersProps, typeof styles>) => IJSX
251
+ }
252
+
244
253
  SectionFilters.defaultProps = {
245
254
  applyButtonText: 'Filter',
246
255
  clearButtonText: 'Clear',
247
256
  filterOnOptionPress: false,
248
257
  }
258
+
259
+ WebStyleRegistry.registerComponent(SectionFilters)
@@ -1,4 +1,4 @@
1
- import { ButtonComposition, createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
+ import { ButtonComposition } from '@codeleap/common'
2
2
 
3
3
  export type SectionFiltersComposition =
4
4
  'wrapper' |
@@ -10,7 +10,3 @@ export type SectionFiltersComposition =
10
10
  'footerWrapper' |
11
11
  `applyButton${Capitalize<ButtonComposition>}` |
12
12
  `clearButton${Capitalize<ButtonComposition>}`
13
-
14
- const createSectionFiltersStyle = createDefaultVariantFactory<SectionFiltersComposition>()
15
-
16
- export const SectionFilterPresets = includePresets((styles) => createSectionFiltersStyle(() => ({ wrapper: styles })))
@@ -1,11 +1,12 @@
1
- import { Button, ButtonComposition } from '../Button'
2
- import { ComponentVariants, PropsOf, StylesOf } from '@codeleap/common'
3
- import { SectionFiltersComposition, SectionFilterPresets } from './styles'
1
+ import { ButtonComposition, ButtonProps } from '../Button'
2
+ import { StylesOf } from '@codeleap/common'
3
+ import { SectionFiltersComposition } from './styles'
4
+ import { StyledProp } from '@codeleap/styles'
4
5
 
5
6
  export type ItemOptionProps = {
6
- label?: string
7
+ label?: string | number
7
8
  value: string | number
8
- itemProps?: Omit<PropsOf<typeof Button>, 'debugName'>
9
+ itemProps?: Omit<ButtonProps, 'debugName'>
9
10
  }
10
11
 
11
12
  export type OnPressOptionProps = {
@@ -17,13 +18,13 @@ export type OnPressOptionProps = {
17
18
 
18
19
  export type ItemProps = {
19
20
  id: string | number
20
- label?: string
21
+ label?: string | number
21
22
  canSelectMultiple?: boolean
22
23
  descriptionLabel?: string
23
24
  showDescriptionLabel?: boolean
24
25
  options?: ItemOptionProps[]
25
- itemProps?: Omit<PropsOf<typeof Button>, 'debugName'>
26
- selectedItemProps?: Omit<PropsOf<typeof Button>, 'debugName'>
26
+ itemProps?: Omit<ButtonProps, 'debugName'>
27
+ selectedItemProps?: Omit<ButtonProps, 'debugName'>
27
28
  }
28
29
 
29
30
  export type onSelectItemProps = {
@@ -52,18 +53,18 @@ export type SectionFiltersProps = {
52
53
  onClearItems?: ClearFunction
53
54
  onApplyItems?: ApplyFunction
54
55
  renderFooterComponent?: (props: SectionFilterFooterProps) => JSX.Element
55
- applyFilterButtonProps?: Omit<PropsOf<typeof Button>, 'debugName'>
56
- clearFilterButtonProps?: Omit<PropsOf<typeof Button>, 'debugName'>
56
+ applyFilterButtonProps?: Omit<ButtonProps, 'debugName'>
57
+ clearFilterButtonProps?: Omit<ButtonProps, 'debugName'>
57
58
  filterOnOptionPress?: boolean
58
59
  applyButtonText?: string
59
60
  clearButtonText?: string
60
- styles?: StylesOf<SectionFiltersComposition>
61
- } & ComponentVariants<typeof SectionFilterPresets>
61
+ style?: StyledProp<SectionFiltersComposition>
62
+ }
62
63
 
63
64
  export type OptionProps = {
64
65
  option: ItemOptionProps
65
66
  item: ItemProps
66
- styles: Partial<StylesOf<ButtonComposition>>
67
+ styles: StylesOf<ButtonComposition>
67
68
  selectedItems: object
68
69
  onPress: () => void
69
70
  canSelectMultiple: boolean