@codeleap/web 3.24.3 → 4.0.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,57 +1,55 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { CSSObject, jsx } from '@emotion/react'
|
|
3
|
-
import { CSSInterpolation } from '@emotion/css'
|
|
4
|
-
import {
|
|
5
|
-
ComponentVariants,
|
|
6
|
-
IconPlaceholder,
|
|
7
|
-
IconStyles,
|
|
8
|
-
useDefaultComponentStyle,
|
|
9
|
-
useCodeleapContext,
|
|
10
|
-
} from '@codeleap/common'
|
|
11
1
|
import { View } from '../View'
|
|
12
|
-
import {
|
|
2
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
3
|
+
import { AnyRecord, AppTheme, IJSX, StyledComponentProps, Theme, useTheme } from '@codeleap/styles'
|
|
4
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
5
|
+
import { IconProps } from './types'
|
|
13
6
|
|
|
14
7
|
export * from './styles'
|
|
8
|
+
export * from './types'
|
|
15
9
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
styles: {
|
|
33
|
-
icon: style,
|
|
34
|
-
},
|
|
35
|
-
rootElement: 'icon',
|
|
36
|
-
})
|
|
10
|
+
export const Icon = (props:IconProps) => {
|
|
11
|
+
const {
|
|
12
|
+
name,
|
|
13
|
+
style,
|
|
14
|
+
renderEmptySpace,
|
|
15
|
+
...otherProps
|
|
16
|
+
} = {
|
|
17
|
+
...Icon.defaultProps,
|
|
18
|
+
...props,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const theme = useTheme(store => store.current) as AppTheme<Theme>
|
|
22
|
+
|
|
23
|
+
const styles = useStylesFor(Icon.styleRegistryName, style)
|
|
24
|
+
|
|
25
|
+
const Component = theme?.icons?.[name]
|
|
37
26
|
|
|
38
27
|
if (!name) {
|
|
39
|
-
const iconStyle =
|
|
40
|
-
return renderEmptySpace ? <View css={{
|
|
41
|
-
height: iconStyle.size ?? iconStyle.height,
|
|
42
|
-
width: iconStyle.size ?? iconStyle.width,
|
|
43
|
-
}}/> : null
|
|
44
|
-
}
|
|
28
|
+
const iconStyle = styles.icon as React.CSSProperties & { size: number }
|
|
45
29
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
return renderEmptySpace ? (
|
|
31
|
+
<View
|
|
32
|
+
style={{
|
|
33
|
+
height: iconStyle.size ?? iconStyle.height,
|
|
34
|
+
width: iconStyle.size ?? iconStyle.width,
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
) : null
|
|
53
38
|
}
|
|
54
|
-
|
|
39
|
+
|
|
40
|
+
if (!Component) return null
|
|
41
|
+
|
|
42
|
+
return <Component {...otherProps} style={styles.icon} />
|
|
55
43
|
}
|
|
56
44
|
|
|
57
|
-
|
|
45
|
+
Icon.styleRegistryName = 'Icon'
|
|
46
|
+
Icon.elements = ['icon']
|
|
47
|
+
Icon.rootElement = 'icon'
|
|
48
|
+
|
|
49
|
+
Icon.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
50
|
+
return Icon as (props: StyledComponentProps<IconProps, typeof styles>) => IJSX
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Icon.defaultProps = {} as Partial<IconProps>
|
|
54
|
+
|
|
55
|
+
WebStyleRegistry.registerComponent(Icon)
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
|
|
2
|
-
|
|
3
1
|
export type IconComposition = 'icon'
|
|
4
|
-
|
|
5
|
-
const createIconStyle = createDefaultVariantFactory<IconComposition>()
|
|
6
|
-
|
|
7
|
-
export const IconPresets = includePresets((styles) =>
|
|
8
|
-
createIconStyle(() => ({ icon: styles }))
|
|
9
|
-
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentCommonProps } from '../../types'
|
|
2
|
+
import { IconComposition } from './styles'
|
|
3
|
+
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
4
|
+
import { CSSProperties } from 'react'
|
|
5
|
+
|
|
6
|
+
export type IconProps =
|
|
7
|
+
ComponentCommonProps &
|
|
8
|
+
{
|
|
9
|
+
name: AppIcon
|
|
10
|
+
style?: StyledProp<IconComposition>
|
|
11
|
+
size?: string | number
|
|
12
|
+
color?: string
|
|
13
|
+
renderEmptySpace?: boolean
|
|
14
|
+
forceStyle?: CSSProperties
|
|
15
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { jsx } from '@emotion/react'
|
|
3
1
|
import React from 'react'
|
|
4
2
|
import { TypeGuards, getRenderedComponent } from '@codeleap/common'
|
|
5
3
|
import { ActionIcon, ActionIconProps } from '../ActionIcon'
|
|
@@ -7,95 +5,103 @@ import { View } from '../View'
|
|
|
7
5
|
import { useInputBaseStyles } from './styles'
|
|
8
6
|
import { InputBaseProps } from './types'
|
|
9
7
|
import { Text } from '../Text'
|
|
8
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
9
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
10
10
|
|
|
11
11
|
export * from './styles'
|
|
12
12
|
export * from './utils'
|
|
13
13
|
export * from './types'
|
|
14
14
|
|
|
15
|
-
export const InputBaseDefaultOrder:InputBaseProps['order'] = [
|
|
15
|
+
export const InputBaseDefaultOrder: InputBaseProps['order'] = [
|
|
16
16
|
'label',
|
|
17
17
|
'description',
|
|
18
18
|
'innerWrapper',
|
|
19
19
|
'error',
|
|
20
20
|
]
|
|
21
|
+
|
|
21
22
|
const KeyPassthrough = (props: React.PropsWithChildren<any>) => {
|
|
22
23
|
return <React.Fragment>{props.children}</React.Fragment>
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export const InputBase =
|
|
26
|
+
export const InputBase = (props: InputBaseProps) => {
|
|
27
|
+
const allProps = {
|
|
28
|
+
...InputBase.defaultProps,
|
|
29
|
+
...props,
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
const {
|
|
27
33
|
children,
|
|
28
|
-
error
|
|
34
|
+
error,
|
|
29
35
|
label,
|
|
30
|
-
description
|
|
31
|
-
leftIcon
|
|
32
|
-
rightIcon
|
|
33
|
-
styles,
|
|
36
|
+
description,
|
|
37
|
+
leftIcon,
|
|
38
|
+
rightIcon,
|
|
34
39
|
wrapper,
|
|
35
40
|
debugName,
|
|
36
41
|
innerWrapper,
|
|
37
42
|
focused,
|
|
38
|
-
innerWrapperProps
|
|
39
|
-
wrapperProps
|
|
40
|
-
disabled
|
|
41
|
-
order
|
|
43
|
+
innerWrapperProps,
|
|
44
|
+
wrapperProps,
|
|
45
|
+
disabled,
|
|
46
|
+
order,
|
|
42
47
|
style,
|
|
43
|
-
noError
|
|
44
|
-
labelAsRow
|
|
48
|
+
noError,
|
|
49
|
+
labelAsRow,
|
|
45
50
|
innerWrapperRef,
|
|
46
51
|
...otherProps
|
|
47
|
-
} =
|
|
52
|
+
} = allProps
|
|
48
53
|
|
|
49
54
|
const WrapperComponent = wrapper || View
|
|
50
55
|
const InnerWrapperComponent = innerWrapper || View
|
|
51
56
|
|
|
52
|
-
const
|
|
57
|
+
const styles = useInputBaseStyles(allProps)
|
|
53
58
|
|
|
54
59
|
const _leftIcon = getRenderedComponent<Partial<ActionIconProps>>(leftIcon, ActionIcon, {
|
|
55
|
-
|
|
56
|
-
styles: _styles.leftIconStyles,
|
|
60
|
+
style: styles.leftIconStyles,
|
|
57
61
|
disabled,
|
|
58
62
|
debugName: `${debugName} left icon`,
|
|
59
63
|
})
|
|
60
64
|
|
|
61
65
|
const _rightIcon = getRenderedComponent<Partial<ActionIconProps>>(rightIcon, ActionIcon, {
|
|
62
|
-
|
|
63
|
-
styles: _styles.rightIconStyles,
|
|
66
|
+
style: styles.rightIconStyles,
|
|
64
67
|
disabled,
|
|
65
68
|
debugName: `${debugName} right icon`,
|
|
66
69
|
})
|
|
67
70
|
|
|
68
|
-
const _label = TypeGuards.isString(label) ? <Text text={label}
|
|
71
|
+
const _label = TypeGuards.isString(label) ? <Text text={label} style={styles.labelStyle} /> : label
|
|
69
72
|
|
|
70
|
-
const _error = TypeGuards.isString(error) ? <Text text={error}
|
|
73
|
+
const _error = TypeGuards.isString(error) ? <Text text={error} style={styles.errorStyle} /> : error
|
|
71
74
|
|
|
72
|
-
const _description = TypeGuards.isString(description) ? <Text text={description}
|
|
75
|
+
const _description = TypeGuards.isString(description) ? <Text text={description} style={styles.descriptionStyle} /> : description
|
|
73
76
|
|
|
74
77
|
const parts = {
|
|
75
|
-
label: labelAsRow ?
|
|
76
|
-
{
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
]} {...innerWrapperProps}>
|
|
83
|
-
{_leftIcon}
|
|
84
|
-
{children}
|
|
85
|
-
{_rightIcon}
|
|
86
|
-
</InnerWrapperComponent>,
|
|
87
|
-
error: noError ? null : (
|
|
88
|
-
_error || <Text children={<React.Fragment>
|
|
89
|
-
|
|
90
|
-
</React.Fragment>} css={_styles.errorStyle}/>
|
|
78
|
+
label: labelAsRow ? (
|
|
79
|
+
<View style={styles.labelRowStyle}>
|
|
80
|
+
{_label}
|
|
81
|
+
{_description}
|
|
82
|
+
</View>
|
|
83
|
+
) : (
|
|
84
|
+
_label
|
|
91
85
|
),
|
|
86
|
+
description: labelAsRow ? null : _description,
|
|
87
|
+
innerWrapper:
|
|
88
|
+
<InnerWrapperComponent
|
|
89
|
+
ref={innerWrapperRef}
|
|
90
|
+
style={styles.innerWrapperStyle}
|
|
91
|
+
{...innerWrapperProps}
|
|
92
|
+
>
|
|
93
|
+
{_leftIcon}
|
|
94
|
+
{children}
|
|
95
|
+
{_rightIcon}
|
|
96
|
+
</InnerWrapperComponent>,
|
|
97
|
+
error: noError ? null : (_error || <Text children={<React.Fragment> </React.Fragment>} style={styles.errorStyle} />),
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
return (
|
|
95
101
|
<WrapperComponent
|
|
96
|
-
css={[_styles.wrapperStyle, style]}
|
|
97
102
|
{...otherProps}
|
|
98
103
|
{...wrapperProps}
|
|
104
|
+
style={styles.wrapperStyle}
|
|
99
105
|
>
|
|
100
106
|
{
|
|
101
107
|
order.map((key) => (
|
|
@@ -106,4 +112,27 @@ export const InputBase = React.forwardRef<unknown, InputBaseProps>((props, ref)
|
|
|
106
112
|
}
|
|
107
113
|
</WrapperComponent>
|
|
108
114
|
)
|
|
109
|
-
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
InputBase.elements = [
|
|
118
|
+
'wrapper',
|
|
119
|
+
'innerWrapper',
|
|
120
|
+
'label',
|
|
121
|
+
'errorMessage',
|
|
122
|
+
'description',
|
|
123
|
+
'labelRow',
|
|
124
|
+
'icon',
|
|
125
|
+
'leftIcon',
|
|
126
|
+
'rightIcon',
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
InputBase.defaultProps = {
|
|
130
|
+
noError: false,
|
|
131
|
+
labelAsRow: false,
|
|
132
|
+
disabled: false,
|
|
133
|
+
order: InputBaseDefaultOrder,
|
|
134
|
+
rightIcon: null,
|
|
135
|
+
leftIcon: null,
|
|
136
|
+
description: null,
|
|
137
|
+
error: null,
|
|
138
|
+
} as Partial<InputBaseProps>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { TypeGuards
|
|
2
|
-
import {
|
|
1
|
+
import { TypeGuards } from '@codeleap/common'
|
|
2
|
+
import { useCompositionStyles } from '@codeleap/styles'
|
|
3
|
+
import { ActionIconParts } from '../ActionIcon'
|
|
3
4
|
import { InputBaseProps } from './types'
|
|
4
5
|
import { concatStyles, getIconStyles, iconStylesOf } from './utils'
|
|
5
6
|
|
|
@@ -24,86 +25,75 @@ export type IconLessInputBaseParts = Exclude<InputBaseParts, InputIconCompositio
|
|
|
24
25
|
|
|
25
26
|
export type InputBaseComposition = `${InputBaseParts}:${InputBaseStates}` | InputBaseParts
|
|
26
27
|
|
|
27
|
-
const createTextInputBaseComposition = createDefaultVariantFactory<InputBaseComposition>()
|
|
28
|
-
|
|
29
|
-
export const InputBasePresets = includePresets((styles) => createTextInputBaseComposition(() => ({ wrapper: styles })))
|
|
30
|
-
|
|
31
28
|
export const useInputBaseStyles = (props: InputBaseProps) => {
|
|
32
29
|
const {
|
|
33
30
|
focused,
|
|
34
31
|
disabled,
|
|
35
32
|
error,
|
|
36
|
-
styles,
|
|
33
|
+
style: styles,
|
|
37
34
|
} = props
|
|
38
35
|
|
|
39
36
|
const hasError = !TypeGuards.isNil(error)
|
|
40
37
|
|
|
41
|
-
const
|
|
42
|
-
rootElement: 'wrapper',
|
|
43
|
-
styles,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const _leftIconStyles = useNestedStylesByKey<ActionIconComposition>('leftIcon', variantStyles)
|
|
47
|
-
const _rightIconStyles = useNestedStylesByKey<ActionIconComposition>('rightIcon', variantStyles)
|
|
48
|
-
const _baseIconStyles = useNestedStylesByKey<ActionIconComposition>('icon', variantStyles)
|
|
38
|
+
const compositionStyles = useCompositionStyles(['leftIcon', 'rightIcon', 'icon'], styles)
|
|
49
39
|
|
|
50
|
-
const baseIconStyles = getIconStyles(
|
|
40
|
+
const baseIconStyles = getIconStyles(compositionStyles.icon, { hasError, disabled, focused })
|
|
51
41
|
|
|
52
|
-
const leftIconStylesCompose = getIconStyles(
|
|
53
|
-
hasError,
|
|
54
|
-
disabled: disabled || props?.leftIcon?.disabled,
|
|
55
|
-
focused
|
|
42
|
+
const leftIconStylesCompose = getIconStyles(compositionStyles.leftIcon, {
|
|
43
|
+
hasError,
|
|
44
|
+
disabled: disabled || props?.leftIcon?.disabled,
|
|
45
|
+
focused,
|
|
56
46
|
})
|
|
57
47
|
|
|
58
|
-
const rightIconStylesCompose = getIconStyles(
|
|
59
|
-
hasError,
|
|
48
|
+
const rightIconStylesCompose = getIconStyles(compositionStyles.rightIcon, {
|
|
49
|
+
hasError,
|
|
60
50
|
disabled: disabled || props?.rightIcon?.disabled,
|
|
61
|
-
focused
|
|
51
|
+
focused,
|
|
62
52
|
})
|
|
63
53
|
|
|
64
54
|
const leftIconStyles = iconStylesOf(baseIconStyles, leftIconStylesCompose)
|
|
65
55
|
const rightIconStyles = iconStylesOf(baseIconStyles, rightIconStylesCompose)
|
|
66
56
|
|
|
67
57
|
const labelStyle = [
|
|
68
|
-
|
|
69
|
-
focused &&
|
|
70
|
-
hasError &&
|
|
71
|
-
disabled &&
|
|
58
|
+
styles.label,
|
|
59
|
+
focused && styles['label:focus'],
|
|
60
|
+
hasError && styles['label:error'],
|
|
61
|
+
disabled && styles['label:disabled'],
|
|
72
62
|
]
|
|
73
63
|
|
|
74
64
|
const errorStyle = [
|
|
75
|
-
|
|
76
|
-
focused &&
|
|
77
|
-
hasError &&
|
|
78
|
-
disabled &&
|
|
65
|
+
styles.errorMessage,
|
|
66
|
+
focused && styles['errorMessage:focus'],
|
|
67
|
+
hasError && styles['errorMessage:error'],
|
|
68
|
+
disabled && styles['errorMessage:disabled'],
|
|
79
69
|
]
|
|
80
70
|
|
|
81
71
|
const descriptionStyle = [
|
|
82
|
-
|
|
83
|
-
focused &&
|
|
84
|
-
hasError &&
|
|
85
|
-
disabled &&
|
|
72
|
+
styles.description,
|
|
73
|
+
focused && styles['description:focus'],
|
|
74
|
+
hasError && styles['description:error'],
|
|
75
|
+
disabled && styles['description:disabled'],
|
|
86
76
|
]
|
|
87
77
|
|
|
88
78
|
const wrapperStyle = [
|
|
89
|
-
|
|
90
|
-
focused &&
|
|
91
|
-
error &&
|
|
92
|
-
disabled &&
|
|
79
|
+
styles.wrapper,
|
|
80
|
+
focused && styles['wrapper:focus'],
|
|
81
|
+
error && styles['wrapper:error'],
|
|
82
|
+
disabled && styles['wrapper:disabled'],
|
|
93
83
|
]
|
|
94
84
|
|
|
95
85
|
const innerWrapperStyle = [
|
|
96
|
-
concatStyles(
|
|
97
|
-
focused &&
|
|
98
|
-
hasError &&
|
|
99
|
-
disabled &&
|
|
86
|
+
concatStyles(Array.isArray(styles.innerWrapper) ? styles.innerWrapper : [styles.innerWrapper]),
|
|
87
|
+
focused && styles['innerWrapper:focus'],
|
|
88
|
+
hasError && styles['innerWrapper:error'],
|
|
89
|
+
disabled && styles['innerWrapper:disabled'],
|
|
100
90
|
]
|
|
101
91
|
|
|
102
92
|
const labelRowStyle = [
|
|
103
|
-
|
|
104
|
-
focused &&
|
|
105
|
-
hasError &&
|
|
106
|
-
disabled &&
|
|
93
|
+
styles.labelRow,
|
|
94
|
+
focused && styles['labelRow:focus'],
|
|
95
|
+
hasError && styles['labelRow:error'],
|
|
96
|
+
disabled && styles['labelRow:disabled'],
|
|
107
97
|
]
|
|
108
98
|
|
|
109
99
|
return {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StylesOf } from '../../types'
|
|
1
|
+
import { StylesOf } from '@codeleap/common'
|
|
3
2
|
import { InputBaseComposition } from './styles'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
type ActionIconProps = PropsOf<typeof ActionIcon>
|
|
3
|
+
import { ActionIconComposition, ActionIconProps } from '../ActionIcon'
|
|
7
4
|
|
|
8
5
|
type OrderedParts = 'label' | 'description' | 'innerWrapper' | 'error'
|
|
9
6
|
|
|
@@ -16,14 +13,29 @@ export type InputBaseProps = React.PropsWithChildren<{
|
|
|
16
13
|
wrapperProps?: any
|
|
17
14
|
innerWrapper?: React.FC<any>
|
|
18
15
|
innerWrapperProps?: any
|
|
19
|
-
|
|
16
|
+
style?: StylesOf<InputBaseComposition>
|
|
20
17
|
description?: React.ReactNode
|
|
21
18
|
debugName: string
|
|
22
19
|
focused?: boolean
|
|
23
20
|
disabled?: boolean
|
|
24
21
|
order?: OrderedParts[]
|
|
25
|
-
style?: any
|
|
26
22
|
labelAsRow?: boolean
|
|
27
23
|
noError?: boolean
|
|
28
24
|
innerWrapperRef?: React.MutableRefObject<HTMLDivElement | null>
|
|
29
25
|
}>
|
|
26
|
+
|
|
27
|
+
export type OmitDiff<T1, T2> = {
|
|
28
|
+
[K in Exclude<keyof T1, keyof T2>]: T1[K]
|
|
29
|
+
} & {
|
|
30
|
+
[K in keyof T2]: T2[K]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type InputBaseKey = keyof InputBaseProps
|
|
34
|
+
|
|
35
|
+
export type IconStyles = StylesOf<ActionIconComposition>
|
|
36
|
+
|
|
37
|
+
export type IconState = {
|
|
38
|
+
focused: boolean
|
|
39
|
+
hasError: boolean
|
|
40
|
+
disabled: boolean
|
|
41
|
+
}
|
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ActionIconComposition } from '../ActionIcon'
|
|
3
|
-
import { InputBaseProps } from './types'
|
|
1
|
+
import { IconState, IconStyles, InputBaseKey, InputBaseProps, OmitDiff } from './types'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
[K in Exclude<keyof T1, keyof T2>]: T1[K]
|
|
7
|
-
} & {
|
|
8
|
-
[K in keyof T2]: T2[K]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type InputBaseKey = keyof InputBaseProps
|
|
12
|
-
|
|
13
|
-
export function selectInputBaseProps<T extends InputBaseProps>(props: T): {
|
|
3
|
+
export function selectInputBaseProps<T extends Omit<InputBaseProps, 'style'>>(props: T): {
|
|
14
4
|
inputBaseProps: InputBaseProps
|
|
15
5
|
others: OmitDiff<T, T>
|
|
16
6
|
} {
|
|
17
7
|
const varList:InputBaseKey[] = [
|
|
18
8
|
'label',
|
|
19
|
-
|
|
20
9
|
'error',
|
|
21
10
|
'innerWrapper',
|
|
22
11
|
'leftIcon',
|
|
23
12
|
'rightIcon',
|
|
24
|
-
// 'styles',
|
|
25
13
|
'description',
|
|
26
14
|
'wrapper',
|
|
27
15
|
'children',
|
|
@@ -42,14 +30,6 @@ export function selectInputBaseProps<T extends InputBaseProps>(props: T): {
|
|
|
42
30
|
return { inputBaseProps: result, others: copy as OmitDiff<T, T> }
|
|
43
31
|
}
|
|
44
32
|
|
|
45
|
-
type IconStyles = StylesOf<ActionIconComposition>
|
|
46
|
-
|
|
47
|
-
type IconState = {
|
|
48
|
-
focused: boolean
|
|
49
|
-
hasError: boolean
|
|
50
|
-
disabled: boolean
|
|
51
|
-
}
|
|
52
|
-
|
|
53
33
|
export const getIconStyles = (obj: IconStyles, state: IconState) => ({
|
|
54
34
|
icon: {
|
|
55
35
|
...obj.icon,
|
|
@@ -100,5 +80,5 @@ export const iconStylesOf = (baseStyles: IconStyles, styles: IconStyles) => ({
|
|
|
100
80
|
'touchableWrapper:disabled': {
|
|
101
81
|
...baseStyles['touchableWrapper:disabled'],
|
|
102
82
|
...styles['touchableWrapper:disabled'],
|
|
103
|
-
}
|
|
83
|
+
},
|
|
104
84
|
})
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { StylesOf, TypeGuards } from '@codeleap/common'
|
|
3
|
-
import { ListComposition, ListParts } from './styles'
|
|
4
|
-
import { ListProps } from './types'
|
|
5
2
|
import { View } from '../View'
|
|
6
|
-
import {
|
|
3
|
+
import { ListLayoutProps, ListRefreshControlComponent } from './types'
|
|
4
|
+
import { mergeStyles } from '@codeleap/styles'
|
|
7
5
|
import { ActivityIndicator } from '../ActivityIndicator'
|
|
6
|
+
import { ListParts } from './styles'
|
|
7
|
+
import { TypeGuards } from '@codeleap/common'
|
|
8
8
|
import { motion } from 'framer-motion'
|
|
9
9
|
|
|
10
|
-
export type ListLayoutProps = Omit<ListProps, 'renderItem'> & UseInfiniteScrollReturn['layoutProps'] & {
|
|
11
|
-
variantStyles: StylesOf<ListComposition>
|
|
12
|
-
children?: React.ReactNode
|
|
13
|
-
showFooter?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type ListRefreshControlComponent = Partial<ListLayoutProps> & {
|
|
17
|
-
variantStyles: StylesOf<ListComposition>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
10
|
const DefaultRefreshIndicator = (props: ListRefreshControlComponent) => {
|
|
21
11
|
const {
|
|
22
12
|
refreshing,
|
|
23
|
-
|
|
13
|
+
styles,
|
|
24
14
|
refreshPosition,
|
|
25
15
|
refreshControlProps,
|
|
26
16
|
debugName,
|
|
@@ -30,19 +20,19 @@ const DefaultRefreshIndicator = (props: ListRefreshControlComponent) => {
|
|
|
30
20
|
|
|
31
21
|
return (
|
|
32
22
|
<motion.div
|
|
33
|
-
css={[variantStyles?.refreshControl]}
|
|
34
23
|
initial={false}
|
|
35
24
|
animate={{
|
|
36
25
|
opacity: refreshing ? 1 : 0,
|
|
37
|
-
top: refreshing ? refreshPosition : 0
|
|
26
|
+
top: refreshing ? refreshPosition : 0,
|
|
38
27
|
}}
|
|
39
28
|
{...refreshControlProps}
|
|
29
|
+
style={styles?.refreshControl}
|
|
40
30
|
>
|
|
41
31
|
<ActivityIndicator
|
|
42
32
|
debugName={debugName + 'refresh-indicator'}
|
|
43
33
|
size={refreshSize}
|
|
44
|
-
style={variantStyles.refreshControlIndicator}
|
|
45
34
|
{...refreshControlIndicatorProps}
|
|
35
|
+
style={styles.refreshControlIndicator}
|
|
46
36
|
/>
|
|
47
37
|
</motion.div>
|
|
48
38
|
)
|
|
@@ -55,11 +45,10 @@ export const ListLayout = (props: ListLayoutProps) => {
|
|
|
55
45
|
ListHeaderComponent,
|
|
56
46
|
refresh,
|
|
57
47
|
ListRefreshControlComponent = DefaultRefreshIndicator,
|
|
58
|
-
|
|
48
|
+
styles,
|
|
59
49
|
isEmpty,
|
|
60
50
|
isLoading,
|
|
61
51
|
placeholder = {},
|
|
62
|
-
style,
|
|
63
52
|
children,
|
|
64
53
|
debugName,
|
|
65
54
|
isFetching,
|
|
@@ -69,33 +58,27 @@ export const ListLayout = (props: ListLayoutProps) => {
|
|
|
69
58
|
showFooter = true,
|
|
70
59
|
} = props
|
|
71
60
|
|
|
72
|
-
const getKeyStyle =
|
|
73
|
-
|
|
74
|
-
isLoading
|
|
75
|
-
isEmpty
|
|
76
|
-
])
|
|
61
|
+
const getKeyStyle = (key: ListParts) => mergeStyles([
|
|
62
|
+
styles[key],
|
|
63
|
+
isLoading ? styles[`${key}:loading`] : null,
|
|
64
|
+
isEmpty ? styles[`${key}:empty`] : null,
|
|
65
|
+
])
|
|
66
|
+
|
|
67
|
+
const showIndicator = (isFetching || isFetchingNextPage) && !TypeGuards.isNil(ListLoadingIndicatorComponent)
|
|
77
68
|
|
|
78
69
|
return (
|
|
79
|
-
|
|
80
|
-
<View css={[getKeyStyle('wrapper'), style]} ref={scrollableRef}>
|
|
70
|
+
<View style={getKeyStyle('wrapper')} ref={scrollableRef}>
|
|
81
71
|
{!!ListHeaderComponent ? <ListHeaderComponent /> : null}
|
|
82
72
|
|
|
83
73
|
{isEmpty ? <ListEmptyComponent debugName={debugName} {...placeholder} /> : null}
|
|
84
74
|
|
|
85
|
-
<View
|
|
86
|
-
{(!ListRefreshControlComponent || !refresh) ? null :
|
|
87
|
-
<ListRefreshControlComponent
|
|
88
|
-
{...props}
|
|
89
|
-
variantStyles={variantStyles}
|
|
90
|
-
/>
|
|
91
|
-
)}
|
|
75
|
+
<View style={[getKeyStyle('innerWrapper'), isEmpty && { display: 'none' }]}>
|
|
76
|
+
{(!ListRefreshControlComponent || !refresh) ? null : <ListRefreshControlComponent {...props} styles={styles} />}
|
|
92
77
|
|
|
93
78
|
{children}
|
|
94
79
|
</View>
|
|
95
80
|
|
|
96
|
-
{
|
|
97
|
-
? <ListLoadingIndicatorComponent />
|
|
98
|
-
: null}
|
|
81
|
+
{showIndicator ? <ListLoadingIndicatorComponent /> : null}
|
|
99
82
|
|
|
100
83
|
{(!!ListFooterComponent && showFooter) ? <ListFooterComponent {...props} /> : null}
|
|
101
84
|
</View>
|