@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
@@ -0,0 +1,173 @@
1
+ import { TypeGuards } from '@codeleap/common'
2
+ import { View } from '../View'
3
+ import { Button } from '../Button'
4
+ import { useMediaQuery, usePagination, useStylesFor, WebStyleRegistry } from '../../lib'
5
+ import { PaginationButtonsProps } from './types'
6
+ import { AnyRecord, AppIcon, AppTheme, IJSX, StyledComponentProps, Theme, useCompositionStyles, useTheme } from '@codeleap/styles'
7
+
8
+ export * from './styles'
9
+ export * from './types'
10
+
11
+ export const PaginationButtons = (props: PaginationButtonsProps) => {
12
+ const allProps = {
13
+ ...PaginationButtons.defaultProps,
14
+ ...props,
15
+ }
16
+
17
+ const {
18
+ shouldAbbreviate,
19
+ displayLeftArrow,
20
+ displayRightArrow,
21
+ disabled,
22
+ style,
23
+ itemProps,
24
+ controlLeftIconName,
25
+ controlRightIconName,
26
+ leftArrowButtonProps,
27
+ rightArrowButtonProps,
28
+ abbreviationSymbol,
29
+ isMobile,
30
+ ...paginationProps
31
+ } = allProps
32
+
33
+ const theme = useTheme(store => store?.current) as AppTheme<Theme>
34
+
35
+ const { boundaries = 2 } = paginationProps
36
+
37
+ const query = theme?.media?.down('tabletSmall' as never)
38
+
39
+ const _isMobile = useMediaQuery(query, { getInitialValueInEffect: false })
40
+ const isMobileQuery = TypeGuards.isBoolean(isMobile) ? isMobile : _isMobile
41
+
42
+ const centeredElementIndex = isMobileQuery ? 3 : boundaries + 1
43
+
44
+ const {
45
+ range,
46
+ first,
47
+ next,
48
+ previous,
49
+ setPage,
50
+ page,
51
+ status,
52
+ } = usePagination({
53
+ abbreviationSymbol,
54
+ isMobile: isMobileQuery,
55
+ displayLeftArrow,
56
+ displayRightArrow,
57
+ shouldAbbreviate,
58
+ ...paginationProps,
59
+ })
60
+
61
+ const styles = useStylesFor(PaginationButtons.styleRegistryName, style)
62
+
63
+ const compositionStyles = useCompositionStyles(['button', 'arrowLeftButton', 'arrowRightButton'], styles)
64
+
65
+ const fetchPreviousPage = () => {
66
+ props?.onFetchPreviousPage?.()
67
+ previous?.()
68
+ }
69
+
70
+ const fetchNextPage = () => {
71
+ props?.onFetchNextPage?.()
72
+ next?.()
73
+ }
74
+
75
+ const fetchPage = (page: number) => {
76
+ setPage?.(page)
77
+ }
78
+
79
+ const onPressItem = ({ item, isArrowLeft, isArrowRight }: { item: string | number; isArrowLeft: boolean; isArrowRight: boolean }) => {
80
+ if (item === abbreviationSymbol) {
81
+ return null
82
+ }
83
+
84
+ if (isArrowLeft) {
85
+ if (displayLeftArrow) {
86
+ return fetchPreviousPage()
87
+ } else {
88
+ return first()
89
+ }
90
+ }
91
+
92
+ if (displayRightArrow && isArrowRight) {
93
+ return fetchNextPage()
94
+ }
95
+
96
+ props?.onPressItem?.(item)
97
+ fetchPage(Number(item))
98
+ }
99
+
100
+ return (
101
+ <View style={styles.wrapper}>
102
+ {displayLeftArrow ? (
103
+ <Button
104
+ icon={controlLeftIconName}
105
+ onPress={() => onPressItem({ item: null, isArrowLeft: true, isArrowRight: false })}
106
+ {...leftArrowButtonProps}
107
+ style={compositionStyles.arrowLeftButton}
108
+ />
109
+ ) : null}
110
+
111
+ {range?.map?.((item, index) => {
112
+ if (props?.renderItem) {
113
+ return props?.renderItem?.(item, index)
114
+ }
115
+
116
+ let selected = null
117
+
118
+ switch (status) {
119
+ case 'initial':
120
+ selected = page === index + 1
121
+ break
122
+ case 'abreviated':
123
+ selected = index === centeredElementIndex - 1
124
+ break
125
+ case 'end':
126
+ selected = page - (Number(item) - index) === index
127
+ }
128
+
129
+ return (
130
+ <Button
131
+ text={String(item)}
132
+ selected={selected}
133
+ onPress={() => onPressItem({ item, isArrowLeft: false, isArrowRight: false })}
134
+ disabled={disabled}
135
+ {...itemProps}
136
+ style={compositionStyles.button}
137
+ />
138
+ )
139
+
140
+ })}
141
+
142
+ {displayRightArrow ? (
143
+ <Button
144
+ icon={controlRightIconName}
145
+ onPress={() => onPressItem({ item: null, isArrowLeft: false, isArrowRight: true })}
146
+ {...rightArrowButtonProps}
147
+ style={compositionStyles.arrowRightButton}
148
+ />
149
+ ) : null}
150
+ </View>
151
+ )
152
+ }
153
+
154
+ PaginationButtons.styleRegistryName = 'PaginationButtons'
155
+ PaginationButtons.elements = ['wrapper', 'button', 'arrowLeftButton', 'arrowRightButton']
156
+ PaginationButtons.rootElement = 'wrapper'
157
+
158
+ PaginationButtons.withVariantTypes = <S extends AnyRecord>(styles: S) => {
159
+ return PaginationButtons as (props: StyledComponentProps<PaginationButtonsProps, typeof styles>) => IJSX
160
+ }
161
+
162
+ PaginationButtons.defaultProps = {
163
+ shouldAbbreviate: true,
164
+ displayLeftArrow: true,
165
+ displayRightArrow: true,
166
+ disabled: false,
167
+ isMobile: null,
168
+ abbreviationSymbol: '...',
169
+ controlLeftIconName: 'chevron-left' as AppIcon,
170
+ controlRightIconName: 'chevron-right' as AppIcon,
171
+ } as Partial<PaginationButtonsProps>
172
+
173
+ WebStyleRegistry.registerComponent(PaginationButtons)
@@ -0,0 +1,7 @@
1
+ import { ButtonComposition } from '../Button'
2
+
3
+ export type PaginationButtonsComposition =
4
+ 'wrapper' |
5
+ `button${Capitalize<ButtonComposition>}` |
6
+ `arrowLeftButton${Capitalize<ButtonComposition>}` |
7
+ `arrowRightButton${Capitalize<ButtonComposition>}`
@@ -0,0 +1,26 @@
1
+ import { AnyFunction } from '@codeleap/common'
2
+ import { PaginationButtonsComposition } from './styles'
3
+ import { ButtonProps } from '../Button'
4
+ import { PaginationParams } from '../../lib'
5
+ import { AppIcon, StyledProp } from '@codeleap/styles'
6
+
7
+ export type PaginationButtonsProps =
8
+ PaginationParams &
9
+ {
10
+ onFetchNextPage?: AnyFunction
11
+ onFetchPreviousPage?: AnyFunction
12
+ renderItem?: (item: string | number, index: number) => JSX.Element
13
+ onPressItem?: (item: string | number) => void
14
+ shouldAbbreviate?: boolean
15
+ abbreviationSymbol?: string
16
+ disabled?: boolean
17
+ displayLeftArrow?: boolean
18
+ displayRightArrow?: boolean
19
+ isMobile?: boolean
20
+ itemProps?: Partial<ButtonProps>
21
+ controlLeftIconName?: AppIcon
22
+ controlRightIconName?: AppIcon
23
+ leftArrowButtonProps?: Partial<ButtonProps>
24
+ rightArrowButtonProps?: Partial<ButtonProps>
25
+ style?: StyledProp<PaginationButtonsComposition>
26
+ }
@@ -0,0 +1,69 @@
1
+ import React from 'react'
2
+ import { TypeGuards } from '@codeleap/common'
3
+ import { ActivityIndicator } from '../ActivityIndicator'
4
+ import { Text } from '../Text'
5
+ import { View } from '../View'
6
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
7
+ import { PaginationIndicatorProps } from './types'
8
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
9
+ import { AnyRecord, IJSX, StyledComponentProps, useNestedStylesByKey } from '@codeleap/styles'
10
+
11
+ export * from './styles'
12
+ export * from './types'
13
+
14
+ export const PaginationIndicator = (props: PaginationIndicatorProps) => {
15
+ const {
16
+ hasMore,
17
+ isFetching,
18
+ noMoreItemsText,
19
+ activityIndicator,
20
+ style,
21
+ indicatorProps,
22
+ debugName,
23
+ } = {
24
+ ...PaginationIndicator.defaultProps,
25
+ ...props,
26
+ }
27
+
28
+ const styles = useStylesFor(PaginationIndicator.styleRegistryName, style)
29
+
30
+ const loaderStyles = useNestedStylesByKey('loader', styles)
31
+
32
+ if (isFetching) {
33
+ return activityIndicator || (
34
+ <View style={styles.wrapper}>
35
+ <ActivityIndicator debugName={debugName} {...indicatorProps} style={loaderStyles} />
36
+ </View>
37
+ )
38
+ }
39
+
40
+ if (!hasMore) {
41
+ if (TypeGuards.isString(noMoreItemsText) || TypeGuards.isNumber(noMoreItemsText)) {
42
+ return (
43
+ <View style={styles.wrapper}>
44
+ <Text
45
+ debugName={debugName}
46
+ style={styles.text}
47
+ text={String(noMoreItemsText)}
48
+ />
49
+ </View>
50
+ )
51
+ }
52
+
53
+ return noMoreItemsText
54
+ }
55
+
56
+ return null
57
+ }
58
+
59
+ PaginationIndicator.styleRegistryName = 'PaginationIndicator'
60
+ PaginationIndicator.elements = ['wrapper', 'text', 'loader']
61
+ PaginationIndicator.rootElement = 'wrapper'
62
+
63
+ PaginationIndicator.withVariantTypes = <S extends AnyRecord>(styles: S) => {
64
+ return PaginationIndicator as (props: StyledComponentProps<PaginationIndicatorProps, typeof styles>) => IJSX
65
+ }
66
+
67
+ PaginationIndicator.defaultProps = {} as Partial<PaginationIndicatorProps>
68
+
69
+ WebStyleRegistry.registerComponent(PaginationIndicator)
@@ -0,0 +1,3 @@
1
+ import { ActivityIndicatorComposition } from '../ActivityIndicator'
2
+
3
+ export type PaginationIndicatorComposition = 'text' | `loader${Capitalize<ActivityIndicatorComposition>}` | 'wrapper'
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import { ActivityIndicatorProps } from '../ActivityIndicator'
3
+ import { TextProps } from '../Text'
4
+ import { ComponentCommonProps } from '../../types'
5
+ import { PaginationIndicatorComposition } from './styles'
6
+ import { StyledProp } from '@codeleap/styles'
7
+
8
+ export type PaginationIndicatorProps =
9
+ ComponentCommonProps &
10
+ {
11
+ isFetching?: boolean
12
+ noMoreItemsText: JSX.Element | string | number
13
+ hasMore?: boolean
14
+ activityIndicator?: JSX.Element
15
+ style?: StyledProp<PaginationIndicatorComposition>
16
+ indicatorProps?: Partial<ActivityIndicatorProps>
17
+ textProps?: Partial<TextProps<'p'>>
18
+ }
@@ -1,42 +1,24 @@
1
- import { ProgressBarPresets } from './styles'
2
- import { TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
1
+ import { TypeGuards } from '@codeleap/common'
3
2
  import { Root, Indicator } from '@radix-ui/react-progress'
4
3
  import { Icon, Text, View } from '../../components'
5
4
  import { ProgressBarProps } from './types'
6
5
  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'
7
9
 
8
10
  export * from './types'
9
11
  export * from './styles'
10
12
 
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
-
23
13
  export const ProgressBar = (props: ProgressBarProps) => {
24
- const allProps = {
25
- ...ProgressBar.defaultProps,
26
- ...props,
27
- }
28
-
29
14
  const {
30
15
  progress,
31
- variants,
32
- responsiveVariants,
33
- styles,
16
+ style,
34
17
  debugName,
35
18
  formatProgress,
36
19
  progressIndicatorProps,
37
20
  progressRootProps,
38
21
  showProgress,
39
-
40
22
  leftIcon,
41
23
  leftIconProps,
42
24
  rightIcon,
@@ -48,75 +30,88 @@ export const ProgressBar = (props: ProgressBarProps) => {
48
30
  rightText,
49
31
  rightTextProps,
50
32
  ...rest
51
- } = allProps
33
+ } = {
34
+ ...ProgressBar.defaultProps,
35
+ ...props,
36
+ }
52
37
 
53
- const variantStyles = useDefaultComponentStyle<
54
- 'u:ProgressBar',
55
- typeof ProgressBarPresets
56
- >('u:ProgressBar', {
57
- variants,
58
- responsiveVariants,
59
- styles,
60
- })
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])
61
45
 
