@codeleap/web 3.25.0 → 3.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/package.json +1 -2
  2. package/src/components/ActionIcon/index.tsx +52 -51
  3. package/src/components/ActionIcon/styles.ts +5 -1
  4. package/src/components/ActivityIndicator/index.tsx +55 -34
  5. package/src/components/ActivityIndicator/styles.ts +6 -0
  6. package/src/components/Badge/index.tsx +80 -43
  7. package/src/components/Badge/styles.ts +11 -1
  8. package/src/components/Button/index.tsx +89 -46
  9. package/src/components/Button/styles.ts +5 -0
  10. package/src/components/Checkbox/index.tsx +97 -83
  11. package/src/components/Checkbox/styles.ts +5 -1
  12. package/src/components/Collapse/index.tsx +83 -41
  13. package/src/components/Collapse/styles.ts +6 -3
  14. package/src/components/ColorPicker/index.tsx +48 -95
  15. package/src/components/ColorPicker/styles.ts +11 -11
  16. package/src/components/ColorPicker/types.ts +12 -26
  17. package/src/components/CropPicker/index.tsx +104 -100
  18. package/src/components/CropPicker/styles.ts +7 -0
  19. package/src/components/CropPicker/types.ts +17 -8
  20. package/src/{lib/hooks/useCropPicker.ts → components/CropPicker/useCropPicker.tsx} +15 -68
  21. package/src/components/CropPicker/utils.ts +51 -0
  22. package/src/components/DatePicker/{components → defaultComponents}/Header.tsx +17 -9
  23. package/src/components/DatePicker/{components → defaultComponents}/OuterInput.tsx +7 -6
  24. package/src/components/DatePicker/index.tsx +124 -110
  25. package/src/components/DatePicker/styles.ts +12 -1
  26. package/src/components/DatePicker/types.ts +33 -16
  27. package/src/components/Drawer/index.tsx +125 -133
  28. package/src/components/Drawer/styles.ts +5 -0
  29. package/src/components/Dropzone/index.tsx +63 -87
  30. package/src/components/Dropzone/styles.ts +6 -0
  31. package/src/components/Dropzone/types.ts +37 -29
  32. package/src/components/EmptyPlaceholder/index.tsx +83 -63
  33. package/src/components/EmptyPlaceholder/styles.ts +5 -0
  34. package/src/components/FileInput.tsx +91 -0
  35. package/src/components/Grid/index.tsx +41 -40
  36. package/src/components/Grid/styles.ts +9 -2
  37. package/src/components/Grid/types.ts +12 -10
  38. package/src/components/Icon/index.tsx +47 -45
  39. package/src/components/Icon/styles.ts +8 -0
  40. package/src/components/InputBase/index.tsx +42 -71
  41. package/src/components/InputBase/styles.ts +47 -37
  42. package/src/components/InputBase/types.ts +7 -19
  43. package/src/components/InputBase/utils.ts +23 -3
  44. package/src/components/List/ListLayout.tsx +37 -20
  45. package/src/components/List/PaginationIndicator.tsx +102 -0
  46. package/src/components/List/index.tsx +41 -36
  47. package/src/components/List/styles.ts +11 -5
  48. package/src/components/List/types.ts +20 -30
  49. package/src/components/List/useInfiniteScroll.ts +159 -0
  50. package/src/components/LoadingOverlay/index.tsx +33 -31
  51. package/src/components/LoadingOverlay/styles.ts +8 -3
  52. package/src/components/Modal/index.tsx +160 -98
  53. package/src/components/Modal/styles.ts +5 -0
  54. package/src/components/NumberIncrement/index.tsx +98 -67
  55. package/src/components/NumberIncrement/styles.ts +5 -0
  56. package/src/components/Overlay/index.tsx +35 -37
  57. package/src/components/Overlay/styles.ts +5 -3
  58. package/src/components/Pager/index.tsx +81 -65
  59. package/src/components/Pager/styles.ts +9 -3
  60. package/src/components/Progress/Bar/index.tsx +50 -45
  61. package/src/components/Progress/Bar/styles.tsx +7 -0
  62. package/src/components/Progress/Bar/types.tsx +30 -0
  63. package/src/components/Progress/Circle/index.tsx +48 -45
  64. package/src/components/Progress/Circle/styles.ts +8 -1
  65. package/src/components/Progress/Circle/types.ts +22 -10
  66. package/src/components/RadioInput/index.tsx +124 -78
  67. package/src/components/RadioInput/styles.ts +6 -0
  68. package/src/components/Scroll/index.tsx +32 -0
  69. package/src/components/Scroll/styles.ts +8 -0
  70. package/src/components/SearchInput/index.tsx +10 -10
  71. package/src/components/SectionFilters/index.tsx +36 -47
  72. package/src/components/SectionFilters/styles.ts +5 -1
  73. package/src/components/SectionFilters/types.ts +13 -14
  74. package/src/components/SegmentedControl/SegmentedControlOption.tsx +84 -0
  75. package/src/components/SegmentedControl/index.tsx +89 -111
  76. package/src/components/SegmentedControl/styles.ts +21 -7
  77. package/src/components/Select/index.tsx +57 -91
  78. package/src/components/Select/styles.ts +36 -19
  79. package/src/components/Select/types.ts +13 -17
  80. package/src/components/Slider/index.tsx +93 -85
  81. package/src/components/Slider/styles.ts +6 -13
  82. package/src/components/Switch/index.tsx +74 -63
  83. package/src/components/Switch/styles.ts +6 -1
  84. package/src/components/Tag/index.tsx +44 -39
  85. package/src/components/Tag/styles.ts +9 -1
  86. package/src/components/Tag/types.ts +10 -10
  87. package/src/components/Text/index.tsx +48 -37
  88. package/src/components/Text/styles.ts +8 -0
  89. package/src/components/Text/types.ts +8 -8
  90. package/src/components/TextEditor/index.tsx +28 -49
  91. package/src/components/TextEditor/styles.ts +8 -1
  92. package/src/components/TextEditor/types.ts +6 -11
  93. package/src/components/TextInput/index.tsx +96 -58
  94. package/src/components/TextInput/mask.tsx +50 -2
  95. package/src/components/TextInput/styles.ts +8 -3
  96. package/src/components/Tooltip/index.tsx +84 -61
  97. package/src/components/Tooltip/styles.ts +10 -3
  98. package/src/components/Touchable/index.tsx +86 -43
  99. package/src/components/Touchable/styles.ts +6 -0
  100. package/src/components/View/index.tsx +50 -36
  101. package/src/components/View/styles.ts +6 -0
  102. package/src/components/View/types.ts +15 -14
  103. package/src/components/components.ts +3 -2
  104. package/src/components/defaultStyles.ts +79 -0
  105. package/src/index.ts +0 -1
  106. package/src/lib/hooks/index.ts +0 -5
  107. package/src/lib/hooks/useBreakpointMatch.ts +7 -8
  108. package/src/lib/hooks/useMediaQuery.ts +3 -4
  109. package/src/lib/hooks/usePagination.ts +63 -79
  110. package/src/lib/index.ts +0 -1
  111. package/src/lib/utils/index.ts +0 -1
  112. package/src/lib/utils/test.ts +2 -2
  113. package/src/components/ActionIcon/types.ts +0 -15
  114. package/src/components/ActivityIndicator/types.ts +0 -12
  115. package/src/components/Badge/types.ts +0 -28
  116. package/src/components/Button/types.ts +0 -25
  117. package/src/components/Checkbox/types.ts +0 -15
  118. package/src/components/Collapse/types.ts +0 -11
  119. package/src/components/Drawer/types.ts +0 -23
  120. package/src/components/EmptyPlaceholder/types.ts +0 -32
  121. package/src/components/FileInput/index.tsx +0 -72
  122. package/src/components/FileInput/types.ts +0 -14
  123. package/src/components/Icon/types.ts +0 -15
  124. package/src/components/LoadingOverlay/types.ts +0 -16
  125. package/src/components/Modal/types.ts +0 -55
  126. package/src/components/NumberIncrement/types.ts +0 -29
  127. package/src/components/Overlay/types.ts +0 -13
  128. package/src/components/Pager/types.ts +0 -35
  129. package/src/components/PaginationButtons/index.tsx +0 -173
  130. package/src/components/PaginationButtons/styles.ts +0 -7
  131. package/src/components/PaginationButtons/types.ts +0 -26
  132. package/src/components/PaginationIndicator/index.tsx +0 -69
  133. package/src/components/PaginationIndicator/styles.ts +0 -3
  134. package/src/components/PaginationIndicator/types.ts +0 -18
  135. package/src/components/Progress/Bar/styles.ts +0 -10
  136. package/src/components/Progress/Bar/types.ts +0 -26
  137. package/src/components/RadioInput/types.ts +0 -29
  138. package/src/components/SegmentedControl/types.ts +0 -44
  139. package/src/components/Slider/types.ts +0 -29
  140. package/src/components/Switch/types.ts +0 -13
  141. package/src/components/TextInput/types.ts +0 -85
  142. package/src/components/Tooltip/types.ts +0 -46
  143. package/src/components/Touchable/types.ts +0 -22
  144. package/src/lib/WebStyleRegistry.ts +0 -51
  145. package/src/lib/hooks/useFileInput.ts +0 -15
  146. package/src/lib/hooks/useInfiniteScroll.ts +0 -77
  147. package/src/lib/hooks/useRefresh.ts +0 -87
  148. package/src/lib/hooks/useStylesFor.ts +0 -13
  149. package/src/lib/utils/cache.ts +0 -9
  150. /package/src/components/DatePicker/{components → defaultComponents}/index.tsx +0 -0
