@codeleap/mobile 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 (131) hide show
  1. package/package.json +4 -6
  2. package/src/components/ActionIcon/index.tsx +37 -55
  3. package/src/components/ActionIcon/styles.ts +4 -2
  4. package/src/components/ActivityIndicator/index.tsx +64 -42
  5. package/src/components/ActivityIndicator/styles.ts +10 -1
  6. package/src/components/Autocomplete/index.tsx +54 -46
  7. package/src/components/Autocomplete/styles.ts +5 -2
  8. package/src/components/Autocomplete/types.ts +23 -13
  9. package/src/components/Avatar/index.tsx +71 -59
  10. package/src/components/Avatar/styles.ts +9 -1
  11. package/src/components/AvatarGroup/index.tsx +44 -30
  12. package/src/components/AvatarGroup/styles.ts +6 -0
  13. package/src/components/Backdrop/index.tsx +34 -51
  14. package/src/components/Backdrop/styles.ts +10 -5
  15. package/src/components/Badge/index.tsx +62 -36
  16. package/src/components/Badge/styles.ts +11 -3
  17. package/src/components/Button/index.tsx +82 -55
  18. package/src/components/Button/styles.ts +14 -13
  19. package/src/components/Calendar/index.tsx +29 -35
  20. package/src/components/Calendar/style.ts +6 -0
  21. package/src/components/Checkbox/index.tsx +64 -43
  22. package/src/components/Checkbox/styles.ts +6 -1
  23. package/src/components/ContentView/index.tsx +63 -0
  24. package/src/components/ContentView/styles.ts +8 -0
  25. package/src/components/DatePickerModal/index.tsx +65 -50
  26. package/src/components/DatePickerModal/styles.ts +10 -9
  27. package/src/components/DatePickerModal/types.ts +54 -36
  28. package/src/components/Drawer/index.tsx +28 -0
  29. package/src/components/Drawer/styles.ts +8 -0
  30. package/src/components/EmptyPlaceholder/index.tsx +63 -40
  31. package/src/components/EmptyPlaceholder/styles.ts +5 -0
  32. package/src/components/FileInput/index.tsx +49 -11
  33. package/src/components/FileInput/styles.ts +8 -0
  34. package/src/components/Grid/index.tsx +116 -84
  35. package/src/components/Grid/styles.ts +5 -0
  36. package/src/components/Icon/index.tsx +79 -44
  37. package/src/components/Icon/styles.ts +6 -0
  38. package/src/components/Image/index.tsx +78 -58
  39. package/src/components/Image/styles.ts +6 -1
  40. package/src/components/ImageView/Spotlight.tsx +4 -1
  41. package/src/components/ImageView/component.tsx +2 -1
  42. package/src/components/InputBase/index.tsx +24 -33
  43. package/src/components/InputBase/styles.ts +75 -66
  44. package/src/components/InputBase/types.ts +4 -3
  45. package/src/components/InputBase/utils.ts +4 -6
  46. package/src/components/InputLabel/index.tsx +38 -0
  47. package/src/components/InputLabel/styles.ts +7 -0
  48. package/src/components/List/PaginationIndicator.tsx +54 -0
  49. package/src/components/List/index.tsx +151 -99
  50. package/src/components/List/styles.ts +6 -0
  51. package/src/components/LoadingOverlay/index.tsx +29 -42
  52. package/src/components/LoadingOverlay/styles.ts +7 -7
  53. package/src/components/Modal/index.tsx +127 -80
  54. package/src/components/Modal/styles.ts +8 -0
  55. package/src/components/Navigation/Navigation.tsx +0 -1
  56. package/src/components/Navigation/types.ts +9 -2
  57. package/src/components/NumberIncrement/index.tsx +60 -50
  58. package/src/components/NumberIncrement/styles.ts +5 -0
  59. package/src/components/NumberIncrement/types.ts +39 -32
  60. package/src/components/Pager/index.tsx +94 -42
  61. package/src/components/Pager/styles.ts +13 -1
  62. package/src/components/RadioInput/index.tsx +57 -32
  63. package/src/components/RadioInput/styles.ts +7 -5
  64. package/src/components/RefreshControl/index.tsx +19 -39
  65. package/src/components/RefreshControl/styles.ts +6 -1
  66. package/src/components/Scroll/index.tsx +105 -89
  67. package/src/components/Scroll/styles.ts +5 -0
  68. package/src/components/Sections/index.tsx +161 -111
  69. package/src/components/Sections/styles.ts +5 -0
  70. package/src/components/SegmentedControl/Option.tsx +31 -46
  71. package/src/components/SegmentedControl/index.tsx +121 -86
  72. package/src/components/SegmentedControl/styles.ts +22 -15
  73. package/src/components/Select/index.tsx +82 -71
  74. package/src/components/Select/styles.ts +5 -3
  75. package/src/components/Select/types.ts +25 -20
  76. package/src/components/Slider/index.tsx +43 -58
  77. package/src/components/Slider/styles.ts +6 -15
  78. package/src/components/Slider/types.ts +14 -9
  79. package/src/components/Switch/index.tsx +56 -43
  80. package/src/components/Switch/styles.ts +7 -1
  81. package/src/components/Text/index.tsx +52 -56
  82. package/src/components/Text/styles.ts +7 -1
  83. package/src/components/TextInput/index.tsx +162 -49
  84. package/src/components/TextInput/styles.ts +8 -2
  85. package/src/components/Touchable/index.tsx +87 -44
  86. package/src/components/Touchable/styles.ts +9 -0
  87. package/src/components/View/index.tsx +92 -23
  88. package/src/components/View/styles.ts +6 -0
  89. package/src/components/components.ts +6 -2
  90. package/src/components/defaultStyles.ts +77 -0
  91. package/src/index.ts +0 -2
  92. package/src/modules/PressableRipple/type.ts +0 -1
  93. package/src/utils/KeyboardAware/context.tsx +2 -0
  94. package/src/utils/KeyboardAware/keyboardHooks.ts +2 -1
  95. package/src/utils/ModalManager/components.tsx +30 -1
  96. package/src/utils/ModalManager/context.tsx +4 -4
  97. package/src/utils/ModalManager/index.ts +4 -1
  98. package/src/utils/hooks.ts +1 -12
  99. package/src/Registry.ts +0 -52
  100. package/src/components/ActionIcon/types.ts +0 -15
  101. package/src/components/ActivityIndicator/types.ts +0 -9
  102. package/src/components/Avatar/types.ts +0 -23
  103. package/src/components/AvatarGroup/types.ts +0 -10
  104. package/src/components/Backdrop/types.ts +0 -14
  105. package/src/components/Badge/types.ts +0 -27
  106. package/src/components/Button/types.ts +0 -20
  107. package/src/components/Checkbox/types.ts +0 -13
  108. package/src/components/EmptyPlaceholder/types.ts +0 -21
  109. package/src/components/FileInput/types.ts +0 -27
  110. package/src/components/Grid/types.ts +0 -20
  111. package/src/components/Icon/types.ts +0 -15
  112. package/src/components/Image/types.ts +0 -18
  113. package/src/components/List/types.ts +0 -41
  114. package/src/components/LoadingOverlay/types.ts +0 -9
  115. package/src/components/Modal/types.ts +0 -41
  116. package/src/components/Pager/types.ts +0 -37
  117. package/src/components/PaginationIndicator/index.tsx +0 -51
  118. package/src/components/PaginationIndicator/styles.ts +0 -3
  119. package/src/components/PaginationIndicator/types.ts +0 -10
  120. package/src/components/RadioInput/types.ts +0 -31
  121. package/src/components/RefreshControl/types.ts +0 -9
  122. package/src/components/Scroll/types.ts +0 -21
  123. package/src/components/SearchInput/index.tsx +0 -90
  124. package/src/components/Sections/types.ts +0 -39
  125. package/src/components/SegmentedControl/types.ts +0 -31
  126. package/src/components/Switch/types.ts +0 -12
  127. package/src/components/Text/types.ts +0 -18
  128. package/src/components/TextInput/types.ts +0 -23
  129. package/src/components/Touchable/types.ts +0 -27
  130. package/src/components/View/types.ts +0 -13
  131. package/src/hooks/index.ts +0 -13
