@codeleap/mobile 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 +6 -4
- package/src/Registry.ts +52 -0
- package/src/components/ActionIcon/index.tsx +55 -37
- package/src/components/ActionIcon/styles.ts +2 -4
- package/src/components/ActionIcon/types.ts +15 -0
- package/src/components/ActivityIndicator/index.tsx +42 -64
- package/src/components/ActivityIndicator/styles.ts +1 -10
- package/src/components/ActivityIndicator/types.ts +9 -0
- package/src/components/Autocomplete/index.tsx +46 -54
- package/src/components/Autocomplete/styles.ts +2 -5
- package/src/components/Autocomplete/types.ts +13 -23
- package/src/components/Avatar/index.tsx +59 -71
- package/src/components/Avatar/styles.ts +1 -9
- package/src/components/Avatar/types.ts +23 -0
- package/src/components/AvatarGroup/index.tsx +30 -44
- package/src/components/AvatarGroup/styles.ts +0 -6
- package/src/components/AvatarGroup/types.ts +10 -0
- package/src/components/Backdrop/index.tsx +51 -34
- package/src/components/Backdrop/styles.ts +5 -10
- package/src/components/Backdrop/types.ts +14 -0
- package/src/components/Badge/index.tsx +36 -62
- package/src/components/Badge/styles.ts +3 -11
- package/src/components/Badge/types.ts +27 -0
- package/src/components/Button/index.tsx +55 -82
- package/src/components/Button/styles.ts +13 -14
- package/src/components/Button/types.ts +20 -0
- package/src/components/Calendar/index.tsx +35 -29
- package/src/components/Checkbox/index.tsx +43 -64
- package/src/components/Checkbox/styles.ts +1 -6
- package/src/components/Checkbox/types.ts +13 -0
- package/src/components/DatePickerModal/index.tsx +50 -65
- package/src/components/DatePickerModal/styles.ts +9 -10
- package/src/components/DatePickerModal/types.ts +36 -54
- package/src/components/EmptyPlaceholder/index.tsx +40 -63
- package/src/components/EmptyPlaceholder/styles.ts +0 -5
- package/src/components/EmptyPlaceholder/types.ts +21 -0
- package/src/components/FileInput/index.tsx +11 -49
- package/src/components/FileInput/types.ts +27 -0
- package/src/components/Grid/index.tsx +84 -116
- package/src/components/Grid/styles.ts +0 -5
- package/src/components/Grid/types.ts +20 -0
- package/src/components/Icon/index.tsx +44 -79
- package/src/components/Icon/styles.ts +0 -6
- package/src/components/Icon/types.ts +15 -0
- package/src/components/Image/index.tsx +58 -78
- package/src/components/Image/styles.ts +1 -6
- package/src/components/Image/types.ts +18 -0
- package/src/components/ImageView/Spotlight.tsx +1 -4
- package/src/components/ImageView/component.tsx +1 -2
- package/src/components/InputBase/index.tsx +33 -24
- package/src/components/InputBase/styles.ts +66 -75
- package/src/components/InputBase/types.ts +3 -4
- package/src/components/InputBase/utils.ts +6 -4
- package/src/components/List/index.tsx +99 -151
- package/src/components/List/styles.ts +0 -6
- package/src/components/List/types.ts +41 -0
- package/src/components/LoadingOverlay/index.tsx +42 -29
- package/src/components/LoadingOverlay/styles.ts +7 -7
- package/src/components/LoadingOverlay/types.ts +9 -0
- package/src/components/Modal/index.tsx +80 -127
- package/src/components/Modal/styles.ts +0 -8
- package/src/components/Modal/types.ts +41 -0
- package/src/components/Navigation/Navigation.tsx +1 -0
- package/src/components/Navigation/types.ts +2 -9
- package/src/components/NumberIncrement/index.tsx +50 -60
- package/src/components/NumberIncrement/styles.ts +0 -5
- package/src/components/NumberIncrement/types.ts +32 -39
- package/src/components/Pager/index.tsx +42 -94
- package/src/components/Pager/styles.ts +1 -13
- package/src/components/Pager/types.ts +37 -0
- package/src/components/PaginationIndicator/index.tsx +51 -0
- package/src/components/PaginationIndicator/styles.ts +3 -0
- package/src/components/PaginationIndicator/types.ts +10 -0
- package/src/components/RadioInput/index.tsx +32 -57
- package/src/components/RadioInput/styles.ts +5 -7
- package/src/components/RadioInput/types.ts +31 -0
- package/src/components/RefreshControl/index.tsx +39 -19
- package/src/components/RefreshControl/styles.ts +1 -6
- package/src/components/RefreshControl/types.ts +9 -0
- package/src/components/Scroll/index.tsx +89 -105
- package/src/components/Scroll/styles.ts +0 -5
- package/src/components/Scroll/types.ts +21 -0
- package/src/components/SearchInput/index.tsx +90 -0
- package/src/components/Sections/index.tsx +111 -161
- package/src/components/Sections/styles.ts +0 -5
- package/src/components/Sections/types.ts +39 -0
- package/src/components/SegmentedControl/Option.tsx +46 -31
- package/src/components/SegmentedControl/index.tsx +86 -121
- package/src/components/SegmentedControl/styles.ts +15 -22
- package/src/components/SegmentedControl/types.ts +31 -0
- package/src/components/Select/index.tsx +71 -82
- package/src/components/Select/styles.ts +3 -5
- package/src/components/Select/types.ts +20 -25
- package/src/components/Slider/index.tsx +58 -43
- package/src/components/Slider/styles.ts +15 -6
- package/src/components/Slider/types.ts +9 -14
- package/src/components/Switch/index.tsx +43 -56
- package/src/components/Switch/styles.ts +1 -7
- package/src/components/Switch/types.ts +12 -0
- package/src/components/Text/index.tsx +56 -52
- package/src/components/Text/styles.ts +1 -7
- package/src/components/Text/types.ts +18 -0
- package/src/components/TextInput/index.tsx +49 -162
- package/src/components/TextInput/styles.ts +2 -8
- package/src/components/TextInput/types.ts +23 -0
- package/src/components/Touchable/index.tsx +44 -87
- package/src/components/Touchable/styles.ts +0 -9
- package/src/components/Touchable/types.ts +27 -0
- package/src/components/View/index.tsx +23 -92
- package/src/components/View/styles.ts +0 -6
- package/src/components/View/types.ts +13 -0
- package/src/components/components.ts +2 -6
- package/src/hooks/index.ts +13 -0
- package/src/index.ts +2 -0
- package/src/modules/PressableRipple/type.ts +1 -0
- package/src/utils/KeyboardAware/context.tsx +0 -2
- package/src/utils/KeyboardAware/keyboardHooks.ts +1 -2
- package/src/utils/ModalManager/components.tsx +1 -30
- package/src/utils/ModalManager/context.tsx +4 -4
- package/src/utils/ModalManager/index.ts +1 -4
- package/src/utils/hooks.ts +12 -1
- package/src/components/Calendar/style.ts +0 -6
- package/src/components/ContentView/index.tsx +0 -63
- package/src/components/ContentView/styles.ts +0 -8
- package/src/components/Drawer/index.tsx +0 -28
- package/src/components/Drawer/styles.ts +0 -8
- package/src/components/FileInput/styles.ts +0 -8
- package/src/components/InputLabel/index.tsx +0 -38
- package/src/components/InputLabel/styles.ts +0 -7
- package/src/components/List/PaginationIndicator.tsx +0 -54
- package/src/components/defaultStyles.ts +0 -77
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import {
|
|
3
|
-
IconPlaceholder,
|
|
4
|
-
useDefaultComponentStyle,
|
|
5
3
|
TypeGuards,
|
|
6
|
-
useNestedStylesByKey,
|
|
7
4
|
FormTypes,
|
|
8
5
|
onMount,
|
|
9
6
|
onUpdate,
|
|
@@ -12,16 +9,19 @@ import {
|
|
|
12
9
|
useBooleanToggle,
|
|
13
10
|
} from '@codeleap/common'
|
|
14
11
|
import React, { useCallback, useMemo } from 'react'
|
|
15
|
-
import { StyleSheet } from 'react-native'
|
|
16
12
|
import { List } from '../List'
|
|
17
|
-
import {
|
|
18
|
-
import { SelectPresets } from './styles'
|
|
13
|
+
import { TextInput } from '../TextInput'
|
|
19
14
|
import { SelectProps, ValueBoundSelectProps } from './types'
|
|
20
15
|
import { ModalManager } from '../../utils'
|
|
21
16
|
import { Button } from '../Button'
|
|
22
|
-
|
|
17
|
+
import { AnyRecord, AppIcon, IJSX, StyledComponentProps, useCompositionStyles } from '@codeleap/styles'
|
|
18
|
+
import Modal from '../Modal'
|
|
19
|
+
import { MobileStyleRegistry } from '../../Registry'
|
|
20
|
+
import { SearchInput } from '../SearchInput'
|
|
21
|
+
import { useStylesFor } from '../../hooks'
|
|
23
22
|
|
|
24
23
|
export * from './styles'
|
|
24
|
+
export * from './types'
|
|
25
25
|
|
|
26
26
|
const defaultFilterFunction = (search: string, options: FormTypes.Options<any>) => {
|
|
27
27
|
return options.filter((option) => {
|
|
@@ -33,6 +33,18 @@ const defaultFilterFunction = (search: string, options: FormTypes.Options<any>)
|
|
|
33
33
|
})
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const defaultGetLabel = (option) => {
|
|
37
|
+
if (TypeGuards.isArray(option)) {
|
|
38
|
+
if (option.length === 0) return null
|
|
39
|
+
|
|
40
|
+
return option.map(o => o.label).join(', ')
|
|
41
|
+
|
|
42
|
+
} else {
|
|
43
|
+
if (!option) return null
|
|
44
|
+
return option?.label
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
const OuterInput: ValueBoundSelectProps<any, boolean>['outerInputComponent'] = (props) => {
|
|
37
49
|
const {
|
|
38
50
|
currentValueLabel,
|
|
@@ -40,7 +52,6 @@ const OuterInput: ValueBoundSelectProps<any, boolean>['outerInputComponent'] = (
|
|
|
40
52
|
clearIcon,
|
|
41
53
|
label,
|
|
42
54
|
toggle,
|
|
43
|
-
styles,
|
|
44
55
|
style,
|
|
45
56
|
placeholder,
|
|
46
57
|
disabled = false,
|
|
@@ -54,7 +65,6 @@ const OuterInput: ValueBoundSelectProps<any, boolean>['outerInputComponent'] = (
|
|
|
54
65
|
disabled={disabled}
|
|
55
66
|
label={label}
|
|
56
67
|
debugName={debugName}
|
|
57
|
-
styles={styles}
|
|
58
68
|
style={style}
|
|
59
69
|
innerWrapperProps={{
|
|
60
70
|
rippleDisabled: true,
|
|
@@ -64,69 +74,48 @@ const OuterInput: ValueBoundSelectProps<any, boolean>['outerInputComponent'] = (
|
|
|
64
74
|
/>
|
|
65
75
|
}
|
|
66
76
|
|
|
67
|
-
const defaultProps: Partial<SelectProps<any, boolean>> = {
|
|
68
|
-
getLabel(option) {
|
|
69
|
-
|
|
70
|
-
if (TypeGuards.isArray(option)) {
|
|
71
|
-
|
|
72
|
-
if (option.length === 0) return null
|
|
73
|
-
|
|
74
|
-
return option.map(o => o.label).join(', ')
|
|
75
|
-
|
|
76
|
-
} else {
|
|
77
|
-
if (!option) return null
|
|
78
|
-
return option?.label
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
outerInputComponent: OuterInput,
|
|
82
|
-
searchInputProps: {},
|
|
83
|
-
arrowIconName: 'chevrons-up-down' as IconPlaceholder,
|
|
84
|
-
clearIconName: 'x' as IconPlaceholder,
|
|
85
|
-
}
|
|
86
|
-
|
|
87
77
|
export const Select = <T extends string | number = string, Multi extends boolean = false>(selectProps: SelectProps<T, Multi>) => {
|
|
88
78
|
const allProps = {
|
|
89
|
-
...defaultProps,
|
|
79
|
+
...Select.defaultProps,
|
|
90
80
|
...selectProps,
|
|
91
81
|
}
|
|
82
|
+
|
|
92
83
|
const {
|
|
93
84
|
value,
|
|
94
85
|
onValueChange,
|
|
95
86
|
label,
|
|
96
|
-
styles = {},
|
|
97
87
|
options = [],
|
|
98
88
|
style,
|
|
99
|
-
variants,
|
|
100
89
|
description,
|
|
101
|
-
renderItem,
|
|
90
|
+
renderItem: Item,
|
|
102
91
|
listProps,
|
|
103
92
|
debugName,
|
|
104
|
-
placeholder
|
|
93
|
+
placeholder,
|
|
105
94
|
arrowIconName,
|
|
106
95
|
clearIconName,
|
|
107
|
-
clearable
|
|
108
|
-
selectedIcon
|
|
96
|
+
clearable,
|
|
97
|
+
selectedIcon,
|
|
109
98
|
inputProps = {},
|
|
110
|
-
hideInput
|
|
99
|
+
hideInput,
|
|
111
100
|
itemProps = {},
|
|
112
101
|
searchable,
|
|
113
102
|
loadOptions,
|
|
114
|
-
multiple
|
|
103
|
+
multiple,
|
|
115
104
|
closeOnSelect = !multiple,
|
|
116
105
|
limit = null,
|
|
117
106
|
defaultOptions = options,
|
|
118
107
|
visible: _visible,
|
|
119
108
|
toggle: _toggle,
|
|
120
109
|
ListHeaderComponent,
|
|
121
|
-
ListComponent
|
|
110
|
+
ListComponent,
|
|
122
111
|
onLoadOptionsError,
|
|
123
112
|
loadOptionsOnMount = defaultOptions.length === 0,
|
|
124
|
-
loadOptionsOnOpen
|
|
125
|
-
filterItems
|
|
113
|
+
loadOptionsOnOpen,
|
|
114
|
+
filterItems,
|
|
126
115
|
getLabel,
|
|
127
116
|
searchInputProps,
|
|
128
117
|
outerInputComponent,
|
|
129
|
-
disabled
|
|
118
|
+
disabled,
|
|
130
119
|
...modalProps
|
|
131
120
|
} = allProps
|
|
132
121
|
|
|
@@ -156,9 +145,7 @@ export const Select = <T extends string | number = string, Multi extends boolean
|
|
|
156
145
|
const currentValueLabel = useMemo(() => {
|
|
157
146
|
const _options = (multiple ? labelOptions : labelOptions?.[0]) as Multi extends true ? FormTypes.Options<T> : FormTypes.Options<T>[number]
|
|
158
147
|
|
|
159
|
-
const label = getLabel(
|
|
160
|
-
_options,
|
|
161
|
-
)
|
|
148
|
+
const label = getLabel(_options)
|
|
162
149
|
|
|
163
150
|
return label
|
|
164
151
|
}, [labelOptions])
|
|
@@ -177,27 +164,15 @@ export const Select = <T extends string | number = string, Multi extends boolean
|
|
|
177
164
|
}
|
|
178
165
|
}, [visible, prevVisible])
|
|
179
166
|
|
|
180
|
-
const
|
|
181
|
-
transform: StyleSheet.flatten,
|
|
182
|
-
rootElement: 'inputWrapper',
|
|
183
|
-
styles,
|
|
184
|
-
variants,
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
const itemStyles = useNestedStylesByKey('item', variantStyles)
|
|
167
|
+
const styles = useStylesFor(Select.styleRegistryName, style)
|
|
188
168
|
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
const inputStyles = useNestedStylesByKey('input', variantStyles)
|
|
192
|
-
|
|
193
|
-
const searchInputStyles = useNestedStylesByKey('searchInput', variantStyles)
|
|
169
|
+
const compositionStyles = useCompositionStyles(['item', 'list', 'input', 'searchInput'], styles)
|
|
194
170
|
|
|
195
171
|
const currentOptions = searchable ? filteredOptions : defaultOptions
|
|
196
172
|
|
|
197
173
|
const close = () => toggle?.()
|
|
198
174
|
|
|
199
175
|
const select = useCallback((selectedValue) => {
|
|
200
|
-
|
|
201
176
|
let newValue = null
|
|
202
177
|
|
|
203
178
|
let newOption = null
|
|
@@ -243,13 +218,9 @@ export const Select = <T extends string | number = string, Multi extends boolean
|
|
|
243
218
|
if (closeOnSelect) {
|
|
244
219
|
close?.()
|
|
245
220
|
}
|
|
246
|
-
|
|
247
221
|
}, [isValueArray, (isValueArray ? value : [value]), limit, multiple])
|
|
248
222
|
|
|
249
|
-
const Item = renderItem || Button
|
|
250
|
-
|
|
251
223
|
const renderListItem = useCallback(({ item, index }) => {
|
|
252
|
-
|
|
253
224
|
let selected = false
|
|
254
225
|
|
|
255
226
|
if (multiple && isValueArray) {
|
|
@@ -268,7 +239,7 @@ export const Select = <T extends string | number = string, Multi extends boolean
|
|
|
268
239
|
icon={selectedIcon}
|
|
269
240
|
// @ts-ignore
|
|
270
241
|
rightIcon={selectedIcon}
|
|
271
|
-
|
|
242
|
+
style={compositionStyles?.item}
|
|
272
243
|
index={index}
|
|
273
244
|
{...itemProps}
|
|
274
245
|
/>
|
|
@@ -297,7 +268,7 @@ export const Select = <T extends string | number = string, Multi extends boolean
|
|
|
297
268
|
}}
|
|
298
269
|
debounce={!!loadOptions ? 800 : null}
|
|
299
270
|
onSearchChange={onChangeSearch}
|
|
300
|
-
|
|
271
|
+
style={compositionStyles?.searchInput}
|
|
301
272
|
{...searchInputProps}
|
|
302
273
|
/> : null
|
|
303
274
|
|
|
@@ -316,26 +287,22 @@ export const Select = <T extends string | number = string, Multi extends boolean
|
|
|
316
287
|
|
|
317
288
|
return <>
|
|
318
289
|
{
|
|
319
|
-
!hideInput
|
|
290
|
+
!hideInput ? (
|
|
320
291
|
// @ts-ignore
|
|
321
292
|
<Input
|
|
322
|
-
|
|
323
293
|
clearIcon={{
|
|
324
|
-
icon: inputIcon as
|
|
294
|
+
icon: inputIcon as AppIcon,
|
|
325
295
|
onPress: disabled ? null : onPressInputIcon,
|
|
326
296
|
}}
|
|
327
|
-
|
|
328
297
|
currentValueLabel={currentValueLabel}
|
|
329
|
-
|
|
330
298
|
debugName={`${debugName} select input`}
|
|
331
|
-
|
|
332
|
-
style={style}
|
|
299
|
+
style={compositionStyles?.input}
|
|
333
300
|
{...allProps}
|
|
334
301
|
{...inputProps}
|
|
335
302
|
visible={visible}
|
|
336
303
|
toggle={toggle}
|
|
337
304
|
/>
|
|
338
|
-
)
|
|
305
|
+
) : null
|
|
339
306
|
}
|
|
340
307
|
|
|
341
308
|
<ModalManager.Modal
|
|
@@ -343,18 +310,17 @@ export const Select = <T extends string | number = string, Multi extends boolean
|
|
|
343
310
|
description={description}
|
|
344
311
|
{...modalProps}
|
|
345
312
|
debugName={`${debugName} modal`}
|
|
346
|
-
|
|
313
|
+
style={styles}
|
|
347
314
|
id={null}
|
|
348
315
|
visible={visible}
|
|
349
316
|
toggle={toggle}
|
|
350
|
-
|
|
351
317
|
>
|
|
352
|
-
<ListComponent
|
|
318
|
+
<ListComponent
|
|
353
319
|
data={searchable ? filteredOptions : options}
|
|
354
320
|
scrollEnabled={false}
|
|
355
321
|
showsHorizontalScrollIndicator={false}
|
|
356
|
-
|
|
357
|
-
keyExtractor={(i) => i.value}
|
|
322
|
+
style={compositionStyles?.list}
|
|
323
|
+
keyExtractor={(i: { value: any }) => i.value}
|
|
358
324
|
renderItem={renderListItem}
|
|
359
325
|
fakeEmpty={loading}
|
|
360
326
|
separators
|
|
@@ -366,11 +332,34 @@ export const Select = <T extends string | number = string, Multi extends boolean
|
|
|
366
332
|
}}
|
|
367
333
|
/>
|
|
368
334
|
</ModalManager.Modal>
|
|
369
|
-
|
|
370
335
|
</>
|
|
371
336
|
}
|
|
372
337
|
|
|
373
|
-
export * from './styles'
|
|
374
|
-
export * from './types'
|
|
375
338
|
|
|
376
|
-
Select.
|
|
339
|
+
Select.styleRegistryName = 'Select'
|
|
340
|
+
Select.elements = [...Modal.elements, 'input', 'list', 'item', 'searchInput']
|
|
341
|
+
Select.rootElement = 'inputWrapper'
|
|
342
|
+
|
|
343
|
+
Select.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
344
|
+
return Select as (<T extends string | number = string, Multi extends boolean = false>(props: StyledComponentProps<SelectProps<T, Multi>, typeof styles>) => IJSX)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
Select.defaultProps = {
|
|
348
|
+
getLabel: defaultGetLabel,
|
|
349
|
+
outerInputComponent: OuterInput,
|
|
350
|
+
searchInputProps: {},
|
|
351
|
+
arrowIconName: 'chevrons-up-down' as AppIcon,
|
|
352
|
+
clearIconName: 'x' as AppIcon,
|
|
353
|
+
placeholder: 'Select',
|
|
354
|
+
clearable: false,
|
|
355
|
+
selectedIcon: 'check' as AppIcon,
|
|
356
|
+
hideInput: false,
|
|
357
|
+
multiple: false,
|
|
358
|
+
loadOptionsOnOpen: false,
|
|
359
|
+
disabled: false,
|
|
360
|
+
filterItems: defaultFilterFunction,
|
|
361
|
+
renderItem: Button,
|
|
362
|
+
ListComponent: List,
|
|
363
|
+
} as Partial<SelectProps<any, boolean>>
|
|
364
|
+
|
|
365
|
+
MobileStyleRegistry.registerComponent(Select)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ButtonComposition
|
|
1
|
+
import { ButtonComposition } from '../Button'
|
|
2
2
|
import { ListComposition } from '../List'
|
|
3
3
|
import { ModalComposition } from '../Modal'
|
|
4
|
+
import { TextInputComposition } from '../TextInput'
|
|
5
|
+
|
|
4
6
|
type ItemStates = '' | ':selected'
|
|
5
7
|
|
|
6
8
|
type ItemParts = ButtonComposition
|
|
@@ -13,7 +15,3 @@ export type SelectComposition =
|
|
|
13
15
|
`list${Capitalize<ListComposition>}` |
|
|
14
16
|
`item${Capitalize<ItemComposition>}` |
|
|
15
17
|
`searchInput${Capitalize<TextInputComposition>}`
|
|
16
|
-
|
|
17
|
-
const createSelectStyle = createDefaultVariantFactory<SelectComposition>()
|
|
18
|
-
|
|
19
|
-
export const SelectPresets = includePresets((style) => createSelectStyle(() => ({ body: style })))
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
FormTypes,
|
|
4
|
-
IconPlaceholder,
|
|
5
|
-
PropsOf,
|
|
6
|
-
} from '@codeleap/common'
|
|
1
|
+
import { FormTypes, PropsOf } from '@codeleap/common'
|
|
2
|
+
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
7
3
|
import { StylesOf } from '../../types/utility'
|
|
8
4
|
import { GetKeyboardAwarePropsOptions } from '../../utils'
|
|
9
5
|
import { ActionIconProps } from '../ActionIcon'
|
|
@@ -11,25 +7,27 @@ import { Icon } from '../Icon'
|
|
|
11
7
|
import { FlatListProps } from '../List'
|
|
12
8
|
import { ModalProps } from '../Modal'
|
|
13
9
|
import { Text } from '../Text'
|
|
14
|
-
import {
|
|
10
|
+
import { TextInputComposition } from '../TextInput'
|
|
11
|
+
import { SearchInputProps } from '../SearchInput'
|
|
15
12
|
import { Touchable } from '../Touchable'
|
|
16
|
-
import { SelectComposition
|
|
13
|
+
import { SelectComposition } from './styles'
|
|
17
14
|
|
|
18
15
|
export type SelectRenderFNProps<T> = {
|
|
19
|
-
|
|
16
|
+
style: StylesOf<SelectComposition>
|
|
20
17
|
onPress: () => void
|
|
21
|
-
|
|
18
|
+
selected?: boolean
|
|
22
19
|
item: FormTypes.Options<T>[number]
|
|
23
20
|
touchableProps?: Partial<PropsOf<typeof Touchable>>
|
|
24
21
|
textProps?: Partial<PropsOf<typeof Text>>
|
|
25
22
|
iconProps?: Partial<PropsOf<typeof Icon>>
|
|
26
23
|
index: number
|
|
27
24
|
debugName: string
|
|
25
|
+
text?: string
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
export type SelectRenderFN<T> = (props: SelectRenderFNProps<T>) => JSX.Element
|
|
31
29
|
|
|
32
|
-
type SelectModalProps = Omit<ModalProps, '
|
|
30
|
+
type SelectModalProps = Omit<ModalProps, 'style'>
|
|
33
31
|
|
|
34
32
|
export type SelectValue<T, Multi extends boolean = false> = Multi extends true ? T[] : T
|
|
35
33
|
|
|
@@ -37,7 +35,7 @@ type SelectHeaderProps = {
|
|
|
37
35
|
searchComponent?: React.ReactNode
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
export type SelectOuterInputProps<T = any, Multi extends boolean = false> =
|
|
38
|
+
export type SelectOuterInputProps<T = any, Multi extends boolean = false> = SelectProps<T, Multi> & {
|
|
41
39
|
currentValueLabel: FormTypes.Label
|
|
42
40
|
styles?: StylesOf<TextInputComposition>
|
|
43
41
|
clearIcon?: Partial<ActionIconProps>
|
|
@@ -69,24 +67,22 @@ export type ReplaceSelectProps<Props, T, Multi extends boolean = false> = Omit<
|
|
|
69
67
|
keyof ValueBoundSelectProps<T, Multi>
|
|
70
68
|
> & ValueBoundSelectProps<T, Multi>
|
|
71
69
|
|
|
72
|
-
export type SelectProps<T = any, Multi extends boolean = false> =
|
|
70
|
+
export type SelectProps<T = any, Multi extends boolean = false> =
|
|
71
|
+
SelectModalProps &
|
|
72
|
+
ValueBoundSelectProps<T, Multi> &
|
|
73
|
+
{
|
|
73
74
|
placeholder?: FormTypes.Label
|
|
74
75
|
label?: FormTypes.Label
|
|
75
|
-
styles?: StylesOf<SelectComposition>
|
|
76
|
-
style?: TextInputProps['style']
|
|
77
76
|
hideInput?: boolean
|
|
78
|
-
selectedIcon?:
|
|
79
|
-
arrowIconName?:
|
|
77
|
+
selectedIcon?: AppIcon
|
|
78
|
+
arrowIconName?: AppIcon
|
|
80
79
|
closeOnSelect?: boolean
|
|
81
|
-
|
|
82
80
|
listProps?: Partial<FlatListProps>
|
|
83
81
|
clearable?: boolean
|
|
84
|
-
clearIconName?:
|
|
82
|
+
clearIconName?: AppIcon
|
|
85
83
|
keyboardAware?: GetKeyboardAwarePropsOptions
|
|
86
84
|
multiple?: Multi
|
|
87
|
-
itemProps?: Partial<
|
|
88
|
-
Pick<SelectRenderFNProps<any>, 'iconProps'|'textProps'|'touchableProps'
|
|
89
|
-
>>
|
|
85
|
+
itemProps?: Partial<Pick<SelectRenderFNProps<any>, 'iconProps' | 'textProps' | 'touchableProps'>>
|
|
90
86
|
searchable?: boolean
|
|
91
87
|
limit?: number
|
|
92
88
|
ListHeaderComponent?: React.ComponentType<SelectHeaderProps>
|
|
@@ -94,6 +90,5 @@ export type SelectProps<T = any, Multi extends boolean = false> = {
|
|
|
94
90
|
searchInputProps?: Partial<SearchInputProps>
|
|
95
91
|
loadOptionsOnMount?: boolean
|
|
96
92
|
loadOptionsOnOpen?: boolean
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
93
|
+
style?: StyledProp<SelectComposition>
|
|
94
|
+
}
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react'
|
|
2
2
|
import { Slider as RNSlider } from '@miblanchard/react-native-slider'
|
|
3
3
|
import { StyleSheet } from 'react-native'
|
|
4
|
-
import {
|
|
5
|
-
TypeGuards,
|
|
6
|
-
useDefaultComponentStyle,
|
|
7
|
-
onUpdate,
|
|
8
|
-
} from '@codeleap/common'
|
|
9
|
-
|
|
4
|
+
import { TypeGuards, onUpdate } from '@codeleap/common'
|
|
10
5
|
import { SliderProps, TrackMarkProps } from './types'
|
|
11
6
|
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
12
|
-
import { SliderPresets } from './styles'
|
|
13
7
|
import { Text } from '../Text'
|
|
14
8
|
import { View } from '../View'
|
|
15
9
|
import { Touchable } from '../Touchable'
|
|
10
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
11
|
+
import { MobileStyleRegistry } from '../../Registry'
|
|
12
|
+
import { useStylesFor } from '../../hooks'
|
|
16
13
|
|
|
17
14
|
export * from './styles'
|
|
15
|
+
export * from './types'
|
|
18
16
|
|
|
19
17
|
const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
20
|
-
const {
|
|
18
|
+
const { style, onPress } = props
|
|
21
19
|
|
|
22
20
|
if (!TypeGuards.isString(props.content)) {
|
|
23
21
|
return <>
|
|
@@ -35,11 +33,14 @@ const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
|
35
33
|
const minimumValue = 0
|
|
36
34
|
const maximumValue = 100
|
|
37
35
|
|
|
38
|
-
export const Slider = (props:SliderProps) => {
|
|
36
|
+
export const Slider = (props: SliderProps) => {
|
|
39
37
|
const {
|
|
40
38
|
inputBaseProps: { label: _label, description: _description, ..._inputBaseProps },
|
|
41
39
|
others,
|
|
42
|
-
} = selectInputBaseProps(
|
|
40
|
+
} = selectInputBaseProps({
|
|
41
|
+
...Slider.defaultProps,
|
|
42
|
+
...props,
|
|
43
|
+
})
|
|
43
44
|
|
|
44
45
|
const {
|
|
45
46
|
debounce = null,
|
|
@@ -48,17 +49,15 @@ export const Slider = (props:SliderProps) => {
|
|
|
48
49
|
label,
|
|
49
50
|
description,
|
|
50
51
|
debugName,
|
|
51
|
-
styles = {},
|
|
52
52
|
style,
|
|
53
53
|
disabled,
|
|
54
|
-
variants,
|
|
55
54
|
trackMarks,
|
|
56
|
-
trackMarksClickable
|
|
57
|
-
labelClickable
|
|
58
|
-
trackMarkComponent
|
|
55
|
+
trackMarksClickable,
|
|
56
|
+
labelClickable,
|
|
57
|
+
trackMarkComponent: SliderTrackMark,
|
|
59
58
|
...sliderProps
|
|
60
59
|
} = others
|
|
61
|
-
|
|
60
|
+
|
|
62
61
|
const [_value, _setValue] = React.useState(value)
|
|
63
62
|
|
|
64
63
|
onUpdate(() => {
|
|
@@ -67,44 +66,40 @@ export const Slider = (props:SliderProps) => {
|
|
|
67
66
|
}
|
|
68
67
|
}, [value])
|
|
69
68
|
|
|
70
|
-
const
|
|
71
|
-
variants,
|
|
72
|
-
styles,
|
|
73
|
-
transform: StyleSheet.flatten,
|
|
74
|
-
})
|
|
69
|
+
const styles = useStylesFor(Slider.styleRegistryName, style)
|
|
75
70
|
|
|
76
71
|
const thumbStyle = React.useMemo(() => {
|
|
77
72
|
return StyleSheet.flatten([
|
|
78
|
-
|
|
79
|
-
disabled &&
|
|
73
|
+
styles?.thumb,
|
|
74
|
+
disabled && styles['thumb:disabled'],
|
|
80
75
|
])
|
|
81
76
|
}, [])
|
|
82
77
|
|
|
83
78
|
const trackStyle = React.useMemo(() => {
|
|
84
79
|
return StyleSheet.flatten([
|
|
85
|
-
|
|
86
|
-
disabled &&
|
|
80
|
+
styles?.track,
|
|
81
|
+
disabled && styles['track:disabled'],
|
|
87
82
|
])
|
|
88
83
|
}, [disabled])
|
|
89
84
|
|
|
90
85
|
const selectedTrackStyle = React.useMemo(() => {
|
|
91
86
|
return StyleSheet.flatten([
|
|
92
|
-
|
|
93
|
-
disabled &&
|
|
87
|
+
styles?.selectedTrack,
|
|
88
|
+
disabled && styles['selectedTrack:disabled'],
|
|
94
89
|
])
|
|
95
90
|
}, [disabled])
|
|
96
91
|
|
|
97
92
|
const unselectedTrackStyle = React.useMemo(() => {
|
|
98
93
|
return StyleSheet.flatten([
|
|
99
|
-
|
|
100
|
-
disabled &&
|
|
94
|
+
styles?.unselectedTrack,
|
|
95
|
+
disabled && styles['unselectedTrack:disabled'],
|
|
101
96
|
])
|
|
102
97
|
}, [disabled])
|
|
103
98
|
|
|
104
99
|
const containerStyle = React.useMemo(() => {
|
|
105
100
|
return StyleSheet.flatten([
|
|
106
|
-
|
|
107
|
-
disabled &&
|
|
101
|
+
styles?.sliderContainer,
|
|
102
|
+
disabled && styles['sliderContainer:disabled'],
|
|
108
103
|
])
|
|
109
104
|
}, [disabled])
|
|
110
105
|
|
|
@@ -119,8 +114,8 @@ export const Slider = (props:SliderProps) => {
|
|
|
119
114
|
|
|
120
115
|
const trackMarkStyle = React.useMemo(() => {
|
|
121
116
|
return StyleSheet.flatten([
|
|
122
|
-
|
|
123
|
-
disabled &&
|
|
117
|
+
styles?.trackMark,
|
|
118
|
+
disabled && styles['trackMark:disabled'],
|
|
124
119
|
])
|
|
125
120
|
}, [disabled])
|
|
126
121
|
|
|
@@ -128,31 +123,32 @@ export const Slider = (props:SliderProps) => {
|
|
|
128
123
|
<InputBase
|
|
129
124
|
{..._inputBaseProps}
|
|
130
125
|
disabled={disabled}
|
|
131
|
-
|
|
126
|
+
style={styles}
|
|
132
127
|
labelAsRow
|
|
133
128
|
>
|
|
134
129
|
{label || description ? (
|
|
135
|
-
<View style={
|
|
130
|
+
<View style={styles.labelRow}>
|
|
136
131
|
{label ? (
|
|
137
132
|
<Touchable
|
|
138
133
|
onPress={() => labelClickable ? onValueChange(sliderProps?.minimumValue || minimumValue) : null}
|
|
139
|
-
|
|
134
|
+
style={styles.labelBtn}
|
|
140
135
|
debugName='slider title'
|
|
141
136
|
>
|
|
142
|
-
<Text style={
|
|
137
|
+
<Text style={styles?.label} text={label} />
|
|
143
138
|
</Touchable>
|
|
144
139
|
) : null}
|
|
145
140
|
{description ? (
|
|
146
141
|
<Touchable
|
|
147
142
|
onPress={() => labelClickable ? onValueChange(sliderProps?.maximumValue || maximumValue) : null}
|
|
148
|
-
|
|
143
|
+
style={styles?.descriptionBtn}
|
|
149
144
|
debugName='slider description'
|
|
150
145
|
>
|
|
151
|
-
<Text style={
|
|
146
|
+
<Text style={styles?.description} text={description} />
|
|
152
147
|
</Touchable>
|
|
153
148
|
) : null}
|
|
154
149
|
</View>
|
|
155
150
|
) : null}
|
|
151
|
+
|
|
156
152
|
<RNSlider
|
|
157
153
|
value={_value}
|
|
158
154
|
onValueChange={_setValue}
|
|
@@ -174,16 +170,17 @@ export const Slider = (props:SliderProps) => {
|
|
|
174
170
|
/>
|
|
175
171
|
{
|
|
176
172
|
trackMarksProp ? (
|
|
177
|
-
<View style={
|
|
173
|
+
<View style={styles?.trackMarkWrapper}>
|
|
178
174
|
{
|
|
179
175
|
trackMarksProp.map((_, idx) => {
|
|
180
176
|
let idxStyle = {}
|
|
181
177
|
|
|
182
178
|
if (idx === 0) {
|
|
183
|
-
idxStyle =
|
|
179
|
+
idxStyle = styles?.firstTrackMark
|
|
184
180
|
} else if (idx === trackMarksProp.length - 1) {
|
|
185
|
-
idxStyle =
|
|
181
|
+
idxStyle = styles?.lastTrackMark
|
|
186
182
|
}
|
|
183
|
+
|
|
187
184
|
const style = [
|
|
188
185
|
trackMarkStyle,
|
|
189
186
|
idxStyle,
|
|
@@ -217,3 +214,21 @@ export const Slider = (props:SliderProps) => {
|
|
|
217
214
|
)
|
|
218
215
|
}
|
|
219
216
|
|
|
217
|
+
Slider.styleRegistryName = 'Slider'
|
|
218
|
+
Slider.rootElement = 'wrapper'
|
|
219
|
+
Slider.elements = [
|
|
220
|
+
...InputBase.elements,
|
|
221
|
+
'thumb', 'track', 'selectedTrack', 'unselectedTrack', 'firstTrackMark', 'lastTrackMark', 'sliderContainer', 'labelBtn', 'descriptionBtn'
|
|
222
|
+
]
|
|
223
|
+
|
|
224
|
+
Slider.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
225
|
+
return Slider as (props: StyledComponentProps<SliderProps, typeof styles>) => IJSX
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
Slider.defaultProps = {
|
|
229
|
+
trackMarksClickable: false,
|
|
230
|
+
labelClickable: false,
|
|
231
|
+
trackMarkComponent: DefaultSliderTrackMark,
|
|
232
|
+
} as Partial<SliderProps>
|
|
233
|
+
|
|
234
|
+
MobileStyleRegistry.registerComponent(Slider)
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import { PartialComponentStyle
|
|
1
|
+
import { PartialComponentStyle } from '@codeleap/common'
|
|
2
2
|
import { IconLessInputBaseParts, InputBaseStates } from '../InputBase'
|
|
3
|
-
import { TouchableStylesGen } from '../Touchable'
|
|
3
|
+
import { TouchableComposition, TouchableStylesGen } from '../Touchable'
|
|
4
|
+
|
|
5
|
+
type SliderParts =
|
|
6
|
+
'thumb' |
|
|
7
|
+
'track' |
|
|
8
|
+
'selectedTrack' |
|
|
9
|
+
'unselectedTrack' |
|
|
10
|
+
'trackMark' |
|
|
11
|
+
'firstTrackMark' |
|
|
12
|
+
'lastTrackMark' |
|
|
13
|
+
'trackMarkWrapper' |
|
|
14
|
+
'sliderContainer' |
|
|
15
|
+
IconLessInputBaseParts
|
|
4
16
|
|
|
5
|
-
type SliderParts = 'thumb' | 'track' | 'selectedTrack' | 'unselectedTrack' | 'trackMark' | 'firstTrackMark' | 'lastTrackMark' | 'trackMarkWrapper' | 'sliderContainer' | IconLessInputBaseParts
|
|
6
17
|
type SliderStates = Exclude<InputBaseStates, 'focus'>
|
|
7
18
|
|
|
8
19
|
export type SliderComposition = `${SliderParts}:${SliderStates}` | SliderParts | 'labelBtn' | 'descriptionBtn'
|
|
20
|
+
|
|
9
21
|
export type SliderStylesGen = {
|
|
10
22
|
labelBtn: PartialComponentStyle<TouchableComposition, TouchableStylesGen>
|
|
11
23
|
descriptionBtn: PartialComponentStyle<TouchableComposition, TouchableStylesGen>
|
|
12
24
|
}
|
|
13
|
-
const createSliderStyle = createDefaultVariantFactory<SliderComposition>()
|
|
14
|
-
|
|
15
|
-
export const SliderPresets = includePresets((styles) => createSliderStyle(() => ({ wrapper: styles })))
|