@codeleap/web 3.25.0 → 3.25.2

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 +58 -92
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.25.0",
3
+ "version": "3.25.2",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -43,7 +43,6 @@
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@codeleap/common": "*",
46
- "@codeleap/styles": "*",
47
46
  "@emotion/react": "11.10.6",
48
47
  "@reach/router": "^1.3.4",
49
48
  "axios": "1.3.5",
@@ -1,93 +1,94 @@
1
- import { TypeGuards } from '@codeleap/common'
2
- import { Icon } from '../Icon'
3
- import { Touchable } from '../Touchable'
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'
4
5
  import { View } from '../View'
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'
6
+ import { ActionIconComposition, ActionIconParts, ActionIconPresets } from './styles'
11
7
 
12
8
  export * from './styles'
13
- export * from './types'
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
+ }
14
25
 
15
26
  export const ActionIcon = (props: ActionIconProps) => {
27
+ const allProps = {
28
+ ...ActionIcon.defaultProps,
29
+ ...props,
30
+ }
31
+
16
32
  const {
17
33
  icon,
18
34
  name,
19
35
  iconProps,
20
36
  onPress,
21
- style,
37
+ responsiveVariants = {},
38
+ variants = [],
39
+ styles = {},
22
40
  children,
23
41
  disabled,
24
42
  debugName,
25
43
  ...touchableProps
26
- } = {
27
- ...ActionIcon.defaultProps,
28
- ...props,
29
- }
44
+ } = allProps
30
45
 
31
- const styles = useStylesFor(ActionIcon.styleRegistryName, style)
46
+ const variantStyles = useDefaultComponentStyle<'u:ActionIcon', typeof ActionIconPresets>('u:ActionIcon', {
47
+ responsiveVariants,
48
+ variants,
49
+ styles,
50
+ rootElement: 'touchableWrapper',
51
+ })
32
52
 
33
53
  const isPressable = TypeGuards.isFunction(onPress) && !disabled
34
54
 
35
- const WrapperComponent: ElementType = isPressable ? Touchable : View
55
+ const WrapperComponent: any = isPressable ? Touchable : View
36
56
 
37
57
  const handlePress = (e) => {
38
58
  if (!isPressable) return
39
-
40
- const pressed = e?.type === 'click' || e?.keyCode === 13 || e?.key === 'Enter'
41
-
42
- if (pressed) {
59
+ if (onPress && (e?.type === 'click' || e?.keyCode === 13 || e?.key === 'Enter')) {
43
60
  onPress?.()
44
61
  }
45
62
  }
46
63
 
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')
64
+ const getStyles = (key: ActionIconParts) => ({
65
+ ...variantStyles[key],
66
+ ...(disabled ? variantStyles[`${key}:disabled`] : {}),
67
+ ...(isPressable ? variantStyles[`${key}:pressable`] : {}),
68
+ })
60
69
 
61
70
  return (
62
71
  <WrapperComponent
72
+ css={getStyles('touchableWrapper')}
63
73
  disabled={disabled}
64
74
  debugName={debugName}
65
- {...wrapperProps}
75
+ {
76
+ ...(isPressable && {
77
+ onPress: () => handlePress({ type: 'click' }),
78
+ onKeyDown: handlePress,
79
+ })
80
+ }
66
81
  {...touchableProps}
67
- style={wrapperStyles}
68
82
  >
69
83
  <Icon
70
84
  debugName={debugName}
71
85
  name={icon ?? name}
86
+ style={getStyles('icon')}
72
87
  {...iconProps}
73
- style={iconStyles}
74
88
  />
75
89
  {children}
76
90
  </WrapperComponent>
77
91
  )
78
92
  }
79
93
 
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)
94
+ ActionIcon.defaultProps = defaultProps
@@ -1,8 +1,12 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
  import { IconComposition } from '../Icon'
2
3
  import { TouchableComposition } from '../Touchable/styles'
3
4
 
4
5
  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 })))
@@ -1,54 +1,75 @@
1
1
  import { View } from '../View'
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'
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'
8
14
 
