@codeleap/web 3.24.3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/package.json +2 -1
  2. package/src/components/ActionIcon/index.tsx +51 -52
  3. package/src/components/ActionIcon/styles.ts +1 -5
  4. package/src/components/ActionIcon/types.ts +15 -0
  5. package/src/components/ActivityIndicator/index.tsx +34 -55
  6. package/src/components/ActivityIndicator/styles.ts +0 -6
  7. package/src/components/ActivityIndicator/types.ts +12 -0
  8. package/src/components/Badge/index.tsx +43 -80
  9. package/src/components/Badge/styles.ts +1 -11
  10. package/src/components/Badge/types.ts +28 -0
  11. package/src/components/Button/index.tsx +46 -89
  12. package/src/components/Button/styles.ts +0 -5
  13. package/src/components/Button/types.ts +25 -0
  14. package/src/components/Checkbox/index.tsx +83 -97
  15. package/src/components/Checkbox/styles.ts +1 -5
  16. package/src/components/Checkbox/types.ts +15 -0
  17. package/src/components/Collapse/index.tsx +41 -83
  18. package/src/components/Collapse/styles.ts +3 -6
  19. package/src/components/Collapse/types.ts +11 -0
  20. package/src/components/ColorPicker/index.tsx +95 -48
  21. package/src/components/ColorPicker/styles.ts +11 -11
  22. package/src/components/ColorPicker/types.ts +26 -12
  23. package/src/components/CropPicker/index.tsx +100 -104
  24. package/src/components/CropPicker/styles.ts +0 -7
  25. package/src/components/CropPicker/types.ts +8 -15
  26. package/src/components/DatePicker/{defaultComponents → components}/Header.tsx +9 -17
  27. package/src/components/DatePicker/{defaultComponents → components}/OuterInput.tsx +6 -7
  28. package/src/components/DatePicker/index.tsx +110 -124
  29. package/src/components/DatePicker/styles.ts +1 -12
  30. package/src/components/DatePicker/types.ts +16 -33
  31. package/src/components/Drawer/index.tsx +133 -125
  32. package/src/components/Drawer/styles.ts +0 -5
  33. package/src/components/Drawer/types.ts +23 -0
  34. package/src/components/Dropzone/index.tsx +87 -63
  35. package/src/components/Dropzone/styles.ts +0 -6
  36. package/src/components/Dropzone/types.ts +29 -37
  37. package/src/components/EmptyPlaceholder/index.tsx +63 -83
  38. package/src/components/EmptyPlaceholder/styles.ts +0 -5
  39. package/src/components/EmptyPlaceholder/types.ts +32 -0
  40. package/src/components/FileInput/index.tsx +72 -0
  41. package/src/components/FileInput/types.ts +14 -0
  42. package/src/components/Grid/index.tsx +40 -41
  43. package/src/components/Grid/styles.ts +2 -9
  44. package/src/components/Grid/types.ts +10 -12
  45. package/src/components/Icon/index.tsx +45 -47
  46. package/src/components/Icon/styles.ts +0 -8
  47. package/src/components/Icon/types.ts +15 -0
  48. package/src/components/InputBase/index.tsx +71 -42
  49. package/src/components/InputBase/styles.ts +37 -47
  50. package/src/components/InputBase/types.ts +19 -7
  51. package/src/components/InputBase/utils.ts +3 -23
  52. package/src/components/List/ListLayout.tsx +20 -37
  53. package/src/components/List/index.tsx +36 -41
  54. package/src/components/List/styles.ts +5 -11
  55. package/src/components/List/types.ts +30 -20
  56. package/src/components/LoadingOverlay/index.tsx +31 -33
  57. package/src/components/LoadingOverlay/styles.ts +3 -8
  58. package/src/components/LoadingOverlay/types.ts +16 -0
  59. package/src/components/Modal/index.tsx +98 -160
  60. package/src/components/Modal/styles.ts +0 -5
  61. package/src/components/Modal/types.ts +55 -0
  62. package/src/components/NumberIncrement/index.tsx +67 -98
  63. package/src/components/NumberIncrement/styles.ts +0 -5
  64. package/src/components/NumberIncrement/types.ts +29 -0
  65. package/src/components/Overlay/index.tsx +37 -35
  66. package/src/components/Overlay/styles.ts +3 -5
  67. package/src/components/Overlay/types.ts +13 -0
  68. package/src/components/Pager/index.tsx +65 -81
  69. package/src/components/Pager/styles.ts +3 -9
  70. package/src/components/Pager/types.ts +35 -0
  71. package/src/components/PaginationButtons/index.tsx +173 -0
  72. package/src/components/PaginationButtons/styles.ts +7 -0
  73. package/src/components/PaginationButtons/types.ts +26 -0
  74. package/src/components/PaginationIndicator/index.tsx +69 -0
  75. package/src/components/PaginationIndicator/styles.ts +3 -0
  76. package/src/components/PaginationIndicator/types.ts +18 -0
  77. package/src/components/Progress/Bar/index.tsx +45 -50
  78. package/src/components/Progress/Bar/styles.ts +10 -0
  79. package/src/components/Progress/Bar/types.ts +26 -0
  80. package/src/components/Progress/Circle/index.tsx +45 -48
  81. package/src/components/Progress/Circle/styles.ts +1 -8
  82. package/src/components/Progress/Circle/types.ts +10 -22
  83. package/src/components/RadioInput/index.tsx +78 -124
  84. package/src/components/RadioInput/styles.ts +0 -6
  85. package/src/components/RadioInput/types.ts +29 -0
  86. package/src/components/SearchInput/index.tsx +10 -10
  87. package/src/components/SectionFilters/index.tsx +47 -36
  88. package/src/components/SectionFilters/styles.ts +1 -5
  89. package/src/components/SectionFilters/types.ts +14 -13
  90. package/src/components/SegmentedControl/index.tsx +111 -89
  91. package/src/components/SegmentedControl/styles.ts +7 -21
  92. package/src/components/SegmentedControl/types.ts +44 -0
  93. package/src/components/Select/index.tsx +92 -56
  94. package/src/components/Select/styles.ts +19 -36
  95. package/src/components/Select/types.ts +15 -10
  96. package/src/components/Slider/index.tsx +85 -93
  97. package/src/components/Slider/styles.ts +13 -6
  98. package/src/components/Slider/types.ts +29 -0
  99. package/src/components/Switch/index.tsx +63 -74
  100. package/src/components/Switch/styles.ts +1 -6
  101. package/src/components/Switch/types.ts +13 -0
  102. package/src/components/Tag/index.tsx +39 -44
  103. package/src/components/Tag/styles.ts +1 -9
  104. package/src/components/Tag/types.ts +10 -10
  105. package/src/components/Text/index.tsx +37 -48
  106. package/src/components/Text/styles.ts +0 -8
  107. package/src/components/Text/types.ts +8 -8
  108. package/src/components/TextEditor/index.tsx +49 -28
  109. package/src/components/TextEditor/styles.ts +1 -8
  110. package/src/components/TextEditor/types.ts +11 -6
  111. package/src/components/TextInput/index.tsx +58 -96
  112. package/src/components/TextInput/mask.tsx +2 -50
  113. package/src/components/TextInput/styles.ts +3 -8
  114. package/src/components/TextInput/types.ts +85 -0
  115. package/src/components/Tooltip/index.tsx +61 -84
  116. package/src/components/Tooltip/styles.ts +3 -10
  117. package/src/components/Tooltip/types.ts +46 -0
  118. package/src/components/Touchable/index.tsx +43 -86
  119. package/src/components/Touchable/styles.ts +0 -6
  120. package/src/components/Touchable/types.ts +22 -0
  121. package/src/components/View/index.tsx +36 -50
  122. package/src/components/View/styles.ts +0 -6
  123. package/src/components/View/types.ts +14 -15
  124. package/src/components/components.ts +2 -3
  125. package/src/index.ts +1 -0
  126. package/src/lib/WebStyleRegistry.ts +51 -0
  127. package/src/lib/hooks/index.ts +5 -0
  128. package/src/lib/hooks/useBreakpointMatch.ts +8 -7
  129. package/src/{components/CropPicker/useCropPicker.tsx → lib/hooks/useCropPicker.ts} +66 -13
  130. package/src/lib/hooks/useFileInput.ts +15 -0
  131. package/src/lib/hooks/useInfiniteScroll.ts +77 -0
  132. package/src/lib/hooks/useMediaQuery.ts +4 -3
  133. package/src/lib/hooks/usePagination.ts +79 -63
  134. package/src/lib/hooks/useRefresh.ts +87 -0
  135. package/src/lib/hooks/useStylesFor.ts +13 -0
  136. package/src/lib/index.ts +1 -0
  137. package/src/lib/utils/cache.ts +9 -0
  138. package/src/lib/utils/index.ts +1 -0
  139. package/src/lib/utils/test.ts +2 -2
  140. package/src/components/CropPicker/utils.ts +0 -51
  141. package/src/components/FileInput.tsx +0 -91
  142. package/src/components/List/PaginationIndicator.tsx +0 -102
  143. package/src/components/List/useInfiniteScroll.ts +0 -159
  144. package/src/components/Progress/Bar/styles.tsx +0 -7
  145. package/src/components/Progress/Bar/types.tsx +0 -30
  146. package/src/components/Scroll/index.tsx +0 -32
  147. package/src/components/Scroll/styles.ts +0 -8
  148. package/src/components/SegmentedControl/SegmentedControlOption.tsx +0 -84
  149. package/src/components/defaultStyles.ts +0 -79
  150. /package/src/components/DatePicker/{defaultComponents → components}/index.tsx +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.24.3",
