@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,9 +1,11 @@
|
|
|
1
|
-
import { capitalize,
|
|
1
|
+
import { capitalize, FormTypes } from '@codeleap/common'
|
|
2
|
+
import { useNestedStylesByKey } from '@codeleap/styles'
|
|
2
3
|
import { CSSInterpolation } from '@emotion/css'
|
|
3
4
|
import { CSSObjectWithLabel, GroupBase, StylesConfig } from 'react-select'
|
|
4
5
|
import { ButtonParts as _ButtonParts } from '../Button'
|
|
5
6
|
import { InputBaseParts } from '../InputBase'
|
|
6
|
-
import { SelectProps } from './types'
|
|
7
|
+
import { SelectProps, UseSelectStylesProps } from './types'
|
|
8
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
7
9
|
|
|
8
10
|
type ButtonParts = _ButtonParts
|
|
9
11
|
|
|
@@ -43,57 +45,38 @@ export type SelectState = 'error' | 'focus' | 'disabled'
|
|
|
43
45
|
|
|
44
46
|
export type SelectComposition = SelectParts | `${SelectParts}:${SelectState}` | SelectStatefulParts
|
|
45
47
|
|
|
46
|
-
const createSelectStyle = createDefaultVariantFactory<SelectComposition>()
|
|
47
|
-
|
|
48
|
-
export const SelectPresets = includePresets((styles) => createSelectStyle(() => ({ wrapper: styles })))
|
|
49
|
-
|
|
50
48
|
export type ComponentState = {
|
|
51
49
|
error?: boolean
|
|
52
50
|
focused?: boolean
|
|
53
51
|
disabled?: boolean
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
export type OptionState = {
|
|
54
|
+
export type OptionState = {
|
|
57
55
|
isSelected: boolean
|
|
58
56
|
isFocused: boolean
|
|
59
|
-
baseStyles: SelectProps['itemProps']['
|
|
57
|
+
baseStyles: SelectProps['itemProps']['style']
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
export function useSelectStyles<T, Multi extends boolean>(props:
|
|
63
|
-
const {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const {
|
|
70
|
-
error,
|
|
71
|
-
focused,
|
|
72
|
-
disabled,
|
|
73
|
-
} = state
|
|
74
|
-
|
|
75
|
-
const variantStyles = useDefaultComponentStyle<'u:Select', typeof SelectPresets>(
|
|
76
|
-
'u:Select',
|
|
77
|
-
{
|
|
78
|
-
responsiveVariants,
|
|
79
|
-
variants,
|
|
80
|
-
styles,
|
|
81
|
-
},
|
|
82
|
-
)
|
|
60
|
+
export function useSelectStyles<T, Multi extends boolean>(props: UseSelectStylesProps, state: ComponentState) {
|
|
61
|
+
const { style } = props
|
|
62
|
+
|
|
63
|
+
const { error, focused, disabled } = state
|
|
64
|
+
|
|
65
|
+
const styles = useStylesFor(props?.styleRegistryName, style)
|
|
83
66
|
|
|
84
67
|
const stylesKey = (key: SelectParts | SelectStatefulParts, _styles: CSSObjectWithLabel = {}) => ({
|
|
85
68
|
..._styles,
|
|
86
|
-
...
|
|
87
|
-
...(focused ?
|
|
88
|
-
...(disabled ?
|
|
89
|
-
...(error ?
|
|
69
|
+
...styles[key],
|
|
70
|
+
...(focused ? styles[key + ':focus'] : {}),
|
|
71
|
+
...(disabled ? styles[key + ':disabled'] : {}),
|
|
72
|
+
...(error ? styles[key + ':error'] : {}),
|
|
90
73
|
})
|
|
91
74
|
|
|
92
|
-
const optionNestedStyles =
|
|
75
|
+
const optionNestedStyles = useNestedStylesByKey('item', styles)
|
|
93
76
|
|
|
94
77
|
const optionStyleKey = (
|
|
95
78
|
key: ButtonParts | `${ButtonParts}:${ItemState}`,
|
|
96
|
-
state: OptionState
|
|
79
|
+
state: OptionState,
|
|
97
80
|
) => {
|
|
98
81
|
return {
|
|
99
82
|
...stylesKey(`item${capitalize(key)}` as any),
|
|
@@ -169,7 +152,7 @@ export function useSelectStyles<T, Multi extends boolean>(props: SelectProps<T,
|
|
|
169
152
|
}
|
|
170
153
|
|
|
171
154
|
return {
|
|
172
|
-
|
|
155
|
+
styles,
|
|
173
156
|
reactSelectStyles,
|
|
174
157
|
optionsStyles,
|
|
175
158
|
placeholderStyles,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FormTypes, yup } from '@codeleap/common'
|
|
2
2
|
import { CSSInterpolation } from '@emotion/css'
|
|
3
|
-
import { CSSObject } from '@emotion/react'
|
|
4
3
|
import { MutableRefObject } from 'react'
|
|
5
4
|
import { GroupBase, NoticeProps, OptionProps, Props } from 'react-select'
|
|
6
5
|
import { AsyncProps } from 'react-select/async'
|
|
7
6
|
import { ComponentCommonProps } from '../../types'
|
|
8
7
|
import { ButtonProps } from '../Button'
|
|
9
8
|
import { InputBaseProps } from '../InputBase'
|
|
10
|
-
import {
|
|
9
|
+
import { SelectComposition, OptionState } from './styles'
|
|
10
|
+
import { StyledProp } from '@codeleap/styles'
|
|
11
11
|
|
|
12
12
|
type SelectValue<T, Multi extends boolean> = Multi extends true ? T[] : T
|
|
13
13
|
|
|
@@ -26,20 +26,20 @@ type DynamicSelectProps<T, Multi extends boolean> =
|
|
|
26
26
|
Props<FormTypes.Option<T>, Multi, GroupBase<FormTypes.Option<T>>>
|
|
27
27
|
>)
|
|
28
28
|
|
|
29
|
-
export type ReactSelectProps<T, Multi extends boolean = false> = Omit<InputBaseProps, '
|
|
29
|
+
export type ReactSelectProps<T, Multi extends boolean = false> = Omit<InputBaseProps, 'style'> & {
|
|
30
30
|
options: FormTypes.Options<T>
|
|
31
31
|
value: SelectValue<T, Multi>
|
|
32
32
|
onValueChange?: (value: SelectValue<T, Multi>) => void
|
|
33
33
|
multiple?: Multi
|
|
34
34
|
validate?: FormTypes.ValidatorWithoutForm<SelectValue<T, Multi>> | yup.SchemaOf<SelectValue<T, Multi>>
|
|
35
|
-
|
|
35
|
+
style?: StyledProp<SelectComposition>
|
|
36
36
|
} & DynamicSelectProps<T, Multi>
|
|
37
37
|
|
|
38
38
|
export type ComponentPartProps = {
|
|
39
39
|
focused: boolean
|
|
40
40
|
error: boolean
|
|
41
41
|
disabled: boolean
|
|
42
|
-
|
|
42
|
+
styles: Record<SelectComposition, React.CSSProperties>
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export type TCustomOption = OptionProps & ComponentPartProps & ComponentCommonProps & {
|
|
@@ -59,6 +59,7 @@ export type PlaceholderProps = NoticeProps & ComponentPartProps & {
|
|
|
59
59
|
icon: CSSInterpolation
|
|
60
60
|
}
|
|
61
61
|
icon: SelectPlaceholderElement
|
|
62
|
+
image: HTMLImageElement['src']
|
|
62
63
|
} & ComponentCommonProps
|
|
63
64
|
|
|
64
65
|
export type LoadingIndicatorProps = NoticeProps & {
|
|
@@ -71,7 +72,6 @@ export type SelectProps<T = any, Multi extends boolean = false> = React.PropsWit
|
|
|
71
72
|
debugName?: string
|
|
72
73
|
clearable?: boolean
|
|
73
74
|
closeOnSelect?: boolean
|
|
74
|
-
css?: CSSObject
|
|
75
75
|
focused?: boolean
|
|
76
76
|
_error?: string
|
|
77
77
|
renderItem?: (props: TCustomOption) => JSX.Element
|
|
@@ -81,8 +81,10 @@ export type SelectProps<T = any, Multi extends boolean = false> = React.PropsWit
|
|
|
81
81
|
LoadingIndicatorComponent?: (props: LoadingIndicatorProps) => JSX.Element
|
|
82
82
|
noItemsText?: SelectPlaceholderElement
|
|
83
83
|
noItemsIcon?: SelectPlaceholderElement
|
|
84
|
+
noItemsImage?: PlaceholderProps['image']
|
|
84
85
|
placeholderText?: SelectPlaceholderElement
|
|
85
86
|
placeholderIcon?: SelectPlaceholderElement
|
|
87
|
+
placeholderImage?: PlaceholderProps['image']
|
|
86
88
|
showDropdownIcon?: boolean
|
|
87
89
|
formatPlaceholderNoItems?: (props: PlaceholderProps & { text: string }) => string
|
|
88
90
|
selectedIcon?: string
|
|
@@ -96,12 +98,15 @@ export type SelectProps<T = any, Multi extends boolean = false> = React.PropsWit
|
|
|
96
98
|
limit?: number
|
|
97
99
|
loadInitialValue?: boolean
|
|
98
100
|
loadingMessage?: string
|
|
99
|
-
selectedOption?: { label: FormTypes.Label; value: T
|
|
101
|
+
selectedOption?: { label: FormTypes.Label; value: T } | SelectValue<T, Multi>
|
|
100
102
|
selectRef?: MutableRefObject<any>
|
|
101
|
-
setSelectedOption?: (value: { label: FormTypes.Label; value: T
|
|
103
|
+
setSelectedOption?: (value: { label: FormTypes.Label; value: T } | SelectValue<T, Multi>) => void
|
|
102
104
|
} & Omit<
|
|
103
105
|
ReactSelectProps<T, Multi>,
|
|
104
106
|
'isSearchable' | 'isClearable' | 'isDisabled' | 'loadingMessage' | 'filterOption' |
|
|
105
107
|
'isLoading' | 'menuPortalTarget' | 'closeMenuOnSelect' | 'isMulti'>
|
|
106
|
-
& ComponentVariants<typeof SelectPresets>
|
|
107
108
|
>
|
|
109
|
+
|
|
110
|
+
export type UseSelectStylesProps = SelectProps & {
|
|
111
|
+
styleRegistryName: string
|
|
112
|
+
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { jsx } from '@emotion/react'
|
|
3
1
|
import React from 'react'
|
|
4
|
-
|
|
5
|
-
import { ComponentVariants, onMount, PropsOf, TypeGuards, useDefaultComponentStyle, useRef } from '@codeleap/common'
|
|
6
|
-
import { SliderComposition } from './styles'
|
|
7
|
-
import { StylesOf } from '../../types'
|
|
2
|
+
import { onMount, TypeGuards, useRef } from '@codeleap/common'
|
|
8
3
|
import { View } from '../View'
|
|
9
|
-
import {
|
|
10
|
-
import { SliderPresets } from './styles'
|
|
4
|
+
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
11
5
|
import { Text } from '../Text'
|
|
12
|
-
|
|
13
6
|
import {
|
|
14
7
|
Root as SliderContainer,
|
|
15
8
|
Track as SliderTrack,
|
|
@@ -17,30 +10,13 @@ import {
|
|
|
17
10
|
Range as SliderRange,
|
|
18
11
|
SliderProps as PrimitiveSliderProps,
|
|
19
12
|
} 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'
|
|
20
17
|
|
|
21
18
|
export * from './styles'
|
|
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
|
-
}
|
|
19
|
+
export * from './types'
|
|
44
20
|
|
|
45
21
|
const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
46
22
|
const { style } = props
|
|
@@ -51,17 +27,17 @@ const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
|
51
27
|
</React.Fragment>
|
|
52
28
|
}
|
|
53
29
|
|
|
54
|
-
return <Text
|
|
55
|
-
text={props.content}
|
|
56
|
-
css={style}
|
|
57
|
-
/>
|
|
30
|
+
return <Text text={props.content} style={style} />
|
|
58
31
|
}
|
|
59
32
|
|
|
60
33
|
export const Slider = (props: SliderProps) => {
|
|
61
34
|
const {
|
|
62
35
|
inputBaseProps,
|
|
63
36
|
others,
|
|
64
|
-
} = selectInputBaseProps(
|
|
37
|
+
} = selectInputBaseProps({
|
|
38
|
+
...Slider.defaultProps,
|
|
39
|
+
...props,
|
|
40
|
+
})
|
|
65
41
|
|
|
66
42
|
const {
|
|
67
43
|
onValueChange,
|
|
@@ -69,25 +45,24 @@ export const Slider = (props: SliderProps) => {
|
|
|
69
45
|
value: _value,
|
|
70
46
|
label,
|
|
71
47
|
debugName,
|
|
72
|
-
styles = {},
|
|
73
|
-
responsiveVariants = {},
|
|
74
48
|
style,
|
|
75
49
|
disabled,
|
|
76
|
-
variants,
|
|
77
50
|
trackMarks,
|
|
78
|
-
trackMarkComponent = DefaultSliderTrackMark,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
indicatorLabel
|
|
83
|
-
description
|
|
84
|
-
minStepsBetweenThumbs
|
|
85
|
-
step
|
|
86
|
-
onPressThumbSetValue
|
|
87
|
-
onPressThumb
|
|
51
|
+
trackMarkComponent: SliderTrackMark = DefaultSliderTrackMark,
|
|
52
|
+
max,
|
|
53
|
+
min,
|
|
54
|
+
defaultValue: defaultSliderValue,
|
|
55
|
+
indicatorLabel,
|
|
56
|
+
description,
|
|
57
|
+
minStepsBetweenThumbs,
|
|
58
|
+
step,
|
|
59
|
+
onPressThumbSetValue,
|
|
60
|
+
onPressThumb,
|
|
88
61
|
...sliderProps
|
|
89
62
|
} = others
|
|
90
63
|
|
|
64
|
+
const styles = useStylesFor(Slider.styleRegistryName, style)
|
|
65
|
+
|
|
91
66
|
const isUniqueValue = !TypeGuards.isArray(_value)
|
|
92
67
|
const value = isUniqueValue ? [_value] : _value
|
|
93
68
|
|
|
@@ -102,49 +77,41 @@ export const Slider = (props: SliderProps) => {
|
|
|
102
77
|
}
|
|
103
78
|
})
|
|
104
79
|
|
|
105
|
-
const SliderTrackMark = trackMarkComponent
|
|
106
|
-
|
|
107
80
|
const handleChange: SliderProps['onValueChange'] = (newValue: Array<number>) => {
|
|
108
|
-
onValueChange(isUniqueValue ? newValue?.[0] : newValue)
|
|
81
|
+
onValueChange?.(isUniqueValue ? newValue?.[0] : newValue)
|
|
109
82
|
}
|
|
110
83
|
|
|
111
84
|
const handleValueCommit = (newValue: Array<number>) => {
|
|
112
85
|
onValueCommit?.(newValue)
|
|
113
86
|
}
|
|
114
87
|
|
|
115
|
-
const variantStyles = useDefaultComponentStyle<'u:Slider', typeof SliderPresets>('u:Slider', {
|
|
116
|
-
responsiveVariants,
|
|
117
|
-
variants,
|
|
118
|
-
styles,
|
|
119
|
-
})
|
|
120
|
-
|
|
121
88
|
const thumbStyle = React.useMemo(() => {
|
|
122
|
-
return
|
|
123
|
-
|
|
124
|
-
disabled &&
|
|
89
|
+
return mergeStyles([
|
|
90
|
+
styles.thumb,
|
|
91
|
+
disabled && styles['thumb:disabled'],
|
|
125
92
|
])
|
|
126
93
|
}, [])
|
|
127
94
|
|
|
128
95
|
const trackStyle = React.useMemo(() => {
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
disabled &&
|
|
132
|
-
|
|
133
|
-
disabled &&
|
|
96
|
+
return mergeStyles([
|
|
97
|
+
styles.track,
|
|
98
|
+
disabled && styles['track:disabled'],
|
|
99
|
+
styles.unselectedTrack,
|
|
100
|
+
disabled && styles['unselectedTrack:disabled'],
|
|
134
101
|
])
|
|
135
102
|
}, [disabled])
|
|
136
103
|
|
|
137
104
|
const selectedTrackStyle = React.useMemo(() => {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
disabled &&
|
|
105
|
+
return mergeStyles([
|
|
106
|
+
styles.selectedTrack,
|
|
107
|
+
disabled && styles['selectedTrack:disabled'],
|
|
141
108
|
])
|
|
142
109
|
}, [disabled])
|
|
143
110
|
|
|
144
111
|
const containerStyle = React.useMemo(() => {
|
|
145
|
-
return
|
|
146
|
-
|
|
147
|
-
disabled &&
|
|
112
|
+
return mergeStyles([
|
|
113
|
+
styles.sliderContainer,
|
|
114
|
+
disabled && styles['sliderContainer:disabled'],
|
|
148
115
|
])
|
|
149
116
|
}, [disabled])
|
|
150
117
|
|
|
@@ -158,17 +125,17 @@ export const Slider = (props: SliderProps) => {
|
|
|
158
125
|
}, [trackMarksHaveContent])
|
|
159
126
|
|
|
160
127
|
const trackMarkStyle = React.useMemo(() => {
|
|
161
|
-
return
|
|
162
|
-
|
|
163
|
-
disabled &&
|
|
128
|
+
return mergeStyles([
|
|
129
|
+
styles.trackMark,
|
|
130
|
+
disabled && styles['trackMark:disabled'],
|
|
164
131
|
])
|
|
165
132
|
}, [disabled])
|
|
166
133
|
|
|
167
134
|
const trackMarkWrapperStyle = React.useMemo(() => {
|
|
168
|
-
return [
|
|
169
|
-
|
|
170
|
-
disabled &&
|
|
171
|
-
]
|
|
135
|
+
return mergeStyles([
|
|
136
|
+
styles.trackMarkWrapper,
|
|
137
|
+
disabled && styles['trackMarkWrapper:disabled'],
|
|
138
|
+
])
|
|
172
139
|
}, [disabled])
|
|
173
140
|
|
|
174
141
|
const sliderLabel = React.useMemo(() => {
|
|
@@ -200,12 +167,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
200
167
|
<InputBase
|
|
201
168
|
{...inputBaseProps}
|
|
202
169
|
disabled={disabled}
|
|
203
|
-
|
|
204
|
-
...variantStyles,
|
|
205
|
-
innerWrapper: [
|
|
206
|
-
variantStyles.innerWrapper,
|
|
207
|
-
],
|
|
208
|
-
}}
|
|
170
|
+
style={styles}
|
|
209
171
|
labelAsRow
|
|
210
172
|
description={sliderLabel}
|
|
211
173
|
>
|
|
@@ -239,7 +201,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
239
201
|
</SliderContainer>
|
|
240
202
|
|
|
241
203
|
{trackMarksProp ?
|
|
242
|
-
<View
|
|
204
|
+
<View style={trackMarkWrapperStyle}>
|
|
243
205
|
{
|
|
244
206
|
trackMarksProp.map((_, idx) => {
|
|
245
207
|
let idxStyle = {}
|
|
@@ -247,9 +209,9 @@ export const Slider = (props: SliderProps) => {
|
|
|
247
209
|
const relativeValue = Number(trackMarksProp[idx])
|
|
248
210
|
|
|
249
211
|
if (idx === 0) {
|
|
250
|
-
idxStyle =
|
|
212
|
+
idxStyle = styles.firstTrackMark
|
|
251
213
|
} else if (idx === trackMarksProp.length - 1) {
|
|
252
|
-
idxStyle =
|
|
214
|
+
idxStyle = styles.lastTrackMark
|
|
253
215
|
} else {
|
|
254
216
|
const markerPosition = (relativeValue / max) * 100
|
|
255
217
|
|
|
@@ -261,10 +223,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
261
223
|
}
|
|
262
224
|
}
|
|
263
225
|
|
|
264
|
-
const style = [
|
|
265
|
-
trackMarkStyle,
|
|
266
|
-
idxStyle,
|
|
267
|
-
]
|
|
226
|
+
const style = mergeStyles([trackMarkStyle, idxStyle])
|
|
268
227
|
|
|
269
228
|
if (!trackMarksHaveContent) {
|
|
270
229
|
return <SliderTrackMark
|
|
@@ -292,4 +251,37 @@ export const Slider = (props: SliderProps) => {
|
|
|
292
251
|
)
|
|
293
252
|
}
|
|
294
253
|
|
|
295
|
-
|
|
254
|
+
Slider.styleRegistryName = 'Slider'
|
|
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)
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
import { IconLessInputBaseParts, InputBaseParts, InputBaseStates } from '../InputBase'
|
|
3
2
|
|
|
4
|
-
type SliderParts =
|
|
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
|
+
|
|
5
16
|
type SliderStates = Exclude<InputBaseStates, 'focus'>
|
|
6
17
|
|
|
7
18
|
export type SliderComposition = `${SliderParts}:${SliderStates}` | SliderParts
|
|
8
|
-
|
|
9
|
-
const createSliderStyle = createDefaultVariantFactory<SliderComposition>()
|
|
10
|
-
|
|
11
|
-
export const SliderPresets = includePresets((styles) => createSliderStyle(() => ({ wrapper: styles })))
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StyledProp } from '@codeleap/styles'
|
|
2
|
+
import { InputBaseProps } from '../InputBase'
|
|
3
|
+
import { SliderComposition } from './styles'
|
|
4
|
+
import { SliderProps as PrimitiveSliderProps } from '@radix-ui/react-slider'
|
|
5
|
+
import { CSSProperties } from 'react'
|
|
6
|
+
|
|
7
|
+
export type SliderProps =
|
|
8
|
+
Partial<Omit<PrimitiveSliderProps, 'value' | 'onValueChange' | 'style'>> &
|
|
9
|
+
Pick<InputBaseProps, 'disabled' | 'debugName' | 'description' | 'label'> &
|
|
10
|
+
{
|
|
11
|
+
indicatorLabel?: {
|
|
12
|
+
order?: number[]
|
|
13
|
+
separator?: string
|
|
14
|
+
transformer?: (value: number[], defaultValue: PrimitiveSliderProps['defaultValue']) => string
|
|
15
|
+
}
|
|
16
|
+
value: number | number[]
|
|
17
|
+
onValueChange: (val: number | number[]) => void
|
|
18
|
+
style?: StyledProp<SliderComposition>
|
|
19
|
+
trackMarks?: Record<number, string>
|
|
20
|
+
trackMarkComponent?: React.ComponentType<TrackMarkProps>
|
|
21
|
+
onPressThumbSetValue?: boolean
|
|
22
|
+
onPressThumb?: (value: number | number[], thumbIndex: number) => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type TrackMarkProps = {
|
|
26
|
+
index: number
|
|
27
|
+
content?: string | React.ReactNode
|
|
28
|
+
style?: CSSProperties
|
|
29
|
+
}
|