9
15
  export * from './styles'
10
- export * from './types'
11
16
 
12
- export const ActivityIndicator = forwardRef<HTMLDivElement, ActivityIndicatorProps>((props, ref) => {
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
+
13
34
  const {
14
- style,
35
+ style = {},
36
+ styles = {},
15
37
  component: Component,
38
+ variants = [],
39
+ responsiveVariants = {},
16
40
  size,
17
- ...rest
18
- } = {
19
- ...ActivityIndicator.defaultProps,
20
- ...props,
21
- }
41
+ ...props
42
+ } = allProps
22
43
 
23
- const styles = useStylesFor(ActivityIndicator.styleRegistryName, style)
44
+ const variantStyles = useDefaultComponentStyle<'u:ActivityIndicator', typeof ActivityIndicatorPresets>(
45
+ 'u:ActivityIndicator',
46
+ {
47
+ responsiveVariants,
48
+ variants,
49
+ styles,
50
+ rootElement: 'wrapper',
51
+ },
52
+ )
24
53
 
25
54
  const _size = React.useMemo(() => {
26
55
  return TypeGuards.isNumber(size) ? {
27
56
  width: size,
28
57
  height: size,
29
- } : null
58
+ } : {}
30
59
  }, [size])
31
60
 
32
61
  return (
33
- <Component
34
- ref={ref}
35
- {...rest}
36
- style={[styles.wrapper, _size]}
37
- />
62
+ <View css={[variantStyles.wrapper, _size, style]}>
63
+ <Component
64
+ ref={ref}
65
+ css={[variantStyles.wrapper, _size, style]}
66
+ {...props}
67
+ />
68
+ </View>
38
69
  )
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
- }
70
+ }) as ComponentWithDefaultProps<ActivityIndicatorProps>
48
71
 
49
72
  ActivityIndicator.defaultProps = {
50
- component: View,
73
+ component: View as ActivityIndicatorProps['component'],
51
74
  size: null,
52
- } as Partial<ActivityIndicatorProps>
53
-
54
- WebStyleRegistry.registerComponent(ActivityIndicator)
75
+ }
@@ -1 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
1
3
  export type ActivityIndicatorComposition = 'wrapper'
4
+
5
+ const createActivityIndicatorStyle = createDefaultVariantFactory<ActivityIndicatorComposition>()
6
+
7
+ export const ActivityIndicatorPresets = includePresets((styles) => createActivityIndicatorStyle(() => ({ wrapper: styles })))
@@ -1,14 +1,42 @@
1
1
  import React from 'react'
2
- import { TypeGuards } from '@codeleap/common'
2
+ import { ComponentVariants, PropsOf, StylesOf, TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
3
3
  import { Text } from '../Text'
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'
4
+ import { View, ViewProps } from '../View'
5
+ import { BadgeComposition, BadgePresets } from './styles'
6
+ import { ComponentCommonProps } from '../../types'
9
7
 
10
8
  export * from './styles'
11
- export * from './types'
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
+ }
12
40
 