3
+ "version": "4.0.0",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -43,6 +43,7 @@
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@codeleap/common": "*",
46
+ "@codeleap/styles": "*",
46
47
  "@emotion/react": "11.10.6",
47
48
  "@reach/router": "^1.3.4",
48
49
  "axios": "1.3.5",
@@ -1,94 +1,93 @@
1
- import { ComponentVariants, TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
2
- import { ComponentCommonProps, StylesOf } from '../../types'
3
- import { Icon, IconProps } from '../Icon'
4
- import { Touchable, TouchableProps } from '../Touchable'
1
+ import { TypeGuards } from '@codeleap/common'
2
+ import { Icon } from '../Icon'
3
+ import { Touchable } from '../Touchable'
5
4
  import { View } from '../View'
6
- import { ActionIconComposition, ActionIconParts, ActionIconPresets } from './styles'
5
+ import { ActionIconParts } from './styles'
6
+ import { ActionIconProps } from './types'
7
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
8
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
9
+ import { AnyRecord, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
10
+ import { ElementType } from 'react'
7
11
 
8
12
  export * from './styles'
9
-
10
- /** IconButton */
11
- export type ActionIconProps = Omit<TouchableProps, 'styles' | 'variants'> & ComponentCommonProps & {
12
- iconProps?: Partial<IconProps>
13
- /** prop */
14
- icon?: IconProps['name']
15
- /** prop */
16
- name?: IconProps['name']
17
-
18
- styles?: StylesOf<ActionIconComposition>
19
- } & ComponentVariants<typeof ActionIconPresets>
20
-
21
- const defaultProps: Partial<ActionIconProps> = {
22
- disabled: false,
23
- tabIndex: 0,
24
- }
13
+ export * from './types'
25
14
 
26
15
  export const ActionIcon = (props: ActionIconProps) => {
27
- const allProps = {
28
- ...ActionIcon.defaultProps,
29
- ...props,
30
- }
31
-
32
16
  const {
33
17
  icon,
34
18
  name,
35
19
  iconProps,
36
20
  onPress,
37
- responsiveVariants = {},
38
- variants = [],
39
- styles = {},
21
+ style,
40
22
  children,
41
23
  disabled,
42
24
  debugName,
43
25
  ...touchableProps
44
- } = allProps
26
+ } = {
27
+ ...ActionIcon.defaultProps,
28
+ ...props,
29
+ }
45
30
 
46
- const variantStyles = useDefaultComponentStyle<'u:ActionIcon', typeof ActionIconPresets>('u:ActionIcon', {
47
- responsiveVariants,
48
- variants,
49
- styles,
50
- rootElement: 'touchableWrapper',
51
- })
31
+ const styles = useStylesFor(ActionIcon.styleRegistryName, style)
52
32
 
53
33
  const isPressable = TypeGuards.isFunction(onPress) && !disabled
54
34
 
55
- const WrapperComponent: any = isPressable ? Touchable : View
35
+ const WrapperComponent: ElementType = isPressable ? Touchable : View
56
36
 
57
37
  const handlePress = (e) => {
58
38
  if (!isPressable) return
59
- if (onPress && (e?.type === 'click' || e?.keyCode === 13 || e?.key === 'Enter')) {
39
+
40
+ const pressed = e?.type === 'click' || e?.keyCode === 13 || e?.key === 'Enter'
41
+
42
+ if (pressed) {
60
43
  onPress?.()
61
44
  }
62
45
  }
63
46
 
64
- const getStyles = (key: ActionIconParts) => ({
65
- ...variantStyles[key],
66
- ...(disabled ? variantStyles[`${key}:disabled`] : {}),
67
- ...(isPressable ? variantStyles[`${key}:pressable`] : {}),
68
- })
47
+ const getStyles = (key: ActionIconParts) => mergeStyles([
48
+ styles[key],
49
+ disabled && styles[`${key}:disabled`],
50
+ isPressable && styles[`${key}:pressable`],
51
+ ])
52
+
53
+ const wrapperProps = isPressable ? {
54
+ onPress: () => handlePress({ type: 'click' }),
55
+ onKeyDown: handlePress,
56
+ } : {}
57
+
58
+ const wrapperStyles = getStyles('touchableWrapper')
59
+ const iconStyles = getStyles('icon')
69
60
 
70
61
  return (
71
62
  <WrapperComponent
72
- css={getStyles('touchableWrapper')}
73
63
  disabled={disabled}
74
64
  debugName={debugName}
75
- {
76
- ...(isPressable && {
77
- onPress: () => handlePress({ type: 'click' }),
78
- onKeyDown: handlePress,
79
- })
80
- }
65
+ {...wrapperProps}
81
66
  {...touchableProps}
67
+ style={wrapperStyles}
82
68
  >
83
69
  <Icon
84
70
  debugName={debugName}
85
71
  name={icon ?? name}
86
- style={getStyles('icon')}
87
72
  {...iconProps}
73
+ style={iconStyles}
88
74
  />
89
75
  {children}
90
76
  </WrapperComponent>
91
77
  )
92
78
  }
93
79
 
94
- ActionIcon.defaultProps = defaultProps
80
+ ActionIcon.styleRegistryName = 'ActionIcon'
81
+ ActionIcon.elements = ['touchable', 'icon']
82
+ ActionIcon.rootElement = 'touchableWrapper'
83
+
84
+ ActionIcon.withVariantTypes = <S extends AnyRecord>(styles: S) => {
85
+ return ActionIcon as (props: StyledComponentProps<ActionIconProps, typeof styles>) => IJSX
86
+ }
87
+
88
+ ActionIcon.defaultProps = {
89
+ disabled: false,
90
+ tabIndex: 0,
91
+ } as Partial<ActionIconProps>
92
+
93
+ WebStyleRegistry.registerComponent(ActionIcon)
@@ -1,12 +1,8 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { IconComposition } from '../Icon'
3
2
  import { TouchableComposition } from '../Touchable/styles'
4
3
 
5
4
  export type ActionIconParts = IconComposition | `touchable${Capitalize<TouchableComposition>}`
5
+
6
6
  export type ActionIconStates = 'disabled' | 'pressable'
7
7
 
8
8
  export type ActionIconComposition = ActionIconParts | `${ActionIconParts}:${ActionIconStates}`
9
-
10
- const createActionIconStyle = createDefaultVariantFactory<ActionIconComposition>()
11
-
12
- export const ActionIconPresets = includePresets((style) => createActionIconStyle(() => ({ touchableWrapper: style })))
@@ -0,0 +1,15 @@
1
+ import { ComponentCommonProps } from '../../types'
2
+ import { TouchableProps } from '../Touchable'
3
+ import { ActionIconComposition } from './styles'
4
+ import { IconProps } from '../Icon'
5
+ import { AppIcon, StyledProp } from '@codeleap/styles'
6
+
7
+ export type ActionIconProps =
8
+ Omit<TouchableProps, 'style'> &
9
+ ComponentCommonProps &
10
+ {
11
+ iconProps?: Partial<IconProps>
12
+ icon?: AppIcon
13
+ name?: AppIcon
14
+ style?: StyledProp<ActionIconComposition>
15
+ }
@@ -1,75 +1,54 @@
1
1
  import { View } from '../View'
2
- import React from 'react'
3
- import {
4
- useDefaultComponentStyle,
5
- ComponentVariants,
6
- ActivityIndicatorStyles,
7
- ActivityIndicatorComposition,
8
- StylesOf,
9
- TypeGuards,
10
- } from '@codeleap/common'
11
- import { ActivityIndicatorPresets } from './styles'
12
- import { CSSInterpolation } from '@emotion/css'
13
- import { ComponentCommonProps, ComponentWithDefaultProps } from '../../types'
2
+ import React, { forwardRef } from 'react'
3
+ import { TypeGuards } from '@codeleap/common'
4
+ import { ActivityIndicatorProps } from './types'
5
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
6
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
7
+ import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
14
8
 
15
9
  export * from './styles'
10
+ export * from './types'
16
11
 
17
- /** * LoadingIndicator */
18
- export type ActivityIndicatorProps = ComponentCommonProps & {
19
- style?: React.CSSProperties
20
- styles?: StylesOf<ActivityIndicatorComposition>
21
- css?: CSSInterpolation | CSSInterpolation[]
22
- /** prop */
23
- component?: React.ComponentType<Omit<ActivityIndicatorProps & {ref?: React.Ref<any>}, 'component'>>
24
- /** prop */
25
- size?: number
26
- } & ComponentVariants<typeof ActivityIndicatorStyles>
27
-
28
- export const ActivityIndicator = React.forwardRef<typeof View, ActivityIndicatorProps>((activityIndicatorProps, ref) => {
29
- const allProps = {
30
- ...ActivityIndicator.defaultProps,
31
- ...activityIndicatorProps,
32
- }
33
-
12
+ export const ActivityIndicator = forwardRef<HTMLDivElement, ActivityIndicatorProps>((props, ref) => {
34
13
  const {
35
- style = {},
36
- styles = {},
14
+ style,
37
15
  component: Component,
38
- variants = [],
39
- responsiveVariants = {},
40
16
  size,
41
- ...props
42
- } = allProps
17
+ ...rest
18
+ } = {
19
+ ...ActivityIndicator.defaultProps,
20
+ ...props,
21
+ }
43
22
 
44
- const variantStyles = useDefaultComponentStyle<'u:ActivityIndicator', typeof ActivityIndicatorPresets>(
45
- 'u:ActivityIndicator',
46
- {
47
- responsiveVariants,
48
- variants,
49
- styles,
50
- rootElement: 'wrapper',
51
- },
52
- )
23
+ const styles = useStylesFor(ActivityIndicator.styleRegistryName, style)
53
24
 
54
25
  const _size = React.useMemo(() => {
55
26
  return TypeGuards.isNumber(size) ? {
56
27
  width: size,
57
28
  height: size,
58
- } : {}
29
+ } : null
59
30
  }, [size])
60
31
 
61
32
  return (
62
- <View css={[variantStyles.wrapper, _size, style]}>
63
- <Component
64
- ref={ref}
65
- css={[variantStyles.wrapper, _size, style]}
66
- {...props}
67
- />
68
- </View>
33
+ <Component
34
+ ref={ref}
35
+ {...rest}
36
+ style={[styles.wrapper, _size]}
37
+ />
69
38
  )
70
- }) as ComponentWithDefaultProps<ActivityIndicatorProps>
39
+ }) as StyledComponentWithProps<ActivityIndicatorProps>
40
+
41
+ ActivityIndicator.styleRegistryName = 'ActivityIndicator'
42
+ ActivityIndicator.elements = ['wrapper']
43
+ ActivityIndicator.rootElement = 'wrapper'
44
+
45
+ ActivityIndicator.withVariantTypes = <S extends AnyRecord>(styles: S) => {
46
+ return ActivityIndicator as (props: StyledComponentProps<ActivityIndicatorProps, typeof styles>) => IJSX
47
+ }
71
48
 