62
46
  return (
63
- <View css={variantStyles.wrapper} debugName={debugName} {...rest}>
47
+ <View debugName={debugName} {...rest} style={styles.wrapper}>
64
48
  {!TypeGuards.isNil(leftIcon) ? (
65
49
  <Icon
66
50
  name={leftIcon}
67
- style={{ ...variantStyles.icon, ...variantStyles.leftIcon }}
68
51
  debugName={`leftIcon-${debugName}`}
69
52
  {...leftIconProps}
53
+ style={leftIconStyles}
70
54
  />
71
55
  ) : null}
72
56
  {TypeGuards.isString(leftText) ? (
73
57
  <Text
74
58
  text={leftText}
75
- css={[variantStyles.text, variantStyles.leftText]}
76
59
  {...leftTextProps}
60
+ style={leftTextStyles}
77
61
  />
78
- ) : (
79
- leftText
80
- )}
62
+ ) : leftText}
63
+
81
64
  <Root
82
- css={variantStyles.progress}
65
+ // @ts-expect-error
66
+ css={styles.progress}
83
67
  value={progress}
84
68
  {...progressRootProps}
85
69
  >
86
70
  <Indicator
87
- css={[
88
- variantStyles.indicator,
89
- { transform: `translateX(-${100 - progress}%)` },
90
- ]}
71
+ css={{ ...styles.indicator, transform: `translateX(-${100 - progress}%)` }}
91
72
  {...progressIndicatorProps}
