@codeleap/web 3.1.2 → 3.2.1
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 +13 -10
- package/src/components/ActionIcon/index.tsx +24 -15
- package/src/components/ActivityIndicator/index.tsx +39 -46
- package/src/components/ActivityIndicator/styles.ts +7 -11
- package/src/components/Button/index.tsx +17 -21
- package/src/components/Checkbox/index.tsx +103 -96
- package/src/components/Collapse/index.tsx +4 -3
- package/src/components/Drawer/index.tsx +25 -17
- package/src/components/FileInput.tsx +60 -32
- package/src/components/Icon/index.tsx +6 -5
- package/src/components/InputBase/index.tsx +9 -4
- package/src/components/InputBase/types.ts +1 -0
- package/src/components/List/index.tsx +3 -0
- package/src/components/LoadingOverlay/index.tsx +36 -23
- package/src/components/Modal/index.tsx +260 -88
- package/src/components/Modal/styles.ts +3 -4
- package/src/components/NumberIncrement/index.tsx +2 -0
- package/src/components/Overlay/index.tsx +11 -10
- package/src/components/Pager/index.tsx +166 -0
- package/src/components/Pager/styles.ts +14 -0
- package/src/components/RadioInput/index.tsx +21 -19
- package/src/components/Scroll/index.tsx +6 -3
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +78 -0
- package/src/components/SegmentedControl/index.tsx +161 -0
- package/src/components/SegmentedControl/styles.ts +26 -0
- package/src/components/Select/index.tsx +13 -11
- package/src/components/Select/types.ts +23 -23
- package/src/components/Slider/index.tsx +77 -72
- package/src/components/Switch/index.tsx +96 -93
- package/src/components/Text/index.tsx +18 -33
- package/src/components/TextInput/index.tsx +14 -8
- package/src/components/Tooltip/index.tsx +1 -1
- package/src/components/Touchable/index.tsx +16 -18
- package/src/components/View/index.tsx +49 -25
- package/src/components/View/styles.ts +0 -1
- package/src/components/components.ts +2 -2
- package/src/components/defaultStyles.ts +16 -3
- package/src/lib/OSAlert.tsx +1 -1
- package/src/types/utility.ts +31 -2
- package/src/components/Link/index.tsx +0 -69
- package/src/components/Link/styles.ts +0 -11
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
3
|
+
|
|
4
|
+
import React, { ReactNode } from 'react'
|
|
3
5
|
import { Text } from '../Text'
|
|
4
6
|
import { Touchable } from '../Touchable'
|
|
5
7
|
import {
|
|
@@ -54,28 +56,28 @@ const Option = <T extends string|number>(props: OptionProps<T>) => {
|
|
|
54
56
|
const isDisabled = disabled || item.disabled
|
|
55
57
|
|
|
56
58
|
const getStyle = (key) => {
|
|
57
|
-
if(isDisabled && selected) {
|
|
59
|
+
if (isDisabled && selected) {
|
|
58
60
|
return styles[`${key}:selectedDisabled`]
|
|
59
61
|
}
|
|
60
|
-
if(isDisabled) {
|
|
62
|
+
if (isDisabled) {
|
|
61
63
|
return styles[`${key}:disabled`]
|
|
62
64
|
}
|
|
63
|
-
if(selected) {
|
|
65
|
+
if (selected) {
|
|
64
66
|
return styles[`${key}:selected`]
|
|
65
67
|
}
|
|
66
68
|
return styles[key]
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
const label = TypeGuards.isString(item.label) ? <Text
|
|
71
|
+
const label = TypeGuards.isString(item.label) ? <Text
|
|
70
72
|
css={[
|
|
71
73
|
styles.optionLabel,
|
|
72
74
|
getStyle('optionLabel'),
|
|
73
75
|
]}
|
|
74
76
|
text={item.label}
|
|
75
|
-
/> : item.label
|
|
77
|
+
/> : item.label
|
|
76
78
|
|
|
77
|
-
return
|
|
78
|
-
<Touchable
|
|
79
|
+
return <React.Fragment>
|
|
80
|
+
<Touchable
|
|
79
81
|
debugName={`${debugName} option ${item.value}`}
|
|
80
82
|
css={[
|
|
81
83
|
styles.optionWrapper,
|
|
@@ -83,11 +85,11 @@ const Option = <T extends string|number>(props: OptionProps<T>) => {
|
|
|
83
85
|
]}
|
|
84
86
|
onPress={onSelect}
|
|
85
87
|
disabled={isDisabled}
|
|
86
|
-
>
|
|
87
|
-
<View
|
|
88
|
+
>
|
|
89
|
+
<View
|
|
88
90
|
css={[
|
|
89
91
|
styles.optionIndicator,
|
|
90
|
-
|
|
92
|
+
getStyle('optionIndicator'),
|
|
91
93
|
]}
|
|
92
94
|
|
|
93
95
|
>
|
|
@@ -99,10 +101,10 @@ const Option = <T extends string|number>(props: OptionProps<T>) => {
|
|
|
99
101
|
/>
|
|
100
102
|
</View>
|
|
101
103
|
{label}
|
|
102
|
-
|
|
104
|
+
|
|
103
105
|
</Touchable>
|
|
104
106
|
{separator && <View style={styles.optionSeparator} />}
|
|
105
|
-
|
|
107
|
+
</React.Fragment>
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
export const RadioGroup = <T extends string|number>(
|
|
@@ -110,7 +112,7 @@ export const RadioGroup = <T extends string|number>(
|
|
|
110
112
|
) => {
|
|
111
113
|
const {
|
|
112
114
|
inputBaseProps,
|
|
113
|
-
others
|
|
115
|
+
others,
|
|
114
116
|
} = selectInputBaseProps(props)
|
|
115
117
|
|
|
116
118
|
const {
|
|
@@ -123,12 +125,12 @@ export const RadioGroup = <T extends string|number>(
|
|
|
123
125
|
debugName,
|
|
124
126
|
} = others
|
|
125
127
|
|
|
126
|
-
const variantStyles = useDefaultComponentStyle<'u:RadioInput', typeof RadioInputPresets>('u:RadioInput', {
|
|
128
|
+
const variantStyles = useDefaultComponentStyle<'u:RadioInput', typeof RadioInputPresets>('u:RadioInput', {
|
|
127
129
|
variants,
|
|
128
130
|
styles,
|
|
129
131
|
})
|
|
130
132
|
|
|
131
|
-
return <InputBase
|
|
133
|
+
return <InputBase
|
|
132
134
|
{...inputBaseProps}
|
|
133
135
|
disabled={disabled}
|
|
134
136
|
styles={{
|
|
@@ -138,13 +140,13 @@ export const RadioGroup = <T extends string|number>(
|
|
|
138
140
|
],
|
|
139
141
|
}}
|
|
140
142
|
debugName={debugName}
|
|
141
|
-
>
|
|
143
|
+
>
|
|
142
144
|
{options?.map((item, idx) => (
|
|
143
145
|
<Option
|
|
144
146
|
debugName={debugName}
|
|
145
147
|
item={item}
|
|
146
148
|
key={idx}
|
|
147
|
-
disabled={disabled}
|
|
149
|
+
disabled={disabled}
|
|
148
150
|
styles={variantStyles}
|
|
149
151
|
selected={value === item.value}
|
|
150
152
|
onSelect={() => onValueChange(item.value)}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
2
3
|
import {
|
|
3
4
|
ElementType,
|
|
4
5
|
forwardRef,
|
|
5
6
|
ReactElement,
|
|
6
7
|
Ref,
|
|
7
8
|
} from 'react'
|
|
9
|
+
import { NativeHTMLElement } from '../../types'
|
|
8
10
|
import { View, ViewProps } from '../View'
|
|
9
11
|
|
|
10
|
-
export const ScrollCP = <T extends
|
|
12
|
+
export const ScrollCP = <T extends NativeHTMLElement = 'div'>(
|
|
11
13
|
props: ViewProps<T>,
|
|
12
14
|
ref: Ref<any>,
|
|
13
15
|
) => {
|
|
14
16
|
|
|
15
17
|
return (
|
|
18
|
+
// @ts-ignore
|
|
16
19
|
<View
|
|
17
20
|
{...props}
|
|
18
21
|
ref={ref}
|
|
@@ -24,6 +27,6 @@ export const ScrollCP = <T extends ElementType = 'div'>(
|
|
|
24
27
|
|
|
25
28
|
export * from './styles'
|
|
26
29
|
|
|
27
|
-
export const Scroll = forwardRef(ScrollCP) as <T extends
|
|
30
|
+
export const Scroll = forwardRef(ScrollCP) as <T extends NativeHTMLElement = 'div'>(
|
|
28
31
|
props: ViewProps<T>
|
|
29
|
-
) =>
|
|
32
|
+
) => JSX.Element
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { CSSObject, jsx } from '@emotion/react'
|
|
3
|
+
|
|
4
|
+
import React, { forwardRef } from 'react'
|
|
5
|
+
import { PropsOf, IconPlaceholder } from '@codeleap/common'
|
|
6
|
+
import { StylesOf } from '../../types'
|
|
7
|
+
import { Text } from '../Text'
|
|
8
|
+
import { Touchable } from '../Touchable'
|
|
9
|
+
import { SegmentedControlComposition } from './styles'
|
|
10
|
+
import { Icon } from '../Icon'
|
|
11
|
+
|
|
12
|
+
type OptionRef = PropsOf<typeof Touchable>['ref']
|
|
13
|
+
|
|
14
|
+
export type SegmentedControlOptionProps = PropsOf<typeof Touchable> & {
|
|
15
|
+
selected?: boolean
|
|
16
|
+
label: string
|
|
17
|
+
variantStyles?: StylesOf<SegmentedControlComposition>
|
|
18
|
+
value?: any
|
|
19
|
+
textProps?: Omit<PropsOf<typeof Text>, 'key'>
|
|
20
|
+
icon?: IconPlaceholder
|
|
21
|
+
ref?: OptionRef
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const SegmentedControlOptionCP = (props: SegmentedControlOptionProps, ref: OptionRef) => {
|
|
25
|
+
const {
|
|
26
|
+
selected,
|
|
27
|
+
onPress,
|
|
28
|
+
style,
|
|
29
|
+
variantStyles,
|
|
30
|
+
label,
|
|
31
|
+
icon,
|
|
32
|
+
textProps,
|
|
33
|
+
|
|
34
|
+
disabled,
|
|
35
|
+
...touchableProps
|
|
36
|
+
} = props
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Touchable
|
|
40
|
+
|
|
41
|
+
key={touchableProps.key}
|
|
42
|
+
ref={ref}
|
|
43
|
+
css={[
|
|
44
|
+
variantStyles.button,
|
|
45
|
+
selected && variantStyles['button:selected'],
|
|
46
|
+
disabled && variantStyles['button:disabled'],
|
|
47
|
+
style,
|
|
48
|
+
]}
|
|
49
|
+
onPress={onPress}
|
|
50
|
+
disabled={disabled}
|
|
51
|
+
{...touchableProps}
|
|
52
|
+
>
|
|
53
|
+
{
|
|
54
|
+
!!icon && (
|
|
55
|
+
<Icon
|
|
56
|
+
name={icon}
|
|
57
|
+
css={[
|
|
58
|
+
variantStyles.icon,
|
|
59
|
+
selected && variantStyles['icon:selected'],
|
|
60
|
+
disabled && variantStyles['icon:disabled'],
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
<Text
|
|
66
|
+
text={label}
|
|
67
|
+
css={[
|
|
68
|
+
variantStyles.text,
|
|
69
|
+
selected && variantStyles['text:selected'],
|
|
70
|
+
disabled && variantStyles['text:disabled'],
|
|
71
|
+
]}
|
|
72
|
+
{...textProps}
|
|
73
|
+
/>
|
|
74
|
+
</Touchable>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const SegmentedControlOption = forwardRef(SegmentedControlOptionCP) as ((props: SegmentedControlOptionProps) => JSX.Element)
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View } from '../View'
|
|
3
|
+
import { SegmentedControlOption } from './SegmentedControlOption'
|
|
4
|
+
import { ComponentVariants, useDefaultComponentStyle, PropsOf, IconPlaceholder, StylesOf, useRef } from '@codeleap/common'
|
|
5
|
+
import { SegmentedControlPresets } from './styles'
|
|
6
|
+
import { Text } from '../Text'
|
|
7
|
+
import { Touchable } from '../Touchable'
|
|
8
|
+
import { SegmentedControlComposition } from './styles'
|
|
9
|
+
import { motion, MotionProps, AnimationProps, ForwardRefComponent } from 'framer-motion'
|
|
10
|
+
import { useAnimatedVariantStyles } from '../../lib'
|
|
11
|
+
|
|
12
|
+
export type SegmentedControlOptionProps<T = string> = {
|
|
13
|
+
label: string
|
|
14
|
+
value: T
|
|
15
|
+
icon?: IconPlaceholder
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type SegmentedControlProps<T = string> = ComponentVariants<typeof SegmentedControlPresets> & {
|
|
19
|
+
|
|
20
|
+
/** options that the segmented control will receive */
|
|
21
|
+
options : SegmentedControlOptionProps[]
|
|
22
|
+
|
|
23
|
+
/** the value of the segmented control */
|
|
24
|
+
value?: T
|
|
25
|
+
|
|
26
|
+
/** all styles from the segmented control */
|
|
27
|
+
styles?: StylesOf<SegmentedControlComposition>
|
|
28
|
+
|
|
29
|
+
/** view style */
|
|
30
|
+
style: PropsOf<typeof View>['style']
|
|
31
|
+
|
|
32
|
+
/** prop to control when te value of the segmented control changes */
|
|
33
|
+
onValueChange?: (v: any) => void
|
|
34
|
+
|
|
35
|
+
/** motion div props */
|
|
36
|
+
bubbleProps?: React.HTMLAttributes<HTMLDivElement> & MotionProps
|
|
37
|
+
|
|
38
|
+
/** label that will be shown above the segmented control */
|
|
39
|
+
label?: string
|
|
40
|
+
|
|
41
|
+
/** * all the touchable props */
|
|
42
|
+
touchableProps?: Partial<PropsOf<typeof Touchable>>
|
|
43
|
+
|
|
44
|
+
debugName?: string
|
|
45
|
+
disabled?: boolean
|
|
46
|
+
animationProps?: AnimationProps
|
|
47
|
+
transitionDuration?: number
|
|
48
|
+
RenderAnimatedView?: ForwardRefComponent<HTMLDivElement, any>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const defaultProps: Partial<SegmentedControlProps> = {
|
|
52
|
+
animationProps: {},
|
|
53
|
+
transitionDuration: 0.2,
|
|
54
|
+
disabled: false,
|
|
55
|
+
RenderAnimatedView: motion.div,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const SegmentedControl = (props: SegmentedControlProps) => {
|
|
59
|
+
const allProps = {
|
|
60
|
+
...SegmentedControl.defaultProps,
|
|
61
|
+
...props,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const {
|
|
65
|
+
label,
|
|
66
|
+
options,
|
|
67
|
+
styles = {},
|
|
68
|
+
value,
|
|
69
|
+
variants = [],
|
|
70
|
+
responsiveVariants = {},
|
|
71
|
+
onValueChange,
|
|
72
|
+
style,
|
|
73
|
+
bubbleProps,
|
|
74
|
+
animationProps,
|
|
75
|
+
transitionDuration,
|
|
76
|
+
disabled,
|
|
77
|
+
RenderAnimatedView: Bubble,
|
|
78
|
+
debugName,
|
|
79
|
+
...rest
|
|
80
|
+
} = allProps
|
|
81
|
+
|
|
82
|
+
const variantStyles = useDefaultComponentStyle<'u:SegmentedControl', typeof SegmentedControlPresets>(
|
|
83
|
+
'u:SegmentedControl',
|
|
84
|
+
{
|
|
85
|
+
variants,
|
|
86
|
+
responsiveVariants,
|
|
87
|
+
styles,
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
const currentOptionIdx = options?.findIndex(o => o?.value === value) || 0
|
|
92
|
+
|
|
93
|
+
const maxDivWidthRef = useRef(null)
|
|
94
|
+
|
|
95
|
+
const biggerWidth = React.useMemo(() => {
|
|
96
|
+
return {
|
|
97
|
+
width: maxDivWidthRef.current,
|
|
98
|
+
}
|
|
99
|
+
}, [maxDivWidthRef.current])
|
|
100
|
+
|
|
101
|
+
const bubbleAnimation = useAnimatedVariantStyles({
|
|
102
|
+
variantStyles,
|
|
103
|
+
animatedProperties: [],
|
|
104
|
+
updater: () => {
|
|
105
|
+
'worklet'
|
|
106
|
+
return {
|
|
107
|
+
translateX: currentOptionIdx * biggerWidth.width,
|
|
108
|
+
transition: {
|
|
109
|
+
ease: 'easeInOut',
|
|
110
|
+
duration: transitionDuration,
|
|
111
|
+
},
|
|
112
|
+
...animationProps,
|
|
113
|
+
} as AnimationProps
|
|
114
|
+
},
|
|
115
|
+
dependencies: [currentOptionIdx, biggerWidth.width],
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const selectedBubbleStyles = [
|
|
119
|
+
variantStyles.selectedBubble,
|
|
120
|
+
disabled && variantStyles['selectedBubble:disabled'],
|
|
121
|
+
biggerWidth,
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<View css={[variantStyles.wrapper, style]} {...rest}>
|
|
126
|
+
{label && <Text text={label} css={[variantStyles.label, disabled && variantStyles['label:disabled']]} />}
|
|
127
|
+
<View css={[variantStyles.innerWrapper, disabled && variantStyles['innerWrapper:disabled']]}>
|
|
128
|
+
<Bubble
|
|
129
|
+
css={selectedBubbleStyles}
|
|
130
|
+
animate={bubbleAnimation}
|
|
131
|
+
initial={false}
|
|
132
|
+
{...bubbleProps}
|
|
133
|
+
/>
|
|
134
|
+
{options.map((o, idx) => (
|
|
135
|
+
<SegmentedControlOption
|
|
136
|
+
ref={(ref) => {
|
|
137
|
+
if (ref && ref.offsetWidth > maxDivWidthRef.current) {
|
|
138
|
+
maxDivWidthRef.current = ref.offsetWidth
|
|
139
|
+
}
|
|
140
|
+
}}
|
|
141
|
+
debugName={debugName}
|
|
142
|
+
label={o.label}
|
|
143
|
+
value={o.value}
|
|
144
|
+
onPress={() => onValueChange(o.value)}
|
|
145
|
+
key={idx}
|
|
146
|
+
icon={o.icon}
|
|
147
|
+
selected={value === o.value}
|
|
148
|
+
variantStyles={variantStyles}
|
|
149
|
+
style={biggerWidth}
|
|
150
|
+
disabled={disabled}
|
|
151
|
+
{...props?.touchableProps}
|
|
152
|
+
/>
|
|
153
|
+
))}
|
|
154
|
+
</View>
|
|
155
|
+
</View>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export * from './styles'
|
|
160
|
+
|
|
161
|
+
SegmentedControl.defaultProps = defaultProps
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets, StylesOf } from '@codeleap/common'
|
|
2
|
+
|
|
3
|
+
export type SegmentedControlStates = 'selected' | 'disabled'
|
|
4
|
+
|
|
5
|
+
type SegmentedControlParts =
|
|
6
|
+
'selectedBubble' |
|
|
7
|
+
'wrapper' |
|
|
8
|
+
'innerWrapper' |
|
|
9
|
+
'text' |
|
|
10
|
+
'icon' |
|
|
11
|
+
'button' |
|
|
12
|
+
`label`
|
|
13
|
+
|
|
14
|
+
export type SegmentedControlComposition = SegmentedControlParts | `${SegmentedControlParts}:${SegmentedControlStates}`
|
|
15
|
+
|
|
16
|
+
export type SegmentedControlStylesGen<TCSS = any> =
|
|
17
|
+
StylesOf<
|
|
18
|
+
Exclude<SegmentedControlComposition, 'buttonFeedback'>
|
|
19
|
+
>
|
|
20
|
+
|
|
21
|
+
const createSegmentedControlStyle = createDefaultVariantFactory<
|
|
22
|
+
SegmentedControlComposition,
|
|
23
|
+
SegmentedControlStylesGen
|
|
24
|
+
>()
|
|
25
|
+
|
|
26
|
+
export const SegmentedControlPresets = includePresets((style) => createSegmentedControlStyle(() => ({ wrapper: style })))
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
1
3
|
import React, { useRef, forwardRef, useImperativeHandle } from 'react'
|
|
2
4
|
import { FormTypes, useValidate, useState, TypeGuards, onUpdate } from '@codeleap/common'
|
|
3
5
|
import _Select, { components, MenuListProps, MenuProps, MultiValueProps, NoticeProps } from 'react-select'
|
|
@@ -5,7 +7,7 @@ import Async from 'react-select/async'
|
|
|
5
7
|
import { useSelectStyles } from './styles'
|
|
6
8
|
import { LoadingIndicatorProps, PlaceholderProps, SelectProps, TCustomOption } from './types'
|
|
7
9
|
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
8
|
-
import { Button } from '../Button'
|
|
10
|
+
import { Button, ButtonProps } from '../Button'
|
|
9
11
|
import { Text } from '../Text'
|
|
10
12
|
import { View } from '../View'
|
|
11
13
|
import { ActivityIndicator } from '../ActivityIndicator'
|
|
@@ -16,7 +18,7 @@ export * from './styles'
|
|
|
16
18
|
export * from './types'
|
|
17
19
|
|
|
18
20
|
const DefaultOption = (props: TCustomOption & { component: (props: TCustomOption) => JSX.Element }) => {
|
|
19
|
-
const { isSelected, optionsStyles, label, selectedIcon, component = null, itemProps = {}, isFocused } = props
|
|
21
|
+
const { isSelected, optionsStyles, label, selectedIcon, component = null, itemProps = {} as TCustomOption['itemProps'], isFocused } = props
|
|
20
22
|
|
|
21
23
|
const styles = optionsStyles({ isSelected, isFocused, baseStyles: (itemProps?.styles ?? {}) })
|
|
22
24
|
|
|
@@ -46,12 +48,12 @@ const DefaultOption = (props: TCustomOption & { component: (props: TCustomOption
|
|
|
46
48
|
const CustomMenu = (props: MenuProps & { Footer: () => JSX.Element }) => {
|
|
47
49
|
const { Footer, children } = props
|
|
48
50
|
|
|
49
|
-
return
|
|
51
|
+
return <React.Fragment>
|
|
50
52
|
<components.Menu {...props}>
|
|
51
53
|
{children}
|
|
52
54
|
{!!Footer && <Footer />}
|
|
53
55
|
</components.Menu>
|
|
54
|
-
|
|
56
|
+
</React.Fragment>
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
const CustomMenuList = (props: MenuListProps & { defaultStyles: { wrapper: React.CSSProperties } }) => {
|
|
@@ -75,8 +77,8 @@ const DefaultPlaceholder = (props: PlaceholderProps) => {
|
|
|
75
77
|
if (TypeGuards.isString(TextPlaceholder)) {
|
|
76
78
|
return <Text text={TextPlaceholder} css={[defaultStyles.text]} />
|
|
77
79
|
} else if (React.isValidElement(TextPlaceholder)) {
|
|
78
|
-
return TextPlaceholder
|
|
79
|
-
} else {
|
|
80
|
+
return TextPlaceholder as JSX.Element
|
|
81
|
+
} else if (TypeGuards.isFunction(TextPlaceholder)) {
|
|
80
82
|
return <TextPlaceholder {...props} />
|
|
81
83
|
}
|
|
82
84
|
}
|
|
@@ -91,7 +93,7 @@ const DefaultPlaceholder = (props: PlaceholderProps) => {
|
|
|
91
93
|
return <View style={defaultStyles.icon}>
|
|
92
94
|
{ IconPlaceholder}
|
|
93
95
|
</View>
|
|
94
|
-
} else {
|
|
96
|
+
} else if (TypeGuards.isFunction(IconPlaceholder)) {
|
|
95
97
|
return <IconPlaceholder {...props} />
|
|
96
98
|
}
|
|
97
99
|
}
|
|
@@ -105,11 +107,11 @@ const DefaultPlaceholder = (props: PlaceholderProps) => {
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
const LoadingIndicator = (props: LoadingIndicatorProps) => {
|
|
108
|
-
const { defaultStyles
|
|
110
|
+
const { defaultStyles } = props
|
|
109
111
|
|
|
110
112
|
return (
|
|
111
113
|
<View css={[defaultStyles.wrapper]}>
|
|
112
|
-
<ActivityIndicator
|
|
114
|
+
<ActivityIndicator />
|
|
113
115
|
</View>
|
|
114
116
|
)
|
|
115
117
|
}
|
|
@@ -162,7 +164,7 @@ const defaultProps: Partial<SelectProps> = {
|
|
|
162
164
|
selectedIcon: 'checkmark',
|
|
163
165
|
searchable: false,
|
|
164
166
|
separatorMultiValue: ', ',
|
|
165
|
-
itemProps: {},
|
|
167
|
+
itemProps: {} as ButtonProps,
|
|
166
168
|
loadingIndicatorSize: 20,
|
|
167
169
|
options: [],
|
|
168
170
|
}
|
|
@@ -415,7 +417,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
415
417
|
<DefaultOption
|
|
416
418
|
{...props}
|
|
417
419
|
{...componentProps}
|
|
418
|
-
itemProps={itemProps}
|
|
420
|
+
itemProps={itemProps as ButtonProps}
|
|
419
421
|
selectedIcon={selectedIcon}
|
|
420
422
|
optionsStyles={optionsStyles}
|
|
421
423
|
component={OptionComponent}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { ComponentVariants, FormTypes, StylesOf, yup } from
|
|
1
|
+
import { ComponentVariants, FormTypes, StylesOf, yup } from '@codeleap/common'
|
|
2
2
|
import { CSSInterpolation } from '@emotion/css'
|
|
3
|
-
import { CSSObject } from
|
|
4
|
-
import { GroupBase, NoticeProps, OptionProps, Props } from
|
|
5
|
-
import { AsyncProps } from
|
|
3
|
+
import { CSSObject } from '@emotion/react'
|
|
4
|
+
import { GroupBase, NoticeProps, OptionProps, Props } from 'react-select'
|
|
5
|
+
import { AsyncProps } from 'react-select/async'
|
|
6
6
|
import { ButtonProps } from '../Button'
|
|
7
|
-
import { InputBaseProps } from
|
|
8
|
-
import { SelectPresets,SelectComposition, OptionState } from
|
|
7
|
+
import { InputBaseProps } from '../InputBase'
|
|
8
|
+
import { SelectPresets, SelectComposition, OptionState } from './styles'
|
|
9
9
|
|
|
10
|
-
type SelectValue<T,Multi extends boolean> = Multi extends true ? T[] : T
|
|
10
|
+
type SelectValue<T, Multi extends boolean> = Multi extends true ? T[] : T
|
|
11
11
|
|
|
12
|
-
type OmitWithValues<T> =
|
|
12
|
+
type OmitWithValues<T> = Omit<T, 'options' | 'value' | 'isMulti' | 'loadOptions'|'styles'>
|
|
13
13
|
|
|
14
|
-
type DynamicSelectProps<T, Multi extends boolean> =
|
|
14
|
+
type DynamicSelectProps<T, Multi extends boolean> =
|
|
15
15
|
({
|
|
16
|
-
loadOptions?: (search: string) => Promise<FormTypes.Options<T>>
|
|
16
|
+
loadOptions?: (search: string) => Promise<FormTypes.Options<T>>
|
|
17
17
|
defaultValues?: FormTypes.Options<T>
|
|
18
|
-
} &
|
|
18
|
+
} & OmitWithValues<
|
|
19
19
|
AsyncProps<FormTypes.Option<T>, Multi, GroupBase<FormTypes.Option<T>>>
|
|
20
|
-
>) |
|
|
20
|
+
>) |
|
|
21
21
|
({
|
|
22
22
|
loadOptions?: never
|
|
23
23
|
} & OmitWithValues<
|
|
24
24
|
Props<FormTypes.Option<T>, Multi, GroupBase<FormTypes.Option<T>>>
|
|
25
25
|
>)
|
|
26
|
-
|
|
27
|
-
export type ReactSelectProps<T, Multi extends boolean = false> = Omit<InputBaseProps
|
|
26
|
+
|
|
27
|
+
export type ReactSelectProps<T, Multi extends boolean = false> = Omit<InputBaseProps, 'styles' | 'variants'> &{
|
|
28
28
|
options: FormTypes.Options<T>
|
|
29
|
-
value: SelectValue<T,Multi>
|
|
30
|
-
onValueChange?: (value: SelectValue<T,Multi>) => void
|
|
29
|
+
value: SelectValue<T, Multi>
|
|
30
|
+
onValueChange?: (value: SelectValue<T, Multi>) => void
|
|
31
31
|
multiple?: Multi
|
|
32
|
-
validate?: FormTypes.ValidatorWithoutForm<SelectValue<T,Multi>> | yup.SchemaOf<SelectValue<T,Multi>>
|
|
32
|
+
validate?: FormTypes.ValidatorWithoutForm<SelectValue<T, Multi>> | yup.SchemaOf<SelectValue<T, Multi>>
|
|
33
33
|
styles?: StylesOf<SelectComposition>
|
|
34
34
|
} & DynamicSelectProps<T, Multi>
|
|
35
35
|
|
|
@@ -40,16 +40,16 @@ export type ComponentPartProps = {
|
|
|
40
40
|
variantStyles: Record<SelectComposition, React.CSSProperties>
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export type TCustomOption = OptionProps & ComponentPartProps & {
|
|
43
|
+
export type TCustomOption = OptionProps & ComponentPartProps & {
|
|
44
44
|
optionsStyles: (state: OptionState) => OptionState['baseStyles']
|
|
45
45
|
selectedIcon?: string
|
|
46
46
|
itemProps?: ButtonProps
|
|
47
47
|
styles?: OptionState['baseStyles']
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
type SelectPlaceholderElement = string | ((props: PlaceholderProps) => JSX.Element) |
|
|
50
|
+
type SelectPlaceholderElement = string | ((props: PlaceholderProps) => JSX.Element) | JSX.Element
|
|
51
51
|
|
|
52
|
-
export type PlaceholderProps = NoticeProps & ComponentPartProps & {
|
|
52
|
+
export type PlaceholderProps = NoticeProps & ComponentPartProps & {
|
|
53
53
|
text: SelectPlaceholderElement
|
|
54
54
|
defaultStyles: {
|
|
55
55
|
wrapper: CSSInterpolation
|
|
@@ -59,7 +59,7 @@ export type PlaceholderProps = NoticeProps & ComponentPartProps & {
|
|
|
59
59
|
icon: SelectPlaceholderElement
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export type LoadingIndicatorProps = NoticeProps & {
|
|
62
|
+
export type LoadingIndicatorProps = NoticeProps & {
|
|
63
63
|
defaultStyles: { wrapper: CSSInterpolation }
|
|
64
64
|
size?: number
|
|
65
65
|
}
|
|
@@ -93,8 +93,8 @@ export type SelectProps<T = any, Multi extends boolean = false> = React.PropsWit
|
|
|
93
93
|
loadingIndicatorSize?: number
|
|
94
94
|
limit?: number
|
|
95
95
|
} & Omit<
|
|
96
|
-
ReactSelectProps<T, Multi>,
|
|
96
|
+
ReactSelectProps<T, Multi>,
|
|
97
97
|
'isSearchable' | 'isClearable' | 'isDisabled' | 'loadingMessage' | 'filterOption' |
|
|
98
|
-
'isLoading' | 'menuPortalTarget' | 'closeMenuOnSelect' | 'isMulti'>
|
|
98
|
+
'isLoading' | 'menuPortalTarget' | 'closeMenuOnSelect' | 'isMulti'>
|
|
99
99
|
& ComponentVariants<typeof SelectPresets>
|
|
100
100
|
>
|