@helpwave/hightide-native 0.5.0 → 0.7.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 +3 -3
- package/src/components/card/Card.tsx +2 -4
- package/src/components/chat/ChatAttachmentMessageBubble.tsx +155 -94
- package/src/components/chat/ChatConversationList.tsx +4 -12
- package/src/components/chat/ChatConversationRow.tsx +159 -164
- package/src/components/chat/ChatDateDivider.tsx +3 -8
- package/src/components/chat/ChatMessageBubble.tsx +54 -52
- package/src/components/chat/ChatMessageComposer.tsx +4 -12
- package/src/components/chat/ChatMessageList.tsx +3 -9
- package/src/components/chat/ChatQuickReplyChip.tsx +41 -27
- package/src/components/chat/ChatSystemLine.tsx +4 -12
- package/src/components/chat/ChatThreadHeader.tsx +136 -101
- package/src/components/layout/Divider.tsx +2 -4
- package/src/components/list/ListActionItem.tsx +57 -65
- package/src/components/list/ListItem.tsx +8 -28
- package/src/components/list/ListItemTextContent.tsx +4 -2
- package/src/components/list/ListNavigationItem.tsx +55 -63
- package/src/components/user-interaction/Button.tsx +43 -49
- package/src/components/user-interaction/Checkbox.tsx +47 -48
- package/src/components/user-interaction/IconButton.tsx +40 -42
- package/src/components/user-interaction/Input.tsx +70 -67
- package/src/components/user-interaction/MultiSelect/MultiSelect.tsx +40 -0
- package/src/components/user-interaction/MultiSelect/MultiSelectContext.tsx +70 -0
- package/src/components/user-interaction/MultiSelect/MultiSelectMenu.tsx +87 -0
- package/src/components/user-interaction/MultiSelect/MultiSelectOption.tsx +87 -0
- package/src/components/user-interaction/MultiSelect/MultiSelectRoot.tsx +194 -0
- package/src/components/user-interaction/MultiSelect/MultiSelectTrigger.tsx +123 -0
- package/src/components/user-interaction/MultiSelect/index.ts +6 -0
- package/src/components/user-interaction/SearchBar.tsx +11 -17
- package/src/components/user-interaction/Select/Select.tsx +40 -0
- package/src/components/user-interaction/Select/SelectContext.tsx +69 -0
- package/src/components/user-interaction/Select/SelectMenu.tsx +87 -0
- package/src/components/user-interaction/Select/SelectOption.tsx +77 -0
- package/src/components/user-interaction/Select/SelectRoot.tsx +186 -0
- package/src/components/user-interaction/Select/SelectTrigger.tsx +92 -0
- package/src/components/user-interaction/Select/index.ts +6 -0
- package/src/components/user-interaction/Switch.tsx +46 -98
- package/src/components/user-interaction/Textarea.tsx +179 -0
- package/src/components/user-interaction/ThemedPressable.tsx +48 -49
- package/src/components/user-interaction/index.ts +1 -0
- package/src/components/visualization-and-display/Avatar.tsx +19 -17
- package/src/components/visualization-and-display/Chip.tsx +4 -12
- package/src/components/visualization-and-display/ThemedText.tsx +12 -5
- package/src/enums/chatMessageDirection.ts +18 -0
- package/src/enums/chatMessageStatus.ts +18 -0
- package/src/enums/hightideThemeModes.ts +18 -0
- package/src/enums/index.ts +7 -0
- package/src/enums/listItemContentOrder.ts +18 -0
- package/src/enums/themedTextAppearance.ts +18 -0
- package/src/enums/useMultiSelectFirstHighlightBehavior.ts +18 -0
- package/src/enums/useSelectFirstHighlightBehavior.ts +18 -0
- package/src/global-contexts/content-theme/ContentThemeProvider.tsx +9 -5
- package/src/global-contexts/theme/ThemeProvider.tsx +4 -1
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useAnimatedStyleTransition.ts +460 -0
- package/src/hooks/useMemoizedTheme.ts +23 -0
- package/src/hooks/useMultiSelect.ts +3 -1
- package/src/hooks/useSelect.ts +3 -1
- package/src/icons/HightideIconRegistry.ts +2 -0
- package/src/theme/adapters/style-adapter-utils.ts +121 -27
- package/src/theme/resolvers/avatar.ts +48 -39
- package/src/theme/resolvers/button.ts +7 -17
- package/src/theme/resolvers/chat/attachment-message-bubble.ts +5 -6
- package/src/theme/resolvers/chat/conversation-row.ts +4 -6
- package/src/theme/resolvers/chat/message-bubble.ts +1 -2
- package/src/theme/resolvers/chat/message-composer.ts +1 -2
- package/src/theme/resolvers/chat/quick-reply-chip.ts +2 -3
- package/src/theme/resolvers/chat/system-line.ts +1 -2
- package/src/theme/resolvers/chat/thread-header.ts +3 -4
- package/src/theme/resolvers/checkbox.ts +2 -2
- package/src/theme/resolvers/chip.ts +1 -2
- package/src/theme/resolvers/iconButton.ts +4 -13
- package/src/theme/resolvers/index.ts +1 -0
- package/src/theme/resolvers/input.ts +30 -14
- package/src/theme/resolvers/listItem.ts +2 -3
- package/src/theme/resolvers/multiSelect.ts +1 -3
- package/src/theme/resolvers/searchBar.ts +1 -2
- package/src/theme/resolvers/select.ts +1 -2
- package/src/theme/resolvers/textarea.ts +14 -0
- package/src/theme/resolvers/themedPressable.ts +4 -15
- package/src/theme/themes/createHightideTheme.ts +6 -0
- package/src/theme/themes/hightideThemes.ts +3 -1
- package/src/theme/types/components/chat.ts +6 -21
- package/src/theme/types/components/hightide.ts +2 -0
- package/src/theme/types/components/index.ts +1 -0
- package/src/theme/types/components/input.ts +3 -0
- package/src/theme/types/components/textarea.ts +9 -0
- package/src/theme/types/resolver.ts +4 -27
- package/src/utils/index.ts +1 -0
- package/src/utils/pressableInteraction.ts +7 -0
- package/src/components/user-interaction/MultiSelect.tsx +0 -281
- package/src/components/user-interaction/Select.tsx +0 -242
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import { Fragment, useMemo } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
FlatList,
|
|
4
|
-
Modal,
|
|
5
|
-
Pressable,
|
|
6
|
-
View,
|
|
7
|
-
type StyleProp,
|
|
8
|
-
type ViewStyle
|
|
9
|
-
} from 'react-native'
|
|
10
|
-
import type { ColorPairToken } from '@helpwave/hightide-design/theme-tokens'
|
|
11
|
-
import { Chip } from '../visualization-and-display/Chip'
|
|
12
|
-
import { ThemedText } from '../visualization-and-display/ThemedText'
|
|
13
|
-
import { ThemedIcon } from '../visualization-and-display/ThemedIcon'
|
|
14
|
-
import { ListActionItem } from '../list/ListActionItem'
|
|
15
|
-
import { IconButton } from './IconButton'
|
|
16
|
-
import { SearchBar } from './SearchBar'
|
|
17
|
-
import { HightideIconRegistry } from '../../icons/HightideIconRegistry'
|
|
18
|
-
import { useTheme } from '../../global-contexts/theme/ThemeContext'
|
|
19
|
-
import {
|
|
20
|
-
useMultiSelect,
|
|
21
|
-
type UseMultiSelectOption
|
|
22
|
-
} from '../../hooks/useMultiSelect'
|
|
23
|
-
import type { MultiSelectState } from '../../theme/types/components/multiSelect'
|
|
24
|
-
import type {
|
|
25
|
-
FormFieldDataHandling,
|
|
26
|
-
FormFieldInteractionStates
|
|
27
|
-
} from '../../types/formField'
|
|
28
|
-
import { useTranslation } from '@helpwave/hightide-utils/context'
|
|
29
|
-
|
|
30
|
-
export type MultiSelectOption = UseMultiSelectOption
|
|
31
|
-
|
|
32
|
-
export type MultiSelectProps = Partial<FormFieldDataHandling<string[]>>
|
|
33
|
-
& Partial<FormFieldInteractionStates>
|
|
34
|
-
& {
|
|
35
|
-
options: ReadonlyArray<MultiSelectOption>,
|
|
36
|
-
value?: string[],
|
|
37
|
-
initialValue?: string[],
|
|
38
|
-
placeholder?: string,
|
|
39
|
-
showSearch?: boolean,
|
|
40
|
-
color?: ColorPairToken,
|
|
41
|
-
style?: StyleProp<ViewStyle>,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const MultiSelect = ({
|
|
45
|
-
options,
|
|
46
|
-
value: controlledValue,
|
|
47
|
-
initialValue = [],
|
|
48
|
-
placeholder = 'Select…',
|
|
49
|
-
showSearch = true,
|
|
50
|
-
color,
|
|
51
|
-
disabled = false,
|
|
52
|
-
readOnly = false,
|
|
53
|
-
invalid = false,
|
|
54
|
-
onValueChange,
|
|
55
|
-
onEditComplete,
|
|
56
|
-
style,
|
|
57
|
-
}: MultiSelectProps) => {
|
|
58
|
-
const { theme } = useTheme()
|
|
59
|
-
const translation = useTranslation()
|
|
60
|
-
const interactive = !disabled && !readOnly
|
|
61
|
-
|
|
62
|
-
const multiSelect = useMultiSelect({
|
|
63
|
-
options,
|
|
64
|
-
value: controlledValue,
|
|
65
|
-
initialValue,
|
|
66
|
-
onValueChange,
|
|
67
|
-
onEditComplete,
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
const isSearchVisible = showSearch && options.length >= 6
|
|
71
|
-
|
|
72
|
-
const selectedOptions = useMemo(() => {
|
|
73
|
-
return options.filter((option) => multiSelect.isSelected(option.id))
|
|
74
|
-
}, [multiSelect, options])
|
|
75
|
-
|
|
76
|
-
const state = useMemo((): MultiSelectState => ({
|
|
77
|
-
color,
|
|
78
|
-
isDisabled: disabled,
|
|
79
|
-
isReadonly: readOnly,
|
|
80
|
-
isInvalid: invalid,
|
|
81
|
-
isOpen: multiSelect.isOpen,
|
|
82
|
-
hasSelections: selectedOptions.length > 0,
|
|
83
|
-
hasValue: selectedOptions.length > 0,
|
|
84
|
-
}), [color, disabled, invalid, multiSelect.isOpen, readOnly, selectedOptions.length])
|
|
85
|
-
|
|
86
|
-
const multiSelectTheme = theme.components.multiSelect
|
|
87
|
-
|
|
88
|
-
const resolvedOverlayStyle = useMemo(
|
|
89
|
-
() => multiSelectTheme.overlay({}),
|
|
90
|
-
[multiSelectTheme]
|
|
91
|
-
)
|
|
92
|
-
const resolvedMenuStyle = useMemo(
|
|
93
|
-
() => multiSelectTheme.menu({ hasSearch: isSearchVisible }),
|
|
94
|
-
[multiSelectTheme, isSearchVisible]
|
|
95
|
-
)
|
|
96
|
-
const resolvedHeaderStyle = useMemo(
|
|
97
|
-
() => multiSelectTheme.header({}),
|
|
98
|
-
[multiSelectTheme]
|
|
99
|
-
)
|
|
100
|
-
const resolvedEmptyTextStyle = useMemo(
|
|
101
|
-
() => multiSelectTheme.emptyText({}),
|
|
102
|
-
[multiSelectTheme]
|
|
103
|
-
)
|
|
104
|
-
const visibleOptions = useMemo(
|
|
105
|
-
() => options.filter((option) => multiSelect.visibleOptionIds.includes(option.id)),
|
|
106
|
-
[options, multiSelect.visibleOptionIds]
|
|
107
|
-
)
|
|
108
|
-
const showEmptySearchResults = isSearchVisible
|
|
109
|
-
&& multiSelect.searchQuery.trim().length > 0
|
|
110
|
-
&& visibleOptions.length === 0
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<View style={[{ width: '100%' }, style]}>
|
|
114
|
-
<Pressable
|
|
115
|
-
disabled={!interactive}
|
|
116
|
-
onPress={() => multiSelect.toggleOpen()}
|
|
117
|
-
style={(pressableState) => {
|
|
118
|
-
const interaction = pressableState as {
|
|
119
|
-
pressed: boolean,
|
|
120
|
-
hovered?: boolean,
|
|
121
|
-
focused?: boolean,
|
|
122
|
-
focusVisible?: boolean,
|
|
123
|
-
}
|
|
124
|
-
return multiSelectTheme.trigger({
|
|
125
|
-
...state,
|
|
126
|
-
isPressed: interaction.pressed,
|
|
127
|
-
isHovered: !!interaction.hovered,
|
|
128
|
-
isFocused: !!interaction.focused,
|
|
129
|
-
isFocusVisible: !!interaction.focusVisible,
|
|
130
|
-
})
|
|
131
|
-
}}
|
|
132
|
-
>
|
|
133
|
-
{(pressableState) => {
|
|
134
|
-
const interaction = pressableState as {
|
|
135
|
-
pressed: boolean,
|
|
136
|
-
hovered?: boolean,
|
|
137
|
-
focused?: boolean,
|
|
138
|
-
focusVisible?: boolean,
|
|
139
|
-
}
|
|
140
|
-
const triggerState = {
|
|
141
|
-
...state,
|
|
142
|
-
isPressed: interaction.pressed,
|
|
143
|
-
isHovered: !!interaction.hovered,
|
|
144
|
-
isFocused: !!interaction.focused,
|
|
145
|
-
isFocusVisible: !!interaction.focusVisible,
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return (
|
|
149
|
-
<Fragment>
|
|
150
|
-
<View
|
|
151
|
-
pointerEvents="none"
|
|
152
|
-
style={multiSelectTheme.stateLayer(triggerState)}
|
|
153
|
-
/>
|
|
154
|
-
{selectedOptions.length > 0
|
|
155
|
-
? (
|
|
156
|
-
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 6, flex: 1 }}>
|
|
157
|
-
{selectedOptions.map((option) => (
|
|
158
|
-
<Chip key={option.id} size="md" color={color} variant="tonal">
|
|
159
|
-
<ThemedText>{option.label ?? option.id}</ThemedText>
|
|
160
|
-
{!state.isReadonly && (
|
|
161
|
-
<View
|
|
162
|
-
style={{
|
|
163
|
-
position: 'relative',
|
|
164
|
-
width: theme.icongraphy.sizes.sm,
|
|
165
|
-
}}
|
|
166
|
-
>
|
|
167
|
-
<IconButton
|
|
168
|
-
accessibilityLabel={translation('remove')}
|
|
169
|
-
size="sm"
|
|
170
|
-
color={theme.colors.negative}
|
|
171
|
-
variant="foreground"
|
|
172
|
-
disabled={!interactive}
|
|
173
|
-
onPress={() => multiSelect.toggleSelection(option.id, false)}
|
|
174
|
-
style={{
|
|
175
|
-
position: 'absolute',
|
|
176
|
-
left: '50%',
|
|
177
|
-
top: '50%',
|
|
178
|
-
transform: [
|
|
179
|
-
{ translateX: '-50%' },
|
|
180
|
-
{ translateY: '-50%' },
|
|
181
|
-
],
|
|
182
|
-
}}
|
|
183
|
-
icon={HightideIconRegistry.X}
|
|
184
|
-
/>
|
|
185
|
-
</View>
|
|
186
|
-
)}
|
|
187
|
-
</Chip>
|
|
188
|
-
))}
|
|
189
|
-
</View>
|
|
190
|
-
)
|
|
191
|
-
: (
|
|
192
|
-
<ThemedText style={multiSelectTheme.triggerText(triggerState)}>
|
|
193
|
-
{placeholder}
|
|
194
|
-
</ThemedText>
|
|
195
|
-
)}
|
|
196
|
-
</Fragment>
|
|
197
|
-
)
|
|
198
|
-
}}
|
|
199
|
-
</Pressable>
|
|
200
|
-
|
|
201
|
-
<Modal
|
|
202
|
-
visible={multiSelect.isOpen}
|
|
203
|
-
transparent
|
|
204
|
-
animationType="fade"
|
|
205
|
-
onRequestClose={() => multiSelect.setIsOpen(false)}
|
|
206
|
-
>
|
|
207
|
-
<Pressable
|
|
208
|
-
style={resolvedOverlayStyle}
|
|
209
|
-
onPress={() => multiSelect.setIsOpen(false)}
|
|
210
|
-
>
|
|
211
|
-
<Pressable
|
|
212
|
-
style={resolvedMenuStyle}
|
|
213
|
-
onPress={(event) => event.stopPropagation()}
|
|
214
|
-
>
|
|
215
|
-
{isSearchVisible && (
|
|
216
|
-
<View style={resolvedHeaderStyle}>
|
|
217
|
-
<SearchBar
|
|
218
|
-
value={multiSelect.searchQuery}
|
|
219
|
-
onValueChange={multiSelect.setSearchQuery}
|
|
220
|
-
onSearch={multiSelect.setSearchQuery}
|
|
221
|
-
/>
|
|
222
|
-
</View>
|
|
223
|
-
)}
|
|
224
|
-
{showEmptySearchResults ? (
|
|
225
|
-
<View
|
|
226
|
-
style={{
|
|
227
|
-
flex: 1,
|
|
228
|
-
justifyContent: 'center',
|
|
229
|
-
alignItems: 'center',
|
|
230
|
-
}}
|
|
231
|
-
>
|
|
232
|
-
<ThemedText style={resolvedEmptyTextStyle}>
|
|
233
|
-
{translation('nothingFound')}
|
|
234
|
-
</ThemedText>
|
|
235
|
-
</View>
|
|
236
|
-
) : (
|
|
237
|
-
<FlatList
|
|
238
|
-
data={visibleOptions}
|
|
239
|
-
keyExtractor={(option) => option.id}
|
|
240
|
-
style={{ flex: 1 }}
|
|
241
|
-
renderItem={({ item }) => {
|
|
242
|
-
const selected = multiSelect.isSelected(item.id)
|
|
243
|
-
const isHighlighted = multiSelect.highlightedId === item.id
|
|
244
|
-
const optionState = {
|
|
245
|
-
color,
|
|
246
|
-
isSelected: selected,
|
|
247
|
-
isHighlighted,
|
|
248
|
-
isDisabled: item.disabled,
|
|
249
|
-
}
|
|
250
|
-
const checkboxIcon = multiSelectTheme.checkboxIcon(optionState)
|
|
251
|
-
const optionColor = selected
|
|
252
|
-
? (color ?? theme.colors.primary)
|
|
253
|
-
: undefined
|
|
254
|
-
|
|
255
|
-
return (
|
|
256
|
-
<ListActionItem
|
|
257
|
-
title={item.label ?? item.id}
|
|
258
|
-
color={optionColor}
|
|
259
|
-
disabled={item.disabled}
|
|
260
|
-
onPress={() => multiSelect.toggleSelection(item.id)}
|
|
261
|
-
leading={(
|
|
262
|
-
<View style={multiSelectTheme.checkbox(optionState)}>
|
|
263
|
-
<ThemedIcon
|
|
264
|
-
icon={HightideIconRegistry.Check}
|
|
265
|
-
size={checkboxIcon.size}
|
|
266
|
-
strokeWidth={checkboxIcon.strokeWidth}
|
|
267
|
-
color={checkboxIcon.color}
|
|
268
|
-
/>
|
|
269
|
-
</View>
|
|
270
|
-
)}
|
|
271
|
-
/>
|
|
272
|
-
)
|
|
273
|
-
}}
|
|
274
|
-
/>
|
|
275
|
-
)}
|
|
276
|
-
</Pressable>
|
|
277
|
-
</Pressable>
|
|
278
|
-
</Modal>
|
|
279
|
-
</View>
|
|
280
|
-
)
|
|
281
|
-
}
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { Fragment, useMemo } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
FlatList,
|
|
4
|
-
Modal,
|
|
5
|
-
Pressable,
|
|
6
|
-
View,
|
|
7
|
-
type StyleProp,
|
|
8
|
-
type ViewStyle
|
|
9
|
-
} from 'react-native'
|
|
10
|
-
|
|
11
|
-
import type { ColorPairToken } from '@helpwave/hightide-design/theme-tokens'
|
|
12
|
-
import { useTranslation } from '@helpwave/hightide-utils/context'
|
|
13
|
-
import { useTheme } from '../../global-contexts/theme/ThemeContext'
|
|
14
|
-
import { ThemedText } from '../visualization-and-display/ThemedText'
|
|
15
|
-
import { ThemedIcon } from '../visualization-and-display/ThemedIcon'
|
|
16
|
-
import { ListActionItem } from '../list/ListActionItem'
|
|
17
|
-
import { HightideIconRegistry } from '../../icons/HightideIconRegistry'
|
|
18
|
-
import {
|
|
19
|
-
useSelect,
|
|
20
|
-
type UseSelectOption
|
|
21
|
-
} from '../../hooks/useSelect'
|
|
22
|
-
import type { SelectState } from '../../theme/types/components/select'
|
|
23
|
-
import type {
|
|
24
|
-
FormFieldDataHandling,
|
|
25
|
-
FormFieldInteractionStates
|
|
26
|
-
} from '../../types/formField'
|
|
27
|
-
import { SearchBar } from './SearchBar'
|
|
28
|
-
|
|
29
|
-
export type SelectOption<T extends string = string> = UseSelectOption & {
|
|
30
|
-
value?: T,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type SelectProps = Partial<FormFieldDataHandling<string>>
|
|
34
|
-
& Partial<FormFieldInteractionStates>
|
|
35
|
-
& {
|
|
36
|
-
options: ReadonlyArray<SelectOption>,
|
|
37
|
-
value?: string | null,
|
|
38
|
-
initialValue?: string | null,
|
|
39
|
-
placeholder?: string,
|
|
40
|
-
showSearch?: boolean,
|
|
41
|
-
color?: ColorPairToken,
|
|
42
|
-
style?: StyleProp<ViewStyle>,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const Select = ({
|
|
46
|
-
options,
|
|
47
|
-
value: controlledValue,
|
|
48
|
-
initialValue = null,
|
|
49
|
-
placeholder = 'Select…',
|
|
50
|
-
showSearch = true,
|
|
51
|
-
color,
|
|
52
|
-
disabled = false,
|
|
53
|
-
readOnly = false,
|
|
54
|
-
invalid = false,
|
|
55
|
-
onValueChange,
|
|
56
|
-
onEditComplete,
|
|
57
|
-
style,
|
|
58
|
-
}: SelectProps) => {
|
|
59
|
-
const { theme } = useTheme()
|
|
60
|
-
const translation = useTranslation()
|
|
61
|
-
const interactive = !disabled && !readOnly
|
|
62
|
-
|
|
63
|
-
const select = useSelect({
|
|
64
|
-
options,
|
|
65
|
-
value: controlledValue,
|
|
66
|
-
initialValue,
|
|
67
|
-
onValueChange,
|
|
68
|
-
onEditComplete,
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const isSearchVisible = showSearch && options.length >= 6
|
|
72
|
-
|
|
73
|
-
const selectedLabel = useMemo(() => {
|
|
74
|
-
const selected = options.find((option) => option.id === select.value)
|
|
75
|
-
return selected?.label ?? placeholder
|
|
76
|
-
}, [options, placeholder, select.value])
|
|
77
|
-
|
|
78
|
-
const visibleOptions = useMemo(
|
|
79
|
-
() => options.filter((option) => select.visibleOptionIds.includes(option.id)),
|
|
80
|
-
[options, select.visibleOptionIds]
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
const state = useMemo((): SelectState => ({
|
|
84
|
-
color,
|
|
85
|
-
isDisabled: disabled,
|
|
86
|
-
isReadonly: readOnly,
|
|
87
|
-
isInvalid: invalid,
|
|
88
|
-
isOpen: select.isOpen,
|
|
89
|
-
hasValue: !!select.value,
|
|
90
|
-
}), [color, disabled, invalid, readOnly, select.isOpen, select.value])
|
|
91
|
-
|
|
92
|
-
const selectTheme = theme.components.select
|
|
93
|
-
|
|
94
|
-
const resolvedOverlayStyle = useMemo(
|
|
95
|
-
() => selectTheme.overlay({}),
|
|
96
|
-
[selectTheme]
|
|
97
|
-
)
|
|
98
|
-
const resolvedMenuStyle = useMemo(
|
|
99
|
-
() => selectTheme.menu({ hasSearch: isSearchVisible }),
|
|
100
|
-
[selectTheme, isSearchVisible]
|
|
101
|
-
)
|
|
102
|
-
const resolvedHeaderStyle = useMemo(
|
|
103
|
-
() => selectTheme.header({}),
|
|
104
|
-
[selectTheme]
|
|
105
|
-
)
|
|
106
|
-
const resolvedEmptyTextStyle = useMemo(
|
|
107
|
-
() => selectTheme.emptyText({}),
|
|
108
|
-
[selectTheme]
|
|
109
|
-
)
|
|
110
|
-
const showEmptySearchResults = isSearchVisible
|
|
111
|
-
&& select.searchQuery.trim().length > 0
|
|
112
|
-
&& visibleOptions.length === 0
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<View style={style}>
|
|
116
|
-
<Pressable
|
|
117
|
-
disabled={!interactive}
|
|
118
|
-
onPress={() => select.toggleOpen()}
|
|
119
|
-
style={(pressableState) => {
|
|
120
|
-
const interaction = pressableState as {
|
|
121
|
-
pressed: boolean,
|
|
122
|
-
hovered?: boolean,
|
|
123
|
-
focused?: boolean,
|
|
124
|
-
focusVisible?: boolean,
|
|
125
|
-
}
|
|
126
|
-
return selectTheme.trigger({
|
|
127
|
-
...state,
|
|
128
|
-
isPressed: interaction.pressed,
|
|
129
|
-
isHovered: !!interaction.hovered,
|
|
130
|
-
isFocused: !!interaction.focused,
|
|
131
|
-
isFocusVisible: !!interaction.focusVisible,
|
|
132
|
-
})
|
|
133
|
-
}}
|
|
134
|
-
>
|
|
135
|
-
{(pressableState) => {
|
|
136
|
-
const interaction = pressableState as {
|
|
137
|
-
pressed: boolean,
|
|
138
|
-
hovered?: boolean,
|
|
139
|
-
focused?: boolean,
|
|
140
|
-
focusVisible?: boolean,
|
|
141
|
-
}
|
|
142
|
-
const triggerState = {
|
|
143
|
-
...state,
|
|
144
|
-
isPressed: interaction.pressed,
|
|
145
|
-
isHovered: !!interaction.hovered,
|
|
146
|
-
isFocused: !!interaction.focused,
|
|
147
|
-
isFocusVisible: !!interaction.focusVisible,
|
|
148
|
-
}
|
|
149
|
-
const icon = selectTheme.icon(triggerState)
|
|
150
|
-
|
|
151
|
-
return (
|
|
152
|
-
<Fragment>
|
|
153
|
-
<View
|
|
154
|
-
pointerEvents="none"
|
|
155
|
-
style={selectTheme.stateLayer(triggerState)}
|
|
156
|
-
/>
|
|
157
|
-
<ThemedText style={[selectTheme.triggerText(triggerState), { flex: 1 }]}>
|
|
158
|
-
{selectedLabel}
|
|
159
|
-
</ThemedText>
|
|
160
|
-
<ThemedIcon
|
|
161
|
-
icon={HightideIconRegistry.ChevronDown}
|
|
162
|
-
size={icon.size}
|
|
163
|
-
strokeWidth={icon.strokeWidth}
|
|
164
|
-
color={icon.color}
|
|
165
|
-
/>
|
|
166
|
-
</Fragment>
|
|
167
|
-
)
|
|
168
|
-
}}
|
|
169
|
-
</Pressable>
|
|
170
|
-
|
|
171
|
-
<Modal
|
|
172
|
-
visible={select.isOpen}
|
|
173
|
-
transparent
|
|
174
|
-
animationType="fade"
|
|
175
|
-
onRequestClose={() => select.setIsOpen(false)}
|
|
176
|
-
>
|
|
177
|
-
<Pressable
|
|
178
|
-
style={resolvedOverlayStyle}
|
|
179
|
-
onPress={() => select.setIsOpen(false)}
|
|
180
|
-
>
|
|
181
|
-
<Pressable
|
|
182
|
-
style={resolvedMenuStyle}
|
|
183
|
-
onPress={(event) => event.stopPropagation()}
|
|
184
|
-
>
|
|
185
|
-
{isSearchVisible && (
|
|
186
|
-
<View style={resolvedHeaderStyle}>
|
|
187
|
-
<SearchBar
|
|
188
|
-
value={select.searchQuery}
|
|
189
|
-
onValueChange={select.setSearchQuery}
|
|
190
|
-
onSearch={select.setSearchQuery}
|
|
191
|
-
/>
|
|
192
|
-
</View>
|
|
193
|
-
)}
|
|
194
|
-
{showEmptySearchResults ? (
|
|
195
|
-
<View
|
|
196
|
-
style={{
|
|
197
|
-
flex: 1,
|
|
198
|
-
justifyContent: 'center',
|
|
199
|
-
alignItems: 'center',
|
|
200
|
-
}}
|
|
201
|
-
>
|
|
202
|
-
<ThemedText style={resolvedEmptyTextStyle}>
|
|
203
|
-
{translation('nothingFound')}
|
|
204
|
-
</ThemedText>
|
|
205
|
-
</View>
|
|
206
|
-
) : (
|
|
207
|
-
<FlatList
|
|
208
|
-
data={visibleOptions}
|
|
209
|
-
keyExtractor={(option) => option.id}
|
|
210
|
-
style={{ flex: 1 }}
|
|
211
|
-
renderItem={({ item }) => {
|
|
212
|
-
const isSelected = select.value === item.id
|
|
213
|
-
const optionColor = isSelected
|
|
214
|
-
? (color ?? theme.colors.primary)
|
|
215
|
-
: undefined
|
|
216
|
-
const checkIcon = theme.components.listItem.action.icon({ color: optionColor })
|
|
217
|
-
|
|
218
|
-
return (
|
|
219
|
-
<ListActionItem
|
|
220
|
-
title={item.label ?? item.id}
|
|
221
|
-
color={optionColor}
|
|
222
|
-
disabled={item.disabled}
|
|
223
|
-
onPress={() => select.selectValue(item.id)}
|
|
224
|
-
leading={(
|
|
225
|
-
<ThemedIcon
|
|
226
|
-
icon={HightideIconRegistry.Check}
|
|
227
|
-
size={checkIcon.size}
|
|
228
|
-
strokeWidth={checkIcon.strokeWidth}
|
|
229
|
-
color={isSelected ? theme.colors.primary.color : 'transparent'}
|
|
230
|
-
/>
|
|
231
|
-
)}
|
|
232
|
-
/>
|
|
233
|
-
)
|
|
234
|
-
}}
|
|
235
|
-
/>
|
|
236
|
-
)}
|
|
237
|
-
</Pressable>
|
|
238
|
-
</Pressable>
|
|
239
|
-
</Modal>
|
|
240
|
-
</View>
|
|
241
|
-
)
|
|
242
|
-
}
|