92
73
  />
93
74
  </Root>
75
+
94
76
  {TypeGuards.isString(text) || showProgress ? (
95
77
  <Text
96
- style={variantStyles.text}
97
78
  text={showProgress ? formatProgress(progress) : text}
98
79
  {...textProps}
80
+ style={styles.text}
99
81
  />
100
82
  ) : text}
83
+
101
84
  {!TypeGuards.isNil(rightIcon) ? (
102
85
  <Icon
103
86
  name={rightIcon}
104
- style={{ ...variantStyles.icon, ...variantStyles.rightIcon }}
105
87
  debugName={`rightIcon-${debugName}`}
106
88
  {...rightIconProps}
89
+ style={rightIconStyles}
107
90
  />
108
91
  ) : null}
109
92
  {TypeGuards.isString(rightText) ? (
110
93
  <Text
111
94
  text={rightText}
112
- css={[variantStyles.text, variantStyles.rightText]}
113
95
  {...rightTextProps}
96
+ style={rightTextStyles}
114
97
  />
115
- ) : (
116
- rightText
117
- )}
98
+ ) : rightText}
118
99
  </View>
119
100
  )
120
101
  }
121
102
 
122
- ProgressBar.defaultProps = defaultProps
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)
@@ -0,0 +1,10 @@
1
+ export type ProgressBarComposition =
2
+ 'wrapper' |
3
+ 'progress' |
4
+ 'indicator' |
5
+ 'text' |
6
+ 'icon' |
7
+ 'leftIcon' |
8
+ 'leftText' |
9
+ 'rightIcon' |
10
+ 'rightText'
@@ -0,0 +1,26 @@
1
+ import { ProgressBarComposition } from './styles'
2
+ import { ProgressProps, ProgressIndicatorProps } from '@radix-ui/react-progress'
3
+ import { ProgressPropsRoot } from '..'
4
+ import { AppIcon, StyledProp } from '@codeleap/styles'
5
+ import { TextProps } from '../../Text/types'
6
+ import { IconProps } from '../../Icon/types'
7
+ import { ViewProps } from '../../View'
8
+
9
+ export type ProgressBarProps =
10
+ Omit<ViewProps, 'style'> &
11
+ Omit<ProgressPropsRoot, 'style'> &
12
+ {
13
+ style?: StyledProp<ProgressBarComposition>
14
+ progressIndicatorProps?: ProgressIndicatorProps
15
+ progressRootProps?: ProgressProps
16
+ leftIcon?: AppIcon
17
+ leftIconProps?: Partial<IconProps>
18
+ rightIcon?: AppIcon
19
+ rightIconProps?: Partial<IconProps>
20
+ text?: string
21
+ textProps?: Partial<TextProps>
22
+ leftText?: TextProps['text'] | JSX.Element
23
+ leftTextProps?: Partial<TextProps>
24
+ rightText?: TextProps['text'] | JSX.Element
25
+ rightTextProps?: Partial<TextProps>
26
+ }
@@ -1,99 +1,81 @@
1
- import {
2
- CircularProgressbarWithChildren,
3
- buildStyles,
4
- } from 'react-circular-progressbar'
5
- import { View, Text, Icon } from '../../components'
6
- import { TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
7
- import { ProgressCirclePresets } from './styles'
1
+ import { CircularProgressbarWithChildren, buildStyles } from 'react-circular-progressbar'
2
+ import { TypeGuards } from '@codeleap/common'
8
3
  import { ProgressCircleProps } from './types'
9
4
  import { formatProgress as _formatProgress } from '../utils'
10
5
  import { useMemo } from '@codeleap/common'
6
+ import { useStylesFor } from '../../../lib/hooks/useStylesFor'
7
+ import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
8
+ import { WebStyleRegistry } from '../../../lib/WebStyleRegistry'
9
+ import { Text } from '../../Text'
10
+ import { Icon } from '../../Icon'
11
+ import { View } from '../../View'
12
+ import { CSSProperties } from 'react'
11
13
 
12
14
  export * from './styles'
13
15
  export * from './types'
14
16
 
15
- const defaultProps: Partial<ProgressCircleProps> = {
16
- progress: 0,
17
- variants: [],
18
- responsiveVariants: {},
19
- styles: {},
20
- showProgress: false,
21
- formatProgress: _formatProgress,
22
- size: null,
23
- }
24
-
25
17
  export const ProgressCircle = (props: ProgressCircleProps) => {
26
- const allProps = {
27
- ...ProgressCircle.defaultProps,
28
- ...props,
29
- }
30
-
31
18
  const {
32
19
  text,
33
20
  progress,
34
21
  icon,
35
22
  iconProps,
36
- variants,
37
- styles,
38
23
  debugName,
39
24
  showProgress,
40
- responsiveVariants,
41
25
  circleProps,
42
26
  children,
43
27
  formatProgress,
44
28
  circleStyles,
29
+ style,
45
30
  textProps,
46
31
  size: propSize,
47
32
  ...rest
48
- } = allProps
33
+ } = {
34
+ ...ProgressCircle.defaultProps,
35
+ ...props,
36
+ }
49
37
 
50
- const variantStyles = useDefaultComponentStyle<
51
- 'u:ProgressCircle',
52
- typeof ProgressCirclePresets
53
- >('u:ProgressCircle', {
54
- variants,
55
- responsiveVariants,
56
- styles,
57
- rootElement: 'wrapper',
58
- })
38
+ const styles = useStylesFor(ProgressCircle.styleRegistryName, style)
59
39
 
60
40
  const wrapperSize = useMemo(() => {
61
41
  if (TypeGuards.isNumber(propSize)) return propSize
62
- const { size, width, height } = variantStyles.circle
63
- const value = size ?? width ?? height
42
+ // @ts-expect-error icss type
43
+ const value = styles.circle?.size ?? styles.circle?.width ?? styles.circle?.height
64
44
  return value ?? 0
65
- }, [variantStyles.circle])
45
+ }, [styles.circle])
46
+
47
+ const lineStyle = styles.line as CSSProperties
66
48
 
