@expressive-ui/native 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +40 -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/Pickers.d.ts +16 -0
- package/dist/Pickers.d.ts.map +1 -0
- package/dist/Pickers.js +100 -0
- package/dist/Pickers.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 +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -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/Pickers.tsx +151 -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 +20 -0
- package/src/primitives.tsx +110 -0
- package/src/theme.tsx +125 -0
package/src/Progress.tsx
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Animated, Easing, View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import Svg, { Path } from 'react-native-svg';
|
|
4
|
+
import {
|
|
5
|
+
circularDash,
|
|
6
|
+
circularGeometry,
|
|
7
|
+
LOADING_CYCLE_MS,
|
|
8
|
+
loadingFrame,
|
|
9
|
+
resolveLoading,
|
|
10
|
+
resolveProgress,
|
|
11
|
+
waveLinePath,
|
|
12
|
+
type ProgressSpec,
|
|
13
|
+
type RuntimeProps,
|
|
14
|
+
} from '@expressive-ui/core';
|
|
15
|
+
import type { LoadingIndicatorData, ProgressIndicatorData } from '@expressive-ui/schema';
|
|
16
|
+
import { tokens, type ColorRole } from '@expressive-ui/tokens';
|
|
17
|
+
import { useExpressiveTheme, useSpringValue } from './theme.js';
|
|
18
|
+
|
|
19
|
+
// --- LoadingIndicator ---------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
export type LoadingIndicatorProps = LoadingIndicatorData &
|
|
22
|
+
RuntimeProps & {
|
|
23
|
+
color?: ColorRole;
|
|
24
|
+
/** Cor já resolvida (ex.: a do conteúdo de um Button); tem prioridade sobre `color`. */
|
|
25
|
+
tint?: string;
|
|
26
|
+
style?: StyleProp<ViewStyle>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Mesma sequência de formas do sprite do mobile-app-rhosse, agora em vetor: o quadro é calculado
|
|
31
|
+
* pelo core a cada frame (forma + rotação no mesmo path). Com "reduzir movimento" gira na metade da velocidade.
|
|
32
|
+
*/
|
|
33
|
+
export function LoadingIndicator({ contained, size, label: labelProp, color, tint, style }: LoadingIndicatorProps) {
|
|
34
|
+
const { labels } = useExpressiveTheme();
|
|
35
|
+
const label = labelProp ?? labels.loading;
|
|
36
|
+
const { colors, reduceMotion } = useExpressiveTheme();
|
|
37
|
+
const spec = resolveLoading({ contained, size });
|
|
38
|
+
const [t, setT] = useState(0);
|
|
39
|
+
const cycle = LOADING_CYCLE_MS * (reduceMotion ? 2 : 1);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const start = Date.now();
|
|
42
|
+
let frame = requestAnimationFrame(function tick() {
|
|
43
|
+
setT(((Date.now() - start) % cycle) / cycle);
|
|
44
|
+
frame = requestAnimationFrame(tick);
|
|
45
|
+
});
|
|
46
|
+
return () => cancelAnimationFrame(frame);
|
|
47
|
+
}, [cycle]);
|
|
48
|
+
return (
|
|
49
|
+
<View
|
|
50
|
+
accessibilityRole="progressbar"
|
|
51
|
+
accessibilityLabel={label}
|
|
52
|
+
accessibilityState={{ busy: true }}
|
|
53
|
+
style={[
|
|
54
|
+
{
|
|
55
|
+
width: spec.size,
|
|
56
|
+
height: spec.size,
|
|
57
|
+
borderRadius: spec.size / 2,
|
|
58
|
+
backgroundColor: spec.container ? colors[spec.container] : undefined,
|
|
59
|
+
alignItems: 'center',
|
|
60
|
+
justifyContent: 'center',
|
|
61
|
+
},
|
|
62
|
+
style,
|
|
63
|
+
]}
|
|
64
|
+
>
|
|
65
|
+
<Svg width={spec.shapeSize} height={spec.shapeSize} viewBox="0 0 100 100">
|
|
66
|
+
<Path d={loadingFrame(t)} fill={tint ?? colors[color ?? spec.content]} />
|
|
67
|
+
</Svg>
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// --- ProgressIndicator --------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
export type ProgressIndicatorProps = ProgressIndicatorData & RuntimeProps & { style?: StyleProp<ViewStyle> };
|
|
75
|
+
|
|
76
|
+
export function ProgressIndicator({ onAction: _, index: __, children: ___, style, ...data }: ProgressIndicatorProps) {
|
|
77
|
+
const spec = resolveProgress(data);
|
|
78
|
+
return spec.type === 'circular' ? <CircularProgress spec={spec} style={style} /> : <LinearProgress spec={spec} style={style} />;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const accessibility = (spec: ProgressSpec) => ({
|
|
82
|
+
accessibilityRole: 'progressbar' as const,
|
|
83
|
+
accessibilityLabel: spec.label,
|
|
84
|
+
accessibilityValue: spec.value === null ? undefined : { min: spec.accessibility.min, max: spec.accessibility.max, now: spec.accessibility.now },
|
|
85
|
+
accessibilityState: spec.value === null ? { busy: true } : undefined,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Laço contínuo 0→1 no driver nativo (só transform).
|
|
89
|
+
function useLoop(duration: number, easing: (t: number) => number, enabled = true) {
|
|
90
|
+
const value = useRef(new Animated.Value(0)).current;
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (!enabled) return;
|
|
93
|
+
const loop = Animated.loop(Animated.timing(value, { toValue: 1, duration, easing, useNativeDriver: true }));
|
|
94
|
+
loop.start();
|
|
95
|
+
return () => loop.stop();
|
|
96
|
+
}, [value, duration, easing, enabled]);
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const linear = Easing.linear;
|
|
101
|
+
const emphasized = Easing.bezier(...tokens.motion.easing.emphasized);
|
|
102
|
+
|
|
103
|
+
/** Onda que "corre": desenhada com um comprimento a mais e deslocada em laço (driver nativo). */
|
|
104
|
+
function Wave({ spec, length, color }: { spec: ProgressSpec; length: number; color: string }) {
|
|
105
|
+
const { reduceMotion } = useExpressiveTheme();
|
|
106
|
+
const phase = useLoop(spec.value === null ? 500 : 1000, linear, !reduceMotion);
|
|
107
|
+
const translateX = phase.interpolate({ inputRange: [0, 1], outputRange: [-spec.wavelength, 0] });
|
|
108
|
+
return (
|
|
109
|
+
<Animated.View style={{ width: length + spec.wavelength, height: spec.waveHeight, transform: [{ translateX }] }}>
|
|
110
|
+
<Svg width={length + spec.wavelength} height={spec.waveHeight}>
|
|
111
|
+
<Path d={waveLinePath(length + spec.wavelength, spec.wavelength, spec.amplitude, spec.waveHeight)} fill="none" stroke={color} strokeWidth={spec.track} />
|
|
112
|
+
</Svg>
|
|
113
|
+
</Animated.View>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function LinearProgress({ spec, style }: { spec: ProgressSpec; style?: StyleProp<ViewStyle> }) {
|
|
118
|
+
const { colors } = useExpressiveTheme();
|
|
119
|
+
const [width, setWidth] = useState(0);
|
|
120
|
+
const active = colors[spec.active];
|
|
121
|
+
const height = spec.wavy ? spec.waveHeight : spec.track;
|
|
122
|
+
const usable = Math.max(0, width - spec.stop - spec.gap);
|
|
123
|
+
const fill = useSpringValue((spec.value ?? 0) * usable, 'effectsSlow');
|
|
124
|
+
const slide = useLoop(1800, emphasized, spec.value === null && width > 0);
|
|
125
|
+
const bar = width * 0.4;
|
|
126
|
+
const segment = (length: number | Animated.Value) => (
|
|
127
|
+
<Animated.View style={{ width: length, height, overflow: 'hidden', justifyContent: 'center', borderRadius: spec.wavy ? 0 : spec.track / 2 }}>
|
|
128
|
+
{spec.wavy ? <Wave spec={spec} length={typeof length === 'number' ? length : usable} color={active} /> : <View style={{ height: spec.track, backgroundColor: active }} />}
|
|
129
|
+
</Animated.View>
|
|
130
|
+
);
|
|
131
|
+
const trackStyle = { height: spec.track, borderRadius: spec.track / 2, backgroundColor: colors[spec.trackColor] };
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<View
|
|
135
|
+
onLayout={(e) => setWidth(e.nativeEvent.layout.width)}
|
|
136
|
+
style={[{ height, flexDirection: 'row', alignItems: 'center', overflow: spec.value === null ? 'hidden' : 'visible' }, style]}
|
|
137
|
+
{...accessibility(spec)}
|
|
138
|
+
>
|
|
139
|
+
{!width ? null : spec.value === null ? (
|
|
140
|
+
<>
|
|
141
|
+
<View style={[trackStyle, { position: 'absolute', left: 0, right: 0 }]} />
|
|
142
|
+
<Animated.View style={{ position: 'absolute', left: 0, transform: [{ translateX: slide.interpolate({ inputRange: [0, 1], outputRange: [-bar, width] }) }] }}>
|
|
143
|
+
{segment(bar)}
|
|
144
|
+
</Animated.View>
|
|
145
|
+
</>
|
|
146
|
+
) : (
|
|
147
|
+
<>
|
|
148
|
+
{segment(fill)}
|
|
149
|
+
{spec.value < 0.995 ? <View style={[trackStyle, { flex: 1, marginLeft: spec.gap }]} /> : null}
|
|
150
|
+
<View style={{ position: 'absolute', right: 0, width: spec.stop, height: spec.stop, borderRadius: spec.stop / 2, backgroundColor: active }} />
|
|
151
|
+
</>
|
|
152
|
+
)}
|
|
153
|
+
</View>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Strokes com comprimento absoluto (react-native-svg não garante pathLength).
|
|
158
|
+
function CircularProgress({ spec, style }: { spec: ProgressSpec; style?: StyleProp<ViewStyle> }) {
|
|
159
|
+
const { colors } = useExpressiveTheme();
|
|
160
|
+
const geo = circularGeometry(spec);
|
|
161
|
+
const indeterminate = spec.value === null;
|
|
162
|
+
const dash = circularDash(spec.value ?? 0.28, geo.gapFraction);
|
|
163
|
+
const spin = useLoop(1600, linear, indeterminate);
|
|
164
|
+
const rotate = spin.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '360deg'] });
|
|
165
|
+
return (
|
|
166
|
+
<Animated.View style={[{ width: spec.size, height: spec.size, transform: indeterminate ? [{ rotate }] : [] }, style]} {...accessibility(spec)}>
|
|
167
|
+
<Svg width={spec.size} height={spec.size}>
|
|
168
|
+
{!indeterminate && dash.showTrack ? (
|
|
169
|
+
<Path
|
|
170
|
+
d={geo.track}
|
|
171
|
+
fill="none"
|
|
172
|
+
stroke={colors[spec.trackColor]}
|
|
173
|
+
strokeWidth={spec.track}
|
|
174
|
+
strokeLinecap="round"
|
|
175
|
+
strokeDasharray={[dash.trackLength * geo.trackLength, geo.trackLength]}
|
|
176
|
+
strokeDashoffset={-dash.trackStart * geo.trackLength}
|
|
177
|
+
/>
|
|
178
|
+
) : null}
|
|
179
|
+
{indeterminate || dash.showActive ? (
|
|
180
|
+
<Path
|
|
181
|
+
d={geo.active}
|
|
182
|
+
fill="none"
|
|
183
|
+
stroke={colors[spec.active]}
|
|
184
|
+
strokeWidth={spec.track}
|
|
185
|
+
strokeLinecap="round"
|
|
186
|
+
strokeDasharray={[dash.active * geo.activeLength, geo.activeLength]}
|
|
187
|
+
/>
|
|
188
|
+
) : null}
|
|
189
|
+
</Svg>
|
|
190
|
+
</Animated.View>
|
|
191
|
+
);
|
|
192
|
+
}
|
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
|
+
});
|