@@ -1,114 +1,126 @@
1
+ import {
2
+ ComponentVariants,
3
+ IconPlaceholder,
4
+ TypeGuards,
5
+ matchInitialToColor,
6
+ useDefaultComponentStyle,
7
+ useMemo,
8
+ getNestedStylesByKey,
9
+ } from '@codeleap/common'
1
10
  import React from 'react'
2
- import { TypeGuards, matchInitialToColor, useMemo } from '@codeleap/common'
3
- import { Image } from '../Image'
11
+ import { StyleSheet } from 'react-native'
12
+ import { StylesOf } from '../../types'
13
+ import { AvatarComposition, AvatarPresets } from './styles'
14
+ import { Image, ImageProps } from '../Image'
4
15
  import { Touchable } from '../Touchable'
5
16
  import { Text } from '../Text'
6
17
  import { View, ViewProps } from '../View'
7
18
  import { Icon } from '../Icon'
8
- import { Badge } from '../Badge'
9
- import { AvatarProps } from './types'
10
- import { MobileStyleRegistry } from '../../Registry'
11
- import { AnyRecord, useNestedStylesByKey, IJSX, StyledComponentProps } from '@codeleap/styles'
12
- import { useStylesFor } from '../../hooks'
13
-
14
- export * from './styles'
15
- export * from './types'
16
-
17
- export const Avatar = (props: AvatarProps) => {
19
+ import { Badge, BadgeComponentProps } from '../Badge'
20
+
21
+ export type AvatarProps = ComponentVariants<typeof AvatarPresets> & {
22
+ styles?: StylesOf<AvatarComposition>
23
+ image?: ImageProps['source']
24
+ name?: string | string[]
25
+ debugName: string
26
+ firstNameOnly?: boolean
27
+ text?: string
28
+ description?: string
29
+ icon?: IconPlaceholder
30
+ badgeIcon?: IconPlaceholder
31
+ style?: ViewProps['style']
32
+ onPress?: () => void
33
+ noFeedback?: boolean
34
+ } & BadgeComponentProps
35
+
36
+ export const Avatar = (props:AvatarProps) => {
18
37
  const {
19
38
  debugName,
20
39
  name = '',
21
- firstNameOnly,
40
+ firstNameOnly = true,
22
41
  image,
42
+ variants = [],
43
+ styles,
44
+ style,
23
45
  icon,
24
46
  badgeIcon,
25
47
  text,
26
48
  description,
27
49
  onPress,
28
50
  noFeedback,
29
- badge,
51
+ badge = false,
30
52
  badgeProps = {},
31
- style,
32
53
  ...viewProps
33
- } = {
34
- ...Avatar.defaultProps,
35
- ...props,
36
- }
54
+ } = props
37
55
 
38
- const styles = useStylesFor(Avatar.styleRegistryName, style)
56
+ const variantStyles = useDefaultComponentStyle('u:Avatar', {
57
+ variants,
58
+ styles,
59
+ transform: StyleSheet.flatten,
60
+ })
39
61
 
40
62
  const hasImage = !!image
41
63
 
42
64
  const { initials, randomColor } = useMemo(() => {
43
- const [first = '', last = ''] = TypeGuards.isString(name) ? name.split(' ') : name
65
+ const [first = '', last = ''] = TypeGuards.isString(name)
66
+ ? name.split(' ')
67
+ : name
44
68
  const initials = [first[0]]
45
-
46
- if (!firstNameOnly) initials.push(last[0])
47
-
69
+ if (!firstNameOnly) {
70
+ initials.push(last[0])
71
+ }
48
72
  return {
49
- initials: initials?.join(' '),
73
+ initials: initials.join(' '),
50
74
  randomColor: matchInitialToColor(first[0]),
51
75
  }
52
76
  }, [name, firstNameOnly])
53
77
 
54
78
  const renderContent = () => {
55
- if (hasImage) return <Image source={image} style={styles.image} />
56
- if (icon) return <Icon name={icon} style={styles.icon} />
57
- return <Text text={text || initials} style={styles.initials} />
79
+ if (hasImage) return <Image source={image} style={variantStyles.image} />
80
+ if (icon) return <Icon name={icon} style={variantStyles.icon} />
81
+ return <Text text={text || initials} style={variantStyles.initials} />
58
82
  }
59
83
 
60
- // @ts-expect-error icss type
61
- const hasBackgroundColor = !!styles?.touchable?.backgroundColor
84
+ const hasBackgroundColor = !!variantStyles?.touchable?.backgroundColor
62
85
 
63
- const badgeStyles = useNestedStylesByKey('badge', styles)
86
+ const badgeStyles = getNestedStylesByKey('badge', variantStyles)
64
87
 
65
88
  return (
66
- <View {...viewProps as ViewProps} style={styles.wrapper}>
89
+ <View style={[variantStyles.wrapper, style]} {...viewProps}>
67
90
  <Touchable
68
- debugName={'Avatar:' + debugName}
91
+ debugName={'Avatar ' + debugName}
69
92
  onPress={() => onPress?.()}
70
93
  style={[
71
- styles.touchable,
72
- !hasBackgroundColor && { backgroundColor: randomColor },
94
+ variantStyles.touchable,
95
+ !hasBackgroundColor && {
96
+ backgroundColor: randomColor,
97
+ },
73
98
  ]}
74
99
  noFeedback={noFeedback || !onPress}
75
100
  >
76
101
  {renderContent()}
77
102
 
78
- {!!description ? (
79
- <View style={styles.descriptionOverlay}>
80
- <Text text={description} style={styles.description} />
103
+ {!!description && (
104
+ <View style={variantStyles.descriptionOverlay}>
105
+ <Text text={description} style={variantStyles.description} />
81
106
  </View>
82
- ) : null}
107
+ )}
83
108
 
84
- <Badge badge={badge} {...badgeProps} style={badgeStyles} />
109
+ <Badge badge={badge} style={badgeStyles} {...badgeProps} />
85
110
  </Touchable>
86
111
 
87
- {badgeIcon ? (
112
+ {badgeIcon && (
88
113
  <Touchable
89
- debugName={`AvatarBadge:${debugName}`}
90
- style={styles.badgeIconWrapper}
114
+ debugName={`${debugName} badge`}
115
+ style={variantStyles.badgeIconWrapper}
91
116
  onPress={() => onPress?.()}
92
117
  noFeedback
93
118
  >
94
- <Icon name={badgeIcon} style={styles.badgeIcon} />
119
+ <Icon name={badgeIcon} style={variantStyles.badgeIcon} />
95
120
  </Touchable>
96
- ) : null}
121
+ )}
97
122
  </View>
98
123
  )
99
124
  }