67
49
  return (
68
- <View debugName={debugName} css={variantStyles.wrapper} {...rest}>
50
+ <View debugName={debugName} {...rest} style={styles.wrapper}>
69
51
  <CircularProgressbarWithChildren
70
52
  value={progress}
71
- css={[
72
- variantStyles.circle,
73
- { width: wrapperSize, height: wrapperSize },
74
- ]}
75
53
  styles={buildStyles({
76
- pathColor: variantStyles.line?.borderColor,
77
- trailColor: variantStyles.line?.backgroundColor,
54
+ pathColor: lineStyle?.borderColor,
55
+ trailColor: lineStyle?.backgroundColor,
78
56
  strokeLinecap: 'butt',
79
57
  ...circleStyles,
80
58
  })}
81
59
  {...circleProps}
60
+ // @ts-expect-error
61
+ css={[styles.circle, { width: wrapperSize, height: wrapperSize }]}
82
62
  >
83
63
  {children}
64
+
84
65
  {!TypeGuards.isNil(icon) ? (
85
66
  <Icon
86
67
  name={icon}
87
- style={variantStyles.icon}
88
68
  debugName={`innerIcon-${debugName}`}
89
69
  {...iconProps}
70
+ style={styles.icon}
90
71
  />
91
72
  ) : null}
73
+
92
74
  {TypeGuards.isString(text) || showProgress ? (
93
75
  <Text
94
- style={variantStyles.text}
95
76
  text={showProgress ? formatProgress(progress) : String(text)}
96
77
  {...textProps}
78
+ style={styles.text}
97
79
  />
98
80
  ) : text}
99
81
  </CircularProgressbarWithChildren>
@@ -101,4 +83,19 @@ export const ProgressCircle = (props: ProgressCircleProps) => {
101
83
  )
102
84
  }