@@ -1,53 +1,51 @@
1
1
  import React from 'react'
2
- import { Touchable } from '../Touchable'
3
- import { View } from '../View'
2
+ import {
3
+ ComponentVariants,
4
+ StylesOf,
5
+ useDefaultComponentStyle,
6
+ } from '@codeleap/common'
7
+ import { Touchable, TouchableProps } from '../Touchable'
8
+ import { View, ViewProps } from '../View'
9
+ import { OverlayComposition, OverlayPresets } from './styles'
10
+ import { NativeHTMLElement } from '../../types'
4
11
  import { usePopState } from '../../lib'
5
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
6
- import { OverlayProps } from './types'
7
- import { useStylesFor } from '../../lib/hooks/useStylesFor'
8
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
12
+
13
+ export type OverlayProps<T extends NativeHTMLElement = 'div'> = {
14
+ visible?: boolean
15
+ styles?: StylesOf<OverlayComposition>
16
+ onPress?: TouchableProps<'div'>['onClick']
17
+ } & ComponentVariants<typeof OverlayPresets> & Omit<ViewProps<T>, 'variants' | 'responsiveVariants'>
9
18
 
10
19
  export * from './styles'
11
- export * from './types'
12
20
 
13
- export const Overlay = (overlayProps: OverlayProps) => {
14
- const {
15
- visible,
16
- style,
17
- ...props
18
- } = {
19
- ...Overlay.defaultProps,
20
- ...overlayProps,
21
- }
21
+ export const Overlay = <T extends NativeHTMLElement>(overlayProps:OverlayProps<T>) => {
22
+ const {
23
+ visible,
24
+ responsiveVariants,
25
+ variants,
26
+ styles,
27
+ ...props
28
+ } = overlayProps
22
29
 
23
- const styles = useStylesFor(Overlay.styleRegistryName, style)
30
+ const variantStyles = useDefaultComponentStyle('Overlay', {
31
+ variants,
32
+ responsiveVariants,
33
+ styles,
34
+ })
24
35
 
25
- usePopState(visible, props?.onPress)
36
+ usePopState(visible, props.onPress)
26
37
 
27
- const isPressable = !!props?.onClick || !!props?.onPress
28
- const Component = isPressable ? Touchable : View
38
+ const Component = props.onClick || props.onPress ? Touchable : View
29
39
 
30
40
  return (
31
- // @ts-expect-error
41
+ // @ts-ignore
32
42
  <Component
33
- {...props}
34
- style={[
43
+ css={[
35
44
  { transition: 'opacity 0.2s ease' },
36
- styles.wrapper,
37
- visible ? styles['wrapper:visible'] : null,
45
+ variantStyles.wrapper,
46
+ visible ? variantStyles['wrapper:visible'] : {},
38
47
  ]}
48
+ {...props}
39
49
  />
40
50
  )
41
51
  }
42
-
43
- Overlay.styleRegistryName = 'Overlay'
44
- Overlay.elements = ['wrapper']
45
- Overlay.rootElement = 'wrapper'
46
-
47
- Overlay.withVariantTypes = <S extends AnyRecord>(styles: S) => {
48
- return Overlay as (props: StyledComponentProps<OverlayProps, typeof styles>) => IJSX
49
- }
50
-
51
- Overlay.defaultProps = {} as Partial<OverlayProps>
52
-
53
- WebStyleRegistry.registerComponent(Overlay)
@@ -1,6 +1,8 @@
1
+ import { createDefaultVariantFactory, includePresets } from "@codeleap/common";
2
+ import { ViewComposition } from "../View";
1
3
 
2
- type OverlayState = 'visible'
4
+ export type OverlayComposition = ViewComposition
3
5
 
4
- type OverlayParts = 'wrapper'
6
+ const createOverlayStyle = createDefaultVariantFactory<OverlayComposition>()
5
7
 
6
- export type OverlayComposition = OverlayParts | `${OverlayParts}:${OverlayState}`
8
+ export const OverlayPresets = includePresets((styles) => createOverlayStyle(() => ({ wrapper: styles })))
@@ -1,40 +1,68 @@
1
- import { onUpdate } from '@codeleap/common'
2
- import Slider from 'react-slick'
3
- import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react'
4
- import { View } from '../View'
5
- import { Touchable } from '../Touchable'
6
- import { DotsProps, PagerProps, PagerRef } from './types'
7
- import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
8
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
9
- import { useStylesFor } from '../../lib/hooks/useStylesFor'
1
+ import {
2
+ ComponentVariants,
3
+ StylesOf,
4
+ onUpdate,
5
+ useDefaultComponentStyle,
6
+ } from '@codeleap/common'
7
+ import Slider, { Settings } from 'react-slick'
8
+ import { PagerComposition, PagerPresets } from './styles'
9
+ import React, {
10
+ forwardRef,
11
+ useCallback,
12
+ useImperativeHandle,
13
+ useRef,
14
+ ReactNode,
15
+ ReactElement,
16
+ CSSProperties,
17
+ } from 'react'
10
18
 
11
19
  import 'slick-carousel/slick/slick.css'
12
20
  import 'slick-carousel/slick/slick-theme.css'
21
+ import { View, ViewProps } from '../View'
22
+ import { Touchable } from '../Touchable'
23
+ import { ComponentCommonProps } from '../../types'
13
24
 
14
- export * from './styles'
15
- export * from './types'
25
+ export type PagerRef = {
26
+ goTo: (page: number) => void
27
+ }
16
28
 
17
- const Dots = (params: DotsProps) => {
18
- const { page, childArray, onPress, styles, dotsDisabled } = params
29
+ export type PagerProps = Settings &
30
+ ComponentVariants<typeof PagerPresets> & {
31
+ styles?: StylesOf<PagerComposition>
32
+ page?: number
33
+ style?: CSSProperties
34
+ children: ReactNode
35
+ onChange?: (page: number) => void
36
+ renderPageWrapper?: React.FC
37
+ footer?: ReactElement
38
+ dotsProps?: DotsProps
39
+ pageWrapperProps?: ViewProps<'div'>
40
+ dotsDisabled?:boolean
41
+ disableSwipe?: boolean
42
+ } & ComponentCommonProps
43
+
44
+ type DotsProps = Pick<PagerProps, 'page' | 'dotsDisabled'> & {
45
+ childArray: ReactNode[]
46
+ onPress?: (index: number) => void
47
+ variantStyles: StylesOf<PagerComposition>
48
+ }
19
49
 
50
+ const Dots = ({ page, childArray, onPress, variantStyles, dotsDisabled }: DotsProps) => {
20
51
  return (
21
- <View style={styles.dots}>
52
+ <View style={variantStyles.dots}>
22
53
  {childArray.map((_, index) => {
23
54
  const isSelected = index === page
24
-
25
- const style = [
26
- styles.dot,
27
- isSelected && styles['dot:selected'],
28
- dotsDisabled && styles['dot:disabled'],
55
+ const css = [
56
+ variantStyles[isSelected ? 'dot:selected' : 'dot'],
57
+ dotsDisabled && variantStyles['dot:disabled'],
29
58
  ]
30
59
 
31
60
  return (
32
61
  <Touchable
33
62
  key={index}
34
63
  onPress={() => onPress?.(index)}
35
- style={style}
64
+ css={css}
36
65
  disabled={dotsDisabled}
37
- debugName='dots'
38
66
  />
39
67
  )
40
68
  })}
@@ -42,31 +70,42 @@ const Dots = (params: DotsProps) => {
42
70
  )
43
71
  }
44
72
 
45
- export const Pager = forwardRef<PagerRef, PagerProps>((props, ref) => {
73
+ const PagerComponent = (
74
+ props: PagerProps,
75
+ ref: React.ForwardedRef<PagerRef>,
76
+ ) => {
46
77
  const sliderRef = useRef<Slider>()
47
-
48
78
  const {
79
+ styles,
49
80
  style,
81
+ variants,
50
82
  children,
51
- renderPageWrapper: PageWrapper,
83
+ renderPageWrapper,
84
+ responsiveVariants,
52
85
  page,
53
- dots,
54
- dotsDisabled,
55
- infinite,
56
- disableSwipe,
86
+ dots = false,
87
+ dotsDisabled = false,
88
+ infinite = false,
89
+ disableSwipe = false,
57
90
  onChange,
58
91
  footer,
59
92
  dotsProps,
60
93
  pageWrapperProps,
61
94
  ...rest
62
- } = {
63
- ...Pager.defaultProps,
64
- ...props,
65
- }
66
-
67
- const styles = useStylesFor(Pager.styleRegistryName, style)
95
+ } = props
96
+
97
+ const variantStyles = useDefaultComponentStyle<
98
+ 'u:Pager',
99
+ typeof PagerPresets
100
+ >('u:Pager', {
101
+ variants,
102
+ responsiveVariants,
103
+ styles,
104
+ rootElement: 'wrapper',
105
+ })
68
106
 
69
107
  const childArray = React.Children.toArray(children)
108
+ const PageWrapper = renderPageWrapper || View
70
109
 
71
110
  const goTo = useCallback(
72
111
  (page: number) => {
@@ -85,7 +124,7 @@ export const Pager = forwardRef<PagerRef, PagerProps>((props, ref) => {
85
124
  }, [page])
86
125
 
87
126
  return (
88
- <View style={styles.wrapper}>
127
+ <View css={[variantStyles.wrapper, style]}>
89
128
  <Slider
90
129
  adaptiveHeight={true}
91
130
  {...rest}
@@ -99,10 +138,9 @@ export const Pager = forwardRef<PagerRef, PagerProps>((props, ref) => {
99
138
  >
100
139
  {childArray.map((child, index) => {
101
140
  return (
102
- // @ts-expect-error @verify
103
141
  <PageWrapper
104
142
  key={index}
105
- style={styles.pageWrapper}
143
+ css={variantStyles.pageWrapper}
106
144
  {...pageWrapperProps}
107
145
  >
108
146
  {child}
@@ -111,46 +149,24 @@ export const Pager = forwardRef<PagerRef, PagerProps>((props, ref) => {
111
149
  })}
112
150
  </Slider>
113
151
 
114
- <View style={styles.footerWrapper}>
152
+ <View css={variantStyles.footerWrapper}>
115
153
  {footer}
116
154
 
117
- {dots ? (
155
+ {dots && (
118
156
  <Dots
119
157
  page={page}
120
158
  onPress={onChange}
121
159
  childArray={childArray}
122
- styles={styles}
160
+ variantStyles={variantStyles}
123
161
  dotsDisabled={dotsDisabled}
124
162
  {...dotsProps}
125
163
  />
126
- ) : null}
164
+ )}
127
165
  </View>
128
166
  </View>
129
167
  )
130
- }) as StyledComponentWithProps<PagerProps>
131
-
132
- Pager.styleRegistryName = 'Pager'
133
-
134
- Pager.elements = [
135
- 'wrapper',
136
- 'dot',
137
- 'dots',
138
- 'pageWrapper',
139
- 'footerWrapper',
140
- ]
141
-
142
- Pager.rootElement = 'wrapper'
143
-
144
- Pager.withVariantTypes = <S extends AnyRecord>(styles: S) => {
145
- return Pager as (props: StyledComponentProps<PagerProps, typeof styles>) => IJSX
146
168
  }
147
169
 
148
- Pager.defaultProps = {
149
- dots: false,
150
- dotsDisabled: false,
151
- infinite: false,
152
- disableSwipe: false,
153
- renderPageWrapper: View,
154
- } as Partial<PagerProps>
170
+ export const Pager = forwardRef(PagerComponent)
155
171
 
156
- WebStyleRegistry.registerComponent(Pager)
172
+ export * from './styles'
@@ -1,8 +1,14 @@
1
-
2
- type Dots = 'dot' | 'dot:selected' | 'dot:disabled' | 'dots'
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
3
2
 
4
3
  export type PagerComposition =
5
4
  | 'wrapper'
5
+ | 'dot'
6
+ | 'dot:selected'
7
+ | 'dots'
6
8
  | 'pageWrapper'
7
9
  | 'footerWrapper'
8
- | Dots
10
+
11
+ const createPagerStyle = createDefaultVariantFactory<PagerComposition>()
12
+
13
+ export const PagerPresets = includePresets((styles) => createPagerStyle(() => ({ wrapper: styles })),
14
+ )
@@ -1,24 +1,42 @@
1
- import { TypeGuards } from '@codeleap/common'
1
+ import { ProgressBarPresets } from './styles'
2
+ import { TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
2
3
  import { Root, Indicator } from '@radix-ui/react-progress'
3
4
  import { Icon, Text, View } from '../../components'
4
5
  import { ProgressBarProps } from './types'
5
6
  import { formatProgress as _formatProgress } from '../utils'
6
- import { WebStyleRegistry } from '../../../lib/WebStyleRegistry'
7
- import { AnyRecord, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
8
- import { useStylesFor } from '../../../lib/hooks/useStylesFor'
9
7
 
10
8
  export * from './types'
11
9
  export * from './styles'
12
10
 
11
+ const defaultProps: Partial<ProgressBarProps> = {
12
+ progress: 0,
13
+ variants: [],
14
+ responsiveVariants: {},
15
+ styles: {},
16
+ textProps: {},
17
+ progressIndicatorProps: {},
18
+ progressRootProps: {},
19
+ showProgress: false,
20
+ formatProgress: _formatProgress,
21
+ }
22
+
13
23
  export const ProgressBar = (props: ProgressBarProps) => {
24
+ const allProps = {
25
+ ...ProgressBar.defaultProps,
26
+ ...props,
27
+ }
28
+
14
29
  const {
15
30
  progress,
16
- style,
31
+ variants,
32
+ responsiveVariants,
33
+ styles,
17
34
  debugName,
18
35
  formatProgress,
19
36
  progressIndicatorProps,
20
37
  progressRootProps,
21
38
  showProgress,
39
+
22
40
  leftIcon,
23
41
  leftIconProps,
24
42
  rightIcon,
@@ -30,88 +48,75 @@ export const ProgressBar = (props: ProgressBarProps) => {
30
48
  rightText,
31
49
  rightTextProps,
32
50
  ...rest
33
- } = {
34
- ...ProgressBar.defaultProps,
35
- ...props,
36
- }
51
+ } = allProps
37
52
 
38
- const styles = useStylesFor(ProgressBar.styleRegistryName, style)
39
-
40
- const leftIconStyles = mergeStyles([styles.icon, styles.leftIcon])
41
- const rightIconStyles = mergeStyles([styles.icon, styles.rightIcon])
42
-
43
- const leftTextStyles = mergeStyles([styles.text, styles.leftText])
44
- const rightTextStyles = mergeStyles([styles.text, styles.rightText])
53
+ const variantStyles = useDefaultComponentStyle<
54
+ 'u:ProgressBar',
55
+ typeof ProgressBarPresets
56
+ >('u:ProgressBar', {
57
+ variants,
58
+ responsiveVariants,
59
+ styles,
60
+ })
45
61
 
46
62
  return (
47
- <View debugName={debugName} {...rest} style={styles.wrapper}>
63
+ <View css={variantStyles.wrapper} debugName={debugName} {...rest}>
48
64
  {!TypeGuards.isNil(leftIcon) ? (
49
65
  <Icon
50
66
  name={leftIcon}
67
+ style={{ ...variantStyles.icon, ...variantStyles.leftIcon }}
51
68
  debugName={`leftIcon-${debugName}`}
52
69
  {...leftIconProps}
53
- style={leftIconStyles}
54
70
  />
55
71
  ) : null}
56
72
  {TypeGuards.isString(leftText) ? (
57
73
  <Text
58
74
  text={leftText}
75
+ css={[variantStyles.text, variantStyles.leftText]}
59
76
  {...leftTextProps}
60
- style={leftTextStyles}
61
77
  />
62
- ) : leftText}
63
-
78
+ ) : (
79
+ leftText
80
+ )}
64
81
  <Root
65
- // @ts-expect-error
66
- css={styles.progress}
82
+ css={variantStyles.progress}
67
83
  value={progress}
68
84
  {...progressRootProps}
69
85
  >
70
86
  <Indicator
71
- css={{ ...styles.indicator, transform: `translateX(-${100 - progress}%)` }}
87
+ css={[
88
+ variantStyles.indicator,
89
+ { transform: `translateX(-${100 - progress}%)` },
90
+ ]}
72
91
  {...progressIndicatorProps}
73
92
  />
74
93
  </Root>
75
-
76
94
  {TypeGuards.isString(text) || showProgress ? (
77
95
  <Text
96
+ style={variantStyles.text}
78
97
  text={showProgress ? formatProgress(progress) : text}
79
98
  {...textProps}
80
- style={styles.text}
81
99
  />
82
100
  ) : text}
83
-
84
101
  {!TypeGuards.isNil(rightIcon) ? (
85
102
  <Icon
86
103
  name={rightIcon}
104
+ style={{ ...variantStyles.icon, ...variantStyles.rightIcon }}
87
105
  debugName={`rightIcon-${debugName}`}
88
106
  {...rightIconProps}
89
- style={rightIconStyles}
90
107
  />
91
108
  ) : null}
92
109
  {TypeGuards.isString(rightText) ? (
93
110
  <Text
94
111
  text={rightText}
112
+ css={[variantStyles.text, variantStyles.rightText]}
95
113
  {...rightTextProps}
96
- style={rightTextStyles}
97
114
  />
98
- ) : rightText}
115
+ ) : (
116
+ rightText
117
+ )}
99
118
  </View>
100
119
  )
101
120
  }
102
121
 
103
- ProgressBar.styleRegistryName = 'ProgressBar'
104
- ProgressBar.elements = ['wrapper', 'progress', 'indicator', 'text', 'icon', 'leftIcon', 'leftText', 'rightIcon', 'rightText']
105
- ProgressBar.rootElement = 'wrapper'
106
-
107
- ProgressBar.withVariantTypes = <S extends AnyRecord>(styles: S) => {
108
- return ProgressBar as (props: StyledComponentProps<ProgressBarProps, typeof styles>) => IJSX
109
- }
110
-
111
- ProgressBar.defaultProps = {
112
- progress: 0,
113
- showProgress: false,
114
- formatProgress: _formatProgress,
115
- } as Partial<ProgressBarProps>
116
-
117
- WebStyleRegistry.registerComponent(ProgressBar)
122
+ ProgressBar.defaultProps = defaultProps
@@ -0,0 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
3
+ export type ProgressBarComposition = 'wrapper' | 'progress' | 'indicator' | 'text' | 'icon' | 'leftIcon' | 'leftText' | 'rightIcon' | 'rightText'
4
+
5
+ const createProgressBarStyle = createDefaultVariantFactory<ProgressBarComposition>()
6
+
7
+ export const ProgressBarPresets = includePresets((styles) => createProgressBarStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,30 @@
1
+ import { ComponentVariants, IconPlaceholder, PropsOf, StylesOf } from '@codeleap/common'
2
+ import { ProgressBarComposition, ProgressBarPresets } from './styles'
3
+ import {
4
+ ProgressProps,
5
+ ProgressIndicatorProps,
6
+ } from '@radix-ui/react-progress'
7
+ import { IconProps, View, TextProps as _TextProps } from '../../components'
8
+ import { ProgressPropsRoot } from '..'
9
+ import { ElementType } from 'react'
10
+
11
+ type TextProps = _TextProps<ElementType>
12
+
13
+ export type ProgressBarProps = ComponentVariants<typeof ProgressBarPresets> &
14
+ Omit<PropsOf<typeof View>, 'variants' | 'responsiveVariants' | 'styles'> &
15
+ ProgressPropsRoot & {
16
+ styles?: StylesOf<ProgressBarComposition>
17
+ progressIndicatorProps?: ProgressIndicatorProps
18
+ progressRootProps?: ProgressProps
19
+
20
+ leftIcon?: IconPlaceholder
21
+ leftIconProps?: Partial<IconProps>
22
+ rightIcon?: IconPlaceholder
23
+ rightIconProps?: Partial<IconProps>
24
+ text?: string
25
+ textProps?: Partial<TextProps>
26
+ leftText?: TextProps['text'] | JSX.Element
27
+ leftTextProps?: Partial<TextProps>
28
+ rightText?: TextProps['text'] | JSX.Element
29
+ rightTextProps?: Partial<TextProps>
30
+ }