@codeleap/web 3.24.2 → 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 -102
  24. package/src/components/CropPicker/styles.ts +0 -7
  25. package/src/components/CropPicker/types.ts +10 -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,87 +1,115 @@
1
- /* eslint-disable max-len */
2
1
  import React, { useCallback } from 'react'
3
- import { ActionIcon, Collapse, ColorPickerPresets, View } from '../components'
2
+ import { ActionIcon, Collapse, View } from '../components'
4
3
  import { HexColorPicker } from 'react-colorful'
5
- import { useBooleanToggle, useDefaultComponentStyle, useState } from '@codeleap/common'
6
- import { ColorPickerProps, ColorTypes } from './types'
4
+ import { TypeGuards, useConditionalState, useState } from '@codeleap/common'
5
+ import { ColorPickerProps, ColorTypes, ColorPickerFooterProps } from './types'
6
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
7
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
8
+ import { AnyRecord, AppIcon, IJSX, StyledComponentProps } from '@codeleap/styles'
7
9
 
8
10
  export * from './styles'
9
11
  export * from './types'
10
12
 
11
- const defaultProps = {
12
- pickerComponent: (props) => <HexColorPicker {...props}/>,
13
- icon: 'edit',
14
- clearIcon: 'trash',
15
- confirmIcon: 'check',
16
- showFooter: true,
13
+ const DefaultFooter = (props: ColorPickerFooterProps) => {
14
+ const { styles, clearIcon, handleClear, confirmIcon, handleConfirmation } = props
15
+
16
+ return (
17
+ <View style={styles.footerWrapper}>
18
+ <ActionIcon
19
+ debugName='ColorPicker footer trash'
20
+ name={clearIcon}
21
+ onPress={handleClear}
22
+ style={styles.clearIcon}
23
+ />
24
+ <ActionIcon
25
+ debugName='ColorPicker footer check'
26
+ name={confirmIcon}
27
+ onPress={handleConfirmation}
28
+ style={styles.confirmIcon}
29
+ />
30
+ </View>
31
+ )
17
32
  }
18
33
 
19
34
  export const ColorPicker = (props: ColorPickerProps) => {
20
35
  const {
21
- isPlain = false,
36
+ isPlain,
22
37
  initialColor,
23
38
  showFooter,
24
39
  icon,
40
+ style,
25
41
  clearIcon,
26
42
  confirmIcon,
27
- variants = [],
28
- styles = {},
29
- responsiveVariants = {},
30
43
  onConfirm,
31
44
  onClear,
32
- closeOnConfirm = true,
45
+ closeOnConfirm,
33
46
  pickerComponent: PickerComponent,
34
47
  openPickerComponent: OpenPickerComponent,
35
- footerComponent: FooterComponent = null,
48
+ footerComponent: FooterComponent,
36
49
  openPickerProps,
37
- } = props
38
- const [visible, toggle] = useBooleanToggle(false)
39
- const [color, setColor] = useState<ColorTypes>(initialColor)
50
+ } = {
51
+ ...ColorPicker.defaultProps,
52
+ ...props,
53
+ }
54
+
55
+ const styles = useStylesFor(ColorPicker.styleRegistryName, style)
40
56
 
41
- const variantStyles = useDefaultComponentStyle<'u:ColorPicker', typeof ColorPickerPresets>('u:ColorPicker', {
42
- variants,
43
- styles,
44
- responsiveVariants,
45
- })
57
+ const [visible, toggle] = useConditionalState(props?.visible, props?.toggle, { initialValue: false })
58
+
59
+ const [color, setColor] = useState<ColorTypes>(initialColor)
46
60
 
47
- const handleConfirmation = useCallback(() => {
61
+ const handleConfirmation = useCallback((color: ColorTypes) => {
48
62
  onConfirm?.(color)
49
- closeOnConfirm && toggle(false)
50
- }, [color])
63
+ if (closeOnConfirm) toggle(false)
64
+ }, [])
51
65
 
52
- const handleClear = useCallback(() => {
66
+ const handleClear = useCallback((initialColor: ColorTypes) => {
53
67
  setColor(initialColor)
54
- onClear?.()
55
- }, [initialColor])
56
-
57
- const Footer = useCallback(() => (
58
- <View style={variantStyles.footerWrapper}>
59
- <ActionIcon debugName='ColorPicker footer trash' name={clearIcon} onPress={handleClear} styles={variantStyles.footerButton} />
60
- <ActionIcon debugName='ColorPicker footer check' name={confirmIcon} onPress={handleConfirmation} styles={variantStyles.footerButton} />
61
- </View>
62
- ), [clearIcon, confirmIcon, handleClear, handleConfirmation])
68
+ if (TypeGuards.isFunction(onClear)) onClear?.()
69
+ }, [])
63
70
 
64
71
  // Dragging to change the color in any other way does not seem to work for some reason.
65
- const picker = <View style={variantStyles.picker}><PickerComponent color={color} onChange={setColor} /></View>
72
+ const picker = <View style={styles.picker}><PickerComponent color={color} onChange={setColor} /></View>
66
73
 
67
- const _footer = !!showFooter && FooterComponent ? <FooterComponent color={color} handleConfirmation={handleConfirmation} handleClear={handleClear}/> : <Footer/>
68
- const openColorPickerBtn = !!OpenPickerComponent ? <OpenPickerComponent color={color} visible={visible} toggle={toggle}/> : <ActionIcon onPress={toggle} icon={icon} {...openPickerProps}/>
74
+ const openColorPickerBtn = !!OpenPickerComponent ? (
75
+ <OpenPickerComponent
76
+ color={color}
77
+ visible={visible}
78
+ toggle={() => toggle(!visible)}
79
+ />
80
+ ) : (
81
+ <ActionIcon
82
+ onPress={() => toggle(!visible)}
83
+ icon={icon}
84
+ {...openPickerProps}
85
+ />
86
+ )
69
87
 
70
88
  return (
71
- <View style={variantStyles.wrapper}>
89
+ <View style={styles.wrapper}>
72
90
  {isPlain ? picker : (
73
91
  <>
74
92
  {openColorPickerBtn}
75
93
  <Collapse
76
94
  open={visible}
77
- styles={{ wrapper: [
78
- variantStyles.dropdown,
79
- visible && variantStyles['dropdown:open'],
80
- ] }}
95
+ style={[
96
+ styles.dropdown,
97
+ visible && styles['dropdown:open'],
98
+ ]}
81
99
  >
82
- <View style={variantStyles.dropdownInnerWrapper}>
100
+ <View style={styles.dropdownInnerWrapper}>
83
101
  {picker}
84
- {_footer}
102
+
103
+ {showFooter ? (
104
+ <FooterComponent
105
+ color={color}
106
+ handleConfirmation={() => handleConfirmation(color)}
107
+ handleClear={() => handleClear(initialColor)}
108
+ styles={styles}
109
+ clearIcon={clearIcon}
110
+ confirmIcon={confirmIcon}
111
+ />
112
+ ) : null}
85
113
  </View>
86
114
  </Collapse>
87
115
  </>
@@ -90,4 +118,23 @@ export const ColorPicker = (props: ColorPickerProps) => {
90
118
  )
91
119
  }
92
120
 
93
- ColorPicker.defaultProps = defaultProps
121
+ ColorPicker.styleRegistryName = 'ColorPicker'
122
+ ColorPicker.elements = ['wrapper', 'picker', 'dropdown', 'dropdownInnerWrapper', 'footerWrapper', 'clearIcon', 'confirmIcon']
123
+ ColorPicker.rootElement = 'wrapper'
124
+
125
+ ColorPicker.withVariantTypes = <S extends AnyRecord>(styles: S) => {
126
+ return ColorPicker as (props: StyledComponentProps<ColorPickerProps, typeof styles>) => IJSX
127
+ }
128
+
129
+ ColorPicker.defaultProps = {
130
+ pickerComponent: (props) => <HexColorPicker {...props} />,
131
+ footerComponent: DefaultFooter,
132
+ icon: 'edit' as AppIcon,
133
+ clearIcon: 'trash' as AppIcon,
134
+ confirmIcon: 'check' as AppIcon,
135
+ showFooter: true,
136
+ isPlain: false,
137
+ closeOnConfirm: true,
138
+ } as Partial<ColorPickerProps>
139
+
140
+ WebStyleRegistry.registerComponent(ColorPicker)
@@ -1,13 +1,13 @@
1
- import { PartialComponentStyle, createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
- import { ActionIconComposition } from '../ActionIcon'
3
-
4
1
  type ColorPickerState = 'open'
5
- export type ColorPickerParts = 'wrapper' | 'picker' | 'dropdown' | `dropdown:${ColorPickerState}` | 'dropdownInnerWrapper' | 'footerWrapper'
6
-
7
- export type ColorPickerComposition = {
8
- footerButton?: PartialComponentStyle<ActionIconComposition, any>
9
- } & {[x in ColorPickerParts]?: any}
10
-
11
- const createColorPickerStyle = createDefaultVariantFactory<'', ColorPickerComposition>()
12
2
 
13
- export const ColorPickerPresets = includePresets((styles) => createColorPickerStyle(() => ({ wrapper: styles })))
3
+ export type ColorPickerParts =
4
+ 'wrapper' |
5
+ 'picker' |
6
+ 'dropdown' |
7
+ `dropdown:${ColorPickerState}` |
8
+ 'dropdownInnerWrapper' |
9
+ 'footerWrapper' |
10
+ 'clearIcon' |
11
+ 'confirmIcon'
12
+
13
+ export type ColorPickerComposition = ColorPickerParts
@@ -1,25 +1,39 @@
1
1
  import React from 'react'
2
- import { ActionIconProps, IconProps } from '../components'
2
+ import { ActionIconProps, ColorPickerComposition } from '../components'
3
+ import { AppIcon, ICSS, StyledProp } from '@codeleap/styles'
3
4
  import { RgbColor, RgbaColor, HslColor, HsvColor, HslaColor, HsvaColor } from 'react-colorful'
4
- import { ComponentVariants } from '@codeleap/common'
5
- import { ColorPickerComposition, ColorPickerPresets } from './styles'
6
5
 
7
6
  export type ColorTypes = RgbColor | HslColor | HsvColor | RgbaColor | HslaColor | HsvaColor | string
8
7
 
9
- export type ColorPickerProps = React.PropsWithChildren<{
10
- styles?: ColorPickerComposition
11
- style?: React.CSSProperties
8
+ export type ColorPickerFooterProps = Pick<ColorPickerProps, 'confirmIcon' | 'clearIcon'> & {
9
+ color?: ColorTypes
10
+ handleConfirmation: (value: ColorTypes) => void
11
+ handleClear: (value: ColorTypes) => void
12
+ styles: Record<ColorPickerComposition, ICSS>
13
+ }
14
+
15
+ export type ColorPickerPickerProps = {
16
+ color: ColorTypes
17
+ visible: boolean
18
+ toggle: (v?: boolean) => void
19
+ }
20
+
21
+ export type ColorPickerProps = {
22
+ style?: StyledProp<ColorPickerComposition>
12
23
  isPlain?: boolean
13
24
  closeOnConfirm?: boolean
14
25
  initialColor?: ColorTypes
15
26
  showFooter?: boolean
16
- icon?: IconProps['name']
17
- clearIcon?: IconProps['name']
18
- confirmIcon?: IconProps['name']
27
+ icon?: AppIcon
28
+ clearIcon?: AppIcon
29
+ confirmIcon?: AppIcon
19
30
  openPickerProps?: ActionIconProps
20
31
  onConfirm?: (color: ColorTypes) => void
21
32
  onClear?: () => void
22
- openPickerComponent?: (props: { color: ColorTypes; visible: boolean; toggle: (v?: boolean) => void }) => JSX.Element
33
+ openPickerComponent?: (props: ColorPickerPickerProps) => JSX.Element
23
34
  pickerComponent?: (props: any) => JSX.Element
24
- footerComponent?: (props: {color: ColorTypes; handleConfirmation: () => void; handleClear: () => void}) => JSX.Element
25
- } & ComponentVariants<typeof ColorPickerPresets>>
35
+ footerComponent?: (props: ColorPickerFooterProps) => JSX.Element
36
+ visible?: boolean
37
+ toggle?: React.Dispatch<React.SetStateAction<boolean>>
38
+ children?: React.ReactNode
39
+ }
@@ -1,117 +1,115 @@
1
- import React, { forwardRef } from 'react'
2
- import {
3
- getNestedStylesByKey,
4
- useDefaultComponentStyle,
5
- } from '@codeleap/common'
6
- import { CropPickerPresets } from './styles'
1
+ import React, { forwardRef, Ref } from 'react'
2
+ import { StyledComponentWithProps, useCompositionStyles } from '@codeleap/styles'
7
3
  import { CropPickerProps } from './types'
8
- import { useCropPicker } from './useCropPicker'
9
- import { Modal, Button, FileInput, FileInputRef, LoadingOverlay } from '../components'
4
+ import { useCropPicker } from '../../lib'
5
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
6
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
7
+ import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
8
+ import { FileInput, FileInputRef } from '../FileInput'
9
+ import { Modal } from '../Modal'
10
+ import { Button } from '../Button'
11
+ import { LoadingOverlay } from '../LoadingOverlay'
10
12
 
11
13
  const ReactCrop: React.ElementType = require('react-image-crop').Component
14
+
12
15
  import 'react-image-crop/dist/ReactCrop.css'
13
16
 
14
17
  export * from './styles'
15
18
  export * from './types'
16
- export * from './utils'
17
- export * from './useCropPicker'
18
19
 
19
- export const _CropPicker = forwardRef<FileInputRef, CropPickerProps>(
20
- (props: CropPickerProps, ref) => {
21
- const allProps = {
22
- // @ts-ignore
23
- ...CropPicker.defaultProps,
24
- ...props,
25
- }
20
+ export const CropPicker = forwardRef<FileInputRef, CropPickerProps>((props, ref) => {
21
+ const {
22
+ onFileSelect,
23
+ targetCrop,
24
+ modalProps,
25
+ title,
26
+ confirmButton,
27
+ debugName,
28
+ handle,
29
+ withLoading,
30
+ style,
31
+ confirmButtonProps,
32
+ ...fileInputProps
33
+ } = {
34
+ ...CropPicker.defaultProps,
35
+ ...props,
36
+ }
26
37
 
27
- const {
28
- onFileSelect,
29
- targetCrop,
30
- variants = [],
31
- responsiveVariants = {},
32
- styles = {},
33
- modalProps = {},
34
- title = 'Crop Image',
35
- confirmButton = 'Confirm Crop',
36
- debugName,
37
- handle,
38
- withLoading = false,
39
- ...fileInputProps
40
- } = allProps
38
+ const {
39
+ onConfirmCrop,
40
+ onFilesReturned,
41
+ onClose,
42
+ fileInputRef,
43
+ visible,
44
+ image,
45
+ crop,
46
+ setRelativeCrop,
47
+ isLoading,
48
+ handleCropChange,
49
+ } = handle || useCropPicker({ onFileSelect, ref: ref as unknown as Ref<FileInputRef>, ...targetCrop })
41
50
 
42
- const {
43
- onConfirmCrop,
44
- onFilesReturned,
45
- onClose,
46
- fileInputRef,
47
- visible,
48
- image,
49
- crop,
50
- setRelativeCrop,
51
- isLoading,
52
- handleCropChange,
53
- } = handle || useCropPicker({ onFileSelect, ref, ...targetCrop })
51
+ const styles = useStylesFor(CropPicker.styleRegistryName, style)
54
52
 
55
- const variantStyles = useDefaultComponentStyle<
56
- 'u:CropPicker',
57
- typeof CropPickerPresets
58
- >('u:CropPicker', {
59
- variants,
60
- responsiveVariants,
61
- styles,
62
- })
53
+ const composition = useCompositionStyles(['confirmButton', 'modal'], styles)
63
54
 
64
- const buttonStyles = getNestedStylesByKey('confirmButton', variantStyles)
65
- const modalStyles = getNestedStylesByKey('modal', variantStyles)
55
+ return (
56
+ <>
57
+ <FileInput
58
+ // @ts-ignore
59
+ ref={fileInputRef}
60
+ onChange={(files) => onFilesReturned(files)}
61
+ {...fileInputProps}
62
+ />
66
63
 
67
- return (
68
- <>
69
- <FileInput
70
- ref={fileInputRef}
71
- onChange={(files) => onFilesReturned(files)}
72
- {...fileInputProps}
73
- />
74
- <Modal
75
- visible={visible}
76
- toggle={onClose}
77
- title={title}
78
- styles={modalStyles}
79
- footer={
80
- <Button
81
- text={confirmButton}
82
- styles={buttonStyles}
83
- onPress={onConfirmCrop}
84
- debugName={debugName}
64
+ <Modal
65
+ visible={visible}
66
+ toggle={onClose}
67
+ title={title}
68
+ footer={
69
+ <Button
70
+ text={confirmButton}
71
+ style={composition?.confirmButton}
72
+ onPress={onConfirmCrop}
73
+ debugName={debugName}
74
+ {...confirmButtonProps}
75
+ />
76
+ }
77
+ {...modalProps}
78
+ style={composition?.modal}
79
+ >
80
+ {!!image?.src ? (
81
+ <ReactCrop
82
+ crop={crop}
83
+ onChange={handleCropChange}
84
+ onComplete={(_, relCrop) => setRelativeCrop(relCrop)}
85
+ {...targetCrop}
86
+ style={styles.previewSize}
87
+ >
88
+ <img
89
+ src={image?.src}
90
+ // @ts-expect-error
91
+ css={[styles.cropPreview, styles.previewSize]}
85
92
  />
86
- }
87
- {...modalProps}
88
- >
89
- {!!image?.src && (
90
- <ReactCrop
91
- crop={crop}
92
- onChange={handleCropChange}
93
- onComplete={(_, relCrop) => setRelativeCrop(relCrop)}
94
- style={variantStyles.previewSize}
95
- {...targetCrop}
96
- >
97
- <img
98
- src={image?.src}
99
- css={[variantStyles.cropPreview, variantStyles.previewSize]}
100
- />
101
- </ReactCrop>
102
- )}
103
- {
104
- withLoading ? (
105
- <LoadingOverlay
106
- debugName='CropPicker'
107
- visible={isLoading}
108
- />
109
- ) : null
110
- }
111
- </Modal>
112
- </>
113
- )
114
- },
115
- )
93
+ </ReactCrop>
94
+ ) : null}
95
+ {withLoading ? <LoadingOverlay debugName='CropPicker' visible={isLoading} /> : null}
96
+ </Modal>
97
+ </>
98
+ )
99
+ }) as StyledComponentWithProps<CropPickerProps>
100
+
101
+ CropPicker.styleRegistryName = 'CropPicker'
102
+ CropPicker.elements = ['previewSize', 'cropPreview', 'confirmButton', 'modal']
103
+ CropPicker.rootElement = 'previewSize'
104
+
105
+ CropPicker.withVariantTypes = <S extends AnyRecord>(styles: S) => {
106
+ return CropPicker as (props: StyledComponentProps<CropPickerProps, typeof styles>) => IJSX
107
+ }
108
+
109
+ CropPicker.defaultProps = {
110
+ title: 'Crop Image',
111
+ confirmButton: 'Confirm Crop',
112
+ withLoading: false,
113
+ } as Partial<CropPickerProps>
116
114
 
117
- export const CropPicker = React.memo(_CropPicker)
115
+ WebStyleRegistry.registerComponent(CropPicker)
@@ -1,4 +1,3 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { ButtonComposition } from '../Button'
3
2
  import { ModalComposition } from '../Modal'
4
3
 
@@ -7,9 +6,3 @@ export type CropPickerComposition =
7
6
  | 'previewSize'
8
7
  | `confirmButton${Capitalize<ButtonComposition>}`
9
8
  | `modal${Capitalize<ModalComposition>}`
10
-
11
- const createCropPickerStyle =
12
- createDefaultVariantFactory<CropPickerComposition>()
13
-
14
- export const CropPickerPresets = includePresets((style) => createCropPickerStyle(() => ({ modalWrapper: style })),
15
- )
@@ -1,30 +1,25 @@
1
- import { AnyRef, ComponentVariants } from '@codeleap/common'
2
- import { FileInputProps, FileInputRef } from '../FileInput'
3
- import { CropPickerComposition, CropPickerPresets } from './styles'
4
- import { StylesOf } from '../../types'
1
+ import { StyledProp } from '@codeleap/styles'
2
+ import { FileInputProps } from '../FileInput'
3
+ import { CropPickerComposition } from './styles'
5
4
  import { ReactCropProps } from 'react-image-crop'
6
5
  import { ModalProps } from '../Modal'
7
- import { useCropPicker } from './useCropPicker'
6
+ import { useCropPicker } from '../../lib'
7
+ import { ButtonProps } from '../Button'
8
8
 
9
9
  export type BaseCropProps = Partial<ReactCropProps>
10
10
 
11
- export type CropPickerProps = Partial<FileInputProps> &
12
- ComponentVariants<typeof CropPickerPresets> & {
13
- styles?: StylesOf<CropPickerComposition>
14
- style?: React.CSSProperties
11
+ export type CropPickerProps =
12
+ Partial<FileInputProps> &
13
+ {
14
+ style?: StyledProp<CropPickerComposition>
15
15
  targetCrop?: BaseCropProps
16
16
  modalProps?: Partial<ModalProps>
17
17
  title?: string
18
18
  confirmButton?: string
19
19
  debugName: string
20
20
  handle?: ReturnType<typeof useCropPicker>
21
- ref: AnyRef<HTMLElement>
22
21
  withLoading?: boolean
22
+ confirmButtonProps?: Partial<ButtonProps>
23
23
  }
24
24
 
25
25
  export type ImageReading = HTMLImageElement
26
-
27
- export type UseCropPickerProps = Partial<ReactCropProps> & {
28
- onFileSelect: FileInputProps['onFileSelect']
29
- ref: React.MutableRefObject<FileInputRef> | React.Ref<FileInputRef>
30
- }
@@ -1,20 +1,13 @@
1
- import {
2
- IconPlaceholder,
3
- TypeGuards,
4
- getNestedStylesByKey,
5
- } from '@codeleap/common'
1
+ import { TypeGuards } from '@codeleap/common'
6
2
  import { ActionIcon, Text, View } from '../../components'
7
3
  import { DatePickerArrowProps, DatePickerHeaderComponent } from '../types'
8
4
  import { format, getYear } from 'date-fns'
5
+ import { AppIcon, useCompositionStyles } from '@codeleap/styles'
9
6
 
10
- export const ArrowLabel: React.FC<DatePickerArrowProps> = ({
11
- name,
12
- direction,
13
- ...props
14
- }) => {
7
+ export const ArrowLabel = ({ name, direction, ...props }: DatePickerArrowProps) => {
15
8
  return (
16
9
  <ActionIcon
17
- name={name ?? (`chevron-${direction}` as IconPlaceholder)}
10
+ name={name ?? (`chevron-${direction}` as AppIcon)}
18
11
  debugName={'Calendar arrowLabel'}
19
12
  {...props}
20
13
  />
@@ -44,15 +37,14 @@ export const Header = (props: DatePickerHeaderComponent) => {
44
37
  ? formatHeaderTitle(date)
45
38
  : `${month} ${year}`
46
39
 
47
- const prevArrow = getNestedStylesByKey('prevButton', styles)
48
- const nextArrow = getNestedStylesByKey('nextButton', styles)
40
+ const compositionStyles = useCompositionStyles(['prevButton', 'nextButton'], styles)
49
41
 
50
42
  return (
51
43
  <View style={styles.wrapper}>
52
44
  <View style={styles.buttonsWrapper}>
53
45
  <ArrowLabel
54
46
  direction='left'
55
- styles={prevArrow}
47
+ style={compositionStyles.prevButton}
56
48
  onPress={decreaseYear}
57
49
  disabled={prevYearButtonDisabled}
58
50
  />
@@ -63,7 +55,7 @@ export const Header = (props: DatePickerHeaderComponent) => {
63
55
  />
64
56
  <ArrowLabel
65
57
  direction='right'
66
- styles={nextArrow}
58
+ style={compositionStyles.nextButton}
67
59
  onPress={increaseYear}
68
60
  disabled={nextYearButtonDisabled}
69
61
  />
@@ -71,13 +63,13 @@ export const Header = (props: DatePickerHeaderComponent) => {
71
63
  <View style={styles.buttonsWrapper}>
72
64
  <ArrowLabel
73
65
  direction='left'
74
- styles={prevArrow}
66
+ style={compositionStyles.prevButton}
75
67
  onPress={decreaseMonth}
76
68
  disabled={prevMonthButtonDisabled}
77
69
  />
78
70
  <ArrowLabel
79
71
  direction='right'
80
- styles={nextArrow}
72
+ style={compositionStyles.nextButton}
81
73
  onPress={increaseMonth}
82
74
  disabled={nextMonthButtonDisabled}
83
75
  />
@@ -1,13 +1,12 @@
1
1
  import { TextInput } from '../../components'
2
2
  import { DatePickerProps } from '../types'
3
3
 
4
- export const OuterInput: DatePickerProps['outerInputComponent'] = ({
5
- valueLabel,
6
- focused,
7
- hideInput,
8
- ...props
9
- }) => {
10
- return hideInput ? null : (
4
+ export const OuterInput: DatePickerProps['outerInputComponent'] = ({ valueLabel, focused, hideInput, ...props }) => {
5
+ if (hideInput) {
6
+ return null
7
+ }
8
+
9
+ return (
11
10
  <TextInput
12
11
  validate={!focused && props?.validate}
13
12
  debugName='DatePicker - OuterInputComponent'