@codeleap/web 3.24.3 → 3.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +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 -104
- package/src/components/CropPicker/styles.ts +0 -7
- package/src/components/CropPicker/types.ts +8 -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,87 +1,115 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
1
|
import React, { useCallback } from 'react'
|
|
3
|
-
import { ActionIcon, Collapse,
|
|
2
|
+
import { ActionIcon, Collapse, View } from '../components'
|
|
4
3
|
import { HexColorPicker } from 'react-colorful'
|
|
5
|
-
import {
|
|
6
|
-
import { ColorPickerProps, ColorTypes } from './types'
|
|
4
|
+
import { TypeGuards, useConditionalState, useState } from '@codeleap/common'
|
|
5
|
+
import { ColorPickerProps, ColorTypes, ColorPickerFooterProps } from './types'
|
|
6
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
7
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
8
|
+
import { AnyRecord, AppIcon, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
7
9
|
|
|
8
10
|
export * from './styles'
|
|
9
11
|
export * from './types'
|
|
10
12
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const DefaultFooter = (props: ColorPickerFooterProps) => {
|
|
14
|
+
const { styles, clearIcon, handleClear, confirmIcon, handleConfirmation } = props
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<View style={styles.footerWrapper}>
|
|
18
|
+
<ActionIcon
|
|
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
|
+
)
|
|
17
32
|
}
|
|
18
33
|
|
|
19
34
|
export const ColorPicker = (props: ColorPickerProps) => {
|
|
20
35
|
const {
|
|
21
|
-
isPlain
|
|
36
|
+
isPlain,
|
|
22
37
|
initialColor,
|
|
23
38
|
showFooter,
|
|
24
39
|
icon,
|
|
40
|
+
style,
|
|
25
41
|
clearIcon,
|
|
26
42
|
confirmIcon,
|
|
27
|
-
variants = [],
|
|
28
|
-
styles = {},
|
|
29
|
-
responsiveVariants = {},
|
|
30
43
|
onConfirm,
|
|
31
44
|
onClear,
|
|
32
|
-
closeOnConfirm
|
|
45
|
+
closeOnConfirm,
|
|
33
46
|
pickerComponent: PickerComponent,
|
|
34
47
|
openPickerComponent: OpenPickerComponent,
|
|
35
|
-
footerComponent: FooterComponent
|
|
48
|
+
footerComponent: FooterComponent,
|
|
36
49
|
openPickerProps,
|
|
37
|
-
} =
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
} = {
|
|
51
|
+
...ColorPicker.defaultProps,
|
|
52
|
+
...props,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const styles = useStylesFor(ColorPicker.styleRegistryName, style)
|
|
40
56
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
responsiveVariants,
|
|
45
|
-
})
|
|
57
|
+
const [visible, toggle] = useConditionalState(props?.visible, props?.toggle, { initialValue: false })
|
|
58
|
+
|
|
59
|
+
const [color, setColor] = useState<ColorTypes>(initialColor)
|
|
46
60
|
|
|
47
|
-
const handleConfirmation = useCallback(() => {
|
|
61
|
+
const handleConfirmation = useCallback((color: ColorTypes) => {
|
|
48
62
|
onConfirm?.(color)
|
|
49
|
-
closeOnConfirm
|
|
50
|
-
}, [
|
|
63
|
+
if (closeOnConfirm) toggle(false)
|
|
64
|
+
}, [])
|
|
51
65
|
|
|
52
|
-
const handleClear = useCallback(() => {
|
|
66
|
+
const handleClear = useCallback((initialColor: ColorTypes) => {
|
|
53
67
|
setColor(initialColor)
|
|
54
|
-
onClear?.()
|
|
55
|
-
}, [
|
|
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])
|
|
68
|
+
if (TypeGuards.isFunction(onClear)) onClear?.()
|
|
69
|
+
}, [])
|
|
63
70
|
|
|
64
71
|
// Dragging to change the color in any other way does not seem to work for some reason.
|
|
65
|
-
const picker = <View style={
|
|
72
|
+
const picker = <View style={styles.picker}><PickerComponent color={color} onChange={setColor} /></View>
|
|
66
73
|
|
|
67
|
-
const
|
|
68
|
-
|
|
74
|
+
const openColorPickerBtn = !!OpenPickerComponent ? (
|
|
75
|
+
<OpenPickerComponent
|
|
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
|
+
)
|
|
69
87
|
|
|
70
88
|
return (
|
|
71
|
-
<View style={
|
|
89
|
+
<View style={styles.wrapper}>
|
|
72
90
|
{isPlain ? picker : (
|
|
73
91
|
<>
|
|
74
92
|
{openColorPickerBtn}
|
|
75
93
|
<Collapse
|
|
76
94
|
open={visible}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
visible &&
|
|
80
|
-
]
|
|
95
|
+
style={[
|
|
96
|
+
styles.dropdown,
|
|
97
|
+
visible && styles['dropdown:open'],
|
|
98
|
+
]}
|
|
81
99
|
>
|
|
82
|
-
<View style={
|
|
100
|
+
<View style={styles.dropdownInnerWrapper}>
|
|
83
101
|
{picker}
|
|
84
|
-
|
|
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}
|
|
85
113
|
</View>
|
|
86
114
|
</Collapse>
|
|
87
115
|
</>
|
|
@@ -90,4 +118,23 @@ export const ColorPicker = (props: ColorPickerProps) => {
|
|
|
90
118
|
)
|
|
91
119
|
}
|
|
92
120
|
|
|
93
|
-
ColorPicker.
|
|
121
|
+
ColorPicker.styleRegistryName = '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)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { PartialComponentStyle, createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
-
import { ActionIconComposition } from '../ActionIcon'
|
|
3
|
-
|
|
4
1
|
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>()
|
|
12
2
|
|
|
13
|
-
export
|
|
3
|
+
export type ColorPickerParts =
|
|
4
|
+
'wrapper' |
|
|
5
|
+
'picker' |
|
|
6
|
+
'dropdown' |
|
|
7
|
+
`dropdown:${ColorPickerState}` |
|
|
8
|
+
'dropdownInnerWrapper' |
|
|
9
|
+
'footerWrapper' |
|
|
10
|
+
'clearIcon' |
|
|
11
|
+
'confirmIcon'
|
|
12
|
+
|
|
13
|
+
export type ColorPickerComposition = ColorPickerParts
|
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { ActionIconProps,
|
|
2
|
+
import { ActionIconProps, ColorPickerComposition } from '../components'
|
|
3
|
+
import { AppIcon, ICSS, StyledProp } from '@codeleap/styles'
|
|
3
4
|
import { RgbColor, RgbaColor, HslColor, HsvColor, HslaColor, HsvaColor } from 'react-colorful'
|
|
4
|
-
import { ComponentVariants } from '@codeleap/common'
|
|
5
|
-
import { ColorPickerComposition, ColorPickerPresets } from './styles'
|
|
6
5
|
|
|
7
6
|
export type ColorTypes = RgbColor | HslColor | HsvColor | RgbaColor | HslaColor | HsvaColor | string
|
|
8
7
|
|
|
9
|
-
export type
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export type ColorPickerFooterProps = Pick<ColorPickerProps, 'confirmIcon' | 'clearIcon'> & {
|
|
9
|
+
color?: ColorTypes
|
|
10
|
+
handleConfirmation: (value: ColorTypes) => void
|
|
11
|
+
handleClear: (value: ColorTypes) => void
|
|
12
|
+
styles: Record<ColorPickerComposition, ICSS>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type ColorPickerPickerProps = {
|
|
16
|
+
color: ColorTypes
|
|
17
|
+
visible: boolean
|
|
18
|
+
toggle: (v?: boolean) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ColorPickerProps = {
|
|
22
|
+
style?: StyledProp<ColorPickerComposition>
|
|
12
23
|
isPlain?: boolean
|
|
13
24
|
closeOnConfirm?: boolean
|
|
14
25
|
initialColor?: ColorTypes
|
|
15
26
|
showFooter?: boolean
|
|
16
|
-
icon?:
|
|
17
|
-
clearIcon?:
|
|
18
|
-
confirmIcon?:
|
|
27
|
+
icon?: AppIcon
|
|
28
|
+
clearIcon?: AppIcon
|
|
29
|
+
confirmIcon?: AppIcon
|
|
19
30
|
openPickerProps?: ActionIconProps
|
|
20
31
|
onConfirm?: (color: ColorTypes) => void
|
|
21
32
|
onClear?: () => void
|
|
22
|
-
openPickerComponent?: (props:
|
|
33
|
+
openPickerComponent?: (props: ColorPickerPickerProps) => JSX.Element
|
|
23
34
|
pickerComponent?: (props: any) => JSX.Element
|
|
24
|
-
footerComponent?: (props:
|
|
25
|
-
|
|
35
|
+
footerComponent?: (props: ColorPickerFooterProps) => JSX.Element
|
|
36
|
+
visible?: boolean
|
|
37
|
+
toggle?: React.Dispatch<React.SetStateAction<boolean>>
|
|
38
|
+
children?: React.ReactNode
|
|
39
|
+
}
|
|
@@ -1,119 +1,115 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
getNestedStylesByKey,
|
|
4
|
-
useDefaultComponentStyle,
|
|
5
|
-
} from '@codeleap/common'
|
|
6
|
-
import { CropPickerPresets } from './styles'
|
|
1
|
+
import React, { forwardRef, Ref } from 'react'
|
|
2
|
+
import { StyledComponentWithProps, useCompositionStyles } from '@codeleap/styles'
|
|
7
3
|
import { CropPickerProps } from './types'
|
|
8
|
-
import { useCropPicker } from '
|
|
9
|
-
import {
|
|
4
|
+
import { useCropPicker } from '../../lib'
|
|
5
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
6
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
7
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
8
|
+
import { FileInput, FileInputRef } from '../FileInput'
|
|
9
|
+
import { Modal } from '../Modal'
|
|
10
|
+
import { Button } from '../Button'
|
|
11
|
+
import { LoadingOverlay } from '../LoadingOverlay'
|
|
10
12
|
|
|
11
13
|
const ReactCrop: React.ElementType = require('react-image-crop').Component
|
|
14
|
+
|
|
12
15
|
import 'react-image-crop/dist/ReactCrop.css'
|
|
13
16
|
|
|
14
17
|
export * from './styles'
|
|
15
18
|
export * from './types'
|
|
16
|
-
export * from './utils'
|
|
17
|
-
export * from './useCropPicker'
|
|
18
19
|
|
|
19
|
-
export const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
export const CropPicker = forwardRef<FileInputRef, CropPickerProps>((props, ref) => {
|
|
21
|
+
const {
|
|
22
|
+
onFileSelect,
|
|
23
|
+
targetCrop,
|
|
24
|
+
modalProps,
|
|
25
|
+
title,
|
|
26
|
+
confirmButton,
|
|
27
|
+
debugName,
|
|
28
|
+
handle,
|
|
29
|
+
withLoading,
|
|
30
|
+
style,
|
|
31
|
+
confirmButtonProps,
|
|
32
|
+
...fileInputProps
|
|
33
|
+
} = {
|
|
34
|
+
...CropPicker.defaultProps,
|
|
35
|
+
...props,
|
|
36
|
+
}
|
|
26
37
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
confirmButtonProps,
|
|
40
|
-
...fileInputProps
|
|
41
|
-
} = allProps
|
|
38
|
+
const {
|
|
39
|
+
onConfirmCrop,
|
|
40
|
+
onFilesReturned,
|
|
41
|
+
onClose,
|
|
42
|
+
fileInputRef,
|
|
43
|
+
visible,
|
|
44
|
+
image,
|
|
45
|
+
crop,
|
|
46
|
+
setRelativeCrop,
|
|
47
|
+
isLoading,
|
|
48
|
+
handleCropChange,
|
|
49
|
+
} = handle || useCropPicker({ onFileSelect, ref: ref as unknown as Ref<FileInputRef>, ...targetCrop })
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
onConfirmCrop,
|
|
45
|
-
onFilesReturned,
|
|
46
|
-
onClose,
|
|
47
|
-
fileInputRef,
|
|
48
|
-
visible,
|
|
49
|
-
image,
|
|
50
|
-
crop,
|
|
51
|
-
setRelativeCrop,
|
|
52
|
-
isLoading,
|
|
53
|
-
handleCropChange,
|
|
54
|
-
} = handle || useCropPicker({ onFileSelect, ref, ...targetCrop })
|
|
51
|
+
const styles = useStylesFor(CropPicker.styleRegistryName, style)
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
'u:CropPicker',
|
|
58
|
-
typeof CropPickerPresets
|
|
59
|
-
>('u:CropPicker', {
|
|
60
|
-
variants,
|
|
61
|
-
responsiveVariants,
|
|
62
|
-
styles,
|
|
63
|
-
})
|
|
53
|
+
const composition = useCompositionStyles(['confirmButton', 'modal'], styles)
|
|
64
54
|
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
<FileInput
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
ref={fileInputRef}
|
|
60
|
+
onChange={(files) => onFilesReturned(files)}
|
|
61
|
+
{...fileInputProps}
|
|
62
|
+
/>
|
|
67
63
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
64
|
+
<Modal
|
|
65
|
+
visible={visible}
|
|
66
|
+
toggle={onClose}
|
|
67
|
+
title={title}
|
|
68
|
+
footer={
|
|
69
|
+
<Button
|
|
70
|
+
text={confirmButton}
|
|
71
|
+
style={composition?.confirmButton}
|
|
72
|
+
onPress={onConfirmCrop}
|
|
73
|
+
debugName={debugName}
|
|
74
|
+
{...confirmButtonProps}
|
|
75
|
+
/>
|
|
76
|
+
}
|
|
77
|
+
{...modalProps}
|
|
78
|
+
style={composition?.modal}
|
|
79
|
+
>
|
|
80
|
+
{!!image?.src ? (
|
|
81
|
+
<ReactCrop
|
|
82
|
+
crop={crop}
|
|
83
|
+
onChange={handleCropChange}
|
|
84
|
+
onComplete={(_, relCrop) => setRelativeCrop(relCrop)}
|
|
85
|
+
{...targetCrop}
|
|
86
|
+
style={styles.previewSize}
|
|
87
|
+
>
|
|
88
|
+
<img
|
|
89
|
+
src={image?.src}
|
|
90
|
+
// @ts-expect-error
|
|
91
|
+
css={[styles.cropPreview, styles.previewSize]}
|
|
87
92
|
/>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
visible={isLoading}
|
|
110
|
-
/>
|
|
111
|
-
) : null
|
|
112
|
-
}
|
|
113
|
-
</Modal>
|
|
114
|
-
</>
|
|
115
|
-
)
|
|
116
|
-
},
|
|
117
|
-
)
|
|
93
|
+
</ReactCrop>
|
|
94
|
+
) : null}
|
|
95
|
+
{withLoading ? <LoadingOverlay debugName='CropPicker' visible={isLoading} /> : null}
|
|
96
|
+
</Modal>
|
|
97
|
+
</>
|
|
98
|
+
)
|
|
99
|
+
}) as StyledComponentWithProps<CropPickerProps>
|
|
100
|
+
|
|
101
|
+
CropPicker.styleRegistryName = 'CropPicker'
|
|
102
|
+
CropPicker.elements = ['previewSize', 'cropPreview', 'confirmButton', 'modal']
|
|
103
|
+
CropPicker.rootElement = 'previewSize'
|
|
104
|
+
|
|
105
|
+
CropPicker.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
106
|
+
return CropPicker as (props: StyledComponentProps<CropPickerProps, typeof styles>) => IJSX
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
CropPicker.defaultProps = {
|
|
110
|
+
title: 'Crop Image',
|
|
111
|
+
confirmButton: 'Confirm Crop',
|
|
112
|
+
withLoading: false,
|
|
113
|
+
} as Partial<CropPickerProps>
|
|
118
114
|
|
|
119
|
-
|
|
115
|
+
WebStyleRegistry.registerComponent(CropPicker)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
import { ButtonComposition } from '../Button'
|
|
3
2
|
import { ModalComposition } from '../Modal'
|
|
4
3
|
|
|
@@ -7,9 +6,3 @@ export type CropPickerComposition =
|
|
|
7
6
|
| 'previewSize'
|
|
8
7
|
| `confirmButton${Capitalize<ButtonComposition>}`
|
|
9
8
|
| `modal${Capitalize<ModalComposition>}`
|
|
10
|
-
|
|
11
|
-
const createCropPickerStyle =
|
|
12
|
-
createDefaultVariantFactory<CropPickerComposition>()
|
|
13
|
-
|
|
14
|
-
export const CropPickerPresets = includePresets((style) => createCropPickerStyle(() => ({ modalWrapper: style })),
|
|
15
|
-
)
|
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FileInputProps
|
|
3
|
-
import { CropPickerComposition
|
|
4
|
-
import { StylesOf } from '../../types'
|
|
1
|
+
import { StyledProp } from '@codeleap/styles'
|
|
2
|
+
import { FileInputProps } from '../FileInput'
|
|
3
|
+
import { CropPickerComposition } from './styles'
|
|
5
4
|
import { ReactCropProps } from 'react-image-crop'
|
|
6
5
|
import { ModalProps } from '../Modal'
|
|
7
|
-
import { useCropPicker } from '
|
|
6
|
+
import { useCropPicker } from '../../lib'
|
|
8
7
|
import { ButtonProps } from '../Button'
|
|
9
8
|
|
|
10
9
|
export type BaseCropProps = Partial<ReactCropProps>
|
|
11
10
|
|
|
12
|
-
export type CropPickerProps =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
style?:
|
|
11
|
+
export type CropPickerProps =
|
|
12
|
+
Partial<FileInputProps> &
|
|
13
|
+
{
|
|
14
|
+
style?: StyledProp<CropPickerComposition>
|
|
16
15
|
targetCrop?: BaseCropProps
|
|
17
16
|
modalProps?: Partial<ModalProps>
|
|
18
17
|
title?: string
|
|
19
18
|
confirmButton?: string
|
|
20
19
|
debugName: string
|
|
21
20
|
handle?: ReturnType<typeof useCropPicker>
|
|
22
|
-
ref: AnyRef<HTMLElement>
|
|
23
21
|
withLoading?: boolean
|
|
24
22
|
confirmButtonProps?: Partial<ButtonProps>
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export type ImageReading = HTMLImageElement
|
|
28
|
-
|
|
29
|
-
export type UseCropPickerProps = Partial<ReactCropProps> & {
|
|
30
|
-
onFileSelect: FileInputProps['onFileSelect']
|
|
31
|
-
ref: React.MutableRefObject<FileInputRef> | React.Ref<FileInputRef>
|
|
32
|
-
}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IconPlaceholder,
|
|
3
|
-
TypeGuards,
|
|
4
|
-
getNestedStylesByKey,
|
|
5
|
-
} from '@codeleap/common'
|
|
1
|
+
import { TypeGuards } from '@codeleap/common'
|
|
6
2
|
import { ActionIcon, Text, View } from '../../components'
|
|
7
3
|
import { DatePickerArrowProps, DatePickerHeaderComponent } from '../types'
|
|
8
4
|
import { format, getYear } from 'date-fns'
|
|
5
|
+
import { AppIcon, useCompositionStyles } from '@codeleap/styles'
|
|
9
6
|
|
|
10
|
-
export const ArrowLabel:
|
|
11
|
-
name,
|
|
12
|
-
direction,
|
|
13
|
-
...props
|
|
14
|
-
}) => {
|
|
7
|
+
export const ArrowLabel = ({ name, direction, ...props }: DatePickerArrowProps) => {
|
|
15
8
|
return (
|
|
16
9
|
<ActionIcon
|
|
17
|
-
name={name ?? (`chevron-${direction}` as
|
|
10
|
+
name={name ?? (`chevron-${direction}` as AppIcon)}
|
|
18
11
|
debugName={'Calendar arrowLabel'}
|
|
19
12
|
{...props}
|
|
20
13
|
/>
|
|
@@ -44,15 +37,14 @@ export const Header = (props: DatePickerHeaderComponent) => {
|
|
|
44
37
|
? formatHeaderTitle(date)
|
|
45
38
|
: `${month} ${year}`
|
|
46
39
|
|
|
47
|
-
const
|
|
48
|
-
const nextArrow = getNestedStylesByKey('nextButton', styles)
|
|
40
|
+
const compositionStyles = useCompositionStyles(['prevButton', 'nextButton'], styles)
|
|
49
41
|
|
|
50
42
|
return (
|
|
51
43
|
<View style={styles.wrapper}>
|
|
52
44
|
<View style={styles.buttonsWrapper}>
|
|
53
45
|
<ArrowLabel
|
|
54
46
|
direction='left'
|
|
55
|
-
|
|
47
|
+
style={compositionStyles.prevButton}
|
|
56
48
|
onPress={decreaseYear}
|
|
57
49
|
disabled={prevYearButtonDisabled}
|
|
58
50
|
/>
|
|
@@ -63,7 +55,7 @@ export const Header = (props: DatePickerHeaderComponent) => {
|
|
|
63
55
|
/>
|
|
64
56
|
<ArrowLabel
|
|
65
57
|
direction='right'
|
|
66
|
-
|
|
58
|
+
style={compositionStyles.nextButton}
|
|
67
59
|
onPress={increaseYear}
|
|
68
60
|
disabled={nextYearButtonDisabled}
|
|
69
61
|
/>
|
|
@@ -71,13 +63,13 @@ export const Header = (props: DatePickerHeaderComponent) => {
|
|
|
71
63
|
<View style={styles.buttonsWrapper}>
|
|
72
64
|
<ArrowLabel
|
|
73
65
|
direction='left'
|
|
74
|
-
|
|
66
|
+
style={compositionStyles.prevButton}
|
|
75
67
|
onPress={decreaseMonth}
|
|
76
68
|
disabled={prevMonthButtonDisabled}
|
|
77
69
|
/>
|
|
78
70
|
<ArrowLabel
|
|
79
71
|
direction='right'
|
|
80
|
-
|
|
72
|
+
style={compositionStyles.nextButton}
|
|
81
73
|
onPress={increaseMonth}
|
|
82
74
|
disabled={nextMonthButtonDisabled}
|
|
83
75
|
/>
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { TextInput } from '../../components'
|
|
2
2
|
import { DatePickerProps } from '../types'
|
|
3
3
|
|
|
4
|
-
export const OuterInput: DatePickerProps['outerInputComponent'] = ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return hideInput ? null : (
|
|
4
|
+
export const OuterInput: DatePickerProps['outerInputComponent'] = ({ valueLabel, focused, hideInput, ...props }) => {
|
|
5
|
+
if (hideInput) {
|
|
6
|
+
return null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return (
|
|
11
10
|
<TextInput
|
|
12
11
|
validate={!focused && props?.validate}
|
|
13
12
|
debugName='DatePicker - OuterInputComponent'
|