@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.
- package/package.json +4 -6
- package/src/components/ActionIcon/index.tsx +37 -55
- package/src/components/ActionIcon/styles.ts +4 -2
- package/src/components/ActivityIndicator/index.tsx +64 -42
- package/src/components/ActivityIndicator/styles.ts +10 -1
- package/src/components/Autocomplete/index.tsx +54 -46
- package/src/components/Autocomplete/styles.ts +5 -2
- package/src/components/Autocomplete/types.ts +23 -13
- package/src/components/Avatar/index.tsx +71 -59
- package/src/components/Avatar/styles.ts +9 -1
- package/src/components/AvatarGroup/index.tsx +44 -30
- package/src/components/AvatarGroup/styles.ts +6 -0
- package/src/components/Backdrop/index.tsx +34 -51
- package/src/components/Backdrop/styles.ts +10 -5
- package/src/components/Badge/index.tsx +62 -36
- package/src/components/Badge/styles.ts +11 -3
- package/src/components/Button/index.tsx +82 -55
- package/src/components/Button/styles.ts +14 -13
- package/src/components/Calendar/index.tsx +29 -35
- package/src/components/Calendar/style.ts +6 -0
- package/src/components/Checkbox/index.tsx +64 -43
- package/src/components/Checkbox/styles.ts +6 -1
- package/src/components/ContentView/index.tsx +63 -0
- package/src/components/ContentView/styles.ts +8 -0
- package/src/components/DatePickerModal/index.tsx +65 -50
- package/src/components/DatePickerModal/styles.ts +10 -9
- package/src/components/DatePickerModal/types.ts +54 -36
- package/src/components/Drawer/index.tsx +28 -0
- package/src/components/Drawer/styles.ts +8 -0
- package/src/components/EmptyPlaceholder/index.tsx +63 -40
- package/src/components/EmptyPlaceholder/styles.ts +5 -0
- package/src/components/FileInput/index.tsx +49 -11
- package/src/components/FileInput/styles.ts +8 -0
- package/src/components/Grid/index.tsx +116 -84
- package/src/components/Grid/styles.ts +5 -0
- package/src/components/Icon/index.tsx +79 -44
- package/src/components/Icon/styles.ts +6 -0
- package/src/components/Image/index.tsx +78 -58
- package/src/components/Image/styles.ts +6 -1
- package/src/components/ImageView/Spotlight.tsx +4 -1
- package/src/components/ImageView/component.tsx +2 -1
- package/src/components/InputBase/index.tsx +24 -33
- package/src/components/InputBase/styles.ts +75 -66
- package/src/components/InputBase/types.ts +4 -3
- package/src/components/InputBase/utils.ts +4 -6
- package/src/components/InputLabel/index.tsx +38 -0
- package/src/components/InputLabel/styles.ts +7 -0
- package/src/components/List/PaginationIndicator.tsx +54 -0
- package/src/components/List/index.tsx +151 -99
- package/src/components/List/styles.ts +6 -0
- package/src/components/LoadingOverlay/index.tsx +29 -42
- package/src/components/LoadingOverlay/styles.ts +7 -7
- package/src/components/Modal/index.tsx +127 -80
- package/src/components/Modal/styles.ts +8 -0
- package/src/components/Navigation/Navigation.tsx +0 -1
- package/src/components/Navigation/types.ts +9 -2
- package/src/components/NumberIncrement/index.tsx +60 -50
- package/src/components/NumberIncrement/styles.ts +5 -0
- package/src/components/NumberIncrement/types.ts +39 -32
- package/src/components/Pager/index.tsx +94 -42
- package/src/components/Pager/styles.ts +13 -1
- package/src/components/RadioInput/index.tsx +57 -32
- package/src/components/RadioInput/styles.ts +7 -5
- package/src/components/RefreshControl/index.tsx +19 -39
- package/src/components/RefreshControl/styles.ts +6 -1
- package/src/components/Scroll/index.tsx +105 -89
- package/src/components/Scroll/styles.ts +5 -0
- package/src/components/Sections/index.tsx +161 -111
- package/src/components/Sections/styles.ts +5 -0
- package/src/components/SegmentedControl/Option.tsx +31 -46
- package/src/components/SegmentedControl/index.tsx +121 -86
- package/src/components/SegmentedControl/styles.ts +22 -15
- package/src/components/Select/index.tsx +82 -71
- package/src/components/Select/styles.ts +5 -3
- package/src/components/Select/types.ts +25 -20
- package/src/components/Slider/index.tsx +43 -58
- package/src/components/Slider/styles.ts +6 -15
- package/src/components/Slider/types.ts +14 -9
- package/src/components/Switch/index.tsx +56 -43
- package/src/components/Switch/styles.ts +7 -1
- package/src/components/Text/index.tsx +52 -56
- package/src/components/Text/styles.ts +7 -1
- package/src/components/TextInput/index.tsx +162 -49
- package/src/components/TextInput/styles.ts +8 -2
- package/src/components/Touchable/index.tsx +87 -44
- package/src/components/Touchable/styles.ts +9 -0
- package/src/components/View/index.tsx +92 -23
- package/src/components/View/styles.ts +6 -0
- package/src/components/components.ts +6 -2
- package/src/components/defaultStyles.ts +77 -0
- package/src/index.ts +0 -2
- package/src/modules/PressableRipple/type.ts +0 -1
- package/src/utils/KeyboardAware/context.tsx +2 -0
- package/src/utils/KeyboardAware/keyboardHooks.ts +2 -1
- package/src/utils/ModalManager/components.tsx +30 -1
- package/src/utils/ModalManager/context.tsx +4 -4
- package/src/utils/ModalManager/index.ts +4 -1
- package/src/utils/hooks.ts +1 -12
- package/src/Registry.ts +0 -52
- package/src/components/ActionIcon/types.ts +0 -15
- package/src/components/ActivityIndicator/types.ts +0 -9
- package/src/components/Avatar/types.ts +0 -23
- package/src/components/AvatarGroup/types.ts +0 -10
- package/src/components/Backdrop/types.ts +0 -14
- package/src/components/Badge/types.ts +0 -27
- package/src/components/Button/types.ts +0 -20
- package/src/components/Checkbox/types.ts +0 -13
- package/src/components/EmptyPlaceholder/types.ts +0 -21
- package/src/components/FileInput/types.ts +0 -27
- package/src/components/Grid/types.ts +0 -20
- package/src/components/Icon/types.ts +0 -15
- package/src/components/Image/types.ts +0 -18
- package/src/components/List/types.ts +0 -41
- package/src/components/LoadingOverlay/types.ts +0 -9
- package/src/components/Modal/types.ts +0 -41
- package/src/components/Pager/types.ts +0 -37
- package/src/components/PaginationIndicator/index.tsx +0 -51
- package/src/components/PaginationIndicator/styles.ts +0 -3
- package/src/components/PaginationIndicator/types.ts +0 -10
- package/src/components/RadioInput/types.ts +0 -31
- package/src/components/RefreshControl/types.ts +0 -9
- package/src/components/Scroll/types.ts +0 -21
- package/src/components/SearchInput/index.tsx +0 -90
- package/src/components/Sections/types.ts +0 -39
- package/src/components/SegmentedControl/types.ts +0 -31
- package/src/components/Switch/types.ts +0 -12
- package/src/components/Text/types.ts +0 -18
- package/src/components/TextInput/types.ts +0 -23
- package/src/components/Touchable/types.ts +0 -27
- package/src/components/View/types.ts +0 -13
- package/src/hooks/index.ts +0 -13
|
@@ -1,119 +1,146 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
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(
|
|
97
|
+
const { getFeedbackStyle } = usePressableFeedback(variantStyles.text, {
|
|
65
98
|
hightlightPropertyIn: 'color',
|
|
66
99
|
hightlightPropertyOut: 'color',
|
|
67
|
-
feedbackConfig:
|
|
100
|
+
feedbackConfig: variantStyles?.textFeedback,
|
|
68
101
|
disabled: disableFeedback,
|
|
69
102
|
})
|
|
70
103
|
|
|
71
|
-
const { getFeedbackStyle: getFeedbackWrapperStyle } = usePressableFeedback(
|
|
104
|
+
const { getFeedbackStyle: getFeedbackWrapperStyle } = usePressableFeedback(variantStyles.wrapper, {
|
|
72
105
|
hightlightPropertyIn: 'borderColor',
|
|
73
106
|
hightlightPropertyOut: 'borderColor',
|
|
74
107
|
disabled: disableFeedback,
|
|
75
|
-
feedbackConfig:
|
|
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
|
-
//
|
|
81
|
-
const isLeftIconHidden =
|
|
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 =
|
|
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
|
|
97
|
-
{(!loading && isLeftIconHidden)
|
|
98
|
-
{text ? <Text text={text} style={[
|
|
99
|
-
{
|
|
100
|
-
|
|
101
|
-
<Badge badge={badge}
|
|
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
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 {
|
|
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:
|
|
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
|
-
|
|
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:
|
|
37
|
+
const stringValue:string = isDateObject ? format(value, 'yyyy/MM/dd') : value
|
|
36
38
|
|
|
37
|
-
function handleChange(date:
|
|
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={
|
|
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
|
-
...
|
|
56
|
-
stylesheet:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
...
|
|
47
|
+
...defaultProps,
|
|
23
48
|
...props,
|
|
24
49
|
})
|
|
25
50
|
|
|
26
51
|
const {
|
|
27
|
-
|
|
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
|
|
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
|
|
71
|
+
variantStyles,
|
|
40
72
|
animatedProperties: ['box:unchecked', 'box:disabled', 'box:checked', 'box:disabled-checked', 'box:disabled-unchecked'],
|
|
41
|
-
transition:
|
|
73
|
+
transition: variantStyles['box:transition'],
|
|
42
74
|
updater: () => {
|
|
43
75
|
'worklet'
|
|
44
76
|
let disabledStyle = {}
|
|
45
77
|
if (disabled) {
|
|
46
|
-
disabledStyle = value ?
|
|
78
|
+
disabledStyle = value ? variantStyles['box:disabled-checked'] : variantStyles['box:disabled-unchecked']
|
|
47
79
|
}
|
|
48
|
-
const style = value ?
|
|
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
|
|
92
|
+
variantStyles,
|
|
61
93
|
animatedProperties: ['checkmarkWrapper:unchecked', 'checkmarkWrapper:disabled', 'checkmarkWrapper:checked', 'checkmarkWrapper:disabled-unchecked', 'checkmarkWrapper:disabled-checked'],
|
|
62
|
-
transition:
|
|
94
|
+
transition: variantStyles['checkmarkWrapper:transition'],
|
|
63
95
|
updater: () => {
|
|
64
96
|
'worklet'
|
|
65
97
|
let disabledStyle = {}
|
|
66
98
|
if (disabled) {
|
|
67
|
-
disabledStyle = value ?
|
|
99
|
+
disabledStyle = value ? variantStyles['checkmarkWrapper:disabled-checked'] : variantStyles['checkmarkWrapper:disabled-unchecked']
|
|
68
100
|
}
|
|
69
|
-
const style = value ?
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
101
|
-
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
|
-
|
|
109
|
-
disabled &&
|
|
139
|
+
variantStyles.checkmarkWrapper,
|
|
140
|
+
disabled && variantStyles['checkmarkWrapper:disabled'],
|
|
141
|
+
checkmarkWrapperAnimation,
|
|
110
142
|
]}
|
|
111
143
|
>
|
|
112
144
|
<Icon
|
|
113
|
-
name={checkIcon}
|
|
114
|
-
style={[
|
|
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.
|
|
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 })))
|