13
41
  const defaultGetBadgeContent = ({ count, maxCount }: BadgeContent) => {
14
42
  if (Number(count) > maxCount) {
@@ -18,44 +46,66 @@ const defaultGetBadgeContent = ({ count, maxCount }: BadgeContent) => {
18
46
  }
19
47
  }
20
48
 
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
+
21
58
  export const Badge = (props: BadgeProps) => {
59
+ const allProps = {
60
+ ...Badge.defaultProps,
61
+ ...props,
62
+ }
63
+
22
64
  const {
23
65
  debugName,
24
- innerWrapperProps,
25
- textProps,
66
+ innerWrapperProps = {},
67
+ textProps = {},
26
68
  maxCount,
27
69
  minCount,
28
70
  getBadgeContent,
29
71
  renderBadgeContent,
72
+ styles = {},
73
+ variants = [],
74
+ responsiveVariants = {},
30
75
  disabled,
31
- style,
76
+ style = {},
77
+ css,
32
78
  badge,
33
79
  ...rest
34
- } = {
35
- ...Badge.defaultProps,
36
- ...props,
37
- }
38
-
39
- const styles = useStylesFor(Badge.styleRegistryName, style)
80
+ } = allProps
40
81
 
41
82
  const visible = (TypeGuards.isBoolean(badge) && badge === true) || TypeGuards.isNumber(badge)
42
83
 
43
84
  if (!visible) return null
44
85
 
86
+ const variantStyles = useDefaultComponentStyle<'u:Badge', typeof BadgePresets>('u:Badge', {
87
+ responsiveVariants,
88
+ variants,
89
+ styles,
90
+ rootElement: 'wrapper',
91
+ })
92
+
45
93
  const wrapperStyles = [
46
- styles?.wrapper,
47
- (disabled && styles?.['wrapper:disabled']),
94
+ variantStyles?.wrapper,
95
+ (disabled && variantStyles?.['wrapper:disabled']),
96
+ css,
97
+ style,
48
98
  ]
49
99
 
50
100
  const innerWrapperStyles = [
51
- styles?.innerWrapper,
52
- (disabled && styles?.['innerWrapper:disabled']),
101
+ variantStyles?.innerWrapper,
102
+ (disabled && variantStyles?.['innerWrapper:disabled']),
53
103
  innerWrapperProps?.style,
54
104
  ]
55
105
 
56
106
  const countStyles = [
57
- styles?.count,
58
- (disabled && styles?.['count:disabled']),
107
+ variantStyles?.count,
108
+ (disabled && variantStyles?.['count:disabled']),
59
109
  textProps?.style,
60
110
  ]
61
111
 
@@ -65,15 +115,18 @@ export const Badge = (props: BadgeProps) => {
65
115
 
66
116
  const showContent = TypeGuards.isNumber(count) && count >= minCount
67
117
 
68
- const BadgeContent = TypeGuards.isNil(renderBadgeContent) ? () => <Text text={content} {...textProps} /> : renderBadgeContent
118
+ let BadgeContent = renderBadgeContent
119
+
120
+ if (TypeGuards.isNil(renderBadgeContent)) {
121
+ BadgeContent = () => <Text text={content} {...textProps} css={countStyles} />
122
+ }
69
123
 
70
124
  return (
71
- <View {...rest} style={wrapperStyles}>
72
- <View {...innerWrapperProps} style={innerWrapperStyles}>
125
+ <View {...rest} css={wrapperStyles}>
126
+ <View {...innerWrapperProps} css={innerWrapperStyles}>
73
127
  {showContent
74
128
  ? <BadgeContent
75
129
  {...props}
76
- style={countStyles}
77
130
  maxCount={maxCount}
78
131
  minCount={minCount}
79
132
  count={count}
@@ -87,20 +140,4 @@ export const Badge = (props: BadgeProps) => {
87
140
  )
88
141
  }
89
142
 
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)
143
+ Badge.defaultProps = defaultProps
@@ -1,5 +1,15 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
1
3
  type BadgeParts = 'wrapper' | 'innerWrapper' | 'count'
2
4
 
3
5
  type BadgeStates = 'disabled'
4
6
 
5
- export type BadgeComposition = `${BadgeParts}:${BadgeStates}` | BadgeParts
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
+ })))
@@ -1,25 +1,62 @@
1
1
  import React from 'react'
2
- import { TypeGuards, StylesOf } from '@codeleap/common'
2
+ import {
3
+ useDefaultComponentStyle,
4
+ ComponentVariants,
5
+ AnyFunction,
6
+ TypeGuards,
7
+ IconPlaceholder,
8
+ StylesOf,
9
+ } from '@codeleap/common'
3
10
  import { Text } from '../Text'
4
- import { Touchable } from '../Touchable'
11
+ import { Touchable, TouchableProps } from '../Touchable'
5
12
  import { Icon } from '../Icon'
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'
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
+ }
12
44
 
13
- export * from './styles'
14
- export * from './types'
45
+ const defaultProps: Partial<ButtonProps> = {
46
+ debounce: 600,
47
+ loadingShowText: false,
48
+ }
15
49
 
