@codeleap/mobile 3.24.3 → 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 (131) hide show
  1. package/package.json +6 -4
  2. package/src/Registry.ts +52 -0
  3. package/src/components/ActionIcon/index.tsx +55 -37
  4. package/src/components/ActionIcon/styles.ts +2 -4
  5. package/src/components/ActionIcon/types.ts +15 -0
  6. package/src/components/ActivityIndicator/index.tsx +42 -64
  7. package/src/components/ActivityIndicator/styles.ts +1 -10
  8. package/src/components/ActivityIndicator/types.ts +9 -0
  9. package/src/components/Autocomplete/index.tsx +46 -54
  10. package/src/components/Autocomplete/styles.ts +2 -5
  11. package/src/components/Autocomplete/types.ts +13 -23
  12. package/src/components/Avatar/index.tsx +59 -71
  13. package/src/components/Avatar/styles.ts +1 -9
  14. package/src/components/Avatar/types.ts +23 -0
  15. package/src/components/AvatarGroup/index.tsx +30 -44
  16. package/src/components/AvatarGroup/styles.ts +0 -6
  17. package/src/components/AvatarGroup/types.ts +10 -0
  18. package/src/components/Backdrop/index.tsx +51 -34
  19. package/src/components/Backdrop/styles.ts +5 -10
  20. package/src/components/Backdrop/types.ts +14 -0
  21. package/src/components/Badge/index.tsx +36 -62
  22. package/src/components/Badge/styles.ts +3 -11
  23. package/src/components/Badge/types.ts +27 -0
  24. package/src/components/Button/index.tsx +55 -82
  25. package/src/components/Button/styles.ts +13 -14
  26. package/src/components/Button/types.ts +20 -0
  27. package/src/components/Calendar/index.tsx +35 -29
  28. package/src/components/Checkbox/index.tsx +43 -64
  29. package/src/components/Checkbox/styles.ts +1 -6
  30. package/src/components/Checkbox/types.ts +13 -0
  31. package/src/components/DatePickerModal/index.tsx +50 -65
  32. package/src/components/DatePickerModal/styles.ts +9 -10
  33. package/src/components/DatePickerModal/types.ts +36 -54
  34. package/src/components/EmptyPlaceholder/index.tsx +40 -63
  35. package/src/components/EmptyPlaceholder/styles.ts +0 -5
  36. package/src/components/EmptyPlaceholder/types.ts +21 -0
  37. package/src/components/FileInput/index.tsx +11 -49
  38. package/src/components/FileInput/types.ts +27 -0
  39. package/src/components/Grid/index.tsx +84 -116
  40. package/src/components/Grid/styles.ts +0 -5
  41. package/src/components/Grid/types.ts +20 -0
  42. package/src/components/Icon/index.tsx +44 -79
  43. package/src/components/Icon/styles.ts +0 -6
  44. package/src/components/Icon/types.ts +15 -0
  45. package/src/components/Image/index.tsx +58 -78
  46. package/src/components/Image/styles.ts +1 -6
  47. package/src/components/Image/types.ts +18 -0
  48. package/src/components/ImageView/Spotlight.tsx +1 -4
  49. package/src/components/ImageView/component.tsx +1 -2
  50. package/src/components/InputBase/index.tsx +33 -24
  51. package/src/components/InputBase/styles.ts +66 -75
  52. package/src/components/InputBase/types.ts +3 -4
  53. package/src/components/InputBase/utils.ts +6 -4
  54. package/src/components/List/index.tsx +99 -151
  55. package/src/components/List/styles.ts +0 -6
  56. package/src/components/List/types.ts +41 -0
  57. package/src/components/LoadingOverlay/index.tsx +42 -29
  58. package/src/components/LoadingOverlay/styles.ts +7 -7
  59. package/src/components/LoadingOverlay/types.ts +9 -0
  60. package/src/components/Modal/index.tsx +80 -127
  61. package/src/components/Modal/styles.ts +0 -8
  62. package/src/components/Modal/types.ts +41 -0
  63. package/src/components/Navigation/Navigation.tsx +1 -0
  64. package/src/components/Navigation/types.ts +2 -9
  65. package/src/components/NumberIncrement/index.tsx +50 -60
  66. package/src/components/NumberIncrement/styles.ts +0 -5
  67. package/src/components/NumberIncrement/types.ts +32 -39
  68. package/src/components/Pager/index.tsx +42 -94
  69. package/src/components/Pager/styles.ts +1 -13
  70. package/src/components/Pager/types.ts +37 -0
  71. package/src/components/PaginationIndicator/index.tsx +51 -0
  72. package/src/components/PaginationIndicator/styles.ts +3 -0
  73. package/src/components/PaginationIndicator/types.ts +10 -0
  74. package/src/components/RadioInput/index.tsx +32 -57
  75. package/src/components/RadioInput/styles.ts +5 -7
  76. package/src/components/RadioInput/types.ts +31 -0
  77. package/src/components/RefreshControl/index.tsx +39 -19
  78. package/src/components/RefreshControl/styles.ts +1 -6
  79. package/src/components/RefreshControl/types.ts +9 -0
  80. package/src/components/Scroll/index.tsx +89 -105
  81. package/src/components/Scroll/styles.ts +0 -5
  82. package/src/components/Scroll/types.ts +21 -0
  83. package/src/components/SearchInput/index.tsx +90 -0
  84. package/src/components/Sections/index.tsx +111 -161
  85. package/src/components/Sections/styles.ts +0 -5
  86. package/src/components/Sections/types.ts +39 -0
  87. package/src/components/SegmentedControl/Option.tsx +46 -31
  88. package/src/components/SegmentedControl/index.tsx +86 -121
  89. package/src/components/SegmentedControl/styles.ts +15 -22
  90. package/src/components/SegmentedControl/types.ts +31 -0
  91. package/src/components/Select/index.tsx +71 -82
  92. package/src/components/Select/styles.ts +3 -5
  93. package/src/components/Select/types.ts +20 -25
  94. package/src/components/Slider/index.tsx +58 -43
  95. package/src/components/Slider/styles.ts +15 -6
  96. package/src/components/Slider/types.ts +9 -14
  97. package/src/components/Switch/index.tsx +43 -56
  98. package/src/components/Switch/styles.ts +1 -7
  99. package/src/components/Switch/types.ts +12 -0
  100. package/src/components/Text/index.tsx +56 -52
  101. package/src/components/Text/styles.ts +1 -7
  102. package/src/components/Text/types.ts +18 -0
  103. package/src/components/TextInput/index.tsx +49 -162
  104. package/src/components/TextInput/styles.ts +2 -8
  105. package/src/components/TextInput/types.ts +23 -0
  106. package/src/components/Touchable/index.tsx +44 -87
  107. package/src/components/Touchable/styles.ts +0 -9
  108. package/src/components/Touchable/types.ts +27 -0
  109. package/src/components/View/index.tsx +23 -92
  110. package/src/components/View/styles.ts +0 -6
  111. package/src/components/View/types.ts +13 -0
  112. package/src/components/components.ts +2 -6
  113. package/src/hooks/index.ts +13 -0
  114. package/src/index.ts +2 -0
  115. package/src/modules/PressableRipple/type.ts +1 -0
  116. package/src/utils/KeyboardAware/context.tsx +0 -2
  117. package/src/utils/KeyboardAware/keyboardHooks.ts +1 -2
  118. package/src/utils/ModalManager/components.tsx +1 -30
  119. package/src/utils/ModalManager/context.tsx +4 -4
  120. package/src/utils/ModalManager/index.ts +1 -4
  121. package/src/utils/hooks.ts +12 -1
  122. package/src/components/Calendar/style.ts +0 -6
  123. package/src/components/ContentView/index.tsx +0 -63
  124. package/src/components/ContentView/styles.ts +0 -8
  125. package/src/components/Drawer/index.tsx +0 -28
  126. package/src/components/Drawer/styles.ts +0 -8
  127. package/src/components/FileInput/styles.ts +0 -8
  128. package/src/components/InputLabel/index.tsx +0 -38
  129. package/src/components/InputLabel/styles.ts +0 -7
  130. package/src/components/List/PaginationIndicator.tsx +0 -54
  131. package/src/components/defaultStyles.ts +0 -77
