@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,119 +1,146 @@
1
- import React, { forwardRef, useState } from 'react'
2
- import { GetRefType } from '@codeleap/common'
3
- import { ButtonParts } from './styles'
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'
4
18
  import { Text } from '../Text'
5
19
  import { Touchable, TouchableProps } from '../Touchable'
6
20
  import { Icon } from '../Icon'
7
21
  import { ActivityIndicator } from '../ActivityIndicator'
8
22
  import { StyleSheet } from 'react-native'
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'
15
-
23
+ import { usePressableFeedback } from '../../utils'
24
+ import { Badge, BadgeComponentProps } from '../Badge'
16
25
  export * from './styles'
17
- export * from './types'
26
+
27
+ type ChildProps = {
28
+ styles: StylesOf<ButtonParts>
29
+ props: Omit<ButtonProps, 'children'>
30
+ }
31
+
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
18
44
 
19
45
  export const Button = forwardRef<GetRefType<TouchableProps['ref']>, ButtonProps>((buttonProps, ref) => {
20
46
  const {
47
+ variants = [],
21
48
  children,
22
49
  icon,
23
50
  text,
24
51
  loading,
52
+ styles = {},
25
53
  onPress,
26
54
  disabled,
27
55
  selected,
28
56
  rightIcon,
29
57
  style,
30
- badge,
58
+ badge = false,
31
59
  badgeProps = {},
32
60
  ...props
33
- } = {
34
- ...Button.defaultProps,
35
- ...buttonProps,
36
- }
37
-
38
- const [pressed, setPressed] = useState(false)
39
-
40
- const styles = useStylesFor(Button.styleRegistryName, style)
61
+ } = buttonProps
62
+ const [pressed, setPressed] = React.useState(false)
63
+ const variantStyles = useDefaultComponentStyle('u:Button', {
64
+ variants,
65
+ transform: StyleSheet.flatten,
66
+ styles,
67
+ })
41
68
 
42
- const getStyles = (key: ButtonParts) => mergeStyles([
43
- styles[key],
44
- selected && styles[key + ':selected'],
45
- disabled && styles[key + ':disabled'],
46
- ])
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
+ ]
78
+ }
47
79
 
48
80
  const iconStyle = getStyles('icon')
49
81
 
50
82
  const leftIconStyle = StyleSheet.flatten([iconStyle, getStyles('leftIcon')])
51
83
  const rightIconStyle = StyleSheet.flatten([iconStyle, getStyles('rightIcon')])
52
84
 