100
125
 
101
- Avatar.styleRegistryName = 'Avatar'
102
- Avatar.elements = ['wrapper', 'touchable', 'initials', 'image', 'icon', 'description', 'badge']
103
- Avatar.rootElement = 'wrapper'
104
-
105
- Avatar.withVariantTypes = <S extends AnyRecord>(styles: S) => {
106
- return Avatar as (props: StyledComponentProps<AvatarProps, typeof styles>) => IJSX
107
- }
108
-
109
- Avatar.defaultProps = {
110
- badge: false,
111
- firstNameOnly: true,
112
- } as AvatarProps
113
-
114
- MobileStyleRegistry.registerComponent(Avatar)
126
+ export * from './styles'
@@ -1,6 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
  import { BadgeComposition } from '../Badge'
2
3
 
3
- export type AvatarComposition =
4
+ export type AvatarParts =
4
5
  | 'wrapper'
5
6
  | 'touchable'
6
7
  | 'initials'
@@ -12,3 +13,10 @@ export type AvatarComposition =
12
13
  | 'badgeIconWrapper'
13
14
  | 'badgeIcon'
14
15
  | `badge${Capitalize<BadgeComposition>}`
16
+
17
+ export type AvatarComposition = AvatarParts
18
+
19
+ const createAvatarStyle = createDefaultVariantFactory<AvatarComposition>()
20
+
21
+ export const AvatarPresets = includePresets((styles) => createAvatarStyle(() => ({ wrapper: styles })),
22
+ )
@@ -1,60 +1,74 @@
1
+ import {
2
+ ComponentVariants,
3
+ useDefaultComponentStyle,
4
+ useNestedStylesByKey,
5
+ } from '@codeleap/common'
1
6
  import React from 'react'
