@expressive-ui/native 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +42 -2
- package/dist/Button.d.ts +48 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Button.js +122 -0
- package/dist/Button.js.map +1 -0
- package/dist/Carousel.d.ts +13 -0
- package/dist/Carousel.d.ts.map +1 -0
- package/dist/Carousel.js +52 -0
- package/dist/Carousel.js.map +1 -0
- package/dist/Chips.d.ts +35 -0
- package/dist/Chips.d.ts.map +1 -0
- package/dist/Chips.js +138 -0
- package/dist/Chips.js.map +1 -0
- package/dist/Dialogs.d.ts +42 -0
- package/dist/Dialogs.d.ts.map +1 -0
- package/dist/Dialogs.js +115 -0
- package/dist/Dialogs.js.map +1 -0
- package/dist/ExpressiveCard.d.ts +20 -0
- package/dist/ExpressiveCard.d.ts.map +1 -0
- package/dist/ExpressiveCard.js +71 -0
- package/dist/ExpressiveCard.js.map +1 -0
- package/dist/Fab.d.ts +16 -0
- package/dist/Fab.d.ts.map +1 -0
- package/dist/Fab.js +104 -0
- package/dist/Fab.js.map +1 -0
- package/dist/Fields.d.ts +90 -0
- package/dist/Fields.d.ts.map +1 -0
- package/dist/Fields.js +211 -0
- package/dist/Fields.js.map +1 -0
- package/dist/Grid.d.ts +8 -0
- package/dist/Grid.d.ts.map +1 -0
- package/dist/Grid.js +16 -0
- package/dist/Grid.js.map +1 -0
- package/dist/Inputs.d.ts +33 -0
- package/dist/Inputs.d.ts.map +1 -0
- package/dist/Inputs.js +172 -0
- package/dist/Inputs.js.map +1 -0
- package/dist/List.d.ts +20 -0
- package/dist/List.d.ts.map +1 -0
- package/dist/List.js +222 -0
- package/dist/List.js.map +1 -0
- package/dist/Menu.d.ts +26 -0
- package/dist/Menu.d.ts.map +1 -0
- package/dist/Menu.js +117 -0
- package/dist/Menu.js.map +1 -0
- package/dist/Navigation.d.ts +34 -0
- package/dist/Navigation.d.ts.map +1 -0
- package/dist/Navigation.js +80 -0
- package/dist/Navigation.js.map +1 -0
- package/dist/Progress.d.ts +20 -0
- package/dist/Progress.d.ts.map +1 -0
- package/dist/Progress.js +93 -0
- package/dist/Progress.js.map +1 -0
- package/dist/Search.d.ts +50 -0
- package/dist/Search.d.ts.map +1 -0
- package/dist/Search.js +121 -0
- package/dist/Search.js.map +1 -0
- package/dist/Sheets.d.ts +44 -0
- package/dist/Sheets.d.ts.map +1 -0
- package/dist/Sheets.js +128 -0
- package/dist/Sheets.js.map +1 -0
- package/dist/Toolbar.d.ts +13 -0
- package/dist/Toolbar.d.ts.map +1 -0
- package/dist/Toolbar.js +38 -0
- package/dist/Toolbar.js.map +1 -0
- package/dist/Transition.d.ts +34 -0
- package/dist/Transition.d.ts.map +1 -0
- package/dist/Transition.js +93 -0
- package/dist/Transition.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives.d.ts +41 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +55 -0
- package/dist/primitives.js.map +1 -0
- package/dist/theme.d.ts +57 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +89 -0
- package/dist/theme.js.map +1 -0
- package/package.json +53 -4
- package/src/Button.tsx +347 -0
- package/src/Carousel.tsx +108 -0
- package/src/Chips.tsx +292 -0
- package/src/Dialogs.tsx +252 -0
- package/src/ExpressiveCard.tsx +205 -0
- package/src/Fab.tsx +187 -0
- package/src/Fields.tsx +556 -0
- package/src/Grid.tsx +29 -0
- package/src/Inputs.tsx +290 -0
- package/src/List.tsx +295 -0
- package/src/Menu.tsx +238 -0
- package/src/Navigation.tsx +198 -0
- package/src/Progress.tsx +192 -0
- package/src/Search.tsx +351 -0
- package/src/Sheets.tsx +273 -0
- package/src/Toolbar.tsx +88 -0
- package/src/Transition.tsx +155 -0
- package/src/index.ts +19 -0
- package/src/primitives.tsx +110 -0
- package/src/theme.tsx +125 -0
package/src/Search.tsx
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { useState, type ReactNode } from 'react';
|
|
2
|
+
import { Animated, Modal, Pressable, ScrollView, StyleSheet, TextInput, View, useWindowDimensions, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
resolveSearchBar,
|
|
5
|
+
resolveSearchView,
|
|
6
|
+
useSearchHistory,
|
|
7
|
+
type SearchBarSize,
|
|
8
|
+
type SearchFilter,
|
|
9
|
+
type SearchFilterStyle,
|
|
10
|
+
type SearchHistoryStorage,
|
|
11
|
+
type SearchViewMode,
|
|
12
|
+
} from '@expressive-ui/core';
|
|
13
|
+
import { tokens } from '@expressive-ui/tokens';
|
|
14
|
+
import { Icon, T, typeStyle, withAlpha } from './primitives.js';
|
|
15
|
+
import { useExpressiveTheme, usePresence } from './theme.js';
|
|
16
|
+
|
|
17
|
+
function SearchIconButton({ icon, label, onPress, size = 48 }: { icon: string; label: string; onPress: () => void; size?: number }) {
|
|
18
|
+
const { colors } = useExpressiveTheme();
|
|
19
|
+
return (
|
|
20
|
+
<Pressable
|
|
21
|
+
accessibilityRole="button"
|
|
22
|
+
accessibilityLabel={label}
|
|
23
|
+
onPress={onPress}
|
|
24
|
+
hitSlop={size < 48 ? (48 - size) / 2 : 0}
|
|
25
|
+
style={({ pressed }) => [
|
|
26
|
+
{ width: size, height: size, borderRadius: size / 2, alignItems: 'center', justifyContent: 'center' },
|
|
27
|
+
pressed && { backgroundColor: withAlpha(colors.onSurfaceVariant, tokens.state.pressed) },
|
|
28
|
+
]}
|
|
29
|
+
>
|
|
30
|
+
<Icon name={icon} size={icon === 'close' ? 20 : 24} color="onSurfaceVariant" />
|
|
31
|
+
</Pressable>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// --- SearchBar ------------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
export type SearchBarProps = {
|
|
38
|
+
value?: string;
|
|
39
|
+
onChange?: (value: string) => void;
|
|
40
|
+
onSubmit?: (value: string) => void;
|
|
41
|
+
placeholder: string;
|
|
42
|
+
/** Modo botão: abre a SearchView (SearchBar com onPress do mobile-app-rhosse). */
|
|
43
|
+
onOpen?: () => void;
|
|
44
|
+
leading?: ReactNode;
|
|
45
|
+
trailing?: ReactNode;
|
|
46
|
+
size?: SearchBarSize;
|
|
47
|
+
style?: StyleProp<ViewStyle>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export function SearchBar({ value = '', onChange, onSubmit, placeholder, onOpen, leading, trailing, size = 'md', style }: SearchBarProps) {
|
|
51
|
+
const { labels } = useExpressiveTheme();
|
|
52
|
+
const { colors, mode } = useExpressiveTheme();
|
|
53
|
+
const spec = resolveSearchBar(size);
|
|
54
|
+
return (
|
|
55
|
+
<View
|
|
56
|
+
style={[
|
|
57
|
+
styles.bar,
|
|
58
|
+
{ height: spec.height, borderRadius: spec.height / 2, backgroundColor: colors[spec.container], paddingLeft: leading ? 4 : spec.paddingStart, paddingRight: spec.paddingEnd, gap: spec.gap },
|
|
59
|
+
style,
|
|
60
|
+
]}
|
|
61
|
+
>
|
|
62
|
+
{leading ?? <Icon name="search" color={spec.placeholder} />}
|
|
63
|
+
{onOpen ? (
|
|
64
|
+
<Pressable accessibilityRole="search" accessibilityLabel={value || placeholder} onPress={onOpen} style={styles.fieldButton}>
|
|
65
|
+
<T variant="bodyLarge" color={value ? spec.content : spec.placeholder} numberOfLines={1}>
|
|
66
|
+
{value || placeholder}
|
|
67
|
+
</T>
|
|
68
|
+
</Pressable>
|
|
69
|
+
) : (
|
|
70
|
+
<TextInput
|
|
71
|
+
accessibilityLabel={placeholder}
|
|
72
|
+
placeholder={placeholder}
|
|
73
|
+
placeholderTextColor={colors[spec.placeholder]}
|
|
74
|
+
keyboardAppearance={mode}
|
|
75
|
+
value={value}
|
|
76
|
+
onChangeText={onChange}
|
|
77
|
+
onSubmitEditing={() => onSubmit?.(value)}
|
|
78
|
+
returnKeyType="search"
|
|
79
|
+
style={[typeStyle('bodyLarge'), styles.input, { color: colors[spec.content] }]}
|
|
80
|
+
/>
|
|
81
|
+
)}
|
|
82
|
+
{value && onChange ? <SearchIconButton icon="close" label={labels.clearSearch} onPress={() => onChange('')} size={40} /> : null}
|
|
83
|
+
{trailing}
|
|
84
|
+
</View>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// --- SearchView -----------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
export type SearchViewProps<K extends string = string> = {
|
|
91
|
+
open: boolean;
|
|
92
|
+
onClose: () => void;
|
|
93
|
+
mode?: SearchViewMode;
|
|
94
|
+
value: string;
|
|
95
|
+
onChange: (value: string) => void;
|
|
96
|
+
onSubmit?: (value: string) => void;
|
|
97
|
+
placeholder: string;
|
|
98
|
+
filters?: readonly SearchFilter<K>[];
|
|
99
|
+
filter?: K | null;
|
|
100
|
+
onFilterChange?: (key: K | null) => void;
|
|
101
|
+
filterStyle?: SearchFilterStyle;
|
|
102
|
+
filtersTitle?: string;
|
|
103
|
+
historyKey?: string;
|
|
104
|
+
/** Ex.: AsyncStorage de @react-native-async-storage/async-storage. Sem isso, só memória. */
|
|
105
|
+
historyStorage?: SearchHistoryStorage | null;
|
|
106
|
+
historyTitle?: string;
|
|
107
|
+
/** Área segura superior no fullscreen (ex.: useSafeAreaInsets().top). */
|
|
108
|
+
topInset?: number;
|
|
109
|
+
children?: ReactNode;
|
|
110
|
+
style?: StyleProp<ViewStyle>;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** SearchView do mobile-app-rhosse: voltar, campo, filtros por tipo e buscas recentes; com texto ou filtro, resultados. */
|
|
114
|
+
export function SearchView<K extends string = string>({
|
|
115
|
+
open,
|
|
116
|
+
onClose,
|
|
117
|
+
mode = 'fullscreen',
|
|
118
|
+
value,
|
|
119
|
+
onChange,
|
|
120
|
+
onSubmit,
|
|
121
|
+
placeholder,
|
|
122
|
+
filters = [],
|
|
123
|
+
filter = null,
|
|
124
|
+
onFilterChange,
|
|
125
|
+
filterStyle = 'circle',
|
|
126
|
+
filtersTitle: filtersTitleProp,
|
|
127
|
+
historyKey,
|
|
128
|
+
historyStorage = null,
|
|
129
|
+
historyTitle: historyTitleProp,
|
|
130
|
+
topInset = 0,
|
|
131
|
+
children,
|
|
132
|
+
style,
|
|
133
|
+
}: SearchViewProps<K>) {
|
|
134
|
+
const { labels } = useExpressiveTheme();
|
|
135
|
+
const filtersTitle = filtersTitleProp ?? labels.searchFilters;
|
|
136
|
+
const historyTitle = historyTitleProp ?? labels.recentSearches;
|
|
137
|
+
const { colors, mode: theme } = useExpressiveTheme();
|
|
138
|
+
const { height: screen } = useWindowDimensions();
|
|
139
|
+
const spec = resolveSearchView(mode);
|
|
140
|
+
const { history, add, remove } = useSearchHistory(historyKey ?? '', historyKey ? historyStorage : null);
|
|
141
|
+
const showResults = Boolean(value.trim()) || filter !== null;
|
|
142
|
+
const { progress: reveal, opacity, mounted } = usePresence(open);
|
|
143
|
+
|
|
144
|
+
const close = () => {
|
|
145
|
+
if (historyKey) add(value);
|
|
146
|
+
onClose();
|
|
147
|
+
};
|
|
148
|
+
if (!mounted) return null;
|
|
149
|
+
|
|
150
|
+
const header = (
|
|
151
|
+
<View style={[styles.header, { height: spec.headerHeight, borderBottomColor: colors[spec.divider] }]}>
|
|
152
|
+
<SearchIconButton icon="arrow_back" label={labels.back} onPress={close} />
|
|
153
|
+
<TextInput
|
|
154
|
+
autoFocus
|
|
155
|
+
accessibilityLabel={placeholder}
|
|
156
|
+
placeholder={placeholder}
|
|
157
|
+
placeholderTextColor={colors.onSurfaceVariant}
|
|
158
|
+
keyboardAppearance={theme}
|
|
159
|
+
value={value}
|
|
160
|
+
onChangeText={onChange}
|
|
161
|
+
onSubmitEditing={() => {
|
|
162
|
+
if (historyKey) add(value);
|
|
163
|
+
onSubmit?.(value);
|
|
164
|
+
}}
|
|
165
|
+
returnKeyType="search"
|
|
166
|
+
style={[typeStyle('bodyLarge'), styles.input, { color: colors.onSurface }]}
|
|
167
|
+
/>
|
|
168
|
+
{value ? <SearchIconButton icon="close" label={labels.clearSearch} onPress={() => onChange('')} /> : <View style={{ width: 48 }} />}
|
|
169
|
+
</View>
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const body = (
|
|
173
|
+
<ScrollView keyboardShouldPersistTaps="handled" contentContainerStyle={{ paddingBottom: 32 }}>
|
|
174
|
+
{filters.length ? (
|
|
175
|
+
<>
|
|
176
|
+
<T variant="titleSmall" style={styles.sectionTitle}>
|
|
177
|
+
{filtersTitle}
|
|
178
|
+
</T>
|
|
179
|
+
<ScrollView
|
|
180
|
+
horizontal
|
|
181
|
+
showsHorizontalScrollIndicator={false}
|
|
182
|
+
keyboardShouldPersistTaps="handled"
|
|
183
|
+
contentContainerStyle={[styles.filters, filterStyle === 'circle' && styles.filtersCircle]}
|
|
184
|
+
>
|
|
185
|
+
{filters.map((item) => {
|
|
186
|
+
const active = filter === item.key;
|
|
187
|
+
const toggle = () => onFilterChange?.(active ? null : item.key);
|
|
188
|
+
if (filterStyle === 'chips') {
|
|
189
|
+
const chip = spec.filter.chip;
|
|
190
|
+
return (
|
|
191
|
+
<Pressable
|
|
192
|
+
key={item.key}
|
|
193
|
+
accessibilityRole="button"
|
|
194
|
+
accessibilityLabel={item.label}
|
|
195
|
+
accessibilityState={{ selected: active }}
|
|
196
|
+
onPress={toggle}
|
|
197
|
+
style={[
|
|
198
|
+
styles.chip,
|
|
199
|
+
{ height: chip.height, borderRadius: active ? chip.height / 2 : tokens.shape.small },
|
|
200
|
+
active ? { backgroundColor: colors[chip.selected.container] } : { borderWidth: 1, borderColor: colors[chip.border] },
|
|
201
|
+
]}
|
|
202
|
+
>
|
|
203
|
+
{active ? <Icon name="check" size={18} color={chip.selected.content} /> : item.icon ? <Icon name={item.icon} size={18} color={chip.content} /> : null}
|
|
204
|
+
<T variant="labelLarge" color={active ? chip.selected.content : chip.content}>
|
|
205
|
+
{item.label}
|
|
206
|
+
</T>
|
|
207
|
+
</Pressable>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const circle = spec.filter.circle;
|
|
211
|
+
return (
|
|
212
|
+
<Pressable key={item.key} accessibilityRole="button" accessibilityLabel={item.label} accessibilityState={{ selected: active }} onPress={toggle} style={styles.circleItem}>
|
|
213
|
+
{({ pressed }) => (
|
|
214
|
+
<>
|
|
215
|
+
<View
|
|
216
|
+
style={{
|
|
217
|
+
width: circle.size,
|
|
218
|
+
height: circle.size,
|
|
219
|
+
borderRadius: pressed ? tokens.shape.extraLarge : circle.size / 2,
|
|
220
|
+
alignItems: 'center',
|
|
221
|
+
justifyContent: 'center',
|
|
222
|
+
backgroundColor: colors[active ? circle.selected.container : circle.container],
|
|
223
|
+
}}
|
|
224
|
+
>
|
|
225
|
+
{item.icon ? <Icon name={item.icon} filled={active} color={active ? circle.selected.content : circle.content} /> : null}
|
|
226
|
+
</View>
|
|
227
|
+
<T variant="bodyMedium" color={active ? 'primary' : 'onSurfaceVariant'} numberOfLines={1} style={{ textAlign: 'center' }}>
|
|
228
|
+
{item.label}
|
|
229
|
+
</T>
|
|
230
|
+
</>
|
|
231
|
+
)}
|
|
232
|
+
</Pressable>
|
|
233
|
+
);
|
|
234
|
+
})}
|
|
235
|
+
</ScrollView>
|
|
236
|
+
</>
|
|
237
|
+
) : null}
|
|
238
|
+
{showResults ? (
|
|
239
|
+
<View style={styles.results}>{children}</View>
|
|
240
|
+
) : historyKey && history.length ? (
|
|
241
|
+
<>
|
|
242
|
+
<T variant="titleSmall" style={styles.sectionTitle}>
|
|
243
|
+
{historyTitle}
|
|
244
|
+
</T>
|
|
245
|
+
{history.map((term) => (
|
|
246
|
+
<Pressable
|
|
247
|
+
key={term}
|
|
248
|
+
accessibilityRole="button"
|
|
249
|
+
accessibilityLabel={term}
|
|
250
|
+
onPress={() => onChange(term)}
|
|
251
|
+
style={({ pressed }) => [styles.historyRow, pressed && { backgroundColor: colors.surfaceContainerHigh }]}
|
|
252
|
+
>
|
|
253
|
+
<Icon name="history" color="onSurfaceVariant" />
|
|
254
|
+
<T variant="bodyLarge" color="onSurfaceVariant" numberOfLines={1} style={{ flex: 1 }}>
|
|
255
|
+
{term}
|
|
256
|
+
</T>
|
|
257
|
+
<SearchIconButton icon="close" label={`Remover "${term}" das buscas recentes`} onPress={() => remove(term)} size={40} />
|
|
258
|
+
</Pressable>
|
|
259
|
+
))}
|
|
260
|
+
</>
|
|
261
|
+
) : null}
|
|
262
|
+
</ScrollView>
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
if (mode === 'docked') {
|
|
266
|
+
return (
|
|
267
|
+
<Animated.View
|
|
268
|
+
style={[
|
|
269
|
+
styles.docked,
|
|
270
|
+
{
|
|
271
|
+
maxHeight: screen * spec.maxHeight,
|
|
272
|
+
borderRadius: spec.radius,
|
|
273
|
+
backgroundColor: colors[spec.container],
|
|
274
|
+
boxShadow: tokens.elevation[theme][spec.elevation],
|
|
275
|
+
opacity,
|
|
276
|
+
transform: [{ scaleY: reveal.interpolate({ inputRange: [0, 1], outputRange: [0.6, 1] }) }],
|
|
277
|
+
transformOrigin: 'top',
|
|
278
|
+
},
|
|
279
|
+
style,
|
|
280
|
+
]}
|
|
281
|
+
>
|
|
282
|
+
{header}
|
|
283
|
+
{body}
|
|
284
|
+
</Animated.View>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
return (
|
|
288
|
+
<Modal visible transparent animationType="none" onRequestClose={close} statusBarTranslucent navigationBarTranslucent>
|
|
289
|
+
<Animated.View style={[styles.fill, { backgroundColor: colors[spec.backdrop ?? 'surfaceContainer'], paddingTop: topInset + 8, opacity }]}>
|
|
290
|
+
<Animated.View
|
|
291
|
+
style={[
|
|
292
|
+
styles.sheet,
|
|
293
|
+
{
|
|
294
|
+
borderTopLeftRadius: spec.radius,
|
|
295
|
+
borderTopRightRadius: spec.radius,
|
|
296
|
+
backgroundColor: colors[spec.container],
|
|
297
|
+
transform: [{ translateY: reveal.interpolate({ inputRange: [0, 1], outputRange: [24, 0] }) }],
|
|
298
|
+
},
|
|
299
|
+
style,
|
|
300
|
+
]}
|
|
301
|
+
>
|
|
302
|
+
{header}
|
|
303
|
+
{body}
|
|
304
|
+
</Animated.View>
|
|
305
|
+
</Animated.View>
|
|
306
|
+
</Modal>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// --- Search (barra + view) ------------------------------------------------------------------
|
|
311
|
+
|
|
312
|
+
export type SearchProps<K extends string = string> = Omit<SearchViewProps<K>, 'open' | 'onClose' | 'style'> & {
|
|
313
|
+
open?: boolean;
|
|
314
|
+
onOpenChange?: (open: boolean) => void;
|
|
315
|
+
size?: SearchBarSize;
|
|
316
|
+
leading?: ReactNode;
|
|
317
|
+
trailing?: ReactNode;
|
|
318
|
+
style?: StyleProp<ViewStyle>;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export function Search<K extends string = string>({ open: controlled, onOpenChange, size, leading, trailing, style, ...view }: SearchProps<K>) {
|
|
322
|
+
const [inner, setInner] = useState(false);
|
|
323
|
+
const open = controlled ?? inner;
|
|
324
|
+
const setOpen = (next: boolean) => {
|
|
325
|
+
if (controlled === undefined) setInner(next);
|
|
326
|
+
onOpenChange?.(next);
|
|
327
|
+
};
|
|
328
|
+
return (
|
|
329
|
+
<View style={[{ zIndex: open ? 30 : undefined }, style]}>
|
|
330
|
+
<SearchBar value={view.value} onChange={view.onChange} placeholder={view.placeholder} size={size} leading={leading} trailing={trailing} onOpen={() => setOpen(true)} />
|
|
331
|
+
<SearchView {...view} open={open} onClose={() => setOpen(false)} />
|
|
332
|
+
</View>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const styles = StyleSheet.create({
|
|
337
|
+
fill: { flex: 1, paddingHorizontal: 8 },
|
|
338
|
+
bar: { flexDirection: 'row', alignItems: 'center' },
|
|
339
|
+
fieldButton: { flex: 1, alignSelf: 'stretch', justifyContent: 'center' },
|
|
340
|
+
input: { flex: 1, paddingVertical: 0 },
|
|
341
|
+
header: { flexDirection: 'row', alignItems: 'center', gap: 4, paddingHorizontal: 4, borderBottomWidth: StyleSheet.hairlineWidth * 2 },
|
|
342
|
+
sheet: { flex: 1, overflow: 'hidden' },
|
|
343
|
+
docked: { position: 'absolute', top: 0, left: 0, right: 0, overflow: 'hidden' },
|
|
344
|
+
sectionTitle: { paddingHorizontal: 24, paddingTop: 24, paddingBottom: 12 },
|
|
345
|
+
filters: { paddingHorizontal: 16, gap: 8 },
|
|
346
|
+
filtersCircle: { flexGrow: 1, justifyContent: 'space-around' },
|
|
347
|
+
circleItem: { alignItems: 'center', width: 96, gap: 10 },
|
|
348
|
+
chip: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingLeft: 8, paddingRight: 16 },
|
|
349
|
+
results: { paddingTop: 16, paddingHorizontal: 16 },
|
|
350
|
+
historyRow: { minHeight: 56, flexDirection: 'row', alignItems: 'center', paddingLeft: 24, paddingRight: 8, gap: 16 },
|
|
351
|
+
});
|
package/src/Sheets.tsx
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
2
|
+
import { Animated, Modal, PanResponder, Pressable, ScrollView, StyleSheet, useWindowDimensions, View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import { resolveBottomSheet, resolveSideSheet, springConfig, type SheetMode } from '@expressive-ui/core';
|
|
4
|
+
import { tokens } from '@expressive-ui/tokens';
|
|
5
|
+
import { Icon, T, withAlpha } from './primitives.js';
|
|
6
|
+
import { useExpressiveTheme, usePresence } from './theme.js';
|
|
7
|
+
|
|
8
|
+
// --- BottomSheet ----------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
export type BottomSheetProps = {
|
|
11
|
+
open: boolean;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
mode?: SheetMode;
|
|
14
|
+
title?: string;
|
|
15
|
+
full?: boolean;
|
|
16
|
+
handle?: boolean;
|
|
17
|
+
/** Área segura inferior (ex.: useSafeAreaInsets().bottom). */
|
|
18
|
+
bottomInset?: number;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
style?: StyleProp<ViewStyle>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Bottom sheet do M3, a partir do Sheet do mobile-app-rhosse: cantos de 28, alça e scrim. */
|
|
24
|
+
export function BottomSheet({ open, onClose, mode = 'modal', title, full = false, handle = true, bottomInset = 0, children, style }: BottomSheetProps) {
|
|
25
|
+
const { labels } = useExpressiveTheme();
|
|
26
|
+
const { colors, mode: theme, motion } = useExpressiveTheme();
|
|
27
|
+
const { height: screen } = useWindowDimensions();
|
|
28
|
+
const spec = resolveBottomSheet({ mode, full });
|
|
29
|
+
const { progress, opacity, mounted } = usePresence(open);
|
|
30
|
+
const drag = useRef(new Animated.Value(0)).current;
|
|
31
|
+
const [height, setHeight] = useState(screen * 0.5);
|
|
32
|
+
const latest = useRef({ height, onClose, motion });
|
|
33
|
+
latest.current = { height, onClose, motion };
|
|
34
|
+
// fechou arrastando: sai do ponto onde foi solto; a próxima abertura começa do zero
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (open) drag.setValue(0);
|
|
37
|
+
}, [open, drag]);
|
|
38
|
+
|
|
39
|
+
// Arrastar a alça para baixo fecha (distância ou velocidade); para cima resiste.
|
|
40
|
+
const responder = useRef(
|
|
41
|
+
PanResponder.create({
|
|
42
|
+
onStartShouldSetPanResponder: () => true,
|
|
43
|
+
onMoveShouldSetPanResponder: (_, g) => Math.abs(g.dy) > 4,
|
|
44
|
+
onPanResponderMove: (_, g) => drag.setValue(g.dy < 0 ? g.dy / 3 : g.dy),
|
|
45
|
+
onPanResponderRelease: (_, g) => {
|
|
46
|
+
const dismiss = g.dy > latest.current.height * spec.dismissThreshold || g.vy > 0.6;
|
|
47
|
+
if (dismiss) return latest.current.onClose?.();
|
|
48
|
+
Animated.spring(drag, { toValue: 0, ...springConfig('spatialDefault', latest.current.motion), useNativeDriver: true }).start();
|
|
49
|
+
},
|
|
50
|
+
onPanResponderTerminate: () =>
|
|
51
|
+
Animated.spring(drag, { toValue: 0, ...springConfig('spatialDefault', latest.current.motion), useNativeDriver: true }).start(),
|
|
52
|
+
}),
|
|
53
|
+
).current;
|
|
54
|
+
|
|
55
|
+
if (!mounted) return null;
|
|
56
|
+
const translateY = Animated.add(progress.interpolate({ inputRange: [0, 1], outputRange: [height, 0] }), drag);
|
|
57
|
+
const sheet = (
|
|
58
|
+
<Animated.View
|
|
59
|
+
accessibilityViewIsModal={mode === 'modal'}
|
|
60
|
+
onLayout={(e) => setHeight(e.nativeEvent.layout.height)}
|
|
61
|
+
style={[
|
|
62
|
+
styles.bottom,
|
|
63
|
+
{
|
|
64
|
+
backgroundColor: colors[spec.container],
|
|
65
|
+
borderTopLeftRadius: spec.radius,
|
|
66
|
+
borderTopRightRadius: spec.radius,
|
|
67
|
+
maxHeight: screen * spec.maxHeight,
|
|
68
|
+
minHeight: screen * spec.minHeight,
|
|
69
|
+
maxWidth: spec.maxWidth,
|
|
70
|
+
paddingBottom: Math.max(16, bottomInset + 8),
|
|
71
|
+
paddingTop: handle ? 0 : 24,
|
|
72
|
+
boxShadow: tokens.elevation[theme][spec.elevation],
|
|
73
|
+
transform: [{ translateY }],
|
|
74
|
+
},
|
|
75
|
+
style,
|
|
76
|
+
]}
|
|
77
|
+
>
|
|
78
|
+
{handle ? (
|
|
79
|
+
<View {...responder.panHandlers} accessible accessibilityRole="button" accessibilityLabel={labels.close} style={styles.handleArea}>
|
|
80
|
+
<Pressable onPress={onClose} hitSlop={12}>
|
|
81
|
+
<View style={{ width: spec.handle.width, height: spec.handle.height, borderRadius: 2, backgroundColor: colors[spec.handle.color], opacity: spec.handle.opacity }} />
|
|
82
|
+
</Pressable>
|
|
83
|
+
</View>
|
|
84
|
+
) : null}
|
|
85
|
+
{title ? (
|
|
86
|
+
<T variant="titleLarge" accessibilityRole="header" style={styles.bottomTitle}>
|
|
87
|
+
{title}
|
|
88
|
+
</T>
|
|
89
|
+
) : null}
|
|
90
|
+
<ScrollView contentContainerStyle={styles.bottomContent}>{children}</ScrollView>
|
|
91
|
+
</Animated.View>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (mode === 'standard') return <View pointerEvents="box-none" style={StyleSheet.absoluteFill}>{sheet}</View>;
|
|
95
|
+
return (
|
|
96
|
+
<Modal visible transparent animationType="none" onRequestClose={onClose} statusBarTranslucent navigationBarTranslucent>
|
|
97
|
+
<View style={styles.fill}>
|
|
98
|
+
<Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: withAlpha(colors.scrim, spec.scrim!.opacity), opacity }]}>
|
|
99
|
+
<Pressable accessibilityRole="button" accessibilityLabel={labels.close} style={StyleSheet.absoluteFill} onPress={onClose} />
|
|
100
|
+
</Animated.View>
|
|
101
|
+
{sheet}
|
|
102
|
+
</View>
|
|
103
|
+
</Modal>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// --- OptionSheet ----------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
export type SheetOption<V extends string> = { value: V; label: string; supporting?: string; icon?: string; destructive?: boolean };
|
|
110
|
+
|
|
111
|
+
export type OptionSheetProps<V extends string> = Omit<BottomSheetProps, 'children' | 'mode'> & {
|
|
112
|
+
options: readonly SheetOption<V>[];
|
|
113
|
+
value?: V | null;
|
|
114
|
+
onSelect: (value: V) => void;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** OptionSheet do mobile-app-rhosse: só a escolhida é pílula; as outras usam o raio dos cards ao pressionar. */
|
|
118
|
+
export function OptionSheet<V extends string>({ options, value, onSelect, ...sheet }: OptionSheetProps<V>) {
|
|
119
|
+
const { colors } = useExpressiveTheme();
|
|
120
|
+
const choice = value !== undefined;
|
|
121
|
+
return (
|
|
122
|
+
<BottomSheet {...sheet} mode="modal">
|
|
123
|
+
<View accessibilityRole={choice ? 'radiogroup' : undefined} style={styles.options}>
|
|
124
|
+
{options.map((option) => {
|
|
125
|
+
const selected = value === option.value;
|
|
126
|
+
const fg = option.destructive ? 'error' : selected ? 'onSecondaryContainer' : 'onSurface';
|
|
127
|
+
return (
|
|
128
|
+
<Pressable
|
|
129
|
+
key={option.value}
|
|
130
|
+
accessibilityRole={choice ? 'radio' : 'button'}
|
|
131
|
+
accessibilityState={choice ? { checked: selected } : undefined}
|
|
132
|
+
onPress={() => onSelect(option.value)}
|
|
133
|
+
style={({ pressed }) => [
|
|
134
|
+
styles.option,
|
|
135
|
+
{
|
|
136
|
+
borderRadius: selected ? 28 : tokens.shape.large,
|
|
137
|
+
backgroundColor: selected ? colors.secondaryContainer : pressed ? colors.surfaceContainerHigh : 'transparent',
|
|
138
|
+
},
|
|
139
|
+
]}
|
|
140
|
+
>
|
|
141
|
+
{option.icon ? <Icon name={option.icon} color={option.destructive ? 'error' : selected ? 'onSecondaryContainer' : 'onSurfaceVariant'} /> : null}
|
|
142
|
+
<View style={styles.optionText}>
|
|
143
|
+
<T variant="bodyLarge" color={fg}>
|
|
144
|
+
{option.label}
|
|
145
|
+
</T>
|
|
146
|
+
{option.supporting ? (
|
|
147
|
+
<T variant="bodyMedium" color="onSurfaceVariant">
|
|
148
|
+
{option.supporting}
|
|
149
|
+
</T>
|
|
150
|
+
) : null}
|
|
151
|
+
</View>
|
|
152
|
+
{selected ? <Icon name="check" color="onSecondaryContainer" /> : null}
|
|
153
|
+
</Pressable>
|
|
154
|
+
);
|
|
155
|
+
})}
|
|
156
|
+
</View>
|
|
157
|
+
</BottomSheet>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// --- SideSheet ------------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
export type SideSheetProps = {
|
|
164
|
+
open: boolean;
|
|
165
|
+
onClose?: () => void;
|
|
166
|
+
onBack?: () => void;
|
|
167
|
+
mode?: SheetMode;
|
|
168
|
+
title: string;
|
|
169
|
+
actions?: ReactNode;
|
|
170
|
+
children?: ReactNode;
|
|
171
|
+
style?: StyleProp<ViewStyle>;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function SheetIconButton({ icon, label, onPress }: { icon: string; label: string; onPress: () => void }) {
|
|
175
|
+
const { colors } = useExpressiveTheme();
|
|
176
|
+
return (
|
|
177
|
+
<Pressable
|
|
178
|
+
accessibilityRole="button"
|
|
179
|
+
accessibilityLabel={label}
|
|
180
|
+
onPress={onPress}
|
|
181
|
+
style={({ pressed }) => [styles.iconButton, pressed && { backgroundColor: withAlpha(colors.onSurfaceVariant, tokens.state.pressed) }]}
|
|
182
|
+
>
|
|
183
|
+
<Icon name={icon} color="onSurfaceVariant" />
|
|
184
|
+
</Pressable>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Side sheet (tablets): modal sobreposto à direita ou standard ao lado do conteúdo (o .drawer do Elo admin). */
|
|
189
|
+
export function SideSheet({ open, onClose, onBack, mode = 'modal', title, actions, children, style }: SideSheetProps) {
|
|
190
|
+
const { labels } = useExpressiveTheme();
|
|
191
|
+
const { colors, mode: theme } = useExpressiveTheme();
|
|
192
|
+
const { width: screen } = useWindowDimensions();
|
|
193
|
+
const spec = resolveSideSheet({ mode });
|
|
194
|
+
const { progress, opacity, mounted } = usePresence(open, false);
|
|
195
|
+
const width = Math.min(spec.width, screen - spec.inset * 2);
|
|
196
|
+
if (!mounted) return null;
|
|
197
|
+
|
|
198
|
+
const content = (
|
|
199
|
+
<>
|
|
200
|
+
<View style={styles.sideHeader}>
|
|
201
|
+
{onBack ? <SheetIconButton icon="arrow_back" label={labels.back} onPress={onBack} /> : null}
|
|
202
|
+
<T variant="titleLarge" accessibilityRole="header" numberOfLines={1} style={[styles.sideTitle, !onBack && { paddingLeft: 12 }]}>
|
|
203
|
+
{title}
|
|
204
|
+
</T>
|
|
205
|
+
{onClose ? <SheetIconButton icon="close" label={labels.close} onPress={onClose} /> : null}
|
|
206
|
+
</View>
|
|
207
|
+
<ScrollView style={styles.fill} contentContainerStyle={styles.sideContent}>
|
|
208
|
+
{children}
|
|
209
|
+
</ScrollView>
|
|
210
|
+
{actions ? <View style={[styles.sideActions, { borderTopColor: colors.outlineVariant }]}>{actions}</View> : null}
|
|
211
|
+
</>
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
if (mode === 'standard') {
|
|
215
|
+
return (
|
|
216
|
+
<Animated.View
|
|
217
|
+
style={[
|
|
218
|
+
{ width: progress.interpolate({ inputRange: [0, 1], outputRange: [0, width] }), overflow: 'hidden', height: '100%' },
|
|
219
|
+
style,
|
|
220
|
+
]}
|
|
221
|
+
>
|
|
222
|
+
<View style={{ width, flex: 1, backgroundColor: colors[spec.container], borderLeftWidth: StyleSheet.hairlineWidth * 2, borderLeftColor: colors[spec.border ?? 'outlineVariant'] }}>
|
|
223
|
+
{content}
|
|
224
|
+
</View>
|
|
225
|
+
</Animated.View>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
return (
|
|
229
|
+
<Modal visible transparent animationType="none" onRequestClose={onClose} statusBarTranslucent>
|
|
230
|
+
<View style={styles.fill}>
|
|
231
|
+
<Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: withAlpha(colors.scrim, spec.scrim!.opacity), opacity }]}>
|
|
232
|
+
<Pressable accessibilityRole="button" accessibilityLabel={labels.close} style={StyleSheet.absoluteFill} onPress={onClose} />
|
|
233
|
+
</Animated.View>
|
|
234
|
+
<Animated.View
|
|
235
|
+
accessibilityViewIsModal
|
|
236
|
+
style={[
|
|
237
|
+
styles.side,
|
|
238
|
+
{
|
|
239
|
+
top: spec.inset,
|
|
240
|
+
bottom: spec.inset,
|
|
241
|
+
right: spec.inset,
|
|
242
|
+
width,
|
|
243
|
+
borderRadius: spec.radius,
|
|
244
|
+
backgroundColor: colors[spec.container],
|
|
245
|
+
boxShadow: tokens.elevation[theme][spec.elevation],
|
|
246
|
+
transform: [{ translateX: progress.interpolate({ inputRange: [0, 1], outputRange: [width + spec.inset, 0] }) }],
|
|
247
|
+
},
|
|
248
|
+
style,
|
|
249
|
+
]}
|
|
250
|
+
>
|
|
251
|
+
{content}
|
|
252
|
+
</Animated.View>
|
|
253
|
+
</View>
|
|
254
|
+
</Modal>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const styles = StyleSheet.create({
|
|
259
|
+
fill: { flex: 1 },
|
|
260
|
+
bottom: { position: 'absolute', left: 0, right: 0, bottom: 0, alignSelf: 'center', width: '100%' },
|
|
261
|
+
handleArea: { alignItems: 'center', paddingTop: 22, paddingBottom: 18 },
|
|
262
|
+
bottomTitle: { paddingHorizontal: 24, paddingBottom: 8 },
|
|
263
|
+
bottomContent: { paddingHorizontal: 24 },
|
|
264
|
+
options: { gap: 2, marginHorizontal: -12, paddingBottom: 8 },
|
|
265
|
+
option: { minHeight: 56, paddingHorizontal: 16, flexDirection: 'row', alignItems: 'center', gap: 16 },
|
|
266
|
+
optionText: { flex: 1, paddingVertical: 8 },
|
|
267
|
+
side: { position: 'absolute', overflow: 'hidden' },
|
|
268
|
+
sideHeader: { flexDirection: 'row', alignItems: 'center', gap: 4, minHeight: 72, paddingHorizontal: 12, paddingTop: 12, paddingBottom: 8 },
|
|
269
|
+
sideTitle: { flex: 1 },
|
|
270
|
+
sideContent: { paddingHorizontal: 24, paddingBottom: 24 },
|
|
271
|
+
sideActions: { flexDirection: 'row', gap: 8, paddingHorizontal: 24, paddingTop: 16, paddingBottom: 24, borderTopWidth: 1 },
|
|
272
|
+
iconButton: { width: 48, height: 48, borderRadius: 24, alignItems: 'center', justifyContent: 'center' },
|
|
273
|
+
});
|