@codeleap/web 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 +1 -2
- package/src/components/ActionIcon/index.tsx +52 -51
- package/src/components/ActionIcon/styles.ts +5 -1
- package/src/components/ActivityIndicator/index.tsx +55 -34
- package/src/components/ActivityIndicator/styles.ts +6 -0
- package/src/components/Badge/index.tsx +80 -43
- package/src/components/Badge/styles.ts +11 -1
- package/src/components/Button/index.tsx +89 -46
- package/src/components/Button/styles.ts +5 -0
- package/src/components/Checkbox/index.tsx +97 -83
- package/src/components/Checkbox/styles.ts +5 -1
- package/src/components/Collapse/index.tsx +83 -41
- package/src/components/Collapse/styles.ts +6 -3
- package/src/components/ColorPicker/index.tsx +48 -95
- package/src/components/ColorPicker/styles.ts +11 -11
- package/src/components/ColorPicker/types.ts +12 -26
- package/src/components/CropPicker/index.tsx +104 -100
- package/src/components/CropPicker/styles.ts +7 -0
- package/src/components/CropPicker/types.ts +17 -8
- package/src/{lib/hooks/useCropPicker.ts → components/CropPicker/useCropPicker.tsx} +15 -68
- package/src/components/CropPicker/utils.ts +51 -0
- package/src/components/DatePicker/{components → defaultComponents}/Header.tsx +17 -9
- package/src/components/DatePicker/{components → defaultComponents}/OuterInput.tsx +7 -6
- package/src/components/DatePicker/index.tsx +124 -110
- package/src/components/DatePicker/styles.ts +12 -1
- package/src/components/DatePicker/types.ts +33 -16
- package/src/components/Drawer/index.tsx +125 -133
- package/src/components/Drawer/styles.ts +5 -0
- package/src/components/Dropzone/index.tsx +63 -87
- package/src/components/Dropzone/styles.ts +6 -0
- package/src/components/Dropzone/types.ts +37 -29
- package/src/components/EmptyPlaceholder/index.tsx +83 -63
- package/src/components/EmptyPlaceholder/styles.ts +5 -0
- package/src/components/FileInput.tsx +91 -0
- package/src/components/Grid/index.tsx +41 -40
- package/src/components/Grid/styles.ts +9 -2
- package/src/components/Grid/types.ts +12 -10
- package/src/components/Icon/index.tsx +47 -45
- package/src/components/Icon/styles.ts +8 -0
- package/src/components/InputBase/index.tsx +42 -71
- package/src/components/InputBase/styles.ts +47 -37
- package/src/components/InputBase/types.ts +7 -19
- package/src/components/InputBase/utils.ts +23 -3
- package/src/components/List/ListLayout.tsx +37 -20
- package/src/components/List/PaginationIndicator.tsx +102 -0
- package/src/components/List/index.tsx +41 -36
- package/src/components/List/styles.ts +11 -5
- package/src/components/List/types.ts +20 -30
- package/src/components/List/useInfiniteScroll.ts +159 -0
- package/src/components/LoadingOverlay/index.tsx +33 -31
- package/src/components/LoadingOverlay/styles.ts +8 -3
- package/src/components/Modal/index.tsx +160 -98
- package/src/components/Modal/styles.ts +5 -0
- package/src/components/NumberIncrement/index.tsx +98 -67
- package/src/components/NumberIncrement/styles.ts +5 -0
- package/src/components/Overlay/index.tsx +35 -37
- package/src/components/Overlay/styles.ts +5 -3
- package/src/components/Pager/index.tsx +81 -65
- package/src/components/Pager/styles.ts +9 -3
- package/src/components/Progress/Bar/index.tsx +50 -45
- package/src/components/Progress/Bar/styles.tsx +7 -0
- package/src/components/Progress/Bar/types.tsx +30 -0
- package/src/components/Progress/Circle/index.tsx +48 -45
- package/src/components/Progress/Circle/styles.ts +8 -1
- package/src/components/Progress/Circle/types.ts +22 -10
- package/src/components/RadioInput/index.tsx +124 -78
- package/src/components/RadioInput/styles.ts +6 -0
- package/src/components/Scroll/index.tsx +32 -0
- package/src/components/Scroll/styles.ts +8 -0
- package/src/components/SearchInput/index.tsx +10 -10
- package/src/components/SectionFilters/index.tsx +36 -47
- package/src/components/SectionFilters/styles.ts +5 -1
- package/src/components/SectionFilters/types.ts +13 -14
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +84 -0
- package/src/components/SegmentedControl/index.tsx +89 -111
- package/src/components/SegmentedControl/styles.ts +21 -7
- package/src/components/Select/index.tsx +57 -91
- package/src/components/Select/styles.ts +36 -19
- package/src/components/Select/types.ts +13 -17
- package/src/components/Slider/index.tsx +93 -85
- package/src/components/Slider/styles.ts +6 -13
- package/src/components/Switch/index.tsx +74 -63
- package/src/components/Switch/styles.ts +6 -1
- package/src/components/Tag/index.tsx +44 -39
- package/src/components/Tag/styles.ts +9 -1
- package/src/components/Tag/types.ts +10 -10
- package/src/components/Text/index.tsx +48 -37
- package/src/components/Text/styles.ts +8 -0
- package/src/components/Text/types.ts +8 -8
- package/src/components/TextEditor/index.tsx +28 -49
- package/src/components/TextEditor/styles.ts +8 -1
- package/src/components/TextEditor/types.ts +6 -11
- package/src/components/TextInput/index.tsx +96 -58
- package/src/components/TextInput/mask.tsx +50 -2
- package/src/components/TextInput/styles.ts +8 -3
- package/src/components/Tooltip/index.tsx +84 -61
- package/src/components/Tooltip/styles.ts +10 -3
- package/src/components/Touchable/index.tsx +86 -43
- package/src/components/Touchable/styles.ts +6 -0
- package/src/components/View/index.tsx +50 -36
- package/src/components/View/styles.ts +6 -0
- package/src/components/View/types.ts +15 -14
- package/src/components/components.ts +3 -2
- package/src/components/defaultStyles.ts +79 -0
- package/src/index.ts +0 -1
- package/src/lib/hooks/index.ts +0 -5
- package/src/lib/hooks/useBreakpointMatch.ts +7 -8
- package/src/lib/hooks/useMediaQuery.ts +3 -4
- package/src/lib/hooks/usePagination.ts +63 -79
- package/src/lib/index.ts +0 -1
- package/src/lib/utils/index.ts +0 -1
- package/src/lib/utils/test.ts +2 -2
- package/src/components/ActionIcon/types.ts +0 -15
- package/src/components/ActivityIndicator/types.ts +0 -12
- package/src/components/Badge/types.ts +0 -28
- package/src/components/Button/types.ts +0 -25
- package/src/components/Checkbox/types.ts +0 -15
- package/src/components/Collapse/types.ts +0 -11
- package/src/components/Drawer/types.ts +0 -23
- package/src/components/EmptyPlaceholder/types.ts +0 -32
- package/src/components/FileInput/index.tsx +0 -72
- package/src/components/FileInput/types.ts +0 -14
- package/src/components/Icon/types.ts +0 -15
- package/src/components/LoadingOverlay/types.ts +0 -16
- package/src/components/Modal/types.ts +0 -55
- package/src/components/NumberIncrement/types.ts +0 -29
- package/src/components/Overlay/types.ts +0 -13
- package/src/components/Pager/types.ts +0 -35
- package/src/components/PaginationButtons/index.tsx +0 -173
- package/src/components/PaginationButtons/styles.ts +0 -7
- package/src/components/PaginationButtons/types.ts +0 -26
- package/src/components/PaginationIndicator/index.tsx +0 -69
- package/src/components/PaginationIndicator/styles.ts +0 -3
- package/src/components/PaginationIndicator/types.ts +0 -18
- package/src/components/Progress/Bar/styles.ts +0 -10
- package/src/components/Progress/Bar/types.ts +0 -26
- package/src/components/RadioInput/types.ts +0 -29
- package/src/components/SegmentedControl/types.ts +0 -44
- package/src/components/Slider/types.ts +0 -29
- package/src/components/Switch/types.ts +0 -13
- package/src/components/TextInput/types.ts +0 -85
- package/src/components/Tooltip/types.ts +0 -46
- package/src/components/Touchable/types.ts +0 -22
- package/src/lib/WebStyleRegistry.ts +0 -51
- package/src/lib/hooks/useFileInput.ts +0 -15
- package/src/lib/hooks/useInfiniteScroll.ts +0 -77
- package/src/lib/hooks/useRefresh.ts +0 -87
- package/src/lib/hooks/useStylesFor.ts +0 -13
- package/src/lib/utils/cache.ts +0 -9
- /package/src/components/DatePicker/{components → defaultComponents}/index.tsx +0 -0
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
1
3
|
import React from 'react'
|
|
2
|
-
|
|
4
|
+
|
|
5
|
+
import { ComponentVariants, onMount, PropsOf, TypeGuards, useDefaultComponentStyle, useRef } from '@codeleap/common'
|
|
6
|
+
import { SliderComposition } from './styles'
|
|
7
|
+
import { StylesOf } from '../../types'
|
|
3
8
|
import { View } from '../View'
|
|
4
|
-
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
9
|
+
import { concatStyles, InputBaseProps, InputBase, selectInputBaseProps } from '../InputBase'
|
|
10
|
+
import { SliderPresets } from './styles'
|
|
5
11
|
import { Text } from '../Text'
|
|
12
|
+
|
|
6
13
|
import {
|
|
7
14
|
Root as SliderContainer,
|
|
8
15
|
Track as SliderTrack,
|
|
@@ -10,13 +17,30 @@ import {
|
|
|
10
17
|
Range as SliderRange,
|
|
11
18
|
SliderProps as PrimitiveSliderProps,
|
|
12
19
|
} from '@radix-ui/react-slider'
|
|
13
|
-
import { SliderProps, TrackMarkProps } from './types'
|
|
14
|
-
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
15
|
-
import { AnyRecord, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
|
|
16
|
-
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
17
20
|
|
|
18
21
|
export * from './styles'
|
|
19
|
-
|
|
22
|
+
|
|
23
|
+
export type SliderProps = Partial<Omit<PrimitiveSliderProps, 'value' | 'onValueChange'>> & Pick<InputBaseProps, 'disabled' | 'debugName' | 'description' | 'label'> & {
|
|
24
|
+
indicatorLabel?: {
|
|
25
|
+
order?: number[]
|
|
26
|
+
separator?: string
|
|
27
|
+
transformer?: (value: number[], defaultValue: PrimitiveSliderProps['defaultValue']) => string
|
|
28
|
+
}
|
|
29
|
+
value: number | number[]
|
|
30
|
+
onValueChange: (val: number | number[]) => void
|
|
31
|
+
styles?: StylesOf<SliderComposition>
|
|
32
|
+
style?: PropsOf<typeof View>['style']
|
|
33
|
+
trackMarks?: Record<number, string>
|
|
34
|
+
trackMarkComponent?: React.ComponentType<TrackMarkProps>
|
|
35
|
+
onPressThumbSetValue?: boolean
|
|
36
|
+
onPressThumb?: (value: number | number[], thumbIndex: number) => void
|
|
37
|
+
} & ComponentVariants<typeof SliderPresets>
|
|
38
|
+
|
|
39
|
+
export type TrackMarkProps = {
|
|
40
|
+
index: number
|
|
41
|
+
content?: string | React.ReactNode
|
|
42
|
+
style?: any
|
|
43
|
+
}
|
|
20
44
|
|
|
21
45
|
const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
22
46
|
const { style } = props
|
|
@@ -27,17 +51,17 @@ const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
|
27
51
|
</React.Fragment>
|
|
28
52
|
}
|
|
29
53
|
|
|
30
|
-
return <Text
|
|
54
|
+
return <Text
|
|
55
|
+
text={props.content}
|
|
56
|
+
css={style}
|
|
57
|
+
/>
|
|
31
58
|
}
|
|
32
59
|
|
|
33
60
|
export const Slider = (props: SliderProps) => {
|
|
34
61
|
const {
|
|
35
62
|
inputBaseProps,
|
|
36
63
|
others,
|
|
37
|
-
} = selectInputBaseProps(
|
|
38
|
-
...Slider.defaultProps,
|
|
39
|
-
...props,
|
|
40
|
-
})
|
|
64
|
+
} = selectInputBaseProps(props)
|
|
41
65
|
|
|
42
66
|
const {
|
|
43
67
|
onValueChange,
|
|
@@ -45,24 +69,25 @@ export const Slider = (props: SliderProps) => {
|
|
|
45
69
|
value: _value,
|
|
46
70
|
label,
|
|
47
71
|
debugName,
|
|
72
|
+
styles = {},
|
|
73
|
+
responsiveVariants = {},
|
|
48
74
|
style,
|
|
49
75
|
disabled,
|
|
76
|
+
variants,
|
|
50
77
|
trackMarks,
|
|
51
|
-
trackMarkComponent
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
indicatorLabel,
|
|
56
|
-
description,
|
|
57
|
-
minStepsBetweenThumbs,
|
|
58
|
-
step,
|
|
59
|
-
onPressThumbSetValue,
|
|
60
|
-
onPressThumb,
|
|
78
|
+
trackMarkComponent = DefaultSliderTrackMark,
|
|
79
|
+
defaultValue: defaultSliderValue = [],
|
|
80
|
+
max = 100,
|
|
81
|
+
min = 0,
|
|
82
|
+
indicatorLabel = null,
|
|
83
|
+
description = null,
|
|
84
|
+
minStepsBetweenThumbs = 0,
|
|
85
|
+
step = 1,
|
|
86
|
+
onPressThumbSetValue = false,
|
|
87
|
+
onPressThumb = null,
|
|
61
88
|
...sliderProps
|
|
62
89
|
} = others
|
|
63
90
|
|
|
64
|
-
const styles = useStylesFor(Slider.styleRegistryName, style)
|
|
65
|
-
|
|
66
91
|
const isUniqueValue = !TypeGuards.isArray(_value)
|
|
67
92
|
const value = isUniqueValue ? [_value] : _value
|
|
68
93
|
|
|
@@ -77,41 +102,49 @@ export const Slider = (props: SliderProps) => {
|
|
|
77
102
|
}
|
|
78
103
|
})
|
|
79
104
|
|
|
105
|
+
const SliderTrackMark = trackMarkComponent
|
|
106
|
+
|
|
80
107
|
const handleChange: SliderProps['onValueChange'] = (newValue: Array<number>) => {
|
|
81
|
-
onValueChange
|
|
108
|
+
onValueChange(isUniqueValue ? newValue?.[0] : newValue)
|
|
82
109
|
}
|
|
83
110
|
|
|
84
111
|
const handleValueCommit = (newValue: Array<number>) => {
|
|
85
112
|
onValueCommit?.(newValue)
|
|
86
113
|
}
|
|
87
114
|
|
|
115
|
+
const variantStyles = useDefaultComponentStyle<'u:Slider', typeof SliderPresets>('u:Slider', {
|
|
116
|
+
responsiveVariants,
|
|
117
|
+
variants,
|
|
118
|
+
styles,
|
|
119
|
+
})
|
|
120
|
+
|
|
88
121
|
const thumbStyle = React.useMemo(() => {
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
disabled &&
|
|
122
|
+
return concatStyles([
|
|
123
|
+
variantStyles.thumb,
|
|
124
|
+
disabled && variantStyles['thumb:disabled'],
|
|
92
125
|
])
|
|
93
126
|
}, [])
|
|
94
127
|
|
|
95
128
|
const trackStyle = React.useMemo(() => {
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
disabled &&
|
|
99
|
-
|
|
100
|
-
disabled &&
|
|
129
|
+
return concatStyles([
|
|
130
|
+
variantStyles.track,
|
|
131
|
+
disabled && variantStyles['track:disabled'],
|
|
132
|
+
variantStyles.unselectedTrack,
|
|
133
|
+
disabled && variantStyles['unselectedTrack:disabled'],
|
|
101
134
|
])
|
|
102
135
|
}, [disabled])
|
|
103
136
|
|
|
104
137
|
const selectedTrackStyle = React.useMemo(() => {
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
disabled &&
|
|
138
|
+
return concatStyles([
|
|
139
|
+
variantStyles.selectedTrack,
|
|
140
|
+
disabled && variantStyles['selectedTrack:disabled'],
|
|
108
141
|
])
|
|
109
142
|
}, [disabled])
|
|
110
143
|
|
|
111
144
|
const containerStyle = React.useMemo(() => {
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
disabled &&
|
|
145
|
+
return concatStyles([
|
|
146
|
+
variantStyles.sliderContainer,
|
|
147
|
+
disabled && variantStyles['sliderContainer:disabled'],
|
|
115
148
|
])
|
|
116
149
|
}, [disabled])
|
|
117
150
|
|
|
@@ -125,17 +158,17 @@ export const Slider = (props: SliderProps) => {
|
|
|
125
158
|
}, [trackMarksHaveContent])
|
|
126
159
|
|
|
127
160
|
const trackMarkStyle = React.useMemo(() => {
|
|
128
|
-
return
|
|
129
|
-
|
|
130
|
-
disabled &&
|
|
161
|
+
return concatStyles([
|
|
162
|
+
variantStyles.trackMark,
|
|
163
|
+
disabled && variantStyles['trackMark:disabled'],
|
|
131
164
|
])
|
|
132
165
|
}, [disabled])
|
|
133
166
|
|
|
134
167
|
const trackMarkWrapperStyle = React.useMemo(() => {
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
disabled &&
|
|
138
|
-
]
|
|
168
|
+
return [
|
|
169
|
+
variantStyles.trackMarkWrapper,
|
|
170
|
+
disabled && variantStyles['trackMarkWrapper:disabled'],
|
|
171
|
+
]
|
|
139
172
|
}, [disabled])
|
|
140
173
|
|
|
141
174
|
const sliderLabel = React.useMemo(() => {
|
|
@@ -167,7 +200,12 @@ export const Slider = (props: SliderProps) => {
|
|
|
167
200
|
<InputBase
|
|
168
201
|
{...inputBaseProps}
|
|
169
202
|
disabled={disabled}
|
|
170
|
-
|
|
203
|
+
styles={{
|
|
204
|
+
...variantStyles,
|
|
205
|
+
innerWrapper: [
|
|
206
|
+
variantStyles.innerWrapper,
|
|
207
|
+
],
|
|
208
|
+
}}
|
|
171
209
|
labelAsRow
|
|
172
210
|
description={sliderLabel}
|
|
173
211
|
>
|
|
@@ -201,7 +239,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
201
239
|
</SliderContainer>
|
|
202
240
|
|
|
203
241
|
{trackMarksProp ?
|
|
204
|
-
<View
|
|
242
|
+
<View css={trackMarkWrapperStyle}>
|
|
205
243
|
{
|
|
206
244
|
trackMarksProp.map((_, idx) => {
|
|
207
245
|
let idxStyle = {}
|
|
@@ -209,9 +247,9 @@ export const Slider = (props: SliderProps) => {
|
|
|
209
247
|
const relativeValue = Number(trackMarksProp[idx])
|
|
210
248
|
|
|
211
249
|
if (idx === 0) {
|
|
212
|
-
idxStyle =
|
|
250
|
+
idxStyle = variantStyles.firstTrackMark
|
|
213
251
|
} else if (idx === trackMarksProp.length - 1) {
|
|
214
|
-
idxStyle =
|
|
252
|
+
idxStyle = variantStyles.lastTrackMark
|
|
215
253
|
} else {
|
|
216
254
|
const markerPosition = (relativeValue / max) * 100
|
|
217
255
|
|
|
@@ -223,7 +261,10 @@ export const Slider = (props: SliderProps) => {
|
|
|
223
261
|
}
|
|
224
262
|
}
|
|
225
263
|
|
|
226
|
-
const style =
|
|
264
|
+
const style = [
|
|
265
|
+
trackMarkStyle,
|
|
266
|
+
idxStyle,
|
|
267
|
+
]
|
|
227
268
|
|
|
228
269
|
if (!trackMarksHaveContent) {
|
|
229
270
|
return <SliderTrackMark
|
|
@@ -251,37 +292,4 @@ export const Slider = (props: SliderProps) => {
|
|
|
251
292
|
)
|
|
252
293
|
}
|
|
253
294
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
Slider.elements = [
|
|
257
|
-
...InputBase.elements,
|
|
258
|
-
'thumb',
|
|
259
|
-
'track',
|
|
260
|
-
'selectedTrack',
|
|
261
|
-
'unselectedTrack',
|
|
262
|
-
'trackMark',
|
|
263
|
-
'firstTrackMark',
|
|
264
|
-
'lastTrackMark',
|
|
265
|
-
'trackMarkWrapper',
|
|
266
|
-
'sliderContainer',
|
|
267
|
-
]
|
|
268
|
-
|
|
269
|
-
Slider.rootElement = 'wrapper'
|
|
270
|
-
|
|
271
|
-
Slider.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
272
|
-
return Slider as (props: StyledComponentProps<SliderProps, typeof styles>) => IJSX
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
Slider.defaultProps = {
|
|
276
|
-
max: 100,
|
|
277
|
-
min: 0,
|
|
278
|
-
minStepsBetweenThumbs: 0,
|
|
279
|
-
defaultValue: [],
|
|
280
|
-
indicatorLabel: null,
|
|
281
|
-
description: null,
|
|
282
|
-
step: 1,
|
|
283
|
-
onPressThumbSetValue: false,
|
|
284
|
-
onPressThumb: null,
|
|
285
|
-
} as Partial<SliderProps>
|
|
286
|
-
|
|
287
|
-
WebStyleRegistry.registerComponent(Slider)
|
|
295
|
+
export * from './styles'
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
1
2
|
import { IconLessInputBaseParts, InputBaseParts, InputBaseStates } from '../InputBase'
|
|
2
3
|
|
|
3
|
-
type SliderParts =
|
|
4
|
-
InputBaseParts |
|
|
5
|
-
'thumb' |
|
|
6
|
-
'track' |
|
|
7
|
-
'selectedTrack' |
|
|
8
|
-
'unselectedTrack' |
|
|
9
|
-
'trackMark' |
|
|
10
|
-
'firstTrackMark' |
|
|
11
|
-
'lastTrackMark' |
|
|
12
|
-
'trackMarkWrapper' |
|
|
13
|
-
'sliderContainer' |
|
|
14
|
-
IconLessInputBaseParts
|
|
15
|
-
|
|
4
|
+
type SliderParts = InputBaseParts | 'thumb' | 'track' | 'selectedTrack' | 'unselectedTrack' | 'trackMark' | 'firstTrackMark' | 'lastTrackMark' | 'trackMarkWrapper' | 'sliderContainer' | IconLessInputBaseParts
|
|
16
5
|
type SliderStates = Exclude<InputBaseStates, 'focus'>
|
|
17
6
|
|
|
18
7
|
export type SliderComposition = `${SliderParts}:${SliderStates}` | SliderParts
|
|
8
|
+
|
|
9
|
+
const createSliderStyle = createDefaultVariantFactory<SliderComposition>()
|
|
10
|
+
|
|
11
|
+
export const SliderPresets = includePresets((styles) => createSliderStyle(() => ({ wrapper: styles })))
|
|
@@ -1,48 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx, CSSObject } from '@emotion/react'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { ComponentVariants, useDefaultComponentStyle, StylesOf, PropsOf } from '@codeleap/common'
|
|
5
|
+
import { View } from '../View'
|
|
6
|
+
import { SwitchPresets, SwitchComposition } from './styles'
|
|
7
|
+
import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
|
|
8
|
+
import { useAnimatedVariantStyles } from '../..'
|
|
5
9
|
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'
|
|
9
10
|
|
|
10
11
|
export * from './styles'
|
|
11
|
-
|
|
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>
|
|
12
24
|
|
|
13
25
|
const reversedOrder = [...InputBaseDefaultOrder].reverse()
|
|
14
26
|
|
|
15
27
|
export const Switch = (props: SwitchProps) => {
|
|
16
28
|
const {
|
|
17
29
|
inputBaseProps,
|
|
18
|
-
others
|
|
19
|
-
} = selectInputBaseProps(
|
|
20
|
-
...Switch.defaultProps,
|
|
21
|
-
...props,
|
|
22
|
-
})
|
|
30
|
+
others,
|
|
31
|
+
} = selectInputBaseProps(props)
|
|
23
32
|
|
|
24
33
|
const {
|
|
25
|
-
|
|
34
|
+
responsiveVariants = {},
|
|
35
|
+
variants = [],
|
|
36
|
+
style = {},
|
|
37
|
+
styles = {},
|
|
26
38
|
value,
|
|
27
39
|
disabled,
|
|
28
40
|
debugName,
|
|
29
41
|
onValueChange,
|
|
30
42
|
onChange,
|
|
31
43
|
switchOnLeft,
|
|
32
|
-
} =
|
|
44
|
+
} = others
|
|
33
45
|
|
|
34
|
-
const
|
|
46
|
+
const variantStyles = useDefaultComponentStyle<'u:Switch', typeof SwitchPresets>('u:Switch', {
|
|
47
|
+
responsiveVariants,
|
|
48
|
+
variants,
|
|
49
|
+
styles,
|
|
50
|
+
rootElement: 'wrapper',
|
|
51
|
+
})
|
|
35
52
|
|
|
36
53
|
const trackAnimation = useAnimatedVariantStyles({
|
|
37
|
-
variantStyles
|
|
54
|
+
variantStyles,
|
|
38
55
|
animatedProperties: ['track:off', 'track:disabled', 'track:on', 'track:disabled-on', 'track:disabled-off'],
|
|
39
56
|
updater: () => {
|
|
40
57
|
'worklet'
|
|
41
58
|
let disabledStyle = {}
|
|
42
59
|
if (disabled) {
|
|
43
|
-
disabledStyle = value ?
|
|
60
|
+
disabledStyle = value ? variantStyles['track:disabled-on'] : variantStyles['track:disabled-off']
|
|
44
61
|
}
|
|
45
|
-
const style = value ?
|
|
62
|
+
const style = value ? variantStyles['track:on'] : variantStyles['track:off']
|
|
46
63
|
|
|
47
64
|
return {
|
|
48
65
|
...style,
|
|
@@ -53,15 +70,15 @@ export const Switch = (props: SwitchProps) => {
|
|
|
53
70
|
})
|
|
54
71
|
|
|
55
72
|
const thumbAnimation = useAnimatedVariantStyles({
|
|
56
|
-
variantStyles
|
|
73
|
+
variantStyles,
|
|
57
74
|
animatedProperties: ['thumb:off', 'thumb:disabled', 'thumb:on', 'thumb:disabled-off', 'thumb:disabled-on'],
|
|
58
75
|
updater: () => {
|
|
59
76
|
'worklet'
|
|
60
77
|
let disabledStyle = {}
|
|
61
78
|
if (disabled) {
|
|
62
|
-
disabledStyle = value ?
|
|
79
|
+
disabledStyle = value ? variantStyles['thumb:disabled-on'] : variantStyles['thumb:disabled-off']
|
|
63
80
|
}
|
|
64
|
-
const style = value ?
|
|
81
|
+
const style = value ? variantStyles['thumb:on'] : variantStyles['thumb:off']
|
|
65
82
|
return {
|
|
66
83
|
...style,
|
|
67
84
|
...disabledStyle,
|
|
@@ -70,11 +87,7 @@ export const Switch = (props: SwitchProps) => {
|
|
|
70
87
|
dependencies: [value, disabled],
|
|
71
88
|
})
|
|
72
89
|
|
|
73
|
-
|
|
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']])
|
|
90
|
+
const _switchOnLeft = switchOnLeft ?? variantStyles.__props?.switchOnLeft
|
|
78
91
|
|
|
79
92
|
const handleChange = (e) => {
|
|
80
93
|
if (disabled) return
|
|
@@ -84,43 +97,41 @@ export const Switch = (props: SwitchProps) => {
|
|
|
84
97
|
}
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
return <InputBase
|
|
101
|
+
{...inputBaseProps}
|
|
102
|
+
debugName={debugName}
|
|
103
|
+
styles={{
|
|
104
|
+
...variantStyles,
|
|
105
|
+
innerWrapper: [
|
|
106
|
+
variantStyles.innerWrapper,
|
|
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}
|
|
95
125
|
>
|
|
96
126
|
<motion.div
|
|
97
|
-
|
|
127
|
+
css={[
|
|
128
|
+
variantStyles.thumb,
|
|
129
|
+
disabled && variantStyles['thumb:disabled'],
|
|
130
|
+
]}
|
|
98
131
|
initial={false}
|
|
99
|
-
animate={
|
|
100
|
-
transition={
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
)
|
|
132
|
+
animate={thumbAnimation}
|
|
133
|
+
transition={variantStyles['thumb:transition']}
|
|
134
|
+
/>
|
|
135
|
+
</motion.div>
|
|
136
|
+
</InputBase>
|
|
114
137
|
}
|
|
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,7 +1,8 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
1
2
|
import { InputBaseParts, InputBaseStates } from '../InputBase'
|
|
2
3
|
|
|
3
4
|
type AnimatableParts = 'track' | 'thumb'
|
|
4
|
-
export type SwitchParts = InputBaseParts | AnimatableParts
|
|
5
|
+
export type SwitchParts = InputBaseParts | AnimatableParts
|
|
5
6
|
|
|
6
7
|
export type SwitchAnimationStates = 'on' | 'off' | 'disabled-on' | 'disabled-off'
|
|
7
8
|
|
|
@@ -13,3 +14,7 @@ export type SwitchComposition =
|
|
|
13
14
|
| `${AnimatableParts}:transition`
|
|
14
15
|
| `${AnimatableParts}:${SwitchAnimationStates}`
|
|
15
16
|
| '__props'
|
|
17
|
+
|
|
18
|
+
const createSwitchStyle = createDefaultVariantFactory<SwitchComposition>()
|
|
19
|
+
|
|
20
|
+
export const SwitchPresets = includePresets((styles) => createSwitchStyle(() => ({ wrapper: styles })))
|
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { TypeGuards } from '@codeleap/common'
|
|
3
|
-
import { TagParts } from './styles'
|
|
2
|
+
import { TypeGuards, useDefaultComponentStyle, useNestedStylesByKey } from '@codeleap/common'
|
|
3
|
+
import { TagParts, TagPresets } 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'
|
|
13
10
|
|
|
14
11
|
export * from './styles'
|
|
15
12
|
export * from './types'
|
|
16
13
|
|
|
14
|
+
const defaultProps: Partial<TagProps> = {
|
|
15
|
+
debugName: 'Tag component',
|
|
16
|
+
disabled: false,
|
|
17
|
+
}
|
|
18
|
+
|
|
17
19
|
export const Tag = (props: TagProps) => {
|
|
20
|
+
const allProps = {
|
|
21
|
+
...Tag.defaultProps,
|
|
22
|
+
...props,
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
const {
|
|
26
|
+
variants,
|
|
19
27
|
rightComponent,
|
|
20
28
|
leftComponent,
|
|
29
|
+
responsiveVariants,
|
|
30
|
+
styles,
|
|
21
31
|
style,
|
|
32
|
+
css,
|
|
22
33
|
leftIcon,
|
|
23
34
|
text,
|
|
24
35
|
textProps,
|
|
@@ -33,14 +44,16 @@ export const Tag = (props: TagProps) => {
|
|
|
33
44
|
onPress,
|
|
34
45
|
disabled,
|
|
35
46
|
...touchableProps
|
|
36
|
-
} =
|
|
37
|
-
...Tag.defaultProps,
|
|
38
|
-
...props,
|
|
39
|
-
}
|
|
47
|
+
} = allProps
|
|
40
48
|
|
|
41
|
-
const
|
|
49
|
+
const variantStyles = useDefaultComponentStyle<'u:Tag', typeof TagPresets>('u:Tag', {
|
|
50
|
+
variants,
|
|
51
|
+
responsiveVariants,
|
|
52
|
+
styles,
|
|
53
|
+
})
|
|
42
54
|
|
|
43
|
-
const
|
|
55
|
+
const leftBadgeStyles = useNestedStylesByKey('leftBadge', variantStyles)
|
|
56
|
+
const rightBadgeStyles = useNestedStylesByKey('rightBadge', variantStyles)
|
|
44
57
|
|
|
45
58
|
const isPressable = TypeGuards.isFunction(onPress)
|
|
46
59
|
|
|
@@ -48,24 +61,29 @@ export const Tag = (props: TagProps) => {
|
|
|
48
61
|
|
|
49
62
|
const wrapperProps = isPressable ? { onPress, ...touchableProps } : touchableProps
|
|
50
63
|
|
|
51
|
-
const getStylesByKey = (styleKey: TagParts) =>
|
|
52
|
-
|
|
53
|
-
isPressable &&
|
|
54
|
-
disabled &&
|
|
64
|
+
const getStylesByKey = (styleKey: TagParts) => ([
|
|
65
|
+
variantStyles?.[styleKey],
|
|
66
|
+
isPressable && variantStyles[`${styleKey}:pressable`],
|
|
67
|
+
disabled && variantStyles[`${styleKey}:disabled`],
|
|
55
68
|
])
|
|
56
69
|
|
|
57
|
-
const wrapperStyles = React.useMemo(() =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
const wrapperStyles = React.useMemo(() => ([
|
|
71
|
+
getStylesByKey('wrapper'),
|
|
72
|
+
css,
|
|
73
|
+
style,
|
|
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])
|
|
61
79
|
|
|
62
80
|
return (
|
|
63
|
-
<Wrapper disabled={disabled} {...wrapperProps}
|
|
81
|
+
<Wrapper css={wrapperStyles} disabled={disabled} {...wrapperProps}>
|
|
64
82
|
{leftComponent}
|
|
65
83
|
{leftBadge && (
|
|
66
84
|
<Badge
|
|
67
85
|
debugName={`${touchableProps?.debugName}:leftBadge`}
|
|
68
|
-
|
|
86
|
+
styles={leftBadgeStyles}
|
|
69
87
|
badge={leftBadge}
|
|
70
88
|
disabled={disabled}
|
|
71
89
|
{...leftBadgeProps}
|
|
@@ -74,19 +92,19 @@ export const Tag = (props: TagProps) => {
|
|
|
74
92
|
{!TypeGuards.isNil(leftIcon) && (
|
|
75
93
|
<Icon
|
|
76
94
|
debugName={`${touchableProps?.debugName}:leftIcon`}
|
|
77
|
-
|
|
95
|
+
css={leftIconStyles}
|
|
78
96
|
name={leftIcon}
|
|
79
97
|
{...leftIconProps}
|
|
80
98
|
/>
|
|
81
99
|
)}
|
|
82
100
|
|
|
83
|
-
{TypeGuards.isString(text) ? <Text text={text}
|
|
101
|
+
{TypeGuards.isString(text) ? <Text text={text} css={textStyles} {...textProps} /> : text}
|
|
84
102
|
{children}
|
|
85
103
|
|
|
86
104
|
{!TypeGuards.isNil(rightIcon) && (
|
|
87
105
|
<Icon
|
|
88
106
|
debugName={`${touchableProps?.debugName}:rightIcon`}
|
|
89
|
-
|
|
107
|
+
css={rightIconStyles}
|
|
90
108
|
name={rightIcon}
|
|
91
109
|
{...rightIconProps}
|
|
92
110
|
/>
|
|
@@ -94,7 +112,7 @@ export const Tag = (props: TagProps) => {
|
|
|
94
112
|
{rightBadge && (
|
|
95
113
|
<Badge
|
|
96
114
|
debugName={`${touchableProps?.debugName}:rightBadge`}
|
|
97
|
-
|
|
115
|
+
styles={rightBadgeStyles}
|
|
98
116
|
badge={rightBadge}
|
|
99
117
|
disabled={disabled}
|
|
100
118
|
{...rightBadgeProps}
|
|
@@ -105,17 +123,4 @@ export const Tag = (props: TagProps) => {
|
|
|
105
123
|
)
|
|
106
124
|
}
|
|
107
125
|
|
|
108
|
-
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)
|
|
126
|
+
Tag.defaultProps = defaultProps
|