@helpwave/hightide-native 0.0.7 → 0.1.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/README.md +4 -4
- package/package.json +8 -19
- package/src/components/card/Card.tsx +41 -0
- package/src/components/card/index.ts +1 -0
- package/src/components/chat/ChatAttachmentMessageBubble.tsx +246 -0
- package/src/components/chat/ChatConversationRow.tsx +21 -16
- package/src/components/chat/ChatDateDivider.tsx +2 -2
- package/src/components/chat/ChatMessageBubble.tsx +62 -52
- package/src/components/chat/ChatMessageComposer.tsx +16 -14
- package/src/components/chat/ChatQuickReplyChip.tsx +41 -43
- package/src/components/chat/ChatSystemLine.tsx +14 -7
- package/src/components/chat/ChatThreadHeader.tsx +60 -6
- package/src/components/chat/index.ts +1 -2
- package/src/components/index.ts +3 -1
- package/src/components/layout/Divider.tsx +60 -0
- package/src/components/layout/index.ts +1 -0
- package/src/components/list/ListActionItem.tsx +99 -0
- package/src/components/list/ListItem.tsx +96 -0
- package/src/components/list/ListNavigationItem.tsx +102 -0
- package/src/components/list/index.ts +3 -0
- package/src/components/user-interaction/Button.tsx +80 -31
- package/src/components/user-interaction/Checkbox.tsx +72 -32
- package/src/components/user-interaction/IconButton.tsx +68 -30
- package/src/components/user-interaction/Input.tsx +61 -14
- package/src/components/user-interaction/MultiSelect.tsx +142 -75
- package/src/components/user-interaction/SearchBar.tsx +222 -0
- package/src/components/user-interaction/Select.tsx +129 -58
- package/src/components/user-interaction/Switch.tsx +207 -0
- package/src/components/user-interaction/ThemedPressable.tsx +136 -0
- package/src/components/user-interaction/index.ts +3 -0
- package/src/components/visualization-and-display/Avatar.tsx +112 -93
- package/src/components/visualization-and-display/Chip.tsx +22 -22
- package/src/components/visualization-and-display/ThemedIcon.tsx +72 -0
- package/src/components/visualization-and-display/ThemedText.tsx +38 -0
- package/src/components/visualization-and-display/index.ts +2 -1
- package/src/global-contexts/HightideProvider.tsx +19 -10
- package/src/global-contexts/content-theme/ContentThemeContext.ts +22 -0
- package/src/global-contexts/content-theme/ContentThemeProvider.tsx +32 -0
- package/src/global-contexts/content-theme/index.ts +2 -0
- package/src/global-contexts/debug/forward-exports.ts +10 -0
- package/src/global-contexts/debug/index.ts +1 -0
- package/src/global-contexts/index.ts +2 -0
- package/src/global-contexts/theme/ThemeProvider.tsx +7 -1
- package/src/icons/HightideIconRegistry.ts +33 -0
- package/src/icons/index.ts +2 -0
- package/src/icons/types.ts +11 -0
- package/src/theme/adapters/container-adapter.ts +323 -0
- package/src/theme/adapters/defined.ts +11 -0
- package/src/theme/adapters/icon-style-adapter.ts +10 -0
- package/src/theme/adapters/index.ts +4 -0
- package/src/theme/adapters/text-style-adapter.ts +16 -0
- package/src/theme/index.ts +1 -0
- package/src/theme/resolvers/avatar.ts +385 -186
- package/src/theme/resolvers/button.ts +50 -82
- package/src/theme/resolvers/card.ts +27 -0
- package/src/theme/resolvers/chat/attachment-message-bubble.ts +163 -0
- package/src/theme/resolvers/chat/chat-theme.ts +69 -0
- package/src/theme/resolvers/chat/conversation-list.ts +35 -0
- package/src/theme/resolvers/chat/conversation-row.ts +64 -0
- package/src/theme/resolvers/chat/date-divider.ts +31 -0
- package/src/theme/resolvers/chat/index.ts +11 -0
- package/src/theme/resolvers/chat/message-bubble.ts +57 -0
- package/src/theme/resolvers/chat/message-composer.ts +38 -0
- package/src/theme/resolvers/chat/message-list.ts +27 -0
- package/src/theme/resolvers/chat/quick-reply-chip.ts +80 -0
- package/src/theme/resolvers/chat/system-line.ts +41 -0
- package/src/theme/resolvers/chat/thread-header.ts +85 -0
- package/src/theme/resolvers/checkbox.ts +87 -74
- package/src/theme/resolvers/chip.ts +30 -67
- package/src/theme/resolvers/colorScheme.ts +136 -0
- package/src/theme/resolvers/divider.ts +34 -0
- package/src/theme/resolvers/icon.ts +21 -0
- package/src/theme/resolvers/iconButton.ts +45 -61
- package/src/theme/resolvers/index.ts +8 -2
- package/src/theme/resolvers/input.ts +64 -42
- package/src/theme/resolvers/listItem.ts +115 -0
- package/src/theme/resolvers/multiSelect.ts +159 -84
- package/src/theme/resolvers/searchBar.ts +121 -0
- package/src/theme/resolvers/select.ts +141 -66
- package/src/theme/resolvers/switch.ts +71 -0
- package/src/theme/resolvers/themedPressable.ts +54 -0
- package/src/theme/themes/createHightideTheme.ts +214 -49
- package/src/theme/themes/hightideThemes.ts +10 -6
- package/src/theme/types/color.ts +2 -59
- package/src/theme/types/components/avatar.ts +37 -36
- package/src/theme/types/components/button.ts +13 -14
- package/src/theme/types/components/card.ts +9 -0
- package/src/theme/types/components/chat.ts +124 -103
- package/src/theme/types/components/checkbox.ts +11 -12
- package/src/theme/types/components/chip.ts +8 -14
- package/src/theme/types/components/divider.ts +18 -0
- package/src/theme/types/components/hightide.ts +41 -40
- package/src/theme/types/components/iconButton.ts +19 -14
- package/src/theme/types/components/index.ts +6 -1
- package/src/theme/types/components/input.ts +17 -8
- package/src/theme/types/components/listItem.ts +86 -0
- package/src/theme/types/components/multiSelect.ts +14 -12
- package/src/theme/types/components/searchBar.ts +28 -0
- package/src/theme/types/components/select.ts +21 -9
- package/src/theme/types/components/switch.ts +22 -0
- package/src/theme/types/components/themedPressable.ts +31 -0
- package/src/theme/types/decoration.ts +1 -11
- package/src/theme/types/icongraphy.ts +8 -0
- package/src/theme/types/index.ts +2 -0
- package/src/theme/types/layout.ts +25 -57
- package/src/theme/types/resolver.ts +54 -1
- package/src/theme/types/semantics.ts +72 -0
- package/src/theme/types/theme.ts +26 -13
- package/src/theme/types/typography.ts +16 -17
- package/src/utils/hitBoxOverlay.ts +44 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/minimumTouchTargetHitSlop.ts +68 -0
- package/src/components/chat/ChatAttachmentCard.tsx +0 -110
- package/src/components/chat/ChatMessageCard.tsx +0 -118
- package/src/components/menu/Menu.tsx +0 -61
- package/src/components/menu/MenuActionItem.tsx +0 -90
- package/src/components/menu/MenuItem.tsx +0 -73
- package/src/components/menu/MenuNavigationItem.tsx +0 -90
- package/src/components/menu/index.ts +0 -4
- package/src/components/visualization-and-display/Icon.tsx +0 -27
- package/src/storybook/helper.tsx +0 -36
- package/src/theme/resolvers/chat.ts +0 -418
- package/src/theme/resolvers/coloring.ts +0 -94
- package/src/theme/resolvers/menu.ts +0 -120
- package/src/theme/types/components/menu.ts +0 -57
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useMemo,
|
|
4
|
+
useState
|
|
5
|
+
} from 'react'
|
|
6
|
+
import {
|
|
7
|
+
TextInput,
|
|
8
|
+
View,
|
|
9
|
+
type StyleProp,
|
|
10
|
+
type TextInputProps,
|
|
11
|
+
type TextStyle,
|
|
12
|
+
type ViewStyle
|
|
13
|
+
} from 'react-native'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
useControlledState,
|
|
17
|
+
useDelay,
|
|
18
|
+
type UseDelayOptionsResolved
|
|
19
|
+
} from '@helpwave/hightide-utils/hooks'
|
|
20
|
+
import { useTranslation } from '@helpwave/hightide-utils/context'
|
|
21
|
+
|
|
22
|
+
import type { ColorPairToken } from '@helpwave/hightide-design/theme-tokens'
|
|
23
|
+
import { useTheme } from '../../global-contexts/theme/ThemeContext'
|
|
24
|
+
import { HightideIconRegistry } from '../../icons/HightideIconRegistry'
|
|
25
|
+
import type {
|
|
26
|
+
SearchBarContainerStyle,
|
|
27
|
+
SearchBarIconButtonStyle,
|
|
28
|
+
SearchBarInputStyle,
|
|
29
|
+
SearchBarState
|
|
30
|
+
} from '../../theme/types/components/searchBar'
|
|
31
|
+
import type { StyleOverwrite } from '../../theme/types/resolver'
|
|
32
|
+
import type {
|
|
33
|
+
FormFieldDataHandling,
|
|
34
|
+
FormFieldInteractionStates
|
|
35
|
+
} from '../../types/formField'
|
|
36
|
+
import { IconButton, type IconButtonProps } from './IconButton'
|
|
37
|
+
|
|
38
|
+
export type SearchBarEditCompleteOptionsResolved = {
|
|
39
|
+
onBlur: boolean,
|
|
40
|
+
afterDelay: boolean,
|
|
41
|
+
allowEnterComplete?: boolean,
|
|
42
|
+
} & Omit<UseDelayOptionsResolved, 'disabled'>
|
|
43
|
+
|
|
44
|
+
export type SearchBarEditCompleteOptions = Partial<SearchBarEditCompleteOptionsResolved>
|
|
45
|
+
|
|
46
|
+
const defaultEditCompleteOptions: SearchBarEditCompleteOptionsResolved = {
|
|
47
|
+
allowEnterComplete: true,
|
|
48
|
+
onBlur: true,
|
|
49
|
+
afterDelay: false,
|
|
50
|
+
delay: 2500,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type SearchBarProps = Omit<TextInputProps, 'value' | 'style'>
|
|
54
|
+
& Partial<FormFieldDataHandling<string>>
|
|
55
|
+
& Partial<FormFieldInteractionStates>
|
|
56
|
+
& {
|
|
57
|
+
color?: ColorPairToken,
|
|
58
|
+
onSearch: (value: string) => void,
|
|
59
|
+
searchButtonProps?: Omit<IconButtonProps, 'onPress' | 'icon' | 'accessibilityLabel'>,
|
|
60
|
+
editCompleteOptions?: SearchBarEditCompleteOptions,
|
|
61
|
+
initialValue?: string,
|
|
62
|
+
style?: StyleProp<ViewStyle>,
|
|
63
|
+
containerStyle?: StyleOverwrite<SearchBarState, SearchBarContainerStyle>,
|
|
64
|
+
inputStyle?: StyleOverwrite<SearchBarState, SearchBarInputStyle>,
|
|
65
|
+
iconButtonStyle?: StyleOverwrite<SearchBarState, SearchBarIconButtonStyle>,
|
|
66
|
+
textStyle?: StyleProp<TextStyle>,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const SearchBar = forwardRef<TextInput, SearchBarProps>(function SearchBar({
|
|
70
|
+
value: controlledValue,
|
|
71
|
+
initialValue,
|
|
72
|
+
color,
|
|
73
|
+
invalid = false,
|
|
74
|
+
disabled = false,
|
|
75
|
+
readOnly = false,
|
|
76
|
+
required = false,
|
|
77
|
+
onValueChange,
|
|
78
|
+
onEditComplete,
|
|
79
|
+
onSearch,
|
|
80
|
+
searchButtonProps,
|
|
81
|
+
editCompleteOptions,
|
|
82
|
+
style,
|
|
83
|
+
containerStyle,
|
|
84
|
+
inputStyle,
|
|
85
|
+
iconButtonStyle,
|
|
86
|
+
textStyle,
|
|
87
|
+
placeholder,
|
|
88
|
+
...props
|
|
89
|
+
}, ref) {
|
|
90
|
+
const { theme } = useTheme()
|
|
91
|
+
const translation = useTranslation()
|
|
92
|
+
const [isHovered, setIsHovered] = useState(false)
|
|
93
|
+
const [isPressed, setIsPressed] = useState(false)
|
|
94
|
+
const [isFocused, setIsFocused] = useState(false)
|
|
95
|
+
|
|
96
|
+
const [value, setValue] = useControlledState({
|
|
97
|
+
value: controlledValue,
|
|
98
|
+
onValueChange,
|
|
99
|
+
defaultValue: initialValue,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const {
|
|
103
|
+
onBlur: allowEditCompleteOnBlur,
|
|
104
|
+
afterDelay,
|
|
105
|
+
delay,
|
|
106
|
+
allowEnterComplete,
|
|
107
|
+
} = { ...defaultEditCompleteOptions, ...editCompleteOptions }
|
|
108
|
+
|
|
109
|
+
const { restartTimer, clearTimer } = useDelay({
|
|
110
|
+
delay,
|
|
111
|
+
disabled: !afterDelay || disabled || readOnly,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const interactive = !disabled && !readOnly
|
|
115
|
+
|
|
116
|
+
const state = useMemo((): SearchBarState => ({
|
|
117
|
+
color,
|
|
118
|
+
isDisabled: disabled,
|
|
119
|
+
isInvalid: invalid,
|
|
120
|
+
isReadonly: readOnly,
|
|
121
|
+
isHovered: interactive && isHovered,
|
|
122
|
+
isPressed: interactive && isPressed,
|
|
123
|
+
isFocused: interactive && isFocused,
|
|
124
|
+
}), [color, disabled, invalid, readOnly, interactive, isHovered, isPressed, isFocused])
|
|
125
|
+
|
|
126
|
+
const searchBarTheme = theme.components.searchBar
|
|
127
|
+
const resolvedContainerStyle = useMemo(
|
|
128
|
+
() => searchBarTheme.container(state, containerStyle),
|
|
129
|
+
[searchBarTheme, state, containerStyle]
|
|
130
|
+
)
|
|
131
|
+
const resolvedInputStyle = useMemo(
|
|
132
|
+
() => searchBarTheme.input(state, inputStyle),
|
|
133
|
+
[searchBarTheme, state, inputStyle]
|
|
134
|
+
)
|
|
135
|
+
const resolvedPlaceholderStyle = useMemo(
|
|
136
|
+
() => searchBarTheme.placeholder(state),
|
|
137
|
+
[searchBarTheme, state]
|
|
138
|
+
)
|
|
139
|
+
const resolvedIconButtonStyle = useMemo(
|
|
140
|
+
() => searchBarTheme.iconButton(state, iconButtonStyle),
|
|
141
|
+
[searchBarTheme, state, iconButtonStyle]
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
const commitSearch = (nextValue: string) => {
|
|
145
|
+
onSearch(nextValue)
|
|
146
|
+
onEditComplete?.(nextValue)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<View style={[resolvedContainerStyle, style]}>
|
|
151
|
+
<TextInput
|
|
152
|
+
{...props}
|
|
153
|
+
ref={ref}
|
|
154
|
+
value={value}
|
|
155
|
+
editable={interactive}
|
|
156
|
+
placeholder={placeholder ?? translation('search')}
|
|
157
|
+
placeholderTextColor={resolvedPlaceholderStyle.color}
|
|
158
|
+
onChangeText={(nextValue) => {
|
|
159
|
+
props.onChangeText?.(nextValue)
|
|
160
|
+
restartTimer(() => {
|
|
161
|
+
commitSearch(nextValue)
|
|
162
|
+
})
|
|
163
|
+
setValue(nextValue)
|
|
164
|
+
}}
|
|
165
|
+
onFocus={(event) => {
|
|
166
|
+
if (interactive) {
|
|
167
|
+
setIsFocused(true)
|
|
168
|
+
}
|
|
169
|
+
props.onFocus?.(event)
|
|
170
|
+
}}
|
|
171
|
+
onBlur={(event) => {
|
|
172
|
+
setIsFocused(false)
|
|
173
|
+
props.onBlur?.(event)
|
|
174
|
+
if (allowEditCompleteOnBlur) {
|
|
175
|
+
commitSearch(value ?? '')
|
|
176
|
+
clearTimer()
|
|
177
|
+
}
|
|
178
|
+
}}
|
|
179
|
+
onPressIn={(event) => {
|
|
180
|
+
if (interactive) {
|
|
181
|
+
setIsPressed(true)
|
|
182
|
+
}
|
|
183
|
+
props.onPressIn?.(event)
|
|
184
|
+
}}
|
|
185
|
+
onPressOut={(event) => {
|
|
186
|
+
setIsPressed(false)
|
|
187
|
+
props.onPressOut?.(event)
|
|
188
|
+
}}
|
|
189
|
+
onPointerEnter={(event) => {
|
|
190
|
+
if (interactive) {
|
|
191
|
+
setIsHovered(true)
|
|
192
|
+
}
|
|
193
|
+
props.onPointerEnter?.(event)
|
|
194
|
+
}}
|
|
195
|
+
onPointerLeave={(event) => {
|
|
196
|
+
setIsHovered(false)
|
|
197
|
+
props.onPointerLeave?.(event)
|
|
198
|
+
}}
|
|
199
|
+
onSubmitEditing={(event) => {
|
|
200
|
+
props.onSubmitEditing?.(event)
|
|
201
|
+
if (allowEnterComplete) {
|
|
202
|
+
commitSearch(value ?? '')
|
|
203
|
+
clearTimer()
|
|
204
|
+
}
|
|
205
|
+
}}
|
|
206
|
+
style={[resolvedInputStyle, textStyle]}
|
|
207
|
+
accessibilityState={{ disabled, selected: required }}
|
|
208
|
+
/>
|
|
209
|
+
<IconButton
|
|
210
|
+
{...searchButtonProps}
|
|
211
|
+
icon={HightideIconRegistry.Search}
|
|
212
|
+
accessibilityLabel={translation('search')}
|
|
213
|
+
size="sm"
|
|
214
|
+
color={searchButtonProps?.color ?? searchBarTheme.iconButtonColor(state)}
|
|
215
|
+
variant={searchButtonProps?.variant ?? 'foreground'}
|
|
216
|
+
disabled={disabled || searchButtonProps?.disabled}
|
|
217
|
+
onPress={() => commitSearch(value ?? '')}
|
|
218
|
+
style={[resolvedIconButtonStyle, searchButtonProps?.style]}
|
|
219
|
+
/>
|
|
220
|
+
</View>
|
|
221
|
+
)
|
|
222
|
+
})
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
1
|
+
import { Fragment, useMemo } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
FlatList,
|
|
4
4
|
Modal,
|
|
5
5
|
Pressable,
|
|
6
|
-
Text,
|
|
7
|
-
TextInput,
|
|
8
6
|
View,
|
|
9
7
|
type StyleProp,
|
|
10
8
|
type ViewStyle
|
|
11
9
|
} from 'react-native'
|
|
12
10
|
|
|
11
|
+
import type { ColorPairToken } from '@helpwave/hightide-design/theme-tokens'
|
|
12
|
+
import { useTranslation } from '@helpwave/hightide-utils/context'
|
|
13
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'
|
|
14
18
|
import {
|
|
15
19
|
useSelect,
|
|
16
20
|
type UseSelectOption
|
|
17
21
|
} from '../../hooks/useSelect'
|
|
18
22
|
import type { SelectState } from '../../theme/types/components/select'
|
|
23
|
+
import type { Color } from '../../theme/types/color'
|
|
19
24
|
import type {
|
|
20
25
|
FormFieldDataHandling,
|
|
21
26
|
FormFieldInteractionStates
|
|
22
27
|
} from '../../types/formField'
|
|
28
|
+
import { SearchBar } from './SearchBar'
|
|
23
29
|
|
|
24
30
|
export type SelectOption<T extends string = string> = UseSelectOption & {
|
|
25
31
|
value?: T,
|
|
@@ -33,6 +39,7 @@ export type SelectProps = Partial<FormFieldDataHandling<string>>
|
|
|
33
39
|
initialValue?: string | null,
|
|
34
40
|
placeholder?: string,
|
|
35
41
|
showSearch?: boolean,
|
|
42
|
+
color?: ColorPairToken,
|
|
36
43
|
style?: StyleProp<ViewStyle>,
|
|
37
44
|
}
|
|
38
45
|
|
|
@@ -42,6 +49,7 @@ export const Select = ({
|
|
|
42
49
|
initialValue = null,
|
|
43
50
|
placeholder = 'Select…',
|
|
44
51
|
showSearch = true,
|
|
52
|
+
color,
|
|
45
53
|
disabled = false,
|
|
46
54
|
readOnly = false,
|
|
47
55
|
invalid = false,
|
|
@@ -50,6 +58,7 @@ export const Select = ({
|
|
|
50
58
|
style,
|
|
51
59
|
}: SelectProps) => {
|
|
52
60
|
const { theme } = useTheme()
|
|
61
|
+
const translation = useTranslation()
|
|
53
62
|
const interactive = !disabled && !readOnly
|
|
54
63
|
|
|
55
64
|
const select = useSelect({
|
|
@@ -65,51 +74,93 @@ export const Select = ({
|
|
|
65
74
|
return selected?.label ?? placeholder
|
|
66
75
|
}, [options, placeholder, select.value])
|
|
67
76
|
|
|
77
|
+
const visibleOptions = useMemo(
|
|
78
|
+
() => options.filter((option) => select.visibleOptionIds.includes(option.id)),
|
|
79
|
+
[options, select.visibleOptionIds]
|
|
80
|
+
)
|
|
81
|
+
|
|
68
82
|
const state = useMemo((): SelectState => ({
|
|
83
|
+
color,
|
|
69
84
|
isDisabled: disabled,
|
|
70
|
-
|
|
85
|
+
isReadonly: readOnly,
|
|
71
86
|
isInvalid: invalid,
|
|
72
87
|
isOpen: select.isOpen,
|
|
73
88
|
hasValue: !!select.value,
|
|
74
|
-
}), [disabled, invalid, readOnly, select.isOpen, select.value])
|
|
89
|
+
}), [color, disabled, invalid, readOnly, select.isOpen, select.value])
|
|
75
90
|
|
|
76
91
|
const selectTheme = theme.components.select
|
|
77
92
|
|
|
78
|
-
const resolvedTriggerStyle = useMemo(
|
|
79
|
-
() => selectTheme.trigger(state),
|
|
80
|
-
[selectTheme, state]
|
|
81
|
-
)
|
|
82
|
-
const resolvedTriggerTextStyle = useMemo(
|
|
83
|
-
() => selectTheme.triggerText(state),
|
|
84
|
-
[selectTheme, state]
|
|
85
|
-
)
|
|
86
93
|
const resolvedOverlayStyle = useMemo(
|
|
87
|
-
() => selectTheme.overlay(
|
|
88
|
-
[selectTheme
|
|
94
|
+
() => selectTheme.overlay({}),
|
|
95
|
+
[selectTheme]
|
|
89
96
|
)
|
|
90
97
|
const resolvedMenuStyle = useMemo(
|
|
91
|
-
() => selectTheme.menu(
|
|
92
|
-
[selectTheme,
|
|
98
|
+
() => selectTheme.menu({ hasSearch: showSearch }),
|
|
99
|
+
[selectTheme, showSearch]
|
|
93
100
|
)
|
|
94
|
-
const
|
|
95
|
-
() => selectTheme.
|
|
96
|
-
[selectTheme
|
|
101
|
+
const resolvedHeaderStyle = useMemo(
|
|
102
|
+
() => selectTheme.header({}),
|
|
103
|
+
[selectTheme]
|
|
97
104
|
)
|
|
98
|
-
const
|
|
99
|
-
() => selectTheme.
|
|
100
|
-
[selectTheme
|
|
105
|
+
const resolvedEmptyTextStyle = useMemo(
|
|
106
|
+
() => selectTheme.emptyText({}),
|
|
107
|
+
[selectTheme]
|
|
101
108
|
)
|
|
109
|
+
const showEmptySearchResults = showSearch
|
|
110
|
+
&& select.searchQuery.trim().length > 0
|
|
111
|
+
&& visibleOptions.length === 0
|
|
102
112
|
|
|
103
113
|
return (
|
|
104
114
|
<View style={style}>
|
|
105
115
|
<Pressable
|
|
106
116
|
disabled={!interactive}
|
|
107
117
|
onPress={() => select.toggleOpen()}
|
|
108
|
-
style={
|
|
118
|
+
style={(pressableState) => {
|
|
119
|
+
const interaction = pressableState as {
|
|
120
|
+
pressed: boolean,
|
|
121
|
+
hovered?: boolean,
|
|
122
|
+
focused?: boolean,
|
|
123
|
+
focusVisible?: boolean,
|
|
124
|
+
}
|
|
125
|
+
return selectTheme.trigger({
|
|
126
|
+
...state,
|
|
127
|
+
isPressed: interaction.pressed,
|
|
128
|
+
isHovered: !!interaction.hovered,
|
|
129
|
+
isFocused: !!interaction.focused,
|
|
130
|
+
isFocusVisible: !!interaction.focusVisible,
|
|
131
|
+
})
|
|
132
|
+
}}
|
|
109
133
|
>
|
|
110
|
-
|
|
111
|
-
{
|
|
112
|
-
|
|
134
|
+
{(pressableState) => {
|
|
135
|
+
const interaction = pressableState as {
|
|
136
|
+
pressed: boolean,
|
|
137
|
+
hovered?: boolean,
|
|
138
|
+
focused?: boolean,
|
|
139
|
+
focusVisible?: boolean,
|
|
140
|
+
}
|
|
141
|
+
const triggerState = {
|
|
142
|
+
...state,
|
|
143
|
+
isPressed: interaction.pressed,
|
|
144
|
+
isHovered: !!interaction.hovered,
|
|
145
|
+
isFocused: !!interaction.focused,
|
|
146
|
+
isFocusVisible: !!interaction.focusVisible,
|
|
147
|
+
}
|
|
148
|
+
const icon = selectTheme.icon(triggerState)
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<Fragment>
|
|
152
|
+
<ThemedText style={[selectTheme.triggerText(triggerState), { flex: 1 }]}>
|
|
153
|
+
{selectedLabel}
|
|
154
|
+
</ThemedText>
|
|
155
|
+
<ThemedIcon
|
|
156
|
+
icon={HightideIconRegistry.ChevronDown}
|
|
157
|
+
size={icon.size}
|
|
158
|
+
strokeWidth={icon.strokeWidth}
|
|
159
|
+
color={icon.color}
|
|
160
|
+
/>
|
|
161
|
+
</Fragment>
|
|
162
|
+
)
|
|
163
|
+
}}
|
|
113
164
|
</Pressable>
|
|
114
165
|
|
|
115
166
|
<Modal
|
|
@@ -127,39 +178,59 @@ export const Select = ({
|
|
|
127
178
|
onPress={(event) => event.stopPropagation()}
|
|
128
179
|
>
|
|
129
180
|
{showSearch && (
|
|
130
|
-
<
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
181
|
+
<View style={resolvedHeaderStyle}>
|
|
182
|
+
<SearchBar
|
|
183
|
+
value={select.searchQuery}
|
|
184
|
+
onValueChange={select.setSearchQuery}
|
|
185
|
+
onSearch={select.setSearchQuery}
|
|
186
|
+
/>
|
|
187
|
+
</View>
|
|
137
188
|
)}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
189
|
+
{showEmptySearchResults ? (
|
|
190
|
+
<View
|
|
191
|
+
style={{
|
|
192
|
+
flex: 1,
|
|
193
|
+
justifyContent: 'center',
|
|
194
|
+
alignItems: 'center',
|
|
195
|
+
}}
|
|
196
|
+
>
|
|
197
|
+
<ThemedText style={resolvedEmptyTextStyle}>
|
|
198
|
+
{translation('nothingFound')}
|
|
199
|
+
</ThemedText>
|
|
200
|
+
</View>
|
|
201
|
+
) : (
|
|
202
|
+
<FlatList
|
|
203
|
+
data={visibleOptions}
|
|
204
|
+
keyExtractor={(option) => option.id}
|
|
205
|
+
style={{ flex: 1 }}
|
|
206
|
+
renderItem={({ item }) => {
|
|
207
|
+
const isSelected = select.value === item.id
|
|
208
|
+
const optionColor = isSelected
|
|
209
|
+
? (color ?? theme.colors.primary)
|
|
210
|
+
: undefined
|
|
211
|
+
const checkIcon = theme.components.listItem.action.icon({ color: optionColor })
|
|
149
212
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
213
|
+
return (
|
|
214
|
+
<ListActionItem
|
|
215
|
+
label={item.label ?? item.id}
|
|
216
|
+
color={optionColor}
|
|
217
|
+
disabled={item.disabled}
|
|
218
|
+
onPress={() => select.selectValue(item.id)}
|
|
219
|
+
trailing={isSelected
|
|
220
|
+
? (
|
|
221
|
+
<ThemedIcon
|
|
222
|
+
icon={HightideIconRegistry.Check}
|
|
223
|
+
size={checkIcon.size}
|
|
224
|
+
strokeWidth={checkIcon.strokeWidth}
|
|
225
|
+
color={checkIcon.color as Color | undefined}
|
|
226
|
+
/>
|
|
227
|
+
)
|
|
228
|
+
: undefined}
|
|
229
|
+
/>
|
|
230
|
+
)
|
|
231
|
+
}}
|
|
232
|
+
/>
|
|
233
|
+
)}
|
|
163
234
|
</Pressable>
|
|
164
235
|
</Pressable>
|
|
165
236
|
</Modal>
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Fragment,
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef
|
|
6
|
+
} from 'react'
|
|
7
|
+
import {
|
|
8
|
+
Animated,
|
|
9
|
+
Pressable,
|
|
10
|
+
View,
|
|
11
|
+
type PressableProps,
|
|
12
|
+
type StyleProp,
|
|
13
|
+
type ViewStyle
|
|
14
|
+
} from 'react-native'
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
useControlledState,
|
|
18
|
+
useEventCallbackStabilizer
|
|
19
|
+
} from '@helpwave/hightide-utils/hooks'
|
|
20
|
+
|
|
21
|
+
import { useDebugContext } from '../../global-contexts/debug'
|
|
22
|
+
import { useTheme } from '../../global-contexts/theme/ThemeContext'
|
|
23
|
+
import type {
|
|
24
|
+
SwitchContainerStyle,
|
|
25
|
+
SwitchState,
|
|
26
|
+
SwitchThumbStyle,
|
|
27
|
+
SwitchTrackStyle
|
|
28
|
+
} from '../../theme/types/components/switch'
|
|
29
|
+
import type { StyleOverwrite } from '../../theme/types/resolver'
|
|
30
|
+
import type {
|
|
31
|
+
FormFieldDataHandling,
|
|
32
|
+
FormFieldInteractionStates
|
|
33
|
+
} from '../../types/formField'
|
|
34
|
+
import { createHitBoxOverlayStyle } from '../../utils/hitBoxOverlay'
|
|
35
|
+
import { useMinimumTouchTargetHitSlop } from '../../utils/minimumTouchTargetHitSlop'
|
|
36
|
+
|
|
37
|
+
const ANIMATION_DURATION_MS = 250
|
|
38
|
+
|
|
39
|
+
export type SwitchProps = Omit<PressableProps, 'children' | 'style' | 'disabled'>
|
|
40
|
+
& Partial<FormFieldInteractionStates>
|
|
41
|
+
& Partial<FormFieldDataHandling<boolean>>
|
|
42
|
+
& {
|
|
43
|
+
initialValue?: boolean,
|
|
44
|
+
style?: StyleProp<ViewStyle>,
|
|
45
|
+
containerStyle?: StyleOverwrite<SwitchState, SwitchContainerStyle>,
|
|
46
|
+
trackStyle?: StyleOverwrite<SwitchState, SwitchTrackStyle>,
|
|
47
|
+
thumbStyle?: StyleOverwrite<SwitchState, SwitchThumbStyle>,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type PressableInteraction = {
|
|
51
|
+
pressed: boolean,
|
|
52
|
+
hovered?: boolean,
|
|
53
|
+
focused?: boolean,
|
|
54
|
+
focusVisible?: boolean,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const toNumber = (value: string | number | undefined, fallback: number): number => (
|
|
58
|
+
typeof value === 'number' ? value : fallback
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
export const Switch = ({
|
|
62
|
+
value: controlledValue,
|
|
63
|
+
initialValue = false,
|
|
64
|
+
invalid = false,
|
|
65
|
+
disabled = false,
|
|
66
|
+
readOnly = false,
|
|
67
|
+
onValueChange,
|
|
68
|
+
onEditComplete,
|
|
69
|
+
style,
|
|
70
|
+
containerStyle,
|
|
71
|
+
trackStyle,
|
|
72
|
+
thumbStyle,
|
|
73
|
+
accessibilityLabel,
|
|
74
|
+
hitSlop: providedHitSlop,
|
|
75
|
+
onLayout: providedOnLayout,
|
|
76
|
+
...props
|
|
77
|
+
}: SwitchProps) => {
|
|
78
|
+
const { theme } = useTheme()
|
|
79
|
+
const { hitBox } = useDebugContext()
|
|
80
|
+
const { hitSlop, onLayout } = useMinimumTouchTargetHitSlop({
|
|
81
|
+
touchTargetSize: theme.semantics.touchTargetSize({}),
|
|
82
|
+
hitSlop: providedHitSlop,
|
|
83
|
+
onLayout: providedOnLayout,
|
|
84
|
+
})
|
|
85
|
+
const interactive = !disabled && !readOnly
|
|
86
|
+
|
|
87
|
+
const onEditCompleteStable = useEventCallbackStabilizer(onEditComplete)
|
|
88
|
+
const onValueChangeStable = useEventCallbackStabilizer(onValueChange)
|
|
89
|
+
|
|
90
|
+
const onChangeWrapper = useCallback((nextValue: boolean) => {
|
|
91
|
+
onValueChangeStable(nextValue)
|
|
92
|
+
onEditCompleteStable(nextValue)
|
|
93
|
+
}, [onEditCompleteStable, onValueChangeStable])
|
|
94
|
+
|
|
95
|
+
const [value, setValue] = useControlledState({
|
|
96
|
+
value: controlledValue,
|
|
97
|
+
onValueChange: onChangeWrapper,
|
|
98
|
+
defaultValue: initialValue,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const progress = useRef(new Animated.Value(value ? 1 : 0)).current
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
Animated.timing(progress, {
|
|
105
|
+
toValue: value ? 1 : 0,
|
|
106
|
+
duration: ANIMATION_DURATION_MS,
|
|
107
|
+
useNativeDriver: false,
|
|
108
|
+
}).start()
|
|
109
|
+
}, [progress, value])
|
|
110
|
+
|
|
111
|
+
const resolveState = (interaction: PressableInteraction): SwitchState => ({
|
|
112
|
+
isActive: value,
|
|
113
|
+
isInvalid: invalid,
|
|
114
|
+
isDisabled: disabled,
|
|
115
|
+
isReadonly: readOnly,
|
|
116
|
+
isPressed: interaction.pressed,
|
|
117
|
+
isHovered: !!interaction.hovered,
|
|
118
|
+
isFocused: !!interaction.focused,
|
|
119
|
+
isFocusVisible: !!interaction.focusVisible,
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<Pressable
|
|
124
|
+
{...props}
|
|
125
|
+
disabled={!interactive}
|
|
126
|
+
accessibilityRole="switch"
|
|
127
|
+
accessibilityLabel={accessibilityLabel}
|
|
128
|
+
accessibilityState={{
|
|
129
|
+
checked: value,
|
|
130
|
+
disabled,
|
|
131
|
+
}}
|
|
132
|
+
hitSlop={hitSlop}
|
|
133
|
+
onLayout={onLayout}
|
|
134
|
+
onPress={(event) => {
|
|
135
|
+
if (interactive) {
|
|
136
|
+
setValue((previous) => !previous)
|
|
137
|
+
}
|
|
138
|
+
props.onPress?.(event)
|
|
139
|
+
}}
|
|
140
|
+
style={(pressableState) => {
|
|
141
|
+
const state = resolveState(pressableState as PressableInteraction)
|
|
142
|
+
return [theme.components.switch.container(state, containerStyle), style]
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
{(pressableState) => {
|
|
146
|
+
const state = resolveState(pressableState as PressableInteraction)
|
|
147
|
+
const inactiveState: SwitchState = { ...state, isActive: false }
|
|
148
|
+
const activeState: SwitchState = { ...state, isActive: true }
|
|
149
|
+
const resolvedTrackStyle = theme.components.switch.track(state, trackStyle)
|
|
150
|
+
const resolvedThumbInactive = theme.components.switch.thumb(inactiveState, thumbStyle)
|
|
151
|
+
const resolvedThumbActive = theme.components.switch.thumb(activeState, thumbStyle)
|
|
152
|
+
const trackWidth = toNumber(resolvedTrackStyle.width as string | number | undefined, 40)
|
|
153
|
+
const trackHeight = toNumber(resolvedTrackStyle.height as string | number | undefined, 28)
|
|
154
|
+
const trackBorderWidth = toNumber(resolvedTrackStyle.borderWidth, 0)
|
|
155
|
+
const thumbInactiveSize = toNumber(resolvedThumbInactive.width as string | number | undefined, 16)
|
|
156
|
+
const thumbActiveSize = toNumber(resolvedThumbActive.width as string | number | undefined, 20)
|
|
157
|
+
const trackInnerWidth = trackWidth - (trackBorderWidth * 2)
|
|
158
|
+
const trackInnerHeight = trackHeight - (trackBorderWidth * 2)
|
|
159
|
+
const thumbOffsetInactive = (trackInnerHeight - thumbInactiveSize) / 2
|
|
160
|
+
const thumbOffsetActive = trackInnerWidth - thumbActiveSize - (
|
|
161
|
+
(trackInnerHeight - thumbActiveSize) / 2
|
|
162
|
+
)
|
|
163
|
+
const thumbTopInactive = (trackInnerHeight - thumbInactiveSize) / 2
|
|
164
|
+
const thumbTopActive = (trackInnerHeight - thumbActiveSize) / 2
|
|
165
|
+
const thumbSize = progress.interpolate({
|
|
166
|
+
inputRange: [0, 1],
|
|
167
|
+
outputRange: [thumbInactiveSize, thumbActiveSize],
|
|
168
|
+
})
|
|
169
|
+
const thumbTranslateX = progress.interpolate({
|
|
170
|
+
inputRange: [0, 1],
|
|
171
|
+
outputRange: [thumbOffsetInactive, thumbOffsetActive],
|
|
172
|
+
})
|
|
173
|
+
const thumbTop = progress.interpolate({
|
|
174
|
+
inputRange: [0, 1],
|
|
175
|
+
outputRange: [thumbTopInactive, thumbTopActive],
|
|
176
|
+
})
|
|
177
|
+
const thumbColor = value
|
|
178
|
+
? resolvedThumbActive.backgroundColor
|
|
179
|
+
: resolvedThumbInactive.backgroundColor
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<Fragment>
|
|
183
|
+
{hitBox.isVisualizing && (
|
|
184
|
+
<View
|
|
185
|
+
pointerEvents="none"
|
|
186
|
+
style={createHitBoxOverlayStyle(hitSlop, hitBox.color)}
|
|
187
|
+
/>
|
|
188
|
+
)}
|
|
189
|
+
<View style={resolvedTrackStyle}>
|
|
190
|
+
<Animated.View
|
|
191
|
+
style={{
|
|
192
|
+
position: 'absolute',
|
|
193
|
+
top: thumbTop,
|
|
194
|
+
width: thumbSize,
|
|
195
|
+
height: thumbSize,
|
|
196
|
+
borderRadius: thumbActiveSize / 2,
|
|
197
|
+
backgroundColor: thumbColor,
|
|
198
|
+
transform: [{ translateX: thumbTranslateX }],
|
|
199
|
+
}}
|
|
200
|
+
/>
|
|
201
|
+
</View>
|
|
202
|
+
</Fragment>
|
|
203
|
+
)
|
|
204
|
+
}}
|
|
205
|
+
</Pressable>
|
|
206
|
+
)
|
|
207
|
+
}
|