72
49
  ActivityIndicator.defaultProps = {
73
- component: View as ActivityIndicatorProps['component'],
50
+ component: View,
74
51
  size: null,
75
- }
52
+ } as Partial<ActivityIndicatorProps>
53
+
54
+ WebStyleRegistry.registerComponent(ActivityIndicator)
@@ -1,7 +1 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
-
3
1
  export type ActivityIndicatorComposition = 'wrapper'
4
-
5
- const createActivityIndicatorStyle = createDefaultVariantFactory<ActivityIndicatorComposition>()
6
-
7
- export const ActivityIndicatorPresets = includePresets((styles) => createActivityIndicatorStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,12 @@
1
+ import React from 'react'
2
+ import { StyledProp } from '@codeleap/styles'
3
+ import { ComponentCommonProps } from '../../types'
4
+ import { ActivityIndicatorComposition } from './styles'
5
+
6
+ export type ActivityIndicatorProps =
7
+ ComponentCommonProps &
8
+ {
9
+ style?: StyledProp<ActivityIndicatorComposition>
10
+ component?: React.ComponentType<Omit<ActivityIndicatorProps & { ref?: React.Ref<HTMLDivElement> }, 'component'>>
11
+ size?: number
12
+ }
@@ -1,42 +1,14 @@
1
1
  import React from 'react'
2
- import { ComponentVariants, PropsOf, StylesOf, TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
2
+ import { TypeGuards } from '@codeleap/common'
3
3
  import { Text } from '../Text'
4
- import { View, ViewProps } from '../View'
5
- import { BadgeComposition, BadgePresets } from './styles'
6
- import { ComponentCommonProps } from '../../types'
4
+ import { View } from '../View'
5
+ import { BadgeContent, BadgeProps } from './types'
6
+ import { useStylesFor } from '../../lib/hooks/useStylesFor'
7
+ import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
8
+ import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
7
9
 
8
10
  export * from './styles'
9
-
10
- /** * Badge */
11
- export type BadgeProps = ComponentVariants<typeof BadgePresets>
12
- & ViewProps<'div'>
13
- & ComponentCommonProps
14
- & {
15
- styles?: StylesOf<BadgeComposition>
16
- /** prop */
17
- maxCount?: number
18
- /** prop */
19
- minCount?: number
20
- /** prop */
21
- debugName?: string
22
- innerWrapperProps?: Partial<PropsOf<typeof View>>
23
- textProps?: Partial<PropsOf<typeof Text>>
24
- /** prop */
25
- getBadgeContent?: (props: BadgeContent) => string
26
- /** prop */
27
- renderBadgeContent?: (props: BadgeContent & { content: string }) => JSX.Element
28
- /** prop */
29
- disabled?: boolean
30
- /** prop */
31
- badge?: number | boolean
32
- }
33
-
34
- type BadgeContent = BadgeProps & { count: number }
35
-
36
- export type BadgeComponentProps = {
37
- badge?: BadgeProps['badge']
38
- badgeProps?: Partial<BadgeProps>
39
- }
11
+ export * from './types'
40
12
 
41
13
  const defaultGetBadgeContent = ({ count, maxCount }: BadgeContent) => {
42
14
  if (Number(count) > maxCount) {
@@ -46,66 +18,44 @@ const defaultGetBadgeContent = ({ count, maxCount }: BadgeContent) => {
46
18
  }
47
19
  }
48
20
 
49
- const defaultProps: Partial<BadgeProps> = {
50
- maxCount: 9,
51
- minCount: 1,
52
- getBadgeContent: defaultGetBadgeContent,
53
- renderBadgeContent: null,
54
- disabled: false,
55
- badge: true,
56
- }
57
-
58
21
  export const Badge = (props: BadgeProps) => {
59
- const allProps = {
60
- ...Badge.defaultProps,
61
- ...props,
62
- }
63
-
64
22
  const {
65
23
  debugName,
66
- innerWrapperProps = {},
67
- textProps = {},
24
+ innerWrapperProps,
25
+ textProps,
68
26
  maxCount,
69
27
  minCount,
70
28
  getBadgeContent,
71
29
  renderBadgeContent,
72
- styles = {},
73
- variants = [],
74
- responsiveVariants = {},
75
30
  disabled,
76
- style = {},
77
- css,
31
+ style,
78
32
  badge,
79
33
  ...rest
80
- } = allProps
34
+ } = {
35
+ ...Badge.defaultProps,
36
+ ...props,
37
+ }
38
+
39
+ const styles = useStylesFor(Badge.styleRegistryName, style)
81
40
 
82
41
  const visible = (TypeGuards.isBoolean(badge) && badge === true) || TypeGuards.isNumber(badge)
83
42
 
84
43
  if (!visible) return null
85
44
 
86
- const variantStyles = useDefaultComponentStyle<'u:Badge', typeof BadgePresets>('u:Badge', {
87
- responsiveVariants,
88
- variants,
89
- styles,
90
- rootElement: 'wrapper',
91
- })
92
-
93
45
  const wrapperStyles = [
94
- variantStyles?.wrapper,
95
- (disabled && variantStyles?.['wrapper:disabled']),
96
- css,
97
- style,
46
+ styles?.wrapper,
47
+ (disabled && styles?.['wrapper:disabled']),
98
48
  ]
99
49
 
100
50
  const innerWrapperStyles = [
101
- variantStyles?.innerWrapper,
102
- (disabled && variantStyles?.['innerWrapper:disabled']),
51
+ styles?.innerWrapper,
52
+ (disabled && styles?.['innerWrapper:disabled']),
103
53
  innerWrapperProps?.style,
104
54
  ]
105
55
 
106
56
  const countStyles = [
107
- variantStyles?.count,
108
- (disabled && variantStyles?.['count:disabled']),
57
+ styles?.count,
58
+ (disabled && styles?.['count:disabled']),
109
59
  textProps?.style,
110
60
  ]
111
61
 
@@ -115,18 +65,15 @@ export const Badge = (props: BadgeProps) => {
115
65
 
116
66
  const showContent = TypeGuards.isNumber(count) && count >= minCount
117
67
 
118
- let BadgeContent = renderBadgeContent
119
-
120
- if (TypeGuards.isNil(renderBadgeContent)) {
121
- BadgeContent = () => <Text text={content} {...textProps} css={countStyles} />
122
- }
68
+ const BadgeContent = TypeGuards.isNil(renderBadgeContent) ? () => <Text text={content} {...textProps} /> : renderBadgeContent
123
69
 
124
70
  return (
125
- <View {...rest} css={wrapperStyles}>
126
- <View {...innerWrapperProps} css={innerWrapperStyles}>
71
+ <View {...rest} style={wrapperStyles}>
72
+ <View {...innerWrapperProps} style={innerWrapperStyles}>
127
73
  {showContent
128
74
  ? <BadgeContent
129
75
  {...props}
76
+ style={countStyles}
130
77
  maxCount={maxCount}
131
78
  minCount={minCount}
132
79
  count={count}
@@ -140,4 +87,20 @@ export const Badge = (props: BadgeProps) => {
140
87
  )
141
88
  }
142
89
 
143
- Badge.defaultProps = defaultProps
90
+ Badge.styleRegistryName = 'Badge'
91
+ Badge.elements = ['wrapper', 'innerWrapper', 'count']
92
+ Badge.rootElement = 'wrapper'
93
+
94
+ Badge.withVariantTypes = <S extends AnyRecord>(styles: S) => {
95
+ return Badge as (props: StyledComponentProps<BadgeProps, typeof styles>) => IJSX
96
+ }
97
+
98
+ Badge.defaultProps = {
99
+ maxCount: 9,
100
+ minCount: 1,
101
+ getBadgeContent: defaultGetBadgeContent,
102
+ disabled: false,
103
+ badge: true,
104
+ } as Partial<BadgeProps>
105
+
106
+ WebStyleRegistry.registerComponent(Badge)
@@ -1,15 +1,5 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
-
3
1
  type BadgeParts = 'wrapper' | 'innerWrapper' | 'count'
4
2
 
5
3
  type BadgeStates = 'disabled'
6
4
 
7
- export type BadgeComposition =
8
- `${BadgeParts}:${BadgeStates}`
9
- | BadgeParts
10
-
11
- const createBadgeStyle = createDefaultVariantFactory<BadgeComposition>()
12
-
13
- export const BadgePresets = includePresets((styles) => createBadgeStyle(() => ({
14
- wrapper: styles
15
- })))
5
+ export type BadgeComposition = `${BadgeParts}:${BadgeStates}` | BadgeParts
@@ -0,0 +1,28 @@
1
+ import { TextProps } from '../Text'
2
+ import { ViewProps } from '../View'
3
+ import { BadgeComposition } from './styles'
4
+ import { ComponentCommonProps } from '../../types'
5
+ import { StyledProp } from '@codeleap/styles'
6
+
7
+ export type BadgeProps =
8
+ Omit<ViewProps, 'style'> &
9
+ ComponentCommonProps &
10
+ {
11
+ style?: StyledProp<BadgeComposition>
12
+ maxCount?: number
13
+ minCount?: number
14
+ debugName?: string
15
+ innerWrapperProps?: Partial<ViewProps>
16
+ textProps?: Partial<TextProps>
17
+ getBadgeContent?: (props: BadgeContent) => string
18
+ renderBadgeContent?: (props: BadgeContent & { content: string }) => JSX.Element
19
+ disabled?: boolean
20
+ badge?: number | boolean
21
+ }
22
+
23
+ export type BadgeContent = BadgeProps & { count: number }
24
+
25
+ export type BadgeComponentProps = {
26
+ badge?: BadgeProps['badge']
27
+ badgeProps?: Partial<BadgeProps>
28
+ }