@@ -0,0 +1,27 @@
1
+ import { PropsOf } from '@codeleap/common'
2
+ import { StyledProp } from '@codeleap/styles'
3
+ import { Text } from '../Text'
4
+ import { View, ViewProps } from '../View'
5
+ import { BadgeComposition } from './styles'
6
+
7
+ export type BadgeProps =
8
+ Omit<ViewProps, 'style'> &
9
+ {
10
+ style?: StyledProp<BadgeComposition>
11
+ maxCount?: number
12
+ minCount?: number
13
+ debugName?: string
14
+ innerWrapperProps?: Partial<PropsOf<typeof View>>
15
+ textProps?: Partial<PropsOf<typeof Text>>
16
+ getBadgeContent?: (props: BadgeContent) => string
17
+ renderBadgeContent?: (props: BadgeContent & { content: string }) => JSX.Element
18
+ disabled?: boolean
19
+ badge?: number | boolean
20
+ }
21
+
22
+ export type BadgeContent = BadgeProps & { count: number }
23
+
24
+ export type BadgeComponentProps = {
25
+ badge?: BadgeProps['badge']
26
+ badgeProps?: Partial<BadgeProps>
27
+ }
@@ -1,146 +1,119 @@
1
- import * as React from 'react'
2
- import {
3
- useDefaultComponentStyle,
4
- ComponentVariants,
5
- IconPlaceholder,
6
- GetRefType,
7
- TypeGuards,
8
- getNestedStylesByKey,
9
- } from '@codeleap/common'
10
-
11
- import {
12
- ButtonPresets,
13
- ButtonComposition,
14
- ButtonParts,
15
- } from './styles'
16
- import { forwardRef } from 'react'
17
- import { StylesOf } from '../../types/utility'
1
+ import React, { forwardRef, useState } from 'react'
2
+ import { GetRefType } from '@codeleap/common'
3
+ import { ButtonParts } from './styles'
18
4
  import { Text } from '../Text'