16
50
  export const Button = (buttonProps: ButtonProps) => {
17
51
  const allProps = {
18
52
  ...Button.defaultProps,
19
- ...buttonProps,
53
+ ...buttonProps
20
54
  }
21
55
 
22
56
  const {
57
+ variants = [],
58
+ responsiveVariants = {},
59
+ styles = {},
23
60
  children,
24
61
  icon,
25
62
  text,
@@ -29,70 +66,76 @@ export const Button = (buttonProps: ButtonProps) => {
29
66
  disabled,
30
67
  rightIcon,
31
68
  selected,
32
- loaderProps,
69
+ loaderProps = {},
33
70
  debugName,
34
- style,
71
+ style = {},
35
72
  ...props
36
73
  } = allProps
37
74
 
38
- const styles = useStylesFor(Button.styleRegistryName, style)
75
+ const variantStyles = useDefaultComponentStyle<'u:Button', typeof ButtonPresets>('u:Button', {
76
+ responsiveVariants,
77
+ variants,
78
+ styles,
79
+ rootElement: 'wrapper',
80
+ })
39
81
 
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
- ])
82
+ const getStyles = (key: ButtonParts) => ({
83
+ ...variantStyles?.[key],
84
+ ...(disabled ? variantStyles?.[key + ':disabled'] : {}),
85
+ ...(selected ? variantStyles?.[key + ':selected'] : {})
86
+ })
46
87
 
47
88
  const iconStyles = getStyles('icon')
48
89
 
49
- const componentStyles: StylesOf<ButtonParts> = {
90
+ const _styles: StylesOf<ButtonParts> = {
50
91
  wrapper: getStyles('wrapper'),
51
92
  text: getStyles('text'),
52
93
  loaderWrapper: getStyles('loaderWrapper'),
53
- leftIcon: getStyles('leftIcon', iconStyles),
54
- rightIcon: getStyles('rightIcon', iconStyles),
94
+ leftIcon: {
95
+ ...iconStyles,
96
+ ...getStyles('leftIcon'),
97
+ },
98
+ rightIcon: {
99
+ ...iconStyles,
100
+ ...getStyles('rightIcon')
101
+ },
55
102
  }
56
103
 
104
+ const childrenContent = TypeGuards.isFunction(children)
105
+ // @ts-ignore
106
+ ? children(allProps)
107
+ : children
108
+
57
109
  // TODO - This is a hack to hide the icon with display: none
58
- const isLeftIconHide = componentStyles?.leftIcon?.display === 'none'
110
+ const isLeftIconHide = _styles?.leftIcon?.display === 'none'
59
111
 
60
- const shouldRenderLeftIcon = !loading && !isLeftIconHide && !!icon
112
+ const shouldRenderLeftIcon = !loading && !isLeftIconHide
61
113
 
62
114
  const _hideTextOnLoading = !loadingShowText && loading
63
115
 
64
116
  return (
65
117
  <Touchable
118
+ css={[_styles.wrapper, style]}
66
119
  component='button'
67
120
  debugComponent='Button'
68
121
  disabled={disabled}
69
122
  onPress={onPress}
70
123
  debugName={debugName}
71
124
  {...props}
72
- style={componentStyles.wrapper}
73
125
  >
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}
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
+ )}
81
135
  </Touchable>
82
136
  )
83
137
  }
84
138
 
85
- Button.styleRegistryName = 'Button'
86
- Button.elements = ['wrapper', 'text', 'icon', 'leftIcon', 'rightIcon', `loader`]
87
- Button.rootElement = 'wrapper'
88
-
89
- Button.withVariantTypes = <S extends AnyRecord>(styles: S) => {
90
- return Button as (props: StyledComponentProps<ButtonProps, typeof styles>) => IJSX
91
- }
139
+ Button.defaultProps = defaultProps
92
140
 
93
- Button.defaultProps = {
94
- debounce: 600,
95
- loadingShowText: false,
96
- } as Partial<ButtonProps>
97
-
98
- WebStyleRegistry.registerComponent(Button)
141
+ export * from './styles'