@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,62 +1,25 @@
1
1
  import React from 'react'
2
- import {
3
- useDefaultComponentStyle,
4
- ComponentVariants,
5
- AnyFunction,
6
- TypeGuards,
7
- IconPlaceholder,
8
- StylesOf,
9
- } from '@codeleap/common'
2
+ import { TypeGuards, StylesOf } from '@codeleap/common'
10
3
  import { Text } from '../Text'
11
- import { Touchable, TouchableProps } from '../Touchable'
4
+ import { Touchable } from '../Touchable'
12
5
  import { Icon } from '../Icon'
13
- import { ActivityIndicator, ActivityIndicatorProps } from '../ActivityIndicator'
14
- import { ButtonComposition, ButtonPresets, ButtonParts } from './styles'
15
- import { ComponentCommonProps } from '../../types'
16
-
17
- /** * Button */
18
- export type ButtonProps =
19
- ComponentVariants<typeof ButtonPresets> &
20
- Partial<Omit<TouchableProps<'button'>, 'variants' | 'styles'>> &
21
- ComponentCommonProps & {
22
- /** prop */
23
- text?: string
24
- /** prop */
25
- rightIcon?: IconPlaceholder
26
- /** prop */
27
- icon?: IconPlaceholder
28
- /** prop */
29
- onPress?: AnyFunction
30
- styles?: StylesOf<ButtonComposition>
31
- style?: React.CSSProperties
32
- /** prop */
33
- loading?: boolean
34
- loadingShowText?: boolean
35
- /** prop */
36
- debugName: string
37
- /** prop */
38
- debounce?: number
39
- /** prop */
40
- selected?: boolean
41
- children?: React.ReactNode | ((props: Partial<Omit<ButtonProps, 'children'>>) => JSX.Element)
42
- loaderProps?: Partial<ActivityIndicatorProps>
43
- }
6
+ import { ActivityIndicator } from '../ActivityIndicator'
7
+ import { ButtonParts } from './styles'
8
+ import { ButtonProps } from './types'
9
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
10
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
11
+ import { AnyRecord, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
44
12
 
45
- const defaultProps: Partial<ButtonProps> = {
46
- debounce: 600,
47
- loadingShowText: false,
48
- }
13
+ export * from './styles'
14
+ export * from './types'
49
15
 
50
16
  export const Button = (buttonProps: ButtonProps) => {
51
17
  const allProps = {
52
18
  ...Button.defaultProps,
53
- ...buttonProps
19
+ ...buttonProps,
54
20
  }
55
21
 
56
22
  const {
57
- variants = [],
58
- responsiveVariants = {},
59
- styles = {},
60
23
  children,
61
24
  icon,
62
25
  text,
@@ -66,76 +29,70 @@ export const Button = (buttonProps: ButtonProps) => {
66
29
  disabled,
67
30
  rightIcon,
68
31
  selected,
69
- loaderProps = {},
32
+ loaderProps,
70
33
  debugName,
71
- style = {},
34
+ style,
72
35
  ...props
73
36
  } = allProps
74
37
 
75
- const variantStyles = useDefaultComponentStyle<'u:Button', typeof ButtonPresets>('u:Button', {
76
- responsiveVariants,
77
- variants,
78
- styles,
79
- rootElement: 'wrapper',
80
- })
38
+ const styles = useStylesFor(Button.styleRegistryName, style)
81
39
 
82
- const getStyles = (key: ButtonParts) => ({
83
- ...variantStyles?.[key],
84
- ...(disabled ? variantStyles?.[key + ':disabled'] : {}),
85
- ...(selected ? variantStyles?.[key + ':selected'] : {})
86
- })
40
+ const getStyles = (key: ButtonParts, partialStyle = null) => mergeStyles([
41
+ styles?.[key],
42
+ disabled ? styles?.[key + ':disabled'] : null,
43
+ selected ? styles?.[key + ':selected'] : null,
44
+ partialStyle,
45
+ ])
87
46
 
88
47
  const iconStyles = getStyles('icon')
89
48
 
90
- const _styles: StylesOf<ButtonParts> = {
49
+ const componentStyles: StylesOf<ButtonParts> = {
91
50
  wrapper: getStyles('wrapper'),
92
51
  text: getStyles('text'),
93
52
  loaderWrapper: getStyles('loaderWrapper'),
94
- leftIcon: {
95
- ...iconStyles,
96
- ...getStyles('leftIcon'),
97
- },
98
- rightIcon: {
99
- ...iconStyles,
100
- ...getStyles('rightIcon')
101
- },
53
+ leftIcon: getStyles('leftIcon', iconStyles),
54
+ rightIcon: getStyles('rightIcon', iconStyles),
102
55
  }
103
56
 
104
- const childrenContent = TypeGuards.isFunction(children)
105
- // @ts-ignore
106
- ? children(allProps)
107
- : children
108
-
109
57
  // TODO - This is a hack to hide the icon with display: none
110
- const isLeftIconHide = _styles?.leftIcon?.display === 'none'
58
+ const isLeftIconHide = componentStyles?.leftIcon?.display === 'none'
111
59
 
112
- const shouldRenderLeftIcon = !loading && !isLeftIconHide
60
+ const shouldRenderLeftIcon = !loading && !isLeftIconHide && !!icon
113
61
 
114
62
  const _hideTextOnLoading = !loadingShowText && loading
115
63
 
116
64
  return (
117
65
  <Touchable
118
- css={[_styles.wrapper, style]}
119
66
  component='button'
120
67
  debugComponent='Button'
121
68
  disabled={disabled}
122
69
  onPress={onPress}
123
70
  debugName={debugName}
124
71
  {...props}
72
+ style={componentStyles.wrapper}
125
73
  >
126
- {shouldRenderLeftIcon && <Icon debugName={debugName} name={icon} style={_styles.leftIcon} />}
127
- {TypeGuards.isString(text) && !_hideTextOnLoading ? <Text debugName={debugName} text={text} css={[_styles.text]} /> : null }
128
-
129
- {childrenContent}
130
-
131
- <Icon debugName={debugName} name={rightIcon} style={_styles.rightIcon}/>
132
- {loading && (
133
- <ActivityIndicator debugName={debugName} style={_styles.loaderWrapper} {...loaderProps} />
134
- )}
74
+ {shouldRenderLeftIcon ? <Icon debugName={debugName} name={icon} style={componentStyles.leftIcon} /> : null}
75
+ {TypeGuards.isString(text) && !_hideTextOnLoading ? <Text debugName={debugName} text={text} style={componentStyles.text} /> : null}
76
+
77
+ {children}
78
+
79
+ {loading ? <ActivityIndicator debugName={debugName} {...loaderProps} style={componentStyles.loaderWrapper} /> : null}
80
+ {!!rightIcon ? <Icon debugName={debugName} name={rightIcon} style={componentStyles.rightIcon} /> : null}
135
81
  </Touchable>
136
82
  )
137
83
  }
138
84
 
139
- Button.defaultProps = defaultProps
85
+ Button.styleRegistryName = 'Button'
86
+ Button.elements = ['wrapper', 'text', 'icon', 'leftIcon', 'rightIcon', `loader`]
87
+ Button.rootElement = 'wrapper'
140
88
 
141
- export * from './styles'
89
+ Button.withVariantTypes = <S extends AnyRecord>(styles: S) => {
90
+ return Button as (props: StyledComponentProps<ButtonProps, typeof styles>) => IJSX
91
+ }
92
+
93
+ Button.defaultProps = {
94
+ debounce: 600,
95
+ loadingShowText: false,
96
+ } as Partial<ButtonProps>
97
+
98
+ WebStyleRegistry.registerComponent(Button)
@@ -1,4 +1,3 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { ActivityIndicatorComposition } from '../ActivityIndicator'
3
2
 
4
3
  export type ButtonStates = 'disabled' | 'selected'
@@ -12,7 +11,3 @@ export type ButtonParts =
12
11
  | `loader${Capitalize<ActivityIndicatorComposition>}`
13
12
 
14
13
  export type ButtonComposition = `${ButtonParts}:${ButtonStates}` | ButtonParts
15
-
16
- const createButtonStyle = createDefaultVariantFactory<ButtonComposition>()
17
-
18
- export const ButtonPresets = includePresets((styles) => createButtonStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,25 @@
1
+ import React from 'react'
2
+ import { AnyFunction } from '@codeleap/common'
3
+ import { AppIcon, StyledProp } from '@codeleap/styles'
4
+ import { TouchableProps } from '../Touchable'
5
+ import { ActivityIndicatorProps } from '../ActivityIndicator'
6
+ import { ButtonComposition } from './styles'
7
+ import { ComponentCommonProps } from '../../types'
8
+
9
+ export type ButtonProps =
10
+ Omit<TouchableProps, 'style'> &
11
+ ComponentCommonProps &
12
+ {
13
+ text?: string
14
+ rightIcon?: AppIcon
15
+ icon?: AppIcon
16
+ onPress?: AnyFunction
17
+ style?: StyledProp<ButtonComposition>
18
+ loading?: boolean
19
+ loadingShowText?: boolean
20
+ debugName: string
21
+ debounce?: number
22
+ selected?: boolean
23
+ children?: React.ReactNode
24
+ loaderProps?: Partial<ActivityIndicatorProps>
25
+ }
@@ -1,93 +1,61 @@
1
- /** @jsx jsx */
2
- import { jsx, CSSObject } from '@emotion/react'
3
- import {
4
- ComponentVariants,
5
- useDefaultComponentStyle,
6
- StylesOf,
7
- PropsOf,
8
- IconPlaceholder,
9
- } from '@codeleap/common'
10
- import { View } from '../View'
11
- import { CheckboxPresets, CheckboxComposition } from './styles'
12
- import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
1
+ import { InputBase, InputBaseDefaultOrder, selectInputBaseProps } from '../InputBase'
13
2
  import { useAnimatedVariantStyles } from '../..'
14
3
  import { Icon } from '../Icon'
15
4
  import { motion } from 'framer-motion'
16
- import { ComponentCommonProps } from '../../types/utility'
5
+ import { CheckboxProps } from './types'
6
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
7
+ import { AnyRecord, AppIcon, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
8
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
9
+ import { CheckboxParts } from './styles'
10
+ import { TypeGuards } from '@codeleap/common'
17
11
 
18
12
  export * from './styles'
19
-
20
- /** * Checkbox */
21
- export type CheckboxProps = Pick<
22
- InputBaseProps,
23
- 'debugName' | 'disabled' | 'label'
24
- > & ComponentCommonProps & {
25
- styles?: StylesOf<CheckboxComposition>
26
- /** prop */
27
- value: boolean
28
- /** prop */
29
- onValueChange: (value: boolean) => void
30
- style?: PropsOf<typeof View>['style']
31
- /** prop */
32
- checkboxOnLeft?: boolean
33
- /** prop */
34
- checkIcon?: IconPlaceholder
35
- } & ComponentVariants<typeof CheckboxPresets>
13
+ export * from './types'
36
14
 
37
15
  const reversedOrder = [...InputBaseDefaultOrder].reverse()
38
16
 
39
- const defaultProps: Partial<CheckboxProps> = {
40
- checkIcon: 'check' as IconPlaceholder,
41
- }
42
-
43
17
  export const Checkbox = (props: CheckboxProps) => {
44
18
  const {
45
19
  inputBaseProps,
46
- others,
47
- } = selectInputBaseProps(props)
20
+ others: checkboxProps,
21
+ } = selectInputBaseProps({
22
+ ...Checkbox.defaultProps,
23
+ ...props,
24
+ })
48
25
 
49
26
  const {
50
- responsiveVariants = {},
51
- variants = [],
52
- style = {},
53
- styles = {},
27
+ style,
54
28
  value,
55
29
  disabled,
56
30
  debugName,
57
31
  onValueChange,
58
32
  checkboxOnLeft,
59
33
  checkIcon,
60
- } = others
34
+ } = checkboxProps
61
35
 
62
- const variantStyles = useDefaultComponentStyle<'u:Checkbox', typeof CheckboxPresets>('u:Checkbox', {
63
- responsiveVariants,
64
- variants,
65
- styles,
66
- rootElement: 'wrapper',
67
- })
36
+ const styles = useStylesFor(Checkbox.styleRegistryName, style)
68
37
 
69
38
  const boxAnimation = useAnimatedVariantStyles({
70
- variantStyles,
39
+ variantStyles: styles,
71
40
  animatedProperties: ['box:unchecked', 'box:disabled', 'box:checked', 'box:disabled-checked', 'box:disabled-unchecked'],
72
41
  updater: () => {
73
42
  'worklet'
74
43
  let disabledStyle = {}
75
44
  if (disabled) {
76
- disabledStyle = value ? variantStyles['box:disabled-checked'] : variantStyles['box:disabled-unchecked']
45
+ disabledStyle = value ? styles['box:disabled-checked'] : styles['box:disabled-unchecked']
77
46
  }
78
- const style = value ? variantStyles['box:checked'] : variantStyles['box:unchecked']
47
+ const style = value ? styles['box:checked'] : styles['box:unchecked']
79
48
 
80
49
  return {
81
50
  ...style,
82
51
  ...disabledStyle,
83
52
  }
84
-
85
53
  },
86
54
  dependencies: [value, disabled],
87
55
  })
88
56
 
89
57
  const checkmarkWrapperAnimation = useAnimatedVariantStyles({
90
- variantStyles,
58
+ variantStyles: styles,
91
59
  animatedProperties: [
92
60
  'checkmarkWrapper:unchecked',
93
61
  'checkmarkWrapper:disabled',
@@ -99,69 +67,87 @@ export const Checkbox = (props: CheckboxProps) => {
99
67
  'worklet'
100
68
  let disabledStyle = {}
101
69
  if (disabled) {
102
- disabledStyle = value ? variantStyles['checkmarkWrapper:disabled-checked'] : variantStyles['checkmarkWrapper:disabled-unchecked']
70
+ disabledStyle = value ? styles['checkmarkWrapper:disabled-checked'] : styles['checkmarkWrapper:disabled-unchecked']
103
71
  }
104
- const style = value ? variantStyles['checkmarkWrapper:checked'] : variantStyles['checkmarkWrapper:unchecked']
72
+ const style = value ? styles['checkmarkWrapper:checked'] : styles['checkmarkWrapper:unchecked']
105
73
  return {
106
74
  ...style,
107
75
  ...disabledStyle,
108
76
  }
109
-
110
77
  },
111
78
  dependencies: [value, disabled],
112
79
  })
113
80
 
114
- const _checkboxOnLeft = checkboxOnLeft ?? variantStyles.__props?.checkboxOnLeft
81
+ // @ts-expect-error __props is ICSS
82
+ const _checkboxOnLeft = checkboxOnLeft ?? styles?.__props?.checkboxOnLeft
115
83
 
116
84
  const handleChange = (e) => {
117
- const isSpaceBarClick = e?.keyCode === 32
118
85
  if (disabled) return
119
- if (onValueChange && (e?.type === 'click' || e?.keyCode === 13 || isSpaceBarClick || e?.key === 'Enter')) onValueChange?.(!value)
86
+ if (!TypeGuards.isFunction(onValueChange)) return
87
+
88
+ const isSpaceBarClick = e?.keyCode === 32
89
+ const isEnterKey = e?.key === 'Enter'
90
+ const isClick = e?.type === 'click'
91
+
92
+ if (isClick || e?.keyCode === 13 || isSpaceBarClick || isEnterKey) {
93
+ onValueChange?.(!value)
94
+ }
120
95
  }
121
96
 
122
- return <InputBase
123
- {...inputBaseProps}
124
- debugName={debugName}
125
- styles={{
126
- ...variantStyles,
127
- innerWrapper: [
128
- variantStyles.innerWrapper,
129
- ],
130
- }}
131
- order={_checkboxOnLeft ? reversedOrder : InputBaseDefaultOrder}
132
- style={style}
133
- >
134
- <motion.div
135
- css={[
136
- variantStyles.box,
137
- disabled && variantStyles['box:disabled'],
138
- ]}
139
- initial={false}
140
- animate={boxAnimation}
141
- transition={variantStyles['box:transition']}
142
- onClick={handleChange}
143
- onKeyDown={handleChange}
144
- tabIndex={0}
97
+ const getStyles = (key: CheckboxParts) => mergeStyles([
98
+ styles[key],
99
+ disabled ? styles[key + ':disabled'] : null,
100
+ ])
101
+
102
+ const componentStyles = {
103
+ box: getStyles('box'),
104
+ checkmarkWrapper: getStyles('checkmarkWrapper'),
105
+ checkmark: getStyles('checkmark'),
106
+ }
107
+
108
+ return (
109
+ <InputBase
110
+ {...inputBaseProps}
111
+ debugName={debugName}
112
+ style={styles}
113
+ order={_checkboxOnLeft ? reversedOrder : InputBaseDefaultOrder}
145
114
  >
146
115
  <motion.div
147
- css={[
148
- variantStyles.checkmarkWrapper,
149
- disabled && variantStyles['checkmarkWrapper:disabled'],
150
- ]}
116
+ style={componentStyles.box}
151
117
  initial={false}
152
- animate={checkmarkWrapperAnimation}
153
- transition={variantStyles['checkmarkWrapper:transition']}
154
-
118
+ animate={boxAnimation}
119
+ transition={styles['box:transition']}
120
+ onClick={handleChange}
121
+ onKeyDown={handleChange}
122
+ tabIndex={0}
155
123
  >
156
- <Icon
157
- debugName={debugName}
158
- name={checkIcon as any}
159
- css={[variantStyles.checkmark, disabled && variantStyles['checkmark:disabled']]}
160
- style={variantStyles.checkmark}
161
- />
124
+ <motion.div
125
+ style={componentStyles.checkmarkWrapper}
126
+ initial={false}
127
+ animate={checkmarkWrapperAnimation}
128
+ transition={styles['checkmarkWrapper:transition']}
129
+ >
130
+ <Icon
131
+ debugName={debugName}
132
+ name={checkIcon as AppIcon}
133
+ style={componentStyles.checkmark}
134
+ />
135
+ </motion.div>
162
136
  </motion.div>
163
- </motion.div>
164
- </InputBase>
137
+ </InputBase>
138
+ )
165
139
  }
166
140
 
167
- Checkbox.defaultProps = defaultProps
141
+ Checkbox.styleRegistryName = 'Checkbox'
142
+ Checkbox.elements = [...InputBase.elements, 'checkmarkWrapper', 'checkmark', 'box', '__props']
143
+ Checkbox.rootElement = 'wrapper'
144
+
145
+ Checkbox.withVariantTypes = <S extends AnyRecord>(styles: S) => {
146
+ return Checkbox as (props: StyledComponentProps<CheckboxProps, typeof styles>) => IJSX
147
+ }
148
+
149
+ Checkbox.defaultProps = {
150
+ checkIcon: 'check' as AppIcon,
151
+ } as Partial<CheckboxProps>
152
+
153
+ WebStyleRegistry.registerComponent(Checkbox)
@@ -1,7 +1,7 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { InputBaseParts, InputBaseStates } from '../InputBase'
3
2
 
4
3
  type AnimatableParts = 'checkmarkWrapper' | 'box'
4
+
5
5
  export type CheckboxParts = InputBaseParts | AnimatableParts | 'checkmark'
6
6
 
7
7
  export type CheckboxAnimationStates = 'checked' | 'unchecked' | 'disabled-checked' | 'disabled-unchecked'
@@ -14,7 +14,3 @@ export type CheckboxComposition =
14
14
  | `${AnimatableParts}:transition`
15
15
  | `${AnimatableParts}:${CheckboxAnimationStates}`
16
16
  | '__props'
17
-
18
- const createCheckboxStyle = createDefaultVariantFactory<CheckboxComposition>()
19
-
20
- export const CheckboxPresets = includePresets((styles) => createCheckboxStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,15 @@
1
+ import { CheckboxComposition } from './styles'
2
+ import { InputBaseProps } from '../InputBase'
3
+ import { ComponentCommonProps } from '../../types'
4
+ import { AppIcon, StyledProp } from '@codeleap/styles'
5
+
6
+ export type CheckboxProps =
7
+ Pick<InputBaseProps, 'disabled' | 'label'> &
8
+ ComponentCommonProps &
9
+ {
10
+ style?: StyledProp<CheckboxComposition>
11
+ value: boolean
12
+ onValueChange: (value: boolean) => void
13
+ checkboxOnLeft?: boolean
14
+ checkIcon?: AppIcon
15
+ }
@@ -1,91 +1,49 @@
1
- /** @jsx jsx */
2
- import { jsx } from '@emotion/react'
1
+ import { CollapseProps } from './types'
2
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
3
+ import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
4
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
5
+ import { motion } from 'framer-motion'
3
6
 
4
- import { capitalize, StylesOf, TypeGuards } from '@codeleap/common'
5
- import { Scroll } from '../Scroll'
6
- import { View, ViewProps } from '../View'
7
- import { ElementType } from 'react'
8
- import { NativeHTMLElement } from '../../types'
7
+ export * from './styles'
8
+ export * from './types'
9
9
 
10
- export type CollapseAxis = 'horizontal' | 'vertical'
11
-
12
- export type GetCollapseStylesArgs = {
13
- direction?: CollapseAxis
14
- value: string | number
15
- animation?: string
16
- scroll ?: boolean
17
- }
18
-
19
- type CollapseComposition = 'wrapper' | 'wrapper:open' |'wrapper:hidden'
20
-
21
- export function getCollapseStyles<
22
- TCSS = React.CSSProperties,
23
- Return extends Record<CollapseComposition, TCSS> = Record<CollapseComposition, TCSS>
24
- >(
25
- args: GetCollapseStylesArgs,
26
- ): Return {
10
+ export const Collapse = (props: CollapseProps) => {
27
11
  const {
28
- direction = 'vertical',
29
- value,
30
- animation = '0.3s ease',
31
- scroll = false,
32
-
33
- } = args
34
-
35
- const dimension = direction === 'horizontal' ? 'width' : 'height'
36
- const capitalizedDimension = capitalize(dimension)
37
- const overflowOpen = scroll ? 'auto' : 'hidden'
38
- const axis = direction === 'vertical' ? 'Y' : 'X'
39
- return {
40
- 'wrapper:closed': {
41
- [`max${capitalizedDimension}`]: '0px',
42
- [`overflow${axis}`]: 'hidden',
43
- },
44
- 'wrapper:open': {
45
- [`max${capitalizedDimension}`]: TypeGuards.isString(value) ? value : `${value}px`,
46
- [`overflow${axis}`]: overflowOpen,
47
- },
48
- wrapper: {
49
- height: 'auto',
50
- transition: `max-${dimension} ${animation}`,
51
- },
52
- } as unknown as Return
53
- }
54
-
55
- export type CollapseProps<T extends NativeHTMLElement = 'div'> = ViewProps<T> & {
56
- open: boolean
57
- scroll?: boolean
58
- size?: string | number
59
- direction?: CollapseAxis
60
- animation?: string
61
- styles: StylesOf<CollapseComposition>
12
+ open,
13
+ children,
14
+ style,
15
+ ...rest
16
+ } = {
17
+ ...Collapse.defaultProps,
18
+ ...props,
19
+ }
20
+
21
+ const styles = useStylesFor(Collapse.styleRegistryName, style)
22
+
23
+ return (
24
+ <motion.div
25
+ initial={false}
26
+ animate={{ height: open ? 'auto' : 0, opacity: open ? 1 : 0 }}
27
+ transition={{ duration: 0.2 }}
28
+ {...rest}
29
+ style={{
30
+ ...styles.wrapper,
31
+ ...(open ? styles?.['wrapper:open'] : styles?.['wrapper:closed']),
32
+ }}
33
+ >
34
+ {children}
35
+ </motion.div>
36
+ )
62
37
  }
63
38
 
64
- export const Collapse = ({
65
- open,
66
- size = 1000,
67
- scroll = false,
68
- children,
69
- direction,
70
- animation,
71
- styles,
72
- ...props
73
- }:CollapseProps) => {
39
+ Collapse.styleRegistryName = 'Collapse'
40
+ Collapse.elements = ['wrapper']
41
+ Collapse.rootElement = 'wrapper'
74
42
 
75
- const Component = scroll ? Scroll : View
76
- const _styles = getCollapseStyles({
77
- value: size,
78
- direction,
79
- animation,
80
- })
81
- // @ts-ignore
82
- return <Component css={[
83
- _styles.wrapper,
84
- open ? _styles['wrapper:open'] : _styles['wrapper:closed'],
85
- styles.wrapper,
86
- ]} {...props}>
87
- {children}
88
- </Component>
43
+ Collapse.withVariantTypes = <S extends AnyRecord>(styles: S) => {
44
+ return Collapse as (props: StyledComponentProps<CollapseProps, typeof styles>) => IJSX
89
45
  }
90
46
 
91
- export * from './styles'
47
+ Collapse.defaultProps = {} as Partial<CollapseProps>
48
+
49
+ WebStyleRegistry.registerComponent(Collapse)
@@ -1,8 +1,5 @@
1
- import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
2
- import { ViewComposition } from "../View"
1
+ type CollapseState = 'open' | 'closed'
3
2
 
4
- export type CollapseComposition = ViewComposition
3
+ type CollapseParts = 'wrapper'
5
4
 
6
- const createCollapseStyle = createDefaultVariantFactory<CollapseComposition>()
7
-
8
- export const CollapsePresets = includePresets((styles) => createCollapseStyle(() => ({ wrapper: styles })))
5
+ export type CollapseComposition = CollapseParts | `${CollapseParts}:${CollapseState}`
@@ -0,0 +1,11 @@
1
+ import { StyledProp } from '@codeleap/styles'
2
+ import { MotionProps } from 'framer-motion'
3
+ import { CollapseComposition } from './styles'
4
+
5
+ export type CollapseProps =
6
+ Omit<MotionProps, 'style'> &
7
+ {
8
+ open: boolean
9
+ style?: StyledProp<CollapseComposition>
10
+ children?: React.ReactNode
11
+ }