53
- const componentStyles = {
85
+ const _styles = {
54
86
  wrapper: getStyles('wrapper'),
55
87
  loader: getStyles('loader'),
56
88
  leftIcon: leftIconStyle,
57
89
  rightIcon: rightIconStyle,
58
90
  text: getStyles('text'),
59
91
  icon: getStyles('icon'),
92
+
60
93
  }
61
94
 
62
95
  const disableFeedback = !onPress || props?.noFeedback
63
96
 
64
- const { getFeedbackStyle } = usePressableFeedback(styles.text, {
97
+ const { getFeedbackStyle } = usePressableFeedback(variantStyles.text, {
65
98
  hightlightPropertyIn: 'color',
66
99
  hightlightPropertyOut: 'color',
67
- feedbackConfig: styles?.textFeedback as TouchableFeedbackConfig,
100
+ feedbackConfig: variantStyles?.textFeedback,
68
101
  disabled: disableFeedback,
69
102
  })
70
103
 
71
- const { getFeedbackStyle: getFeedbackWrapperStyle } = usePressableFeedback(styles.wrapper, {
104
+ const { getFeedbackStyle: getFeedbackWrapperStyle } = usePressableFeedback(variantStyles.wrapper, {
72
105
  hightlightPropertyIn: 'borderColor',
73
106
  hightlightPropertyOut: 'borderColor',
74
107
  disabled: disableFeedback,
75
- feedbackConfig: styles?.wrapperFeedback as TouchableFeedbackConfig,
108
+ feedbackConfig: variantStyles?.wrapperFeedback,
76
109
  })
77
110
 
111
+ const childrenContent = TypeGuards.isFunction(children) ?
112
+ // @ts-ignore
113
+ children({ styles: _styles, props: buttonProps })
114
+ : children
115
+
78
116
  const rightFeedback = getFeedbackStyle(pressed)
79
117
 
80
- // @ts-expect-error This is a hack to hide the icon when there is no text
81
- const isLeftIconHidden = componentStyles?.leftIcon?.display != 'none'
118
+ // TODO - This is a hack to hide the icon when there is no text
119
+ const isLeftIconHidden = _styles?.leftIcon?.display != 'none'
82
120
 
83
- const badgeStyles = useNestedStylesByKey('badge', styles)
121
+ const badgeStyles = getNestedStylesByKey('badge', variantStyles)
84
122
 
85
123
  return (
86
124
  <Touchable
125
+ style={[_styles.wrapper, getFeedbackWrapperStyle(pressed)]}
87
126
  ref={ref}
88
127
  disabled={disabled}
128
+ styles={{
129
+ feedback: variantStyles.feedback,
130
+ }}
89
131
  onPress={onPress}
90
132
  debugComponent={'Button'}
91
133
  noFeedback={!onPress}
92
134
  setPressed={setPressed}
93
135
  {...props}
94
- style={[componentStyles.wrapper, { feedback: styles.feedback }, getFeedbackWrapperStyle(pressed)]}
95
136
  >
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} />
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} />
102
143
  </Touchable>
103
144
  )
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>
145
+ }) as ((props: ButtonProps) => JSX.Element)
118
146
 
119
- MobileStyleRegistry.registerComponent(Button)
@@ -1,22 +1,19 @@
1
- import { StylesOf } from '@codeleap/common'
1
+ import { createDefaultVariantFactory, includePresets, 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
-
8
7
  export type ButtonParts =
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>}`
8
+ | 'text'
9
+ | 'inner'
10
+ | 'wrapper'
11
+ | 'icon'
12
+ | 'leftIcon'
13
+ | 'rightIcon'
14
+ | 'loader'
15
+ | `loader${Capitalize<ActivityIndicatorComposition>}`
16
+ | `badge${Capitalize<BadgeComposition>}`
20
17
 
21
18
  export type ButtonComposition = `${ButtonParts}:${ButtonStates}` | ButtonParts
22
19
 
@@ -25,3 +22,7 @@ export type ButtonStylesGen<TCSS = any> = StylesOf<ButtonComposition, TCSS> & {
25
22
  textFeedback?: TouchableStylesGen['feedback']
26
23
  wrapperFeedback?: TouchableStylesGen['feedback']
27
24
  }
25
+
26
+ const createButtonStyle = createDefaultVariantFactory<ButtonComposition, ButtonStylesGen >()
27
+
28
+ export const ButtonPresets = includePresets((styles) => createButtonStyle(() => ({ wrapper: styles })))
@@ -1,40 +1,42 @@
1
1
  import React from 'react'
2
- import { TypeGuards } from '@codeleap/common'
3
- import { format } from 'date-fns'
2
+ import { ComponentVariants, PropsOf, TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
3
+ import { StyleSheet } from 'react-native'
4
+ import { format, formatISO } from 'date-fns'
4
5
  // @ts-ignore
5
6
  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
- }
20
7
 
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'
21
18
  export * from './types'
22
19
 
23
- export const Calendar = (props: CalendarProps) => {
20
+ export const Calendar = (props:CalendarProps) => {
24
21
  const {
22
+ variants = [],
25
23
  style,
24
+ styles = {},
26
25
  calendarProps,
27
26
  value,
28
27
  onValueChange,
29
28
  ...viewProps
30
29
  } = props
31
-
32
- const styles = useStylesFor(Calendar.styleRegistryName, style)
33
-
30
+ const variantStyles = useDefaultComponentStyle<'u:Calendar', typeof CalendarPresets>('u:Calendar', {
31
+ variants,
32
+ styles,
33
+ transform: StyleSheet.flatten,
34
+ rootElement: 'wrapper',
35
+ })
34
36
  const isDateObject = TypeGuards.isInstance(value, Date)
35
- const stringValue: string = isDateObject ? format(value, 'yyyy/MM/dd') : value
37
+ const stringValue:string = isDateObject ? format(value, 'yyyy/MM/dd') : value
36
38
 
37
- function handleChange(date: DateData) {
39
+ function handleChange(date:DateData) {
38
40
  if (!onValueChange) return
39
41
  if (isDateObject) {
40
42
  onValueChange(new Date(date.timestamp))
@@ -43,7 +45,7 @@ export const Calendar = (props: CalendarProps) => {
43
45
  }
44
46
  }
45
47
 
46
- return <View style={styles?.wrapper} {...viewProps}>
48
+ return <View style={[variantStyles.wrapper, style]} {...viewProps}>
47
49
  <RNCalendar
48
50
  onDayPress={handleChange}
49
51
  current={new Date(value).toISOString()}
@@ -52,20 +54,12 @@ export const Calendar = (props: CalendarProps) => {
52
54
  [stringValue]: { selected: true },
53
55
  }}
54
56
  theme={{
55
- ...styles?.theme,
56
- stylesheet: styles,
57
+ ...variantStyles.theme,
58
+ stylesheet: {
59
+ ...variantStyles,
60
+ },
57
61
  }}
58
62
  {...calendarProps}
59
63
  />
60
64
  </View>
61
65
  }
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)
@@ -0,0 +1,6 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import { TCalendarStyles, CalendarComposition } from './types'
3
+
4
+ const createCalendarStyle = createDefaultVariantFactory<CalendarComposition, TCalendarStyles>()
5
+
6
+ export const CalendarPresets = includePresets((style) => createCalendarStyle(() => ({ theme: style })))
@@ -1,30 +1,57 @@
1
- import React from 'react'
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'
2
12
  import { View } from '../View'
3
- import { InputBase, InputBaseDefaultOrder, selectInputBaseProps } from '../InputBase'
13
+
14
+ import {
15
+ CheckboxPresets,
16
+ CheckboxComposition,
17
+ } from './styles'
18
+ import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
4
19
  import { useAnimatedVariantStyles } from '../..'
5
20
  import { Touchable } from '../Touchable'
6
21
  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'
11
22
 
12
23
  export * from './styles'
13
- export * from './types'
14
24
 
15
- const reversedOrder = [...InputBaseDefaultOrder].reverse()
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
+ }
16
37
 
38
+ const reversedOrder = [...InputBaseDefaultOrder].reverse()
39
+ const defaultProps: Partial<CheckboxProps> = {
40
+ checkIcon: 'check' as IconPlaceholder,
41
+ }
17
42
  export const Checkbox = (props: CheckboxProps) => {
18
43
  const {
19
44
  inputBaseProps,
20
45
  others,
21
46
  } = selectInputBaseProps({
22
- ...Checkbox.defaultProps,
47
+ ...defaultProps,
23
48
  ...props,
24
49
  })
25
50
 
26
51
  const {
27
- style,
52
+ variants = [],
53
+ style = {},
54
+ styles = {},
28
55
  value,
29
56
  disabled,
30
57
  debugName,
@@ -33,19 +60,24 @@ export const Checkbox = (props: CheckboxProps) => {
33
60
  checkIcon,
34
61
  } = others
35
62
 
36
- const styles = useStylesFor(Checkbox.styleRegistryName, style)
63
+ const variantStyles = useDefaultComponentStyle<'u:Checkbox', typeof CheckboxPresets>('u:Checkbox', {
64
+ variants,
65
+ styles,
66
+ rootElement: 'wrapper',
67
+ transform: StyleSheet.flatten,
68
+ })
37
69
 
38
70
  const boxAnimation = useAnimatedVariantStyles({
39
- variantStyles: styles,
71
+ variantStyles,
40
72
  animatedProperties: ['box:unchecked', 'box:disabled', 'box:checked', 'box:disabled-checked', 'box:disabled-unchecked'],
41
- transition: styles['box:transition'],
73
+ transition: variantStyles['box:transition'],
42
74
  updater: () => {
43
75
  'worklet'
44
76
  let disabledStyle = {}
45
77
  if (disabled) {
46
- disabledStyle = value ? styles['box:disabled-checked'] : styles['box:disabled-unchecked']
78
+ disabledStyle = value ? variantStyles['box:disabled-checked'] : variantStyles['box:disabled-unchecked']
47
79
  }
48
- const style = value ? styles['box:checked'] : styles['box:unchecked']
80
+ const style = value ? variantStyles['box:checked'] : variantStyles['box:unchecked']
49
81
 
50
82
  return {
51
83
  ...style,
@@ -57,16 +89,16 @@ export const Checkbox = (props: CheckboxProps) => {
57
89
  })
58
90
 
59
91
  const checkmarkWrapperAnimation = useAnimatedVariantStyles({
60
- variantStyles: styles,
92
+ variantStyles,
61
93
  animatedProperties: ['checkmarkWrapper:unchecked', 'checkmarkWrapper:disabled', 'checkmarkWrapper:checked', 'checkmarkWrapper:disabled-unchecked', 'checkmarkWrapper:disabled-checked'],
62
- transition: styles['checkmarkWrapper:transition'],
94
+ transition: variantStyles['checkmarkWrapper:transition'],
63
95
  updater: () => {
64
96
  'worklet'
65
97
  let disabledStyle = {}
66
98
  if (disabled) {
67
- disabledStyle = value ? styles['checkmarkWrapper:disabled-checked'] : styles['checkmarkWrapper:disabled-unchecked']
99
+ disabledStyle = value ? variantStyles['checkmarkWrapper:disabled-checked'] : variantStyles['checkmarkWrapper:disabled-unchecked']
68
100
  }
69
- const style = value ? styles['checkmarkWrapper:checked'] : styles['checkmarkWrapper:unchecked']
101
+ const style = value ? variantStyles['checkmarkWrapper:checked'] : variantStyles['checkmarkWrapper:unchecked']
70
102
  return {
71
103
  ...style,
72
104
  ...disabledStyle,
@@ -76,14 +108,13 @@ export const Checkbox = (props: CheckboxProps) => {
76
108
  dependencies: [value, disabled],
77
109
  })
78
110
 
79
- // @ts-expect-error
80
- const _checkboxOnLeft = checkboxOnLeft ?? styles.__props?.checkboxOnLeft
111
+ const _checkboxOnLeft = checkboxOnLeft ?? variantStyles.__props?.checkboxOnLeft
81
112
 
82
113
  return <InputBase
83
114
  {...inputBaseProps}
84
115
  debugName={debugName}
85
116
  wrapper={Touchable}
86
- style={styles}
117
+ styles={variantStyles}
87
118
  wrapperProps={{
88
119
  onPress: () => {
89
120
  onValueChange(!value)
@@ -92,42 +123,32 @@ export const Checkbox = (props: CheckboxProps) => {
92
123
  rippleDisabled: true,
93
124
  }}
94
125
  order={_checkboxOnLeft ? reversedOrder : InputBaseDefaultOrder}
126
+ style={style}
95
127
  >
96
128
  <View
97
129
  animated
98
- animatedStyle={boxAnimation}
99
130
  style={[
100
- styles.box,
101
- disabled && styles['box:disabled'],
131
+ variantStyles.box,
132
+ disabled && variantStyles['box:disabled'],
133
+ boxAnimation,
102
134
  ]}
103
135
  >
104
136
  <View
105
137
  animated
106
- animatedStyle={checkmarkWrapperAnimation}
107
138
  style={[
108
- styles.checkmarkWrapper,
109
- disabled && styles['checkmarkWrapper:disabled'],
139
+ variantStyles.checkmarkWrapper,
140
+ disabled && variantStyles['checkmarkWrapper:disabled'],
141
+ checkmarkWrapperAnimation,
110
142
  ]}
111
143
  >
112
144
  <Icon
113
- name={checkIcon}
114
- style={[styles.checkmark, disabled && styles['checkmark:disabled']]}
145
+ name={checkIcon as any}
146
+ style={[variantStyles.checkmark, disabled && variantStyles['checkmark:disabled']]}
147
+
115
148
  />
116
149
  </View>
117
150
  </View>
118
151
  </InputBase>
119
152
  }
120
153
 
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)
154
+ Checkbox.defaultProps = defaultProps
@@ -1,7 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
  import { InputBaseParts, InputBaseStates } from '../InputBase'
2
3
 
3
4
  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,3 +14,8 @@ 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,63 @@
1
+ import React from 'react'
2
+ import {
3
+
4
+ ComponentVariants,
5
+ useDefaultComponentStyle,
6
+
7
+ } from '@codeleap/common'
8
+ import {
9
+ ContentViewPresets,
10
+ } from './styles'
11
+ import { ViewProps, View, ViewComposition } from '../View'
12
+ import { Text } from '../Text'
13
+ import { StylesOf } from '../../types'
14
+ import { ActivityIndicator } from '../ActivityIndicator'
15
+ import { StyleSheet } from 'react-native'
16
+
17
+ export * from './styles'
18
+
19
+ export type ContentViewProps = Omit<
20
+ ViewProps,
21
+ 'variants' | 'responsiveVariants'
22
+ > & {
23
+ message?: string
24
+ loading?: boolean
25
+ styles?: StylesOf<ViewComposition>
26
+ } & ComponentVariants<typeof ContentViewPresets>
27
+
28
+ const WrapContent = ({ children, ...props }) => (
29
+ <View {...props}>{children}</View>
30
+ )
31
+
32
+ export const ContentView: React.FC<ContentViewProps> = (rawProps) => {
33
+ const { children, message, loading, variants, styles, ...props } =
34
+ rawProps
35
+
36
+ const variantStyle = useDefaultComponentStyle('ContentView', {
37
+ variants,
38
+ transform: StyleSheet.flatten,
39
+ styles,
40
+ })
41
+
42
+ if (loading) {
43
+ return (
44
+ <WrapContent {...props} style={variantStyle.wrapper}>
45
+ <ActivityIndicator styles={{ wrapper: variantStyle.loader }} />
46
+ </WrapContent>
47
+ )
48
+ }
49
+ const hasChildren = Object.keys(children || {}).length > 0
50
+ if (hasChildren) {
51
+ return (
52
+ <WrapContent {...props} style={variantStyle.wrapper}>
53
+ {children}
54
+ </WrapContent>
55
+ )
56
+ }
57
+
58
+ return (
59
+ <WrapContent {...props} style={styles}>
60
+ <Text text={message} />
61
+ </WrapContent>
62
+ )
63
+ }
@@ -0,0 +1,8 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
3
+ export type ContentViewComposition = 'placeholder' | 'wrapper' | 'loader'
4
+
5
+ const createContentViewStyle =
6
+ createDefaultVariantFactory<ContentViewComposition>()
7
+
8
+ export const ContentViewPresets = includePresets((styles) => createContentViewStyle(() => ({ wrapper: styles })))