@codeleap/web 3.25.0 → 3.25.2
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 +58 -92
- 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,3 +1,4 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
1
2
|
import { ActivityIndicatorComposition } from '../ActivityIndicator'
|
|
2
3
|
|
|
3
4
|
export type ButtonStates = 'disabled' | 'selected'
|
|
@@ -11,3 +12,7 @@ export type ButtonParts =
|
|
|
11
12
|
| `loader${Capitalize<ActivityIndicatorComposition>}`
|
|
12
13
|
|
|
13
14
|
export type ButtonComposition = `${ButtonParts}:${ButtonStates}` | ButtonParts
|
|
15
|
+
|
|
16
|
+
const createButtonStyle = createDefaultVariantFactory<ButtonComposition>()
|
|
17
|
+
|
|
18
|
+
export const ButtonPresets = includePresets((styles) => createButtonStyle(() => ({ wrapper: styles })))
|
|
@@ -1,61 +1,93 @@
|
|
|
1
|
-
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx, CSSObject } from '@emotion/react'
|
|
3
|
+
import {
|
|
4
|
+
ComponentVariants,
|
|
5
|
+
useDefaultComponentStyle,
|
|
6
|
+
StylesOf,
|
|
7
|
+
PropsOf,
|
|
8
|
+
IconPlaceholder,
|
|
9
|
+
} from '@codeleap/common'
|
|
10
|
+
import { View } from '../View'
|
|
11
|
+
import { CheckboxPresets, CheckboxComposition } from './styles'
|
|
12
|
+
import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
|
|
2
13
|
import { useAnimatedVariantStyles } from '../..'
|
|
3
14
|
import { Icon } from '../Icon'
|
|
4
15
|
import { motion } from 'framer-motion'
|
|
5
|
-
import {
|
|
6
|
-
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
7
|
-
import { AnyRecord, AppIcon, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
|
|
8
|
-
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
9
|
-
import { CheckboxParts } from './styles'
|
|
10
|
-
import { TypeGuards } from '@codeleap/common'
|
|
16
|
+
import { ComponentCommonProps } from '../../types/utility'
|
|
11
17
|
|
|
12
18
|
export * from './styles'
|
|
13
|
-
|
|
19
|
+
|
|
20
|
+
/** * Checkbox */
|
|
21
|
+
export type CheckboxProps = Pick<
|
|
22
|
+
InputBaseProps,
|
|
23
|
+
'debugName' | 'disabled' | 'label'
|
|
24
|
+
> & ComponentCommonProps & {
|
|
25
|
+
styles?: StylesOf<CheckboxComposition>
|
|
26
|
+
/** prop */
|
|
27
|
+
value: boolean
|
|
28
|
+
/** prop */
|
|
29
|
+
onValueChange: (value: boolean) => void
|
|
30
|
+
style?: PropsOf<typeof View>['style']
|
|
31
|
+
/** prop */
|
|
32
|
+
checkboxOnLeft?: boolean
|
|
33
|
+
/** prop */
|
|
34
|
+
checkIcon?: IconPlaceholder
|
|
35
|
+
} & ComponentVariants<typeof CheckboxPresets>
|
|
14
36
|
|
|
15
37
|
const reversedOrder = [...InputBaseDefaultOrder].reverse()
|
|
16
38
|
|
|
39
|
+
const defaultProps: Partial<CheckboxProps> = {
|
|
40
|
+
checkIcon: 'check' as IconPlaceholder,
|
|
41
|
+
}
|
|
42
|
+
|
|
17
43
|
export const Checkbox = (props: CheckboxProps) => {
|
|
18
44
|
const {
|
|
19
45
|
inputBaseProps,
|
|
20
|
-
others
|
|
21
|
-
} = selectInputBaseProps(
|
|
22
|
-
...Checkbox.defaultProps,
|
|
23
|
-
...props,
|
|
24
|
-
})
|
|
46
|
+
others,
|
|
47
|
+
} = selectInputBaseProps(props)
|
|
25
48
|
|
|
26
49
|
const {
|
|
27
|
-
|
|
50
|
+
responsiveVariants = {},
|
|
51
|
+
variants = [],
|
|
52
|
+
style = {},
|
|
53
|
+
styles = {},
|
|
28
54
|
value,
|
|
29
55
|
disabled,
|
|
30
56
|
debugName,
|
|
31
57
|
onValueChange,
|
|
32
58
|
checkboxOnLeft,
|
|
33
59
|
checkIcon,
|
|
34
|
-
} =
|
|
60
|
+
} = others
|
|
35
61
|
|
|
36
|
-
const
|
|
62
|
+
const variantStyles = useDefaultComponentStyle<'u:Checkbox', typeof CheckboxPresets>('u:Checkbox', {
|
|
63
|
+
responsiveVariants,
|
|
64
|
+
variants,
|
|
65
|
+
styles,
|
|
66
|
+
rootElement: 'wrapper',
|
|
67
|
+
})
|
|
37
68
|
|
|
38
69
|
const boxAnimation = useAnimatedVariantStyles({
|
|
39
|
-
variantStyles
|
|
70
|
+
variantStyles,
|
|
40
71
|
animatedProperties: ['box:unchecked', 'box:disabled', 'box:checked', 'box:disabled-checked', 'box:disabled-unchecked'],
|
|
41
72
|
updater: () => {
|
|
42
73
|
'worklet'
|
|
43
74
|
let disabledStyle = {}
|
|
44
75
|
if (disabled) {
|
|
45
|
-
disabledStyle = value ?
|
|
76
|
+
disabledStyle = value ? variantStyles['box:disabled-checked'] : variantStyles['box:disabled-unchecked']
|
|
46
77
|
}
|
|
47
|
-
const style = value ?
|
|
78
|
+
const style = value ? variantStyles['box:checked'] : variantStyles['box:unchecked']
|
|
48
79
|
|
|
49
80
|
return {
|
|
50
81
|
...style,
|
|
51
82
|
...disabledStyle,
|
|
52
83
|
}
|
|
84
|
+
|
|
53
85
|
},
|
|
54
86
|
dependencies: [value, disabled],
|
|
55
87
|
})
|
|
56
88
|
|
|
57
89
|
const checkmarkWrapperAnimation = useAnimatedVariantStyles({
|
|
58
|
-
variantStyles
|
|
90
|
+
variantStyles,
|
|
59
91
|
animatedProperties: [
|
|
60
92
|
'checkmarkWrapper:unchecked',
|
|
61
93
|
'checkmarkWrapper:disabled',
|
|
@@ -67,87 +99,69 @@ export const Checkbox = (props: CheckboxProps) => {
|
|
|
67
99
|
'worklet'
|
|
68
100
|
let disabledStyle = {}
|
|
69
101
|
if (disabled) {
|
|
70
|
-
disabledStyle = value ?
|
|
102
|
+
disabledStyle = value ? variantStyles['checkmarkWrapper:disabled-checked'] : variantStyles['checkmarkWrapper:disabled-unchecked']
|
|
71
103
|
}
|
|
72
|
-
const style = value ?
|
|
104
|
+
const style = value ? variantStyles['checkmarkWrapper:checked'] : variantStyles['checkmarkWrapper:unchecked']
|
|
73
105
|
return {
|
|
74
106
|
...style,
|
|
75
107
|
...disabledStyle,
|
|
76
108
|
}
|
|
109
|
+
|
|
77
110
|
},
|
|
78
111
|
dependencies: [value, disabled],
|
|
79
112
|
})
|
|
80
113
|
|
|
81
|
-
|
|
82
|
-
const _checkboxOnLeft = checkboxOnLeft ?? styles?.__props?.checkboxOnLeft
|
|
114
|
+
const _checkboxOnLeft = checkboxOnLeft ?? variantStyles.__props?.checkboxOnLeft
|
|
83
115
|
|
|
84
116
|
const handleChange = (e) => {
|
|
85
|
-
if (disabled) return
|
|
86
|
-
if (!TypeGuards.isFunction(onValueChange)) return
|
|
87
|
-
|
|
88
117
|
const isSpaceBarClick = e?.keyCode === 32
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (isClick || e?.keyCode === 13 || isSpaceBarClick || isEnterKey) {
|
|
93
|
-
onValueChange?.(!value)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const getStyles = (key: CheckboxParts) => mergeStyles([
|
|
98
|
-
styles[key],
|
|
99
|
-
disabled ? styles[key + ':disabled'] : null,
|
|
100
|
-
])
|
|
101
|
-
|
|
102
|
-
const componentStyles = {
|
|
103
|
-
box: getStyles('box'),
|
|
104
|
-
checkmarkWrapper: getStyles('checkmarkWrapper'),
|
|
105
|
-
checkmark: getStyles('checkmark'),
|
|
118
|
+
if (disabled) return
|
|
119
|
+
if (onValueChange && (e?.type === 'click' || e?.keyCode === 13 || isSpaceBarClick || e?.key === 'Enter')) onValueChange?.(!value)
|
|
106
120
|
}
|
|
107
121
|
|
|
108
|
-
return
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
return <InputBase
|
|
123
|
+
{...inputBaseProps}
|
|
124
|
+
debugName={debugName}
|
|
125
|
+
styles={{
|
|
126
|
+
...variantStyles,
|
|
127
|
+
innerWrapper: [
|
|
128
|
+
variantStyles.innerWrapper,
|
|
129
|
+
],
|
|
130
|
+
}}
|
|
131
|
+
order={_checkboxOnLeft ? reversedOrder : InputBaseDefaultOrder}
|
|
132
|
+
style={style}
|
|
133
|
+
>
|
|
134
|
+
<motion.div
|
|
135
|
+
css={[
|
|
136
|
+
variantStyles.box,
|
|
137
|
+
disabled && variantStyles['box:disabled'],
|
|
138
|
+
]}
|
|
139
|
+
initial={false}
|
|
140
|
+
animate={boxAnimation}
|
|
141
|
+
transition={variantStyles['box:transition']}
|
|
142
|
+
onClick={handleChange}
|
|
143
|
+
onKeyDown={handleChange}
|
|
144
|
+
tabIndex={0}
|
|
114
145
|
>
|
|
115
146
|
<motion.div
|
|
116
|
-
|
|
147
|
+
css={[
|
|
148
|
+
variantStyles.checkmarkWrapper,
|
|
149
|
+
disabled && variantStyles['checkmarkWrapper:disabled'],
|
|
150
|
+
]}
|
|
117
151
|
initial={false}
|
|
118
|
-
animate={
|
|
119
|
-
transition={
|
|
120
|
-
|
|
121
|
-
onKeyDown={handleChange}
|
|
122
|
-
tabIndex={0}
|
|
152
|
+
animate={checkmarkWrapperAnimation}
|
|
153
|
+
transition={variantStyles['checkmarkWrapper:transition']}
|
|
154
|
+
|
|
123
155
|
>
|
|
124
|
-
<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
<Icon
|
|
131
|
-
debugName={debugName}
|
|
132
|
-
name={checkIcon as AppIcon}
|
|
133
|
-
style={componentStyles.checkmark}
|
|
134
|
-
/>
|
|
135
|
-
</motion.div>
|
|
156
|
+
<Icon
|
|
157
|
+
debugName={debugName}
|
|
158
|
+
name={checkIcon as any}
|
|
159
|
+
css={[variantStyles.checkmark, disabled && variantStyles['checkmark:disabled']]}
|
|
160
|
+
style={variantStyles.checkmark}
|
|
161
|
+
/>
|
|
136
162
|
</motion.div>
|
|
137
|
-
</
|
|
138
|
-
|
|
163
|
+
</motion.div>
|
|
164
|
+
</InputBase>
|
|
139
165
|
}
|
|
140
166
|
|
|
141
|
-
Checkbox.
|
|
142
|
-
Checkbox.elements = [...InputBase.elements, 'checkmarkWrapper', 'checkmark', 'box', '__props']
|
|
143
|
-
Checkbox.rootElement = 'wrapper'
|
|
144
|
-
|
|
145
|
-
Checkbox.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
146
|
-
return Checkbox as (props: StyledComponentProps<CheckboxProps, typeof styles>) => IJSX
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
Checkbox.defaultProps = {
|
|
150
|
-
checkIcon: 'check' as AppIcon,
|
|
151
|
-
} as Partial<CheckboxProps>
|
|
152
|
-
|
|
153
|
-
WebStyleRegistry.registerComponent(Checkbox)
|
|
167
|
+
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,7 @@ 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 })))
|
|
@@ -1,49 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
4
|
-
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
5
|
-
import { motion } from 'framer-motion'
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { capitalize, StylesOf, TypeGuards } from '@codeleap/common'
|
|
5
|
+
import { Scroll } from '../Scroll'
|
|
6
|
+
import { View, ViewProps } from '../View'
|
|
7
|
+
import { ElementType } from 'react'
|
|
8
|
+
import { NativeHTMLElement } from '../../types'
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
...Collapse.defaultProps,
|
|
18
|
-
...props,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const styles = useStylesFor(Collapse.styleRegistryName, style)
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<motion.div
|
|
25
|
-
initial={false}
|
|
26
|
-
animate={{ height: open ? 'auto' : 0, opacity: open ? 1 : 0 }}
|
|
27
|
-
transition={{ duration: 0.2 }}
|
|
28
|
-
{...rest}
|
|
29
|
-
style={{
|
|
30
|
-
...styles.wrapper,
|
|
31
|
-
...(open ? styles?.['wrapper:open'] : styles?.['wrapper:closed']),
|
|
32
|
-
}}
|
|
33
|
-
>
|
|
34
|
-
{children}
|
|
35
|
-
</motion.div>
|
|
36
|
-
)
|
|
10
|
+
export type CollapseAxis = 'horizontal' | 'vertical'
|
|
11
|
+
|
|
12
|
+
export type GetCollapseStylesArgs = {
|
|
13
|
+
direction?: CollapseAxis
|
|
14
|
+
value: string | number
|
|
15
|
+
animation?: string
|
|
16
|
+
scroll ?: boolean
|
|
37
17
|
}
|
|
38
18
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
19
|
+
type CollapseComposition = 'wrapper' | 'wrapper:open' |'wrapper:hidden'
|
|
20
|
+
|
|
21
|
+
export function getCollapseStyles<
|
|
22
|
+
TCSS = React.CSSProperties,
|
|
23
|
+
Return extends Record<CollapseComposition, TCSS> = Record<CollapseComposition, TCSS>
|
|
24
|
+
>(
|
|
25
|
+
args: GetCollapseStylesArgs,
|
|
26
|
+
): Return {
|
|
27
|
+
const {
|
|
28
|
+
direction = 'vertical',
|
|
29
|
+
value,
|
|
30
|
+
animation = '0.3s ease',
|
|
31
|
+
scroll = false,
|
|
32
|
+
|
|
33
|
+
} = args
|
|
42
34
|
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
const dimension = direction === 'horizontal' ? 'width' : 'height'
|
|
36
|
+
const capitalizedDimension = capitalize(dimension)
|
|
37
|
+
const overflowOpen = scroll ? 'auto' : 'hidden'
|
|
38
|
+
const axis = direction === 'vertical' ? 'Y' : 'X'
|
|
39
|
+
return {
|
|
40
|
+
'wrapper:closed': {
|
|
41
|
+
[`max${capitalizedDimension}`]: '0px',
|
|
42
|
+
[`overflow${axis}`]: 'hidden',
|
|
43
|
+
},
|
|
44
|
+
'wrapper:open': {
|
|
45
|
+
[`max${capitalizedDimension}`]: TypeGuards.isString(value) ? value : `${value}px`,
|
|
46
|
+
[`overflow${axis}`]: overflowOpen,
|
|
47
|
+
},
|
|
48
|
+
wrapper: {
|
|
49
|
+
height: 'auto',
|
|
50
|
+
transition: `max-${dimension} ${animation}`,
|
|
51
|
+
},
|
|
52
|
+
} as unknown as Return
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
|
|
55
|
+
export type CollapseProps<T extends NativeHTMLElement = 'div'> = ViewProps<T> & {
|
|
56
|
+
open: boolean
|
|
57
|
+
scroll?: boolean
|
|
58
|
+
size?: string | number
|
|
59
|
+
direction?: CollapseAxis
|
|
60
|
+
animation?: string
|
|
61
|
+
styles: StylesOf<CollapseComposition>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const Collapse = ({
|
|
65
|
+
open,
|
|
66
|
+
size = 1000,
|
|
67
|
+
scroll = false,
|
|
68
|
+
children,
|
|
69
|
+
direction,
|
|
70
|
+
animation,
|
|
71
|
+
styles,
|
|
72
|
+
...props
|
|
73
|
+
}:CollapseProps) => {
|
|
74
|
+
|
|
75
|
+
const Component = scroll ? Scroll : View
|
|
76
|
+
const _styles = getCollapseStyles({
|
|
77
|
+
value: size,
|
|
78
|
+
direction,
|
|
79
|
+
animation,
|
|
80
|
+
})
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
return <Component css={[
|
|
83
|
+
_styles.wrapper,
|
|
84
|
+
open ? _styles['wrapper:open'] : _styles['wrapper:closed'],
|
|
85
|
+
styles.wrapper,
|
|
86
|
+
]} {...props}>
|
|
87
|
+
{children}
|
|
88
|
+
</Component>
|
|
89
|
+
}
|
|
48
90
|
|
|
49
|
-
|
|
91
|
+
export * from './styles'
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
|
|
2
|
+
import { ViewComposition } from "../View"
|
|
2
3
|
|
|
3
|
-
type
|
|
4
|
+
export type CollapseComposition = ViewComposition
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
const createCollapseStyle = createDefaultVariantFactory<CollapseComposition>()
|
|
7
|
+
|
|
8
|
+
export const CollapsePresets = includePresets((styles) => createCollapseStyle(() => ({ wrapper: styles })))
|
|
@@ -1,115 +1,87 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
1
2
|
import React, { useCallback } from 'react'
|
|
2
|
-
import { ActionIcon, Collapse, View } from '../components'
|
|
3
|
+
import { ActionIcon, Collapse, ColorPickerPresets, View } from '../components'
|
|
3
4
|
import { HexColorPicker } from 'react-colorful'
|
|
4
|
-
import {
|
|
5
|
-
import { ColorPickerProps, ColorTypes
|
|
6
|
-
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
7
|
-
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
8
|
-
import { AnyRecord, AppIcon, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
5
|
+
import { useBooleanToggle, useDefaultComponentStyle, useState } from '@codeleap/common'
|
|
6
|
+
import { ColorPickerProps, ColorTypes } from './types'
|
|
9
7
|
|
|
10
8
|
export * from './styles'
|
|
11
9
|
export * from './types'
|
|
12
10
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
debugName='ColorPicker footer trash'
|
|
20
|
-
name={clearIcon}
|
|
21
|
-
onPress={handleClear}
|
|
22
|
-
style={styles.clearIcon}
|
|
23
|
-
/>
|
|
24
|
-
<ActionIcon
|
|
25
|
-
debugName='ColorPicker footer check'
|
|
26
|
-
name={confirmIcon}
|
|
27
|
-
onPress={handleConfirmation}
|
|
28
|
-
style={styles.confirmIcon}
|
|
29
|
-
/>
|
|
30
|
-
</View>
|
|
31
|
-
)
|
|
11
|
+
const defaultProps = {
|
|
12
|
+
pickerComponent: (props) => <HexColorPicker {...props}/>,
|
|
13
|
+
icon: 'edit',
|
|
14
|
+
clearIcon: 'trash',
|
|
15
|
+
confirmIcon: 'check',
|
|
16
|
+
showFooter: true,
|
|
32
17
|
}
|
|
33
18
|
|
|
34
19
|
export const ColorPicker = (props: ColorPickerProps) => {
|
|
35
20
|
const {
|
|
36
|
-
isPlain,
|
|
21
|
+
isPlain = false,
|
|
37
22
|
initialColor,
|
|
38
23
|
showFooter,
|
|
39
24
|
icon,
|
|
40
|
-
style,
|
|
41
25
|
clearIcon,
|
|
42
26
|
confirmIcon,
|
|
27
|
+
variants = [],
|
|
28
|
+
styles = {},
|
|
29
|
+
responsiveVariants = {},
|
|
43
30
|
onConfirm,
|
|
44
31
|
onClear,
|
|
45
|
-
closeOnConfirm,
|
|
32
|
+
closeOnConfirm = true,
|
|
46
33
|
pickerComponent: PickerComponent,
|
|
47
34
|
openPickerComponent: OpenPickerComponent,
|
|
48
|
-
footerComponent: FooterComponent,
|
|
35
|
+
footerComponent: FooterComponent = null,
|
|
49
36
|
openPickerProps,
|
|
50
|
-
} =
|
|
51
|
-
|
|
52
|
-
...props,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const styles = useStylesFor(ColorPicker.styleRegistryName, style)
|
|
56
|
-
|
|
57
|
-
const [visible, toggle] = useConditionalState(props?.visible, props?.toggle, { initialValue: false })
|
|
58
|
-
|
|
37
|
+
} = props
|
|
38
|
+
const [visible, toggle] = useBooleanToggle(false)
|
|
59
39
|
const [color, setColor] = useState<ColorTypes>(initialColor)
|
|
60
40
|
|
|
61
|
-
const
|
|
41
|
+
const variantStyles = useDefaultComponentStyle<'u:ColorPicker', typeof ColorPickerPresets>('u:ColorPicker', {
|
|
42
|
+
variants,
|
|
43
|
+
styles,
|
|
44
|
+
responsiveVariants,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const handleConfirmation = useCallback(() => {
|
|
62
48
|
onConfirm?.(color)
|
|
63
|
-
|
|
64
|
-
}, [])
|
|
49
|
+
closeOnConfirm && toggle(false)
|
|
50
|
+
}, [color])
|
|
65
51
|
|
|
66
|
-
const handleClear = useCallback((
|
|
52
|
+
const handleClear = useCallback(() => {
|
|
67
53
|
setColor(initialColor)
|
|
68
|
-
|
|
69
|
-
}, [])
|
|
54
|
+
onClear?.()
|
|
55
|
+
}, [initialColor])
|
|
56
|
+
|
|
57
|
+
const Footer = useCallback(() => (
|
|
58
|
+
<View style={variantStyles.footerWrapper}>
|
|
59
|
+
<ActionIcon debugName='ColorPicker footer trash' name={clearIcon} onPress={handleClear} styles={variantStyles.footerButton} />
|
|
60
|
+
<ActionIcon debugName='ColorPicker footer check' name={confirmIcon} onPress={handleConfirmation} styles={variantStyles.footerButton} />
|
|
61
|
+
</View>
|
|
62
|
+
), [clearIcon, confirmIcon, handleClear, handleConfirmation])
|
|
70
63
|
|
|
71
64
|
// Dragging to change the color in any other way does not seem to work for some reason.
|
|
72
|
-
const picker = <View style={
|
|
65
|
+
const picker = <View style={variantStyles.picker}><PickerComponent color={color} onChange={setColor} /></View>
|
|
73
66
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
color={color}
|
|
77
|
-
visible={visible}
|
|
78
|
-
toggle={() => toggle(!visible)}
|
|
79
|
-
/>
|
|
80
|
-
) : (
|
|
81
|
-
<ActionIcon
|
|
82
|
-
onPress={() => toggle(!visible)}
|
|
83
|
-
icon={icon}
|
|
84
|
-
{...openPickerProps}
|
|
85
|
-
/>
|
|
86
|
-
)
|
|
67
|
+
const _footer = !!showFooter && FooterComponent ? <FooterComponent color={color} handleConfirmation={handleConfirmation} handleClear={handleClear}/> : <Footer/>
|
|
68
|
+
const openColorPickerBtn = !!OpenPickerComponent ? <OpenPickerComponent color={color} visible={visible} toggle={toggle}/> : <ActionIcon onPress={toggle} icon={icon} {...openPickerProps}/>
|
|
87
69
|
|
|
88
70
|
return (
|
|
89
|
-
<View style={
|
|
71
|
+
<View style={variantStyles.wrapper}>
|
|
90
72
|
{isPlain ? picker : (
|
|
91
73
|
<>
|
|
92
74
|
{openColorPickerBtn}
|
|
93
75
|
<Collapse
|
|
94
76
|
open={visible}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
visible &&
|
|
98
|
-
]}
|
|
77
|
+
styles={{ wrapper: [
|
|
78
|
+
variantStyles.dropdown,
|
|
79
|
+
visible && variantStyles['dropdown:open'],
|
|
80
|
+
] }}
|
|
99
81
|
>
|
|
100
|
-
<View style={
|
|
82
|
+
<View style={variantStyles.dropdownInnerWrapper}>
|
|
101
83
|
{picker}
|
|
102
|
-
|
|
103
|
-
{showFooter ? (
|
|
104
|
-
<FooterComponent
|
|
105
|
-
color={color}
|
|
106
|
-
handleConfirmation={() => handleConfirmation(color)}
|
|
107
|
-
handleClear={() => handleClear(initialColor)}
|
|
108
|
-
styles={styles}
|
|
109
|
-
clearIcon={clearIcon}
|
|
110
|
-
confirmIcon={confirmIcon}
|
|
111
|
-
/>
|
|
112
|
-
) : null}
|
|
84
|
+
{_footer}
|
|
113
85
|
</View>
|
|
114
86
|
</Collapse>
|
|
115
87
|
</>
|
|
@@ -118,23 +90,4 @@ export const ColorPicker = (props: ColorPickerProps) => {
|
|
|
118
90
|
)
|
|
119
91
|
}
|
|
120
92
|
|
|
121
|
-
ColorPicker.
|
|
122
|
-
ColorPicker.elements = ['wrapper', 'picker', 'dropdown', 'dropdownInnerWrapper', 'footerWrapper', 'clearIcon', 'confirmIcon']
|
|
123
|
-
ColorPicker.rootElement = 'wrapper'
|
|
124
|
-
|
|
125
|
-
ColorPicker.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
126
|
-
return ColorPicker as (props: StyledComponentProps<ColorPickerProps, typeof styles>) => IJSX
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
ColorPicker.defaultProps = {
|
|
130
|
-
pickerComponent: (props) => <HexColorPicker {...props} />,
|
|
131
|
-
footerComponent: DefaultFooter,
|
|
132
|
-
icon: 'edit' as AppIcon,
|
|
133
|
-
clearIcon: 'trash' as AppIcon,
|
|
134
|
-
confirmIcon: 'check' as AppIcon,
|
|
135
|
-
showFooter: true,
|
|
136
|
-
isPlain: false,
|
|
137
|
-
closeOnConfirm: true,
|
|
138
|
-
} as Partial<ColorPickerProps>
|
|
139
|
-
|
|
140
|
-
WebStyleRegistry.registerComponent(ColorPicker)
|
|
93
|
+
ColorPicker.defaultProps = defaultProps
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { PartialComponentStyle, createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
+
import { ActionIconComposition } from '../ActionIcon'
|
|
3
|
+
|
|
1
4
|
type ColorPickerState = 'open'
|
|
5
|
+
export type ColorPickerParts = 'wrapper' | 'picker' | 'dropdown' | `dropdown:${ColorPickerState}` | 'dropdownInnerWrapper' | 'footerWrapper'
|
|
6
|
+
|
|
7
|
+
export type ColorPickerComposition = {
|
|
8
|
+
footerButton?: PartialComponentStyle<ActionIconComposition, any>
|
|
9
|
+
} & {[x in ColorPickerParts]?: any}
|
|
10
|
+
|
|
11
|
+
const createColorPickerStyle = createDefaultVariantFactory<'', ColorPickerComposition>()
|
|
2
12
|
|
|
3
|
-
export
|
|
4
|
-
'wrapper' |
|
|
5
|
-
'picker' |
|
|
6
|
-
'dropdown' |
|
|
7
|
-
`dropdown:${ColorPickerState}` |
|
|
8
|
-
'dropdownInnerWrapper' |
|
|
9
|
-
'footerWrapper' |
|
|
10
|
-
'clearIcon' |
|
|
11
|
-
'confirmIcon'
|
|
12
|
-
|
|
13
|
-
export type ColorPickerComposition = ColorPickerParts
|
|
13
|
+
export const ColorPickerPresets = includePresets((styles) => createColorPickerStyle(() => ({ wrapper: styles })))
|