2
- import { View } from '../View'
3
- import { Avatar } from '../Avatar'
4
- import { AvatarGroupProps } from './types'
5
- import { AnyRecord, useNestedStylesByKey, IJSX, StyledComponentProps } from '@codeleap/styles'
6
- import { MobileStyleRegistry } from '../../Registry'
7
- import { useStylesFor } from '../../hooks'
7
+ import { StyleSheet, StyleProp, ViewStyle } from 'react-native'
8
+ import { StylesOf } from '../../types'
9
+ import { AvatarGroupComposition, AvatarGroupPresets } from './styles'
10
+ import { View, ViewProps } from '../View'
11
+ import { Avatar, AvatarProps } from '../Avatar'
8
12
 
9
- export * from './styles'
10
- export * from './types'
13
+ export type AvatarGroupProps = ComponentVariants<typeof AvatarGroupPresets> & {
14
+ styles?: StylesOf<AvatarGroupComposition>
15
+ style?: ViewProps['style']
16
+ avatars: AvatarProps[]
17
+ displacement?: number
18
+ avatarVariants?: AvatarProps['variants']
19
+ }
11
20
 
12
- const getAvatarStyle = (index: number, displacement: number = 20.5) => {
13
- const right = index * displacement
14
- return { right: `${right}%` }
21
+ const defaultProps: Partial<AvatarGroupProps> = {
22
+ displacement: 20.5,
15
23
  }
16
24
 
17
25
  export const AvatarGroup = (props: AvatarGroupProps) => {
18
26
  const {
27
+ variants = [],
19
28
  avatars = [],
29
+ avatarVariants,
30
+ styles,
20
31
  style,
21
32
  displacement,
22
- debugName,
23
33
  ...viewProps
24
34
  } = {
25
- ...AvatarGroup.defaultProps,
35
+ ...defaultProps,
26
36
  ...props,
27
37
  }
28
38
 
29
- const styles = useStylesFor(AvatarGroup.styleRegistryName, style)
39
+ const variantStyles = useDefaultComponentStyle('u:AvatarGroup', {
40
+ variants,
41
+ styles,
42
+ transform: StyleSheet.flatten,
43
+ })
30
44
 
31
- const avatarStyles = useNestedStylesByKey('avatar', styles)
45
+ const avatarStyles = useNestedStylesByKey('avatar', variantStyles)
32
46
 
33
47
  return (
34
- <View {...viewProps} style={styles.wrapper}>
35
- {avatars?.map?.((avatar, index) => (
48
+ <View
49
+ style={[variantStyles.wrapper, style]}
50
+ variants={['row']}
51
+ {...viewProps}
52
+ >
53
+ {avatars.map((avatar, index) => (
36
54
  <Avatar
37
55
  firstNameOnly
38
- key={debugName + index}
39
- debugName={`${debugName}: ${avatar?.debugName ?? index}`}
56
+ key={avatar.debugName || index}
40
57
  {...avatar}
41
- style={[avatarStyles, (avatar?.style ?? {}), getAvatarStyle(index, displacement)]}
58
+ variants={avatar.variants || avatarVariants}
59
+ style={getAvatarStyle(index, displacement)}
60
+ styles={avatarStyles}
42
61
  />
43
62
  ))}
44
63
  </View>
45
64
  )
46
65
  }
47
66
 
48
- AvatarGroup.styleRegistryName = 'AvatarGroup'
49
- AvatarGroup.elements = ['wrapper', 'avatar']
50
- AvatarGroup.rootElement = 'wrapper'
67
+ AvatarGroup.defaultProps = defaultProps
51
68
 
52
- AvatarGroup.withVariantTypes = <S extends AnyRecord>(styles: S) => {
53
- return AvatarGroup as (props: StyledComponentProps<AvatarGroupProps, typeof styles>) => IJSX
69
+ const getAvatarStyle = (index: number, displacementPixels: number): StyleProp<ViewStyle> => {
70
+ const displacement = index * 20.5
71
+ return { right: `${displacement}%` }
54
72
  }
55
73
 
56
- AvatarGroup.defaultProps = {
57
- displacement: 20.5,
58
- } as Partial<AvatarGroupProps>
59
-
60
- MobileStyleRegistry.registerComponent(AvatarGroup)
74
+ export * from './styles'
@@ -1,5 +1,11 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
  import { AvatarComposition } from '../components'
2
3
 
3
4
  export type AvatarGroupParts = 'wrapper'
4
5
 
5
6
  export type AvatarGroupComposition = AvatarGroupParts | `avatar${Capitalize<AvatarComposition>}`
7
+
8
+ const createAvatarStyle = createDefaultVariantFactory<AvatarGroupComposition>()
9
+
10
+ export const AvatarGroupPresets = includePresets((styles) => createAvatarStyle(() => ({ wrapper: styles })),
11
+ )
@@ -1,68 +1,51 @@
1
1
  import React from 'react'
2
+ import { ComponentVariants, onUpdate, PropsOf, useDefaultComponentStyle } from '@codeleap/common'
2
3
  import { Touchable } from '../Touchable'
3
4
  import { View } from '../View'
5
+
6
+ import { StylesOf } from '../../types/utility'
7
+ import { StyleSheet } from 'react-native'
4
8
  import { useAnimatedVariantStyles } from '../../utils'
5
- import { BackdropProps } from './types'
6
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
7
- import { MobileStyleRegistry } from '../../Registry'
8
- import { useStylesFor } from '../../hooks'
9
+ import { BackdropComposition, BackdropPresets } from './styles'
9
10
 
10
11
  export * from './styles'
11
- export * from './types'
12
-
13
- export const Backdrop = (props: BackdropProps) => {
14
- const {
15
- visible,
16
- children,
17
- wrapperProps = {},
18
- style,
19
- ...rest
20
- } = {
21
- ...Backdrop.defaultProps,
22
- ...props,
23
- }
24
-
25
- const styles = useStylesFor(Backdrop.styleRegistryName, style)
12
+ export type BackdropProps = React.PropsWithChildren<
13
+
14
+ PropsOf<typeof Touchable> & {
15
+ visible: boolean
16
+ wrapperProps?: PropsOf<typeof View>
17
+ variants?: ComponentVariants<typeof BackdropPresets>['variants']
18
+ styles?: StylesOf<BackdropComposition>
19
+ }>
20
+
21
+ export const Backdrop = (backdropProps:BackdropProps) => {
22
+ const { variants = [], styles = {}, visible, children, wrapperProps = {}, ...props } = backdropProps
23
+
24
+ const variantStyles = useDefaultComponentStyle<'u:Backdrop', typeof BackdropPresets>('u:Backdrop', {
25
+ variants,
26
+ rootElement: 'wrapper',
27
+ styles,
28
+ transform: StyleSheet.flatten,
29
+ })
26
30
 
27
31
  const animation = useAnimatedVariantStyles({
28
- variantStyles: styles,
32
+ variantStyles,
29
33
  animatedProperties: ['wrapper:hidden', 'wrapper:visible'],
30
34
  updater: (s) => {
31
35
  'worklet'
32
- return visible ? s['wrapper:visible'] : s['wrapper:hidden']
36
+ return visible ? s['wrapper:visible'] : s['wrapper:hidden']
33
37
  },
34
38
  dependencies: [visible],
35
- transition: styles.transition,
39
+ transition: variantStyles.transition,
36
40
  })
37
41
 
38
- const isPressable = !!props?.onPress
39
-
40
- return (
41
- <View
42
- animated
43
- pointerEvents={visible ? 'auto' : 'none'}
44
- animatedStyle={animation}
45
- {...wrapperProps}
46
- style={styles.wrapper}
47
- >
48
- {isPressable
49
- ? <Touchable {...rest} style={styles.touchable} noFeedback android_ripple={null} />
50
- : null}
51
42
 
52
- {children}
53
- </View>
54
- )
43
+ return <View pointerEvents={visible ? 'auto' : 'none' } animated style={[variantStyles.wrapper, animation]} {...wrapperProps}>
44
+ {
45
+ !!props?.onPress ?
46
+ <Touchable style={variantStyles.touchable} {...props} noFeedback android_ripple={null}/>
47
+ : null
48
+ }
49
+ {children}
50
+ </View>
55
51
  }
56
-
57
-
58
- Backdrop.styleRegistryName = 'Backdrop'
59
- Backdrop.elements = ['wrapper', 'touchable', 'transition']
60
- Backdrop.rootElement = 'wrapper'
61
-
62
- Backdrop.withVariantTypes = <S extends AnyRecord>(styles: S) => {
63
- return Backdrop as (props: StyledComponentProps<BackdropProps, typeof styles>) => IJSX
64
- }
65
-
66
- Backdrop.defaultProps = {} as Partial<BackdropProps>
67
-
68
- MobileStyleRegistry.registerComponent(Backdrop)
@@ -1,7 +1,12 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
 
2
3
  export type BackdropComposition =
3
- 'wrapper' |
4
- 'touchable' |
5
- 'wrapper:visible' |
6
- 'wrapper:hidden' |
7
- 'transition'
4
+ 'wrapper'|
5
+ 'touchable' |
6
+ 'wrapper:visible' |
7
+ 'wrapper:hidden' |
8
+ 'transition'
9
+
10
+ const createBackdropVariant = createDefaultVariantFactory<BackdropComposition>()
11
+
12
+ export const BackdropPresets = includePresets((style) => createBackdropVariant(() => ({ wrapper: style })))
@@ -1,14 +1,33 @@
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
4
  import { View, ViewProps } from '../View'
5
- import { BadgeContent, BadgeProps } from './types'
6
- import { MobileStyleRegistry } from '../../Registry'
7
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
8
- import { useStylesFor } from '../../hooks'
5
+ import { BadgeComposition, BadgePresets } from './styles'
6
+ import { StyleSheet } from 'react-native'
9
7
 
10
8
  export * from './styles'
11
- export * from './types'
9
+
10
+ export type BadgeProps = ComponentVariants<typeof BadgePresets>
11
+ & ViewProps
12
+ & {
13
+ styles?: StylesOf<BadgeComposition>
14
+ maxCount?: number
15
+ minCount?: number
16
+ debugName?: string
17
+ innerWrapperProps?: Partial<PropsOf<typeof View>>
18
+ textProps?: Partial<PropsOf<typeof Text>>
19
+ getBadgeContent?: (props: BadgeContent) => string
20
+ renderBadgeContent?: (props: BadgeContent & { content: string }) => JSX.Element
21
+ disabled?: boolean
22
+ badge?: number | boolean
23
+ }
24
+
25
+ type BadgeContent = BadgeProps & { count: number }
26
+
27
+ export type BadgeComponentProps = {
28
+ badge?: BadgeProps['badge']
29
+ badgeProps?: Partial<BadgeProps>
30
+ }
12
31
 
13
32
  const defaultGetBadgeContent = ({ count, maxCount }: BadgeContent) => {
14
33
  if (Number(count) > maxCount) {
@@ -18,6 +37,15 @@ const defaultGetBadgeContent = ({ count, maxCount }: BadgeContent) => {
18
37
  }
19
38
  }
20
39
 
40
+ const defaultProps: Partial<BadgeProps> = {
41
+ maxCount: 9,
42
+ minCount: 1,
43
+ getBadgeContent: defaultGetBadgeContent,
44
+ renderBadgeContent: null,
45
+ disabled: false,
46
+ badge: true,
47
+ }
48
+
21
49
  export const Badge = (props: BadgeProps) => {
22
50
  const allProps = {
23
51
  ...Badge.defaultProps,
@@ -32,32 +60,40 @@ export const Badge = (props: BadgeProps) => {
32
60
  minCount,
33
61
  getBadgeContent,
34
62
  renderBadgeContent,
63
+ styles = {},
64
+ variants,
35
65
  disabled,
36
- style,
66
+ style = {},
37
67
  badge,
38
68
  ...rest
39
69
  } = allProps
40
70
 
41
71
  const visible = (TypeGuards.isBoolean(badge) && badge === true) || TypeGuards.isNumber(badge)
42
72
 
43
- const styles = useStylesFor(Badge.styleRegistryName, style)
44
-
45
73
  if (!visible) return null
46
-
74
+
75
+ const variantStyles = useDefaultComponentStyle<'u:Badge', typeof BadgePresets>('u:Badge', {
76
+ variants,
77
+ styles,
78
+ rootElement: 'wrapper',
79
+ transform: StyleSheet.flatten,
80
+ })
81
+
47
82
  const wrapperStyles: ViewProps['style'] = [
48
- styles?.wrapper,
49
- (disabled && styles?.['wrapper:disabled']),
83
+ variantStyles?.wrapper,
84
+ (disabled && variantStyles?.['wrapper:disabled']),
85
+ style,
50
86
  ]
51
87
 
52
88
  const innerWrapperStyles: ViewProps['style'] = [
53
- styles?.innerWrapper,
54
- (disabled && styles?.['innerWrapper:disabled']),
89
+ variantStyles?.innerWrapper,
90
+ (disabled && variantStyles?.['innerWrapper:disabled']),
55
91
  innerWrapperProps?.style,
56
92
  ]
57
93
 
58
94
  const countStyles = [
59
- styles?.count,
60
- (disabled && styles?.['count:disabled']),
95
+ variantStyles?.count,
96
+ (disabled && variantStyles?.['count:disabled']),
61
97
  textProps?.style,
62
98
  ]
63
99
 
@@ -67,10 +103,17 @@ export const Badge = (props: BadgeProps) => {
67
103
 
68
104
  const showContent = TypeGuards.isNumber(count) && count >= minCount
69
105
 
70
- const BadgeContent = TypeGuards.isNil(renderBadgeContent) ? () => <Text text={content} {...textProps} style={countStyles} /> : renderBadgeContent
106
+ let BadgeContent = renderBadgeContent
107
+
108
+ if (TypeGuards.isNil(renderBadgeContent)) {
109
+ BadgeContent = () => <Text text={content} {...textProps} style={countStyles} />
110
+ }
71
111
 
72
112
  return (
73
- <View {...rest} style={wrapperStyles}>
113
+ <View
114
+ {...rest}
115
+ style={wrapperStyles}
116
+ >
74
117
  <View {...innerWrapperProps} style={innerWrapperStyles}>
75
118
  {showContent
76
119
  ? <BadgeContent
@@ -88,21 +131,4 @@ export const Badge = (props: BadgeProps) => {
88
131
  )
89
132
  }
90
133
 
91
- Badge.styleRegistryName = 'Badge'
92
- Badge.elements = ['wrapper', 'innerWrapper', 'count']
93
- Badge.rootElement = 'wrapper'
94
-
95
- Badge.defaultProps = {
96
- maxCount: 9,
97
- minCount: 1,
98
- getBadgeContent: defaultGetBadgeContent,
99
- renderBadgeContent: null,
100
- disabled: false,
101
- badge: true,
102
- } as Partial<BadgeProps>
103
-
104
- Badge.withVariantTypes = <S extends AnyRecord>(styles: S) => {
105
- return Badge as (props: StyledComponentProps<BadgeProps, typeof styles>) => IJSX
106
- }
107
-
108
- MobileStyleRegistry.registerComponent(Badge)
134
+ Badge.defaultProps = defaultProps
@@ -1,6 +1,14 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
 
2
- type BadgeParts = 'wrapper' | 'innerWrapper' | 'count'
3
+ type BadgeParts = 'wrapper' | 'innerWrapper' | 'count'
3
4
 
4
- type BadgeStates = 'disabled'
5
+ type BadgeStates = 'disabled'
5
6
 
6
- export type BadgeComposition = `${BadgeParts}:${BadgeStates}` | BadgeParts
7
+ export type BadgeComposition =
8
+ `${BadgeParts}:${BadgeStates}`
9
+ | BadgeParts
10
+
11
+ const createBadgeStyle =
12
+ createDefaultVariantFactory<BadgeComposition>()
13
+
14
+ export const BadgePresets = includePresets((styles) => createBadgeStyle(() => ({ wrapper: styles })))