19
5
  import { Touchable, TouchableProps } from '../Touchable'
20
6
  import { Icon } from '../Icon'
21
7
  import { ActivityIndicator } from '../ActivityIndicator'
22
8
  import { StyleSheet } from 'react-native'
23
- import { usePressableFeedback } from '../../utils'
24
- import { Badge, BadgeComponentProps } from '../Badge'
25
- export * from './styles'
26
-
27
- type ChildProps = {
28
- styles: StylesOf<ButtonParts>
29
- props: Omit<ButtonProps, 'children'>
30
- }
9
+ import { TouchableFeedbackConfig, usePressableFeedback } from '../../utils'
10
+ import { Badge } from '../Badge'
11
+ import { ButtonProps } from './types'
12
+ import { AnyRecord, useNestedStylesByKey, IJSX, mergeStyles, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
13
+ import { MobileStyleRegistry } from '../../Registry'
14
+ import { useStylesFor } from '../../hooks'
31
15
 
32
- export type ButtonProps = Omit<TouchableProps, 'variants'> &
33
- ComponentVariants<typeof ButtonPresets> & {
34
- text?: string
35
- rightIcon?: IconPlaceholder
36
- icon?: IconPlaceholder
37
- styles?: StylesOf<ButtonComposition>
38
- loading?: boolean
39
- debounce?: number
40
- debugName: string
41
- selected?: boolean
42
- children?: React.ReactNode | ((props: ChildProps) => React.ReactNode)
43
- } & BadgeComponentProps
16
+ export * from './styles'
17
+ export * from './types'
44
18
 
45
19
  export const Button = forwardRef<GetRefType<TouchableProps['ref']>, ButtonProps>((buttonProps, ref) => {
46
20
  const {
47
- variants = [],
48
21
  children,
49
22
  icon,
50
23
  text,
51
24
  loading,
52
- styles = {},
53
25
  onPress,
54
26
  disabled,
55
27
  selected,
56
28
  rightIcon,
57
29
  style,
58
- badge = false,
30
+ badge,
59
31
  badgeProps = {},
60
32
  ...props
61
- } = buttonProps
62
- const [pressed, setPressed] = React.useState(false)
63
- const variantStyles = useDefaultComponentStyle('u:Button', {
64
- variants,
65
- transform: StyleSheet.flatten,
66
- styles,
67
- })
68
-
69
- function getStyles(key: ButtonParts) {
70
- return [
71
- variantStyles[key],
72
- key === 'wrapper' && style,
73
- disabled && variantStyles[key + ':disabled'],
74
- styles[key],
75
- selected && variantStyles[key + ':selected'],
76
- disabled && styles[key + ':disabled'],
77
- ]
33
+ } = {
34
+ ...Button.defaultProps,
35
+ ...buttonProps,
78
36
  }
79
37
 
38
+ const [pressed, setPressed] = useState(false)
39
+
40
+ const styles = useStylesFor(Button.styleRegistryName, style)
41
+
42
+ const getStyles = (key: ButtonParts) => mergeStyles([
43
+ styles[key],
44
+ selected && styles[key + ':selected'],
45
+ disabled && styles[key + ':disabled'],
46
+ ])
47
+
80
48
  const iconStyle = getStyles('icon')
81
49
 
82
50
  const leftIconStyle = StyleSheet.flatten([iconStyle, getStyles('leftIcon')])
83
51
  const rightIconStyle = StyleSheet.flatten([iconStyle, getStyles('rightIcon')])
84
52
 
85
- const _styles = {
53
+ const componentStyles = {
86
54
  wrapper: getStyles('wrapper'),
87
55
  loader: getStyles('loader'),
88
56
  leftIcon: leftIconStyle,
89
57
  rightIcon: rightIconStyle,
90
58
  text: getStyles('text'),
91
59
  icon: getStyles('icon'),
92
-
93
60
  }
94
61
 
95
62
  const disableFeedback = !onPress || props?.noFeedback
96
63
 
97
- const { getFeedbackStyle } = usePressableFeedback(variantStyles.text, {
64
+ const { getFeedbackStyle } = usePressableFeedback(styles.text, {
98
65
  hightlightPropertyIn: 'color',
99
66
  hightlightPropertyOut: 'color',
100
- feedbackConfig: variantStyles?.textFeedback,
67
+ feedbackConfig: styles?.textFeedback as TouchableFeedbackConfig,
101
68
  disabled: disableFeedback,
102
69
  })
103
70
 
104
- const { getFeedbackStyle: getFeedbackWrapperStyle } = usePressableFeedback(variantStyles.wrapper, {
71
+ const { getFeedbackStyle: getFeedbackWrapperStyle } = usePressableFeedback(styles.wrapper, {
105
72
  hightlightPropertyIn: 'borderColor',
106
73
  hightlightPropertyOut: 'borderColor',
107
74
  disabled: disableFeedback,
108
- feedbackConfig: variantStyles?.wrapperFeedback,
75
+ feedbackConfig: styles?.wrapperFeedback as TouchableFeedbackConfig,
109
76
  })
110
77
 
111
- const childrenContent = TypeGuards.isFunction(children) ?
112
- // @ts-ignore
113
- children({ styles: _styles, props: buttonProps })
114
- : children
115
-
116
78
  const rightFeedback = getFeedbackStyle(pressed)
117
79
 
118
- // TODO - This is a hack to hide the icon when there is no text
119
- const isLeftIconHidden = _styles?.leftIcon?.display != 'none'
80
+ // @ts-expect-error This is a hack to hide the icon when there is no text
81
+ const isLeftIconHidden = componentStyles?.leftIcon?.display != 'none'
120
82
 
121
- const badgeStyles = getNestedStylesByKey('badge', variantStyles)
83
+ const badgeStyles = useNestedStylesByKey('badge', styles)
122
84
 
123
85
  return (
124
86
  <Touchable
125
- style={[_styles.wrapper, getFeedbackWrapperStyle(pressed)]}
126
87
  ref={ref}
127
88
  disabled={disabled}
128
- styles={{
129
- feedback: variantStyles.feedback,
130
- }}
131
89
  onPress={onPress}
132
90
  debugComponent={'Button'}
133
91
  noFeedback={!onPress}
134
92
  setPressed={setPressed}
135
93
  {...props}
94
+ style={[componentStyles.wrapper, { feedback: styles.feedback }, getFeedbackWrapperStyle(pressed)]}
136
95
  >
137
- {loading && <ActivityIndicator style={[_styles.loader, getFeedbackStyle(pressed)]} />}
138
- {(!loading && isLeftIconHidden) && <Icon name={icon} style={[_styles.leftIcon, getFeedbackStyle(pressed)]} />}
139
- {text ? <Text text={text} style={[_styles.text, getFeedbackStyle(pressed)]} /> : null}
140
- {childrenContent}
141
- <Icon name={rightIcon} style={[_styles.rightIcon, rightFeedback]} />
142
- <Badge badge={badge} style={badgeStyles} {...badgeProps} />
96
+ {loading ? <ActivityIndicator style={[componentStyles.loader, getFeedbackStyle(pressed)]} /> : null}
97
+ {(!loading && isLeftIconHidden) ? <Icon name={icon} style={[componentStyles.leftIcon, getFeedbackStyle(pressed)]} /> : null}
98
+ {text ? <Text text={text} style={[componentStyles.text, getFeedbackStyle(pressed)]} /> : null}
99
+ {children}
100
+ {rightIcon ? <Icon name={rightIcon} style={[componentStyles.rightIcon, rightFeedback]} /> : null}
101
+ <Badge badge={badge} {...badgeProps} style={badgeStyles} />
143
102
  </Touchable>
144
103
  )
145
- }) as ((props: ButtonProps) => JSX.Element)
104
+ }) as StyledComponentWithProps<ButtonProps>
105
+
106
+ Button.styleRegistryName = 'Button'
107
+ Button.elements = ['wrapper', 'text', 'icon', 'leftIcon', 'rightIcon', 'loader', 'badge']
108
+ Button.rootElement = 'wrapper'
109
+
110
+ Button.withVariantTypes = <S extends AnyRecord>(styles: S) => {
111
+ return Button as (props: StyledComponentProps<ButtonProps, typeof styles>) => IJSX
112
+ }
113
+
114
+ Button.defaultProps = {
115
+ hitSlop: 10,
116
+ badge: false
117
+ } as Partial<ButtonProps>
146
118
 
119
+ MobileStyleRegistry.registerComponent(Button)
@@ -1,19 +1,22 @@
1
- import { createDefaultVariantFactory, includePresets, StylesOf } from '@codeleap/common'
1
+ import { StylesOf } from '@codeleap/common'
2
2
  import { ActivityIndicatorComposition } from '../ActivityIndicator'
3
3
  import { BadgeComposition } from '../Badge'
4
4
  import { TouchableStylesGen } from '../Touchable'
5
5
 
6
6
  export type ButtonStates = 'disabled' | 'selected'
7
+
7
8
  export type ButtonParts =
8
- | 'text'
9
- | 'inner'
10
- | 'wrapper'
11
- | 'icon'
12
- | 'leftIcon'
13
- | 'rightIcon'
14
- | 'loader'
15
- | `loader${Capitalize<ActivityIndicatorComposition>}`
16
- | `badge${Capitalize<BadgeComposition>}`
9
+ | 'text'
10
+ | 'textFeedback'
11
+ | 'wrapper'
12
+ | 'wrapperFeedback'
13
+ | 'feedback'
14
+ | 'icon'
15
+ | 'leftIcon'
16
+ | 'rightIcon'
17
+ | 'loader'
18
+ | `loader${Capitalize<ActivityIndicatorComposition>}`
19
+ | `badge${Capitalize<BadgeComposition>}`
17
20
 
18
21
  export type ButtonComposition = `${ButtonParts}:${ButtonStates}` | ButtonParts
19
22
 
@@ -22,7 +25,3 @@ export type ButtonStylesGen<TCSS = any> = StylesOf<ButtonComposition, TCSS> & {
22
25
  textFeedback?: TouchableStylesGen['feedback']
23
26
  wrapperFeedback?: TouchableStylesGen['feedback']
24
27
  }
25
-
26
- const createButtonStyle = createDefaultVariantFactory<ButtonComposition, ButtonStylesGen >()
27
-
28
- export const ButtonPresets = includePresets((styles) => createButtonStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,20 @@
1
+ import { AppIcon, StyledProp } from '@codeleap/styles'
2
+ import { ReactNode } from 'react'
3
+ import { BadgeComponentProps } from '../Badge'
4
+ import { TouchableProps } from '../Touchable'
5
+ import { ButtonComposition } from './styles'
6
+
7
+ export type ButtonProps =
8
+ Omit<TouchableProps, 'style'> &
9
+ BadgeComponentProps &
10
+ {
11
+ text?: string
12
+ rightIcon?: AppIcon
13
+ icon?: AppIcon
14
+ loading?: boolean
15
+ debounce?: number
16
+ debugName: string
17
+ selected?: boolean
18
+ children?: ReactNode
19
+ style?: StyledProp<ButtonComposition>
20
+ }
@@ -1,42 +1,40 @@
1
1
  import React from 'react'
2
- import { ComponentVariants, PropsOf, TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
3
- import { StyleSheet } from 'react-native'
4
- import { format, formatISO } from 'date-fns'
2
+ import { TypeGuards } from '@codeleap/common'
3
+ import { format } from 'date-fns'
5
4
  // @ts-ignore
6
5
  import { Calendar as RNCalendar, CalendarProps as RNCalendarProps, DateData } from 'react-native-calendars'
6
+ import { View, ViewProps } from '../View'
7
+ import { CalendarComposition } from './types'
8
+ import { AnyRecord, IJSX, StyledComponentProps, StyledProp } from '@codeleap/styles'
9
+ import { MobileStyleRegistry } from '../../Registry'
10
+ import { useStylesFor } from '../../hooks'
11
+
12
+ export type CalendarProps =
13
+ Omit<ViewProps, 'style'> &
14
+ {
15
+ onValueChange?: (date: Date | string) => any
16
+ value?: Date | string
17
+ calendarProps?: RNCalendarProps
18
+ style?: StyledProp<CalendarComposition>
19
+ }
7
20
 
8
- import { View } from '../View'
9
- import { TCalendarStyles } from './types'
10
- import { CalendarPresets } from './style'
11
- export type CalendarProps = PropsOf<typeof View> & {
12
- styles?: TCalendarStyles
13
- onValueChange?: (date: Date|string) => any
14
- value?: Date|string
15
- calendarProps?: RNCalendarProps
16
- } & ComponentVariants<typeof CalendarPresets>
17
- export * from './style'
18
21
  export * from './types'
19
22
 
20
- export const Calendar = (props:CalendarProps) => {
23
+ export const Calendar = (props: CalendarProps) => {
21
24
  const {
22
- variants = [],
23
25
  style,
24
- styles = {},
25
26
  calendarProps,
26
27
  value,
27
28
  onValueChange,
28
29
  ...viewProps
29
30
  } = props
30
- const variantStyles = useDefaultComponentStyle<'u:Calendar', typeof CalendarPresets>('u:Calendar', {
31
- variants,
32
- styles,
33
- transform: StyleSheet.flatten,
34
- rootElement: 'wrapper',
35
- })
31
+
32
+ const styles = useStylesFor(Calendar.styleRegistryName, style)
33
+
36
34
  const isDateObject = TypeGuards.isInstance(value, Date)
37
- const stringValue:string = isDateObject ? format(value, 'yyyy/MM/dd') : value
35
+ const stringValue: string = isDateObject ? format(value, 'yyyy/MM/dd') : value
38
36
 
39
- function handleChange(date:DateData) {
37
+ function handleChange(date: DateData) {
40
38
  if (!onValueChange) return
41
39
  if (isDateObject) {
42
40
  onValueChange(new Date(date.timestamp))
@@ -45,7 +43,7 @@ export const Calendar = (props:CalendarProps) => {
45
43
  }
46
44
  }
47
45
 
48
- return <View style={[variantStyles.wrapper, style]} {...viewProps}>
46
+ return <View style={styles?.wrapper} {...viewProps}>
49
47
  <RNCalendar
50
48
  onDayPress={handleChange}
51
49
  current={new Date(value).toISOString()}
@@ -54,12 +52,20 @@ export const Calendar = (props:CalendarProps) => {
54
52
  [stringValue]: { selected: true },
55
53
  }}
56
54
  theme={{
57
- ...variantStyles.theme,
58
- stylesheet: {
59
- ...variantStyles,
60
- },
55
+ ...styles?.theme,
56
+ stylesheet: styles,
61
57
  }}
62
58
  {...calendarProps}
63
59
  />
64
60
  </View>
65
61
  }
62
+
63
+ Calendar.styleRegistryName = 'Calendar'
64
+ Calendar.elements = ['wrapper', 'theme', 'calendar', 'day', 'agenda', 'expandable', 'event', 'timeLabel', 'textDayStyle', 'dotStyle', 'arrowStyle', 'contentStyle', 'timelineContainer', 'line', 'verticalLine', 'nowIndicator']
65
+ Calendar.rootElement = 'wrapper'
66
+
67
+ Calendar.withVariantTypes = <S extends AnyRecord>(styles: S) => {
68
+ return Calendar as (props: StyledComponentProps<CalendarProps, typeof styles>) => IJSX
69
+ }
70
+
71
+ MobileStyleRegistry.registerComponent(Calendar)
@@ -1,57 +1,30 @@
1
- import * as React from 'react'
2
- import {
3
-
4
- ComponentVariants,
5
- useDefaultComponentStyle,
6
- StylesOf,
7
- PropsOf,
8
- IconPlaceholder,
9
- } from '@codeleap/common'
10
- import { ReactNode } from 'react'
11
- import { StyleSheet } from 'react-native'
1
+ import React from 'react'
12
2
  import { View } from '../View'
13
-
14
- import {
15
- CheckboxPresets,
16
- CheckboxComposition,
17
- } from './styles'
18
- import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
3
+ import { InputBase, InputBaseDefaultOrder, selectInputBaseProps } from '../InputBase'
19
4
  import { useAnimatedVariantStyles } from '../..'
20
5
  import { Touchable } from '../Touchable'
21
6
  import { Icon } from '../Icon'
7
+ import { CheckboxProps } from './types'
8
+ import { AnyRecord, AppIcon, IJSX, StyledComponentProps } from '@codeleap/styles'
9
+ import { MobileStyleRegistry } from '../../Registry'
10
+ import { useStylesFor } from '../../hooks'
22
11
 
23
12
  export * from './styles'
24
-
25
- export type CheckboxProps = Pick<
26
- InputBaseProps,
27
- 'debugName' | 'disabled' | 'label'
28
- > & {
29
- variants?: ComponentVariants<typeof CheckboxPresets>['variants']
30
- styles?: StylesOf<CheckboxComposition>
31
- value: boolean
32
- onValueChange: (value: boolean) => void
33
- style?: PropsOf<typeof View>['style']
34
- checkboxOnLeft?: boolean
35
- checkIcon?: IconPlaceholder
36
- }
13
+ export * from './types'
37
14
 
38
15
  const reversedOrder = [...InputBaseDefaultOrder].reverse()
39
- const defaultProps: Partial<CheckboxProps> = {
40
- checkIcon: 'check' as IconPlaceholder,
41
- }
16
+
42
17
  export const Checkbox = (props: CheckboxProps) => {
43
18
  const {
44
19
  inputBaseProps,
45
20
  others,
46
21
  } = selectInputBaseProps({
47
- ...defaultProps,
22
+ ...Checkbox.defaultProps,
48
23
  ...props,
49
24
  })
50
25
 
51
26
  const {
52
- variants = [],
53
- style = {},
54
- styles = {},
27
+ style,
55
28
  value,
56
29
  disabled,
57
30
  debugName,
@@ -60,24 +33,19 @@ export const Checkbox = (props: CheckboxProps) => {
60
33
  checkIcon,
61
34
  } = others
62
35
 
63
- const variantStyles = useDefaultComponentStyle<'u:Checkbox', typeof CheckboxPresets>('u:Checkbox', {
64
- variants,
65
- styles,
66
- rootElement: 'wrapper',
67
- transform: StyleSheet.flatten,
68
- })
36
+ const styles = useStylesFor(Checkbox.styleRegistryName, style)
69
37
 
70
38
  const boxAnimation = useAnimatedVariantStyles({
71
- variantStyles,
39
+ variantStyles: styles,
72
40
  animatedProperties: ['box:unchecked', 'box:disabled', 'box:checked', 'box:disabled-checked', 'box:disabled-unchecked'],
73
- transition: variantStyles['box:transition'],
41
+ transition: styles['box:transition'],
74
42
  updater: () => {
75
43
  'worklet'
76
44
  let disabledStyle = {}
77
45
  if (disabled) {
78
- disabledStyle = value ? variantStyles['box:disabled-checked'] : variantStyles['box:disabled-unchecked']
46
+ disabledStyle = value ? styles['box:disabled-checked'] : styles['box:disabled-unchecked']
79
47
  }
80
- const style = value ? variantStyles['box:checked'] : variantStyles['box:unchecked']
48
+ const style = value ? styles['box:checked'] : styles['box:unchecked']
81
49
 
82
50
  return {
83
51
  ...style,
@@ -89,16 +57,16 @@ export const Checkbox = (props: CheckboxProps) => {
89
57
  })
90
58
 
91
59
  const checkmarkWrapperAnimation = useAnimatedVariantStyles({
92
- variantStyles,
60
+ variantStyles: styles,
93
61
  animatedProperties: ['checkmarkWrapper:unchecked', 'checkmarkWrapper:disabled', 'checkmarkWrapper:checked', 'checkmarkWrapper:disabled-unchecked', 'checkmarkWrapper:disabled-checked'],
94
- transition: variantStyles['checkmarkWrapper:transition'],
62
+ transition: styles['checkmarkWrapper:transition'],
95
63
  updater: () => {
96
64
  'worklet'
97
65
  let disabledStyle = {}
98
66
  if (disabled) {
99
- disabledStyle = value ? variantStyles['checkmarkWrapper:disabled-checked'] : variantStyles['checkmarkWrapper:disabled-unchecked']
67
+ disabledStyle = value ? styles['checkmarkWrapper:disabled-checked'] : styles['checkmarkWrapper:disabled-unchecked']
100
68
  }
101
- const style = value ? variantStyles['checkmarkWrapper:checked'] : variantStyles['checkmarkWrapper:unchecked']
69
+ const style = value ? styles['checkmarkWrapper:checked'] : styles['checkmarkWrapper:unchecked']
102
70
  return {
103
71
  ...style,
104
72
  ...disabledStyle,
@@ -108,13 +76,14 @@ export const Checkbox = (props: CheckboxProps) => {
108
76
  dependencies: [value, disabled],
109
77
  })
110
78
 
111
- const _checkboxOnLeft = checkboxOnLeft ?? variantStyles.__props?.checkboxOnLeft
79
+ // @ts-expect-error
80
+ const _checkboxOnLeft = checkboxOnLeft ?? styles.__props?.checkboxOnLeft
112
81
 
113
82
  return <InputBase
114
83
  {...inputBaseProps}
115
84
  debugName={debugName}
116
85
  wrapper={Touchable}
117
- styles={variantStyles}
86
+ style={styles}
118
87
  wrapperProps={{
119
88
  onPress: () => {
120
89
  onValueChange(!value)
@@ -123,32 +92,42 @@ export const Checkbox = (props: CheckboxProps) => {
123
92
  rippleDisabled: true,
124
93
  }}
125
94
  order={_checkboxOnLeft ? reversedOrder : InputBaseDefaultOrder}
126
- style={style}
127
95
  >
128
96
  <View
129
97
  animated
98
+ animatedStyle={boxAnimation}
130
99
  style={[
131
- variantStyles.box,
132
- disabled && variantStyles['box:disabled'],
133
- boxAnimation,
100
+ styles.box,
101
+ disabled && styles['box:disabled'],
134
102
  ]}
135
103
  >
136
104
  <View
137
105
  animated
106
+ animatedStyle={checkmarkWrapperAnimation}
138
107
  style={[
139
- variantStyles.checkmarkWrapper,
140
- disabled && variantStyles['checkmarkWrapper:disabled'],
141
- checkmarkWrapperAnimation,
108
+ styles.checkmarkWrapper,
109
+ disabled && styles['checkmarkWrapper:disabled'],
142
110
  ]}
143
111
  >
144
112
  <Icon
145
- name={checkIcon as any}
146
- style={[variantStyles.checkmark, disabled && variantStyles['checkmark:disabled']]}
147
-
113
+ name={checkIcon}
114
+ style={[styles.checkmark, disabled && styles['checkmark:disabled']]}
148
115
  />
149
116
  </View>
150
117
  </View>
151
118
  </InputBase>
152
119
  }
153
120
 
154
- Checkbox.defaultProps = defaultProps
121
+ Checkbox.styleRegistryName = 'Checkbox'
122
+ Checkbox.rootElement = 'wrapper'
123
+ Checkbox.elements = [...InputBase.elements, 'checkmark', 'box', '__props']
124
+
125
+ Checkbox.withVariantTypes = <S extends AnyRecord>(styles: S) => {
126
+ return Checkbox as (props: StyledComponentProps<CheckboxProps, typeof styles>) => IJSX
127
+ }
128
+
129
+ Checkbox.defaultProps = {
130
+ checkIcon: 'check' as AppIcon,
131
+ } as Partial<CheckboxProps>
132
+
133
+ MobileStyleRegistry.registerComponent(Checkbox)
@@ -1,7 +1,7 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { InputBaseParts, InputBaseStates } from '../InputBase'
3
2
 
4
3
  type AnimatableParts = 'checkmarkWrapper' | 'box'
4
+
5
5
  export type CheckboxParts = InputBaseParts | AnimatableParts | 'checkmark'
6
6
 
7
7
  export type CheckboxAnimationStates = 'checked' | 'unchecked' | 'disabled-checked' | 'disabled-unchecked'
@@ -14,8 +14,3 @@ export type CheckboxComposition =
14
14
  | `${AnimatableParts}:transition`
15
15
  | `${AnimatableParts}:${CheckboxAnimationStates}`
16
16
  | '__props'
17
-
18
- const createCheckboxStyle = createDefaultVariantFactory<CheckboxComposition>()
19
-
20
- export const CheckboxPresets = includePresets((styles) => createCheckboxStyle(() => ({ wrapper: styles })))
21
-
@@ -0,0 +1,13 @@
1
+ import { AppIcon, StyledProp } from '@codeleap/styles'
2
+ import { InputBaseProps } from '../InputBase'
3
+ import { CheckboxComposition } from './styles'
4
+
5
+ export type CheckboxProps =
6
+ Pick<InputBaseProps, 'debugName' | 'disabled' | 'label'> &
7
+ {
8
+ value: boolean
9
+ onValueChange: (value: boolean) => void
10
+ style?: StyledProp<CheckboxComposition>
11
+ checkboxOnLeft?: boolean
12
+ checkIcon?: AppIcon
13
+ }