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