@codeleap/web 3.24.2 → 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 +2 -1
- package/src/components/ActionIcon/index.tsx +51 -52
- package/src/components/ActionIcon/styles.ts +1 -5
- package/src/components/ActionIcon/types.ts +15 -0
- package/src/components/ActivityIndicator/index.tsx +34 -55
- package/src/components/ActivityIndicator/styles.ts +0 -6
- package/src/components/ActivityIndicator/types.ts +12 -0
- package/src/components/Badge/index.tsx +43 -80
- package/src/components/Badge/styles.ts +1 -11
- package/src/components/Badge/types.ts +28 -0
- package/src/components/Button/index.tsx +46 -89
- package/src/components/Button/styles.ts +0 -5
- package/src/components/Button/types.ts +25 -0
- package/src/components/Checkbox/index.tsx +83 -97
- package/src/components/Checkbox/styles.ts +1 -5
- package/src/components/Checkbox/types.ts +15 -0
- package/src/components/Collapse/index.tsx +41 -83
- package/src/components/Collapse/styles.ts +3 -6
- package/src/components/Collapse/types.ts +11 -0
- package/src/components/ColorPicker/index.tsx +95 -48
- package/src/components/ColorPicker/styles.ts +11 -11
- package/src/components/ColorPicker/types.ts +26 -12
- package/src/components/CropPicker/index.tsx +100 -102
- package/src/components/CropPicker/styles.ts +0 -7
- package/src/components/CropPicker/types.ts +10 -15
- package/src/components/DatePicker/{defaultComponents → components}/Header.tsx +9 -17
- package/src/components/DatePicker/{defaultComponents → components}/OuterInput.tsx +6 -7
- package/src/components/DatePicker/index.tsx +110 -124
- package/src/components/DatePicker/styles.ts +1 -12
- package/src/components/DatePicker/types.ts +16 -33
- package/src/components/Drawer/index.tsx +133 -125
- package/src/components/Drawer/styles.ts +0 -5
- package/src/components/Drawer/types.ts +23 -0
- package/src/components/Dropzone/index.tsx +87 -63
- package/src/components/Dropzone/styles.ts +0 -6
- package/src/components/Dropzone/types.ts +29 -37
- package/src/components/EmptyPlaceholder/index.tsx +63 -83
- package/src/components/EmptyPlaceholder/styles.ts +0 -5
- package/src/components/EmptyPlaceholder/types.ts +32 -0
- package/src/components/FileInput/index.tsx +72 -0
- package/src/components/FileInput/types.ts +14 -0
- package/src/components/Grid/index.tsx +40 -41
- package/src/components/Grid/styles.ts +2 -9
- package/src/components/Grid/types.ts +10 -12
- package/src/components/Icon/index.tsx +45 -47
- package/src/components/Icon/styles.ts +0 -8
- package/src/components/Icon/types.ts +15 -0
- package/src/components/InputBase/index.tsx +71 -42
- package/src/components/InputBase/styles.ts +37 -47
- package/src/components/InputBase/types.ts +19 -7
- package/src/components/InputBase/utils.ts +3 -23
- package/src/components/List/ListLayout.tsx +20 -37
- package/src/components/List/index.tsx +36 -41
- package/src/components/List/styles.ts +5 -11
- package/src/components/List/types.ts +30 -20
- package/src/components/LoadingOverlay/index.tsx +31 -33
- package/src/components/LoadingOverlay/styles.ts +3 -8
- package/src/components/LoadingOverlay/types.ts +16 -0
- package/src/components/Modal/index.tsx +98 -160
- package/src/components/Modal/styles.ts +0 -5
- package/src/components/Modal/types.ts +55 -0
- package/src/components/NumberIncrement/index.tsx +67 -98
- package/src/components/NumberIncrement/styles.ts +0 -5
- package/src/components/NumberIncrement/types.ts +29 -0
- package/src/components/Overlay/index.tsx +37 -35
- package/src/components/Overlay/styles.ts +3 -5
- package/src/components/Overlay/types.ts +13 -0
- package/src/components/Pager/index.tsx +65 -81
- package/src/components/Pager/styles.ts +3 -9
- package/src/components/Pager/types.ts +35 -0
- package/src/components/PaginationButtons/index.tsx +173 -0
- package/src/components/PaginationButtons/styles.ts +7 -0
- package/src/components/PaginationButtons/types.ts +26 -0
- package/src/components/PaginationIndicator/index.tsx +69 -0
- package/src/components/PaginationIndicator/styles.ts +3 -0
- package/src/components/PaginationIndicator/types.ts +18 -0
- package/src/components/Progress/Bar/index.tsx +45 -50
- package/src/components/Progress/Bar/styles.ts +10 -0
- package/src/components/Progress/Bar/types.ts +26 -0
- package/src/components/Progress/Circle/index.tsx +45 -48
- package/src/components/Progress/Circle/styles.ts +1 -8
- package/src/components/Progress/Circle/types.ts +10 -22
- package/src/components/RadioInput/index.tsx +78 -124
- package/src/components/RadioInput/styles.ts +0 -6
- package/src/components/RadioInput/types.ts +29 -0
- package/src/components/SearchInput/index.tsx +10 -10
- package/src/components/SectionFilters/index.tsx +47 -36
- package/src/components/SectionFilters/styles.ts +1 -5
- package/src/components/SectionFilters/types.ts +14 -13
- package/src/components/SegmentedControl/index.tsx +111 -89
- package/src/components/SegmentedControl/styles.ts +7 -21
- package/src/components/SegmentedControl/types.ts +44 -0
- package/src/components/Select/index.tsx +92 -56
- package/src/components/Select/styles.ts +19 -36
- package/src/components/Select/types.ts +15 -10
- package/src/components/Slider/index.tsx +85 -93
- package/src/components/Slider/styles.ts +13 -6
- package/src/components/Slider/types.ts +29 -0
- package/src/components/Switch/index.tsx +63 -74
- package/src/components/Switch/styles.ts +1 -6
- package/src/components/Switch/types.ts +13 -0
- package/src/components/Tag/index.tsx +39 -44
- package/src/components/Tag/styles.ts +1 -9
- package/src/components/Tag/types.ts +10 -10
- package/src/components/Text/index.tsx +37 -48
- package/src/components/Text/styles.ts +0 -8
- package/src/components/Text/types.ts +8 -8
- package/src/components/TextEditor/index.tsx +49 -28
- package/src/components/TextEditor/styles.ts +1 -8
- package/src/components/TextEditor/types.ts +11 -6
- package/src/components/TextInput/index.tsx +58 -96
- package/src/components/TextInput/mask.tsx +2 -50
- package/src/components/TextInput/styles.ts +3 -8
- package/src/components/TextInput/types.ts +85 -0
- package/src/components/Tooltip/index.tsx +61 -84
- package/src/components/Tooltip/styles.ts +3 -10
- package/src/components/Tooltip/types.ts +46 -0
- package/src/components/Touchable/index.tsx +43 -86
- package/src/components/Touchable/styles.ts +0 -6
- package/src/components/Touchable/types.ts +22 -0
- package/src/components/View/index.tsx +36 -50
- package/src/components/View/styles.ts +0 -6
- package/src/components/View/types.ts +14 -15
- package/src/components/components.ts +2 -3
- package/src/index.ts +1 -0
- package/src/lib/WebStyleRegistry.ts +51 -0
- package/src/lib/hooks/index.ts +5 -0
- package/src/lib/hooks/useBreakpointMatch.ts +8 -7
- package/src/{components/CropPicker/useCropPicker.tsx → lib/hooks/useCropPicker.ts} +66 -13
- package/src/lib/hooks/useFileInput.ts +15 -0
- package/src/lib/hooks/useInfiniteScroll.ts +77 -0
- package/src/lib/hooks/useMediaQuery.ts +4 -3
- package/src/lib/hooks/usePagination.ts +79 -63
- package/src/lib/hooks/useRefresh.ts +87 -0
- package/src/lib/hooks/useStylesFor.ts +13 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/utils/cache.ts +9 -0
- package/src/lib/utils/index.ts +1 -0
- package/src/lib/utils/test.ts +2 -2
- package/src/components/CropPicker/utils.ts +0 -51
- package/src/components/FileInput.tsx +0 -91
- package/src/components/List/PaginationIndicator.tsx +0 -102
- package/src/components/List/useInfiniteScroll.ts +0 -159
- package/src/components/Progress/Bar/styles.tsx +0 -7
- package/src/components/Progress/Bar/types.tsx +0 -30
- package/src/components/Scroll/index.tsx +0 -32
- package/src/components/Scroll/styles.ts +0 -8
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +0 -84
- package/src/components/defaultStyles.ts +0 -79
- /package/src/components/DatePicker/{defaultComponents → components}/index.tsx +0 -0
|
@@ -1,65 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { View } from '../View'
|
|
6
|
-
import { SwitchPresets, SwitchComposition } from './styles'
|
|
7
|
-
import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
|
|
8
|
-
import { useAnimatedVariantStyles } from '../..'
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { InputBase, InputBaseDefaultOrder, selectInputBaseProps } from '../InputBase'
|
|
3
|
+
import { useAnimatedVariantStyles } from '../../lib'
|
|
4
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
9
5
|
import { motion } from 'framer-motion'
|
|
6
|
+
import { AnyRecord, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
|
|
7
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
8
|
+
import { SwitchProps } from './types'
|
|
10
9
|
|
|
11
10
|
export * from './styles'
|
|
12
|
-
|
|
13
|
-
export type SwitchProps = Pick<
|
|
14
|
-
InputBaseProps,
|
|
15
|
-
'debugName' | 'disabled' | 'label'
|
|
16
|
-
> & {
|
|
17
|
-
styles?: StylesOf<SwitchComposition>
|
|
18
|
-
value: boolean
|
|
19
|
-
onValueChange: (value: boolean) => void
|
|
20
|
-
onChange?: (value: boolean) => void
|
|
21
|
-
style?: PropsOf<typeof View>['style']
|
|
22
|
-
switchOnLeft?: boolean
|
|
23
|
-
} & ComponentVariants<typeof SwitchPresets>
|
|
11
|
+
export * from './types'
|
|
24
12
|
|
|
25
13
|
const reversedOrder = [...InputBaseDefaultOrder].reverse()
|
|
26
14
|
|
|
27
15
|
export const Switch = (props: SwitchProps) => {
|
|
28
16
|
const {
|
|
29
17
|
inputBaseProps,
|
|
30
|
-
others,
|
|
31
|
-
} = selectInputBaseProps(
|
|
18
|
+
others: switchProps,
|
|
19
|
+
} = selectInputBaseProps({
|
|
20
|
+
...Switch.defaultProps,
|
|
21
|
+
...props,
|
|
22
|
+
})
|
|
32
23
|
|
|
33
24
|
const {
|
|
34
|
-
|
|
35
|
-
variants = [],
|
|
36
|
-
style = {},
|
|
37
|
-
styles = {},
|
|
25
|
+
style,
|
|
38
26
|
value,
|
|
39
27
|
disabled,
|
|
40
28
|
debugName,
|
|
41
29
|
onValueChange,
|
|
42
30
|
onChange,
|
|
43
31
|
switchOnLeft,
|
|
44
|
-
} =
|
|
32
|
+
} = switchProps
|
|
45
33
|
|
|
46
|
-
const
|
|
47
|
-
responsiveVariants,
|
|
48
|
-
variants,
|
|
49
|
-
styles,
|
|
50
|
-
rootElement: 'wrapper',
|
|
51
|
-
})
|
|
34
|
+
const styles = useStylesFor(Switch.styleRegistryName, style)
|
|
52
35
|
|
|
53
36
|
const trackAnimation = useAnimatedVariantStyles({
|
|
54
|
-
variantStyles,
|
|
37
|
+
variantStyles: styles,
|
|
55
38
|
animatedProperties: ['track:off', 'track:disabled', 'track:on', 'track:disabled-on', 'track:disabled-off'],
|
|
56
39
|
updater: () => {
|
|
57
40
|
'worklet'
|
|
58
41
|
let disabledStyle = {}
|
|
59
42
|
if (disabled) {
|
|
60
|
-
disabledStyle = value ?
|
|
43
|
+
disabledStyle = value ? styles['track:disabled-on'] : styles['track:disabled-off']
|
|
61
44
|
}
|
|
62
|
-
const style = value ?
|
|
45
|
+
const style = value ? styles['track:on'] : styles['track:off']
|
|
63
46
|
|
|
64
47
|
return {
|
|
65
48
|
...style,
|
|
@@ -70,15 +53,15 @@ export const Switch = (props: SwitchProps) => {
|
|
|
70
53
|
})
|
|
71
54
|
|
|
72
55
|
const thumbAnimation = useAnimatedVariantStyles({
|
|
73
|
-
variantStyles,
|
|
56
|
+
variantStyles: styles,
|
|
74
57
|
animatedProperties: ['thumb:off', 'thumb:disabled', 'thumb:on', 'thumb:disabled-off', 'thumb:disabled-on'],
|
|
75
58
|
updater: () => {
|
|
76
59
|
'worklet'
|
|
77
60
|
let disabledStyle = {}
|
|
78
61
|
if (disabled) {
|
|
79
|
-
disabledStyle = value ?
|
|
62
|
+
disabledStyle = value ? styles['thumb:disabled-on'] : styles['thumb:disabled-off']
|
|
80
63
|
}
|
|
81
|
-
const style = value ?
|
|
64
|
+
const style = value ? styles['thumb:on'] : styles['thumb:off']
|
|
82
65
|
return {
|
|
83
66
|
...style,
|
|
84
67
|
...disabledStyle,
|
|
@@ -87,7 +70,11 @@ export const Switch = (props: SwitchProps) => {
|
|
|
87
70
|
dependencies: [value, disabled],
|
|
88
71
|
})
|
|
89
72
|
|
|
90
|
-
|
|
73
|
+
// @ts-expect-error icss type
|
|
74
|
+
const _switchOnLeft = switchOnLeft ?? styles.__props?.switchOnLeft
|
|
75
|
+
|
|
76
|
+
const thumbStyles = mergeStyles([styles.thumb, disabled && styles['thumb:disabled']])
|
|
77
|
+
const trackStyles = mergeStyles([styles.track, disabled && styles['track:disabled']])
|
|
91
78
|
|
|
92
79
|
const handleChange = (e) => {
|
|
93
80
|
if (disabled) return
|
|
@@ -97,41 +84,43 @@ export const Switch = (props: SwitchProps) => {
|
|
|
97
84
|
}
|
|
98
85
|
}
|
|
99
86
|
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}}
|
|
109
|
-
order={_switchOnLeft ? reversedOrder : InputBaseDefaultOrder}
|
|
110
|
-
style={style}
|
|
111
|
-
disabled={disabled}
|
|
112
|
-
noError
|
|
113
|
-
>
|
|
114
|
-
<motion.div
|
|
115
|
-
css={[
|
|
116
|
-
variantStyles.track,
|
|
117
|
-
disabled && variantStyles['track:disabled'],
|
|
118
|
-
]}
|
|
119
|
-
initial={false}
|
|
120
|
-
animate={trackAnimation}
|
|
121
|
-
transition={variantStyles['track:transition']}
|
|
122
|
-
onClick={handleChange}
|
|
123
|
-
onKeyDown={handleChange}
|
|
124
|
-
tabIndex={0}
|
|
87
|
+
return (
|
|
88
|
+
<InputBase
|
|
89
|
+
{...inputBaseProps}
|
|
90
|
+
debugName={debugName}
|
|
91
|
+
style={styles}
|
|
92
|
+
order={_switchOnLeft ? reversedOrder : InputBaseDefaultOrder}
|
|
93
|
+
disabled={disabled}
|
|
94
|
+
noError
|
|
125
95
|
>
|
|
126
96
|
<motion.div
|
|
127
|
-
|
|
128
|
-
variantStyles.thumb,
|
|
129
|
-
disabled && variantStyles['thumb:disabled'],
|
|
130
|
-
]}
|
|
97
|
+
style={trackStyles}
|
|
131
98
|
initial={false}
|
|
132
|
-
animate={
|
|
133
|
-
transition={
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
99
|
+
animate={trackAnimation}
|
|
100
|
+
transition={styles['track:transition']}
|
|
101
|
+
onClick={handleChange}
|
|
102
|
+
onKeyDown={handleChange}
|
|
103
|
+
tabIndex={0}
|
|
104
|
+
>
|
|
105
|
+
<motion.div
|
|
106
|
+
style={thumbStyles}
|
|
107
|
+
initial={false}
|
|
108
|
+
animate={thumbAnimation}
|
|
109
|
+
transition={styles['thumb:transition']}
|
|
110
|
+
/>
|
|
111
|
+
</motion.div>
|
|
112
|
+
</InputBase>
|
|
113
|
+
)
|
|
137
114
|
}
|
|
115
|
+
|
|
116
|
+
Switch.styleRegistryName = 'Switch'
|
|
117
|
+
Switch.elements = [...InputBase.elements, 'track', 'thumb', '__props']
|
|
118
|
+
Switch.rootElement = 'wrapper'
|
|
119
|
+
|
|
120
|
+
Switch.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
121
|
+
return Switch as (props: StyledComponentProps<SwitchProps, typeof styles>) => IJSX
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
Switch.defaultProps = {} as Partial<SwitchProps>
|
|
125
|
+
|
|
126
|
+
WebStyleRegistry.registerComponent(Switch)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
import { InputBaseParts, InputBaseStates } from '../InputBase'
|
|
3
2
|
|
|
4
3
|
type AnimatableParts = 'track' | 'thumb'
|
|
5
|
-
export type SwitchParts = InputBaseParts | AnimatableParts
|
|
4
|
+
export type SwitchParts = InputBaseParts | AnimatableParts
|
|
6
5
|
|
|
7
6
|
export type SwitchAnimationStates = 'on' | 'off' | 'disabled-on' | 'disabled-off'
|
|
8
7
|
|
|
@@ -14,7 +13,3 @@ export type SwitchComposition =
|
|
|
14
13
|
| `${AnimatableParts}:transition`
|
|
15
14
|
| `${AnimatableParts}:${SwitchAnimationStates}`
|
|
16
15
|
| '__props'
|
|
17
|
-
|
|
18
|
-
const createSwitchStyle = createDefaultVariantFactory<SwitchComposition>()
|
|
19
|
-
|
|
20
|
-
export const SwitchPresets = includePresets((styles) => createSwitchStyle(() => ({ wrapper: styles })))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StyledProp } from '@codeleap/styles'
|
|
2
|
+
import { InputBaseProps } from '../InputBase'
|
|
3
|
+
import { SwitchComposition } from './styles'
|
|
4
|
+
|
|
5
|
+
export type SwitchProps =
|
|
6
|
+
Pick<InputBaseProps, 'debugName' | 'disabled' | 'label'> &
|
|
7
|
+
{
|
|
8
|
+
style?: StyledProp<SwitchComposition>
|
|
9
|
+
value: boolean
|
|
10
|
+
onValueChange: (value: boolean) => void
|
|
11
|
+
onChange?: (value: boolean) => void
|
|
12
|
+
switchOnLeft?: boolean
|
|
13
|
+
}
|
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { TypeGuards
|
|
3
|
-
import { TagParts
|
|
2
|
+
import { TypeGuards } from '@codeleap/common'
|
|
3
|
+
import { TagParts } from './styles'
|
|
4
4
|
import { TagProps } from './types'
|
|
5
5
|
import { Icon } from '../Icon'
|
|
6
6
|
import { Text } from '../Text'
|
|
7
7
|
import { Touchable } from '../Touchable'
|
|
8
8
|
import { View } from '../View'
|
|
9
9
|
import { Badge } from '../Badge'
|
|
10
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
11
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
12
|
+
import { AnyRecord, IJSX, mergeStyles, StyledComponentProps, useCompositionStyles } from '@codeleap/styles'
|
|
10
13
|
|
|
11
14
|
export * from './styles'
|
|
12
15
|
export * from './types'
|
|
13
16
|
|
|
14
|
-
const defaultProps: Partial<TagProps> = {
|
|
15
|
-
debugName: 'Tag component',
|
|
16
|
-
disabled: false,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
17
|
export const Tag = (props: TagProps) => {
|
|
20
|
-
const allProps = {
|
|
21
|
-
...Tag.defaultProps,
|
|
22
|
-
...props,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
18
|
const {
|
|
26
|
-
variants,
|
|
27
19
|
rightComponent,
|
|
28
20
|
leftComponent,
|
|
29
|
-
responsiveVariants,
|
|
30
|
-
styles,
|
|
31
21
|
style,
|
|
32
|
-
css,
|
|
33
22
|
leftIcon,
|
|
34
23
|
text,
|
|
35
24
|
textProps,
|
|
@@ -44,16 +33,14 @@ export const Tag = (props: TagProps) => {
|
|
|
44
33
|
onPress,
|
|
45
34
|
disabled,
|
|
46
35
|
...touchableProps
|
|
47
|
-
} =
|
|
36
|
+
} = {
|
|
37
|
+
...Tag.defaultProps,
|
|
38
|
+
...props,
|
|
39
|
+
}
|
|
48
40
|
|
|
49
|
-
const
|
|
50
|
-
variants,
|
|
51
|
-
responsiveVariants,
|
|
52
|
-
styles,
|
|
53
|
-
})
|
|
41
|
+
const styles = useStylesFor(Tag.styleRegistryName, style)
|
|
54
42
|
|
|
55
|
-
const
|
|
56
|
-
const rightBadgeStyles = useNestedStylesByKey('rightBadge', variantStyles)
|
|
43
|
+
const compositionStyles = useCompositionStyles(['rightBadge', 'leftBadge'], styles)
|
|
57
44
|
|
|
58
45
|
const isPressable = TypeGuards.isFunction(onPress)
|
|
59
46
|
|
|
@@ -61,29 +48,24 @@ export const Tag = (props: TagProps) => {
|
|
|
61
48
|
|
|
62
49
|
const wrapperProps = isPressable ? { onPress, ...touchableProps } : touchableProps
|
|
63
50
|
|
|
64
|
-
const getStylesByKey = (styleKey: TagParts) => ([
|
|
65
|
-
|
|
66
|
-
isPressable &&
|
|
67
|
-
disabled &&
|
|
51
|
+
const getStylesByKey = (styleKey: TagParts) => mergeStyles([
|
|
52
|
+
styles?.[styleKey],
|
|
53
|
+
isPressable && styles[`${styleKey}:pressable`],
|
|
54
|
+
disabled && styles[`${styleKey}:disabled`],
|
|
68
55
|
])
|
|
69
56
|
|
|
70
|
-
const wrapperStyles = React.useMemo(() => ([
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
]), [variantStyles, disabled, isPressable, style])
|
|
75
|
-
|
|
76
|
-
const textStyles = React.useMemo(() => getStylesByKey('text'), [variantStyles, disabled, isPressable])
|
|
77
|
-
const leftIconStyles = React.useMemo(() => getStylesByKey('leftIcon'), [variantStyles, disabled, isPressable])
|
|
78
|
-
const rightIconStyles = React.useMemo(() => getStylesByKey('rightIcon'), [variantStyles, disabled, isPressable])
|
|
57
|
+
const wrapperStyles = React.useMemo(() => getStylesByKey('wrapper'), [styles, disabled, isPressable, style])
|
|
58
|
+
const textStyles = React.useMemo(() => getStylesByKey('text'), [styles, disabled, isPressable])
|
|
59
|
+
const leftIconStyles = React.useMemo(() => getStylesByKey('leftIcon'), [styles, disabled, isPressable])
|
|
60
|
+
const rightIconStyles = React.useMemo(() => getStylesByKey('rightIcon'), [styles, disabled, isPressable])
|
|
79
61
|
|
|
80
62
|
return (
|
|
81
|
-
<Wrapper
|
|
63
|
+
<Wrapper disabled={disabled} {...wrapperProps} style={wrapperStyles}>
|
|
82
64
|
{leftComponent}
|
|
83
65
|
{leftBadge && (
|
|
84
66
|
<Badge
|
|
85
67
|
debugName={`${touchableProps?.debugName}:leftBadge`}
|
|
86
|
-
|
|
68
|
+
style={compositionStyles.leftBadge}
|
|
87
69
|
badge={leftBadge}
|
|
88
70
|
disabled={disabled}
|
|
89
71
|
{...leftBadgeProps}
|
|
@@ -92,19 +74,19 @@ export const Tag = (props: TagProps) => {
|
|
|
92
74
|
{!TypeGuards.isNil(leftIcon) && (
|
|
93
75
|
<Icon
|
|
94
76
|
debugName={`${touchableProps?.debugName}:leftIcon`}
|
|
95
|
-
|
|
77
|
+
style={leftIconStyles}
|
|
96
78
|
name={leftIcon}
|
|
97
79
|
{...leftIconProps}
|
|
98
80
|
/>
|
|
99
81
|
)}
|
|
100
82
|
|
|
101
|
-
{TypeGuards.isString(text) ? <Text text={text}
|
|
83
|
+
{TypeGuards.isString(text) ? <Text text={text} style={textStyles} {...textProps} /> : text}
|
|
102
84
|
{children}
|
|
103
85
|
|
|
104
86
|
{!TypeGuards.isNil(rightIcon) && (
|
|
105
87
|
<Icon
|
|
106
88
|
debugName={`${touchableProps?.debugName}:rightIcon`}
|
|
107
|
-
|
|
89
|
+
style={rightIconStyles}
|
|
108
90
|
name={rightIcon}
|
|
109
91
|
{...rightIconProps}
|
|
110
92
|
/>
|
|
@@ -112,7 +94,7 @@ export const Tag = (props: TagProps) => {
|
|
|
112
94
|
{rightBadge && (
|
|
113
95
|
<Badge
|
|
114
96
|
debugName={`${touchableProps?.debugName}:rightBadge`}
|
|
115
|
-
|
|
97
|
+
style={compositionStyles.rightBadge}
|
|
116
98
|
badge={rightBadge}
|
|
117
99
|
disabled={disabled}
|
|
118
100
|
{...rightBadgeProps}
|
|
@@ -123,4 +105,17 @@ export const Tag = (props: TagProps) => {
|
|
|
123
105
|
)
|
|
124
106
|
}
|
|
125
107
|
|
|
126
|
-
Tag.
|
|
108
|
+
Tag.styleRegistryName = 'Tag'
|
|
109
|
+
Tag.elements = ['wrapper', 'text', 'leftIcon', 'rightIcon', 'leftBadge', 'rightBadge']
|
|
110
|
+
Tag.rootElement = 'wrapper'
|
|
111
|
+
|
|
112
|
+
Tag.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
113
|
+
return Tag as (props: StyledComponentProps<TagProps, typeof styles>) => IJSX
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Tag.defaultProps = {
|
|
117
|
+
debugName: 'Tag component',
|
|
118
|
+
disabled: false,
|
|
119
|
+
} as Partial<TagProps>
|
|
120
|
+
|
|
121
|
+
WebStyleRegistry.registerComponent(Tag)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
import { BadgeComposition } from '../Badge'
|
|
3
2
|
|
|
4
3
|
export type TagStates = 'pressable' | 'disabled'
|
|
5
4
|
|
|
6
|
-
type TagBadgeParts =
|
|
5
|
+
type TagBadgeParts =
|
|
7
6
|
| `leftBadge${Capitalize<BadgeComposition>}`
|
|
8
7
|
| `rightBadge${Capitalize<BadgeComposition>}`
|
|
9
8
|
|
|
@@ -14,10 +13,3 @@ export type TagParts =
|
|
|
14
13
|
| 'rightIcon'
|
|
15
14
|
|
|
16
15
|
export type TagComposition = TagParts | TagBadgeParts | `${TagParts}:${TagStates}`
|
|
17
|
-
|
|
18
|
-
const createTagStyle = createDefaultVariantFactory<TagComposition>()
|
|
19
|
-
|
|
20
|
-
export const TagPresets = includePresets((styles) => createTagStyle(() => ({
|
|
21
|
-
wrapper: styles,
|
|
22
|
-
})),
|
|
23
|
-
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
2
2
|
import { ReactElement } from 'react'
|
|
3
|
-
import { TagComposition
|
|
3
|
+
import { TagComposition } from './styles'
|
|
4
4
|
import { BadgeProps } from '../Badge'
|
|
5
5
|
import { TextProps } from '../Text'
|
|
6
6
|
import { IconProps } from '../Icon'
|
|
@@ -8,17 +8,17 @@ import { ComponentCommonProps } from '../../types'
|
|
|
8
8
|
import { TouchableProps } from '../Touchable'
|
|
9
9
|
import { ViewProps } from '../View'
|
|
10
10
|
|
|
11
|
-
export type TagProps =
|
|
12
|
-
Omit<ViewProps
|
|
13
|
-
Omit<TouchableProps, '
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
export type TagProps =
|
|
12
|
+
Omit<ViewProps, 'style'> &
|
|
13
|
+
Omit<TouchableProps, 'style'> &
|
|
14
|
+
ComponentCommonProps &
|
|
15
|
+
{
|
|
16
|
+
style?: StyledProp<TagComposition>
|
|
17
17
|
text?: TextProps<'p'>['text'] | ReactElement
|
|
18
18
|
textProps?: Partial<TextProps<'p'>>
|
|
19
|
-
leftIcon?:
|
|
19
|
+
leftIcon?: AppIcon
|
|
20
20
|
leftIconProps?: Partial<IconProps>
|
|
21
|
-
rightIcon?:
|
|
21
|
+
rightIcon?: AppIcon
|
|
22
22
|
rightIconProps?: Partial<IconProps>
|
|
23
23
|
leftComponent?: ReactElement
|
|
24
24
|
rightComponent?: ReactElement
|
|
@@ -1,38 +1,21 @@
|
|
|
1
|
-
import { TypeGuards
|
|
1
|
+
import { TypeGuards } from '@codeleap/common'
|
|
2
2
|
import { motion } from 'framer-motion'
|
|
3
|
-
import React, { ElementType } from 'react'
|
|
4
|
-
import { TextPresets } from './styles'
|
|
3
|
+
import React, { ElementType, forwardRef } from 'react'
|
|
5
4
|
import { TextProps } from './types'
|
|
5
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
6
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
7
|
+
import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
|
|
6
8
|
|
|
7
9
|
export * from './styles'
|
|
8
10
|
export * from './types'
|
|
9
11
|
|
|
10
|
-
const
|
|
11
|
-
debugName: 'Text component',
|
|
12
|
-
component: 'p',
|
|
13
|
-
debounce: null,
|
|
14
|
-
pressDisabled: false,
|
|
15
|
-
animated: false,
|
|
16
|
-
animatedProps: {},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const Text = <T extends ElementType>(textProps: TextProps<T>) => {
|
|
20
|
-
const allProps = {
|
|
21
|
-
...Text.defaultProps,
|
|
22
|
-
...textProps,
|
|
23
|
-
}
|
|
24
|
-
|
|
12
|
+
export const Text = forwardRef<HTMLParagraphElement, TextProps>((textProps, ref) => {
|
|
25
13
|
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
styles = {},
|
|
29
|
-
style = {},
|
|
30
|
-
css,
|
|
31
|
-
text = null,
|
|
14
|
+
style,
|
|
15
|
+
text,
|
|
32
16
|
children,
|
|
33
17
|
component,
|
|
34
18
|
debugName,
|
|
35
|
-
msg = null,
|
|
36
19
|
onPress,
|
|
37
20
|
debounce,
|
|
38
21
|
pressDisabled,
|
|
@@ -40,18 +23,16 @@ export const Text = <T extends ElementType>(textProps: TextProps<T>) => {
|
|
|
40
23
|
animated,
|
|
41
24
|
animatedProps,
|
|
42
25
|
...props
|
|
43
|
-
} =
|
|
26
|
+
} = {
|
|
27
|
+
...Text.defaultProps,
|
|
28
|
+
...textProps,
|
|
29
|
+
}
|
|
44
30
|
|
|
45
|
-
const
|
|
31
|
+
const styles = useStylesFor(Text.styleRegistryName, style)
|
|
46
32
|
|
|
47
|
-
const
|
|
33
|
+
const Component: ElementType = animated ? (motion?.[component as string] || motion.p) : (component || 'p')
|
|
48
34
|
|
|
49
|
-
const
|
|
50
|
-
responsiveVariants,
|
|
51
|
-
variants,
|
|
52
|
-
styles,
|
|
53
|
-
rootElement: 'text',
|
|
54
|
-
})
|
|
35
|
+
const pressedRef = React.useRef(false)
|
|
55
36
|
|
|
56
37
|
const isPressable = (TypeGuards.isFunction(onPress) || TypeGuards.isFunction(onClick)) && !pressDisabled
|
|
57
38
|
|
|
@@ -80,31 +61,39 @@ export const Text = <T extends ElementType>(textProps: TextProps<T>) => {
|
|
|
80
61
|
}
|
|
81
62
|
}
|
|
82
63
|
|
|
83
|
-
const _styles = React.useMemo(() => ([
|
|
84
|
-
variantStyles.text,
|
|
85
|
-
disabled && variantStyles['text:disabled'],
|
|
86
|
-
css,
|
|
87
|
-
style,
|
|
88
|
-
]), [css, style, disabled])
|
|
89
|
-
|
|
90
64
|
const pressProps = isPressable ? {
|
|
91
65
|
onClick: disabled ? null : _onPress,
|
|
92
66
|
} : {}
|
|
93
67
|
|
|
94
|
-
const componentProps:
|
|
68
|
+
const componentProps: AnyRecord = {
|
|
95
69
|
...props,
|
|
96
70
|
...pressProps,
|
|
97
|
-
...animatedProps
|
|
71
|
+
...animatedProps,
|
|
98
72
|
}
|
|
99
73
|
|
|
100
74
|
return (
|
|
101
|
-
<Component
|
|
102
|
-
css={_styles}
|
|
103
|
-
{...componentProps}
|
|
104
|
-
>
|
|
75
|
+
<Component {...componentProps} ref={ref} css={[styles.text, disabled && styles['text:disabled']]}>
|
|
105
76
|
{text || children}
|
|
106
77
|
</Component>
|
|
107
78
|
)
|
|
79
|
+
}) as StyledComponentWithProps<TextProps>
|
|
80
|
+
|
|
81
|
+
Text.styleRegistryName = 'Text'
|
|
82
|
+
Text.elements = ['text']
|
|
83
|
+
Text.rootElement = 'text'
|
|
84
|
+
|
|
85
|
+
Text.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
86
|
+
return Text as <T extends ElementType = 'p'>(props: StyledComponentProps<TextProps<T>, typeof styles>) => IJSX
|
|
108
87
|
}
|
|
109
88
|
|
|
110
|
-
Text.defaultProps =
|
|
89
|
+
Text.defaultProps = {
|
|
90
|
+
debugName: 'Text component',
|
|
91
|
+
component: 'p',
|
|
92
|
+
text: null,
|
|
93
|
+
debounce: null,
|
|
94
|
+
pressDisabled: false,
|
|
95
|
+
animated: false,
|
|
96
|
+
animatedProps: {},
|
|
97
|
+
} as Partial<TextProps>
|
|
98
|
+
|
|
99
|
+
WebStyleRegistry.registerComponent(Text)
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
|
|
2
|
-
|
|
3
1
|
export type TextComposition = 'text' | 'text:disabled'
|
|
4
|
-
|
|
5
|
-
const createTextStyle = createDefaultVariantFactory<TextComposition>()
|
|
6
|
-
|
|
7
|
-
export const TextPresets = includePresets((styles) => createTextStyle(() => ({
|
|
8
|
-
text: styles
|
|
9
|
-
})))
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { StylesOf, ComponentVariants } from '@codeleap/common'
|
|
2
|
-
import { MotionProps } from 'framer-motion'
|
|
3
1
|
import { ComponentPropsWithoutRef, ElementType } from 'react'
|
|
4
|
-
import { TextComposition
|
|
2
|
+
import { TextComposition } from './styles'
|
|
3
|
+
import { AnyRecord, StyledProp } from '@codeleap/styles'
|
|
4
|
+
import { MotionProps } from 'framer-motion'
|
|
5
5
|
|
|
6
|
-
export type TextProps<T extends ElementType
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export type TextProps<T extends ElementType = 'p'> =
|
|
7
|
+
Omit<ComponentPropsWithoutRef<T>, 'style'> &
|
|
8
|
+
{
|
|
9
|
+
component?: ElementType<AnyRecord>
|
|
9
10
|
text?: string
|
|
10
|
-
|
|
11
|
-
msg?: string
|
|
11
|
+
style?: StyledProp<TextComposition>
|
|
12
12
|
debugName?: string
|
|
13
13
|
debounce?: number
|
|
14
14
|
pressDisabled?: boolean
|