103
85
 
104
- ProgressCircle.defaultProps = defaultProps
86
+ ProgressCircle.styleRegistryName = 'ProgressCircle'
87
+ ProgressCircle.elements = ['wrapper', 'line', 'circle', 'text', 'icon', 'text']
88
+ ProgressCircle.rootElement = 'wrapper'
89
+
90
+ ProgressCircle.withVariantTypes = <S extends AnyRecord>(styles: S) => {
91
+ return ProgressCircle as (props: StyledComponentProps<ProgressCircleProps, typeof styles>) => IJSX
92
+ }
93
+
94
+ ProgressCircle.defaultProps = {
95
+ progress: 0,
96
+ showProgress: false,
97
+ formatProgress: _formatProgress,
98
+ size: null,
99
+ } as Partial<ProgressCircleProps>
100
+
101
+ WebStyleRegistry.registerComponent(ProgressCircle)
@@ -1,8 +1 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
- import 'react-circular-progressbar/dist/styles.css'
3
-
4
- export type ProgressCircleComposition = 'wrapper' | 'line' | 'circle' | 'text' | 'icon' | 'text'
5
-
6
- const createProgressCircleStyle = createDefaultVariantFactory<ProgressCircleComposition>()
7
-
8
- export const ProgressCirclePresets = includePresets((styles) => createProgressCircleStyle(() => ({ wrapper: styles })))
1
+ export type ProgressCircleComposition = 'wrapper' | 'line' | 'circle' | 'text' | 'icon'