@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/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
|
+
});
|
package/src/Toolbar.tsx
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
|
|
2
|
+
import { resolveToolbar, type RuntimeProps } from '@expressive-ui/core';
|
|
3
|
+
import type { FabVariant, ToolbarData } from '@expressive-ui/schema';
|
|
4
|
+
import { tokens } from '@expressive-ui/tokens';
|
|
5
|
+
import { Fab } from './Fab.js';
|
|
6
|
+
import { Icon, T, withAlpha } from './primitives.js';
|
|
7
|
+
import { useExpressiveTheme } from './theme.js';
|
|
8
|
+
|
|
9
|
+
export type ToolbarProps = ToolbarData &
|
|
10
|
+
RuntimeProps & {
|
|
11
|
+
/** Item selecionado: fica em pílula e mostra o rótulo, como o Dock do mobile-app-rhosse. */
|
|
12
|
+
value?: string;
|
|
13
|
+
/** Área segura inferior da toolbar docked. */
|
|
14
|
+
bottomInset?: number;
|
|
15
|
+
style?: StyleProp<ViewStyle>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Toolbar do M3 Expressive: floating (o Dock do mobile-app-rhosse, com FAB opcional) ou docked. */
|
|
19
|
+
export function Toolbar({ items, fab, type, color, orientation, value, bottomInset = 0, onAction, index: _, children: __, style }: ToolbarProps) {
|
|
20
|
+
const { colors, mode } = useExpressiveTheme();
|
|
21
|
+
const spec = resolveToolbar({ type, color, orientation });
|
|
22
|
+
const floating = spec.type === 'floating';
|
|
23
|
+
return (
|
|
24
|
+
<View style={[styles.wrap, spec.vertical && styles.wrapVertical, !floating && { alignSelf: 'stretch' }, style]}>
|
|
25
|
+
<View
|
|
26
|
+
accessibilityRole="toolbar"
|
|
27
|
+
style={[
|
|
28
|
+
styles.bar,
|
|
29
|
+
spec.vertical ? { flexDirection: 'column', width: spec.height, paddingVertical: spec.padding } : { height: floating ? spec.height : undefined, paddingHorizontal: spec.padding },
|
|
30
|
+
!floating && { flex: 1, justifyContent: 'space-around', minHeight: spec.height, paddingTop: 8, paddingBottom: Math.max(8, bottomInset) },
|
|
31
|
+
{ gap: spec.gap, borderRadius: spec.radius, backgroundColor: colors[spec.container], boxShadow: tokens.elevation[mode][spec.elevation] },
|
|
32
|
+
]}
|
|
33
|
+
>
|
|
34
|
+
{items.map((item) => {
|
|
35
|
+
const selected = value === item.id;
|
|
36
|
+
return (
|
|
37
|
+
<View key={item.id} style={selected ? { backgroundColor: colors[spec.selected.container], borderRadius: spec.item / 2 } : undefined}>
|
|
38
|
+
<ToolbarItem
|
|
39
|
+
item={item}
|
|
40
|
+
selected={selected}
|
|
41
|
+
vertical={spec.vertical}
|
|
42
|
+
tint={colors[selected ? spec.selected.content : spec.content]}
|
|
43
|
+
layer={colors[spec.content]}
|
|
44
|
+
onPress={() => onAction?.({ id: item.id, label: item.label })}
|
|
45
|
+
/>
|
|
46
|
+
</View>
|
|
47
|
+
);
|
|
48
|
+
})}
|
|
49
|
+
</View>
|
|
50
|
+
{fab && floating ? (
|
|
51
|
+
<Fab action={{ id: fab.id, label: fab.label }} icon={fab.icon} variant={spec.fab.container as FabVariant} onPress={() => onAction?.({ id: fab.id, label: fab.label })} />
|
|
52
|
+
) : null}
|
|
53
|
+
</View>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Item: ícone; selecionado ganha pílula e rótulo (o fundo vem do wrapper); pressionado, cantos menores.
|
|
58
|
+
function ToolbarItem({ item, selected, vertical, tint, layer, onPress }: { item: ToolbarData['items'][number]; selected: boolean; vertical: boolean; tint: string; layer: string; onPress: () => void }) {
|
|
59
|
+
return (
|
|
60
|
+
<Pressable
|
|
61
|
+
accessibilityRole="button"
|
|
62
|
+
accessibilityLabel={item.label}
|
|
63
|
+
accessibilityState={{ selected }}
|
|
64
|
+
onPress={onPress}
|
|
65
|
+
style={({ pressed }) => [
|
|
66
|
+
styles.item,
|
|
67
|
+
selected && !vertical && styles.itemSelected,
|
|
68
|
+
pressed && { borderRadius: tokens.shape.medium, backgroundColor: withAlpha(layer, tokens.state.pressed) },
|
|
69
|
+
]}
|
|
70
|
+
>
|
|
71
|
+
<Icon name={item.icon} tint={tint} filled={selected} />
|
|
72
|
+
{selected && !vertical ? (
|
|
73
|
+
<T variant="labelLarge" emphasized numberOfLines={1} style={{ color: tint }}>
|
|
74
|
+
{item.label}
|
|
75
|
+
</T>
|
|
76
|
+
) : null}
|
|
77
|
+
</Pressable>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const styles = StyleSheet.create({
|
|
82
|
+
wrap: { flexDirection: 'row', alignItems: 'center', gap: 8 },
|
|
83
|
+
wrapVertical: { flexDirection: 'column' },
|
|
84
|
+
bar: { flexDirection: 'row', alignItems: 'center' },
|
|
85
|
+
item: { height: 48, minWidth: 48, paddingHorizontal: 12, borderRadius: 24, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8 },
|
|
86
|
+
itemSelected: { paddingLeft: 12, paddingRight: 16 },
|
|
87
|
+
});
|
|
88
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react';
|
|
2
|
+
import { Animated, Easing, StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
easingCurve,
|
|
5
|
+
resolveScreenTransition,
|
|
6
|
+
type MotionTrack,
|
|
7
|
+
type ScreenTransitionSpec,
|
|
8
|
+
type TransitionDirection,
|
|
9
|
+
type TransitionPattern,
|
|
10
|
+
} from '@expressive-ui/core';
|
|
11
|
+
import { useExpressiveTheme } from './theme.js';
|
|
12
|
+
|
|
13
|
+
/** Retângulo do elemento de origem relativo ao ScreenTransition (ex.: via measureLayout). */
|
|
14
|
+
export type TransitionOrigin = { x: number; y: number; width: number; height: number; radius?: number };
|
|
15
|
+
|
|
16
|
+
export type ScreenTransitionProps = {
|
|
17
|
+
/** Identidade da tela atual: trocar a chave dispara a transição. */
|
|
18
|
+
screenKey: string | number;
|
|
19
|
+
/**
|
|
20
|
+
* Padrão do M3. forwardBackward: avançar/voltar na hierarquia. lateral: telas irmãs (abas).
|
|
21
|
+
* topLevel: destinos da navegação principal. enterExit: tela que surge por cima.
|
|
22
|
+
* containerTransform: o retângulo `origin` cresce até virar a tela.
|
|
23
|
+
*/
|
|
24
|
+
pattern?: TransitionPattern;
|
|
25
|
+
/** forward ao avançar (ou ir para a aba à direita); backward ao voltar. */
|
|
26
|
+
direction?: TransitionDirection;
|
|
27
|
+
/** containerTransform: de onde a tela nasce (e para onde volta). Sem ele vira enterExit. */
|
|
28
|
+
origin?: TransitionOrigin | null;
|
|
29
|
+
style?: StyleProp<ViewStyle>;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type Slot = 'opacity' | 'translateX' | 'scale' | 'reveal' | 'content';
|
|
34
|
+
type Values = Record<Slot, Animated.Value>;
|
|
35
|
+
type Change = { id: number; spec: ScreenTransitionSpec; origin: TransitionOrigin | null; enter: Values; exit: Values };
|
|
36
|
+
type State = { key: string | number; previous: { key: string | number; node: ReactNode } | null; change: Change | null };
|
|
37
|
+
type Size = { width: number; height: number };
|
|
38
|
+
|
|
39
|
+
const slot = (m: MotionTrack): Slot => (m.target === 'content' ? 'content' : m.property);
|
|
40
|
+
|
|
41
|
+
// Cada trilha começa no próprio `from`; o que não anima fica no repouso (visível, no lugar).
|
|
42
|
+
function layerValues(tracks: MotionTrack[]): Values {
|
|
43
|
+
const rest: Record<Slot, number> = { opacity: 1, translateX: 0, scale: 1, reveal: 1, content: 1 };
|
|
44
|
+
for (const m of [...tracks].reverse()) rest[slot(m)] = m.from;
|
|
45
|
+
return Object.fromEntries(Object.entries(rest).map(([k, v]) => [k, new Animated.Value(v)])) as Values;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Troca de telas com os padrões de transição do M3. As telas ficam empilhadas (absoluteFill)
|
|
50
|
+
* durante a troca; a que sai não recebe toques e é desmontada no fim. O container precisa
|
|
51
|
+
* de tamanho (ex.: flex: 1).
|
|
52
|
+
*/
|
|
53
|
+
export function ScreenTransition({ screenKey, pattern = 'forwardBackward', direction = 'forward', origin = null, style, children }: ScreenTransitionProps) {
|
|
54
|
+
const { colors, reduceMotion } = useExpressiveTheme();
|
|
55
|
+
const [size, setSize] = useState<Size>({ width: 0, height: 0 });
|
|
56
|
+
const committed = useRef(children);
|
|
57
|
+
const [state, setState] = useState<State>({ key: screenKey, previous: null, change: null });
|
|
58
|
+
|
|
59
|
+
// chave nova: a tela que estava na tela vira a que sai (estado derivado durante o render)
|
|
60
|
+
let current = state;
|
|
61
|
+
if (screenKey !== state.key) {
|
|
62
|
+
const hasOrigin = !!origin && size.width > 0;
|
|
63
|
+
const spec = resolveScreenTransition(pattern, direction, { width: size.width, hasOrigin, reduceMotion });
|
|
64
|
+
current = {
|
|
65
|
+
key: screenKey,
|
|
66
|
+
previous: { key: state.key, node: committed.current },
|
|
67
|
+
change: { id: (state.change?.id ?? 0) + 1, spec, origin: hasOrigin ? origin : null, enter: layerValues(spec.enter), exit: layerValues(spec.exit) },
|
|
68
|
+
};
|
|
69
|
+
setState(current);
|
|
70
|
+
}
|
|
71
|
+
const { previous, change } = current;
|
|
72
|
+
|
|
73
|
+
useLayoutEffect(() => {
|
|
74
|
+
committed.current = children;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!change) return;
|
|
79
|
+
// left/top/width/height não rodam no driver nativo: com reveal, tudo vai pelo JS
|
|
80
|
+
const useNativeDriver = ![...change.spec.enter, ...change.spec.exit].some((m) => m.property === 'reveal');
|
|
81
|
+
const timings = (tracks: MotionTrack[], values: Values) =>
|
|
82
|
+
tracks.map((m) =>
|
|
83
|
+
Animated.timing(values[slot(m)], {
|
|
84
|
+
toValue: m.to,
|
|
85
|
+
duration: m.duration,
|
|
86
|
+
delay: m.delay,
|
|
87
|
+
easing: Easing.bezier(...easingCurve(m.easing)),
|
|
88
|
+
useNativeDriver,
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
const animation = Animated.parallel([...timings(change.spec.exit, change.exit), ...timings(change.spec.enter, change.enter)]);
|
|
92
|
+
animation.start(({ finished }) => finished && setState((s) => (s.change?.id === change.id ? { ...s, previous: null, change: null } : s)));
|
|
93
|
+
return () => animation.stop();
|
|
94
|
+
}, [change]);
|
|
95
|
+
|
|
96
|
+
const layer = (key: string | number, node: ReactNode, values: Values | null, exiting: boolean) => {
|
|
97
|
+
const o = change?.origin;
|
|
98
|
+
const reveal = values && o && change.spec.pattern === 'containerTransform' ? values.reveal : null;
|
|
99
|
+
const at = (from: number, to: number) => reveal!.interpolate({ inputRange: [0, 1], outputRange: [from, to] });
|
|
100
|
+
const outer: Animated.WithAnimatedValue<ViewStyle> = reveal
|
|
101
|
+
? {
|
|
102
|
+
position: 'absolute',
|
|
103
|
+
left: at(o!.x, 0),
|
|
104
|
+
top: at(o!.y, 0),
|
|
105
|
+
width: at(o!.width, size.width),
|
|
106
|
+
height: at(o!.height, size.height),
|
|
107
|
+
borderRadius: at(o!.radius ?? 0, 0),
|
|
108
|
+
overflow: 'hidden',
|
|
109
|
+
backgroundColor: colors.surface,
|
|
110
|
+
}
|
|
111
|
+
: fill;
|
|
112
|
+
return (
|
|
113
|
+
<Animated.View
|
|
114
|
+
key={key}
|
|
115
|
+
accessibilityElementsHidden={exiting}
|
|
116
|
+
importantForAccessibility={exiting ? 'no-hide-descendants' : 'auto'}
|
|
117
|
+
pointerEvents={exiting ? 'none' : 'auto'}
|
|
118
|
+
style={[
|
|
119
|
+
outer,
|
|
120
|
+
values && { opacity: values.opacity, transform: [{ translateX: values.translateX }, { scale: values.scale }] },
|
|
121
|
+
exiting && change?.spec.exitOnTop ? { zIndex: 1 } : null,
|
|
122
|
+
]}
|
|
123
|
+
>
|
|
124
|
+
<Animated.View
|
|
125
|
+
style={[
|
|
126
|
+
reveal
|
|
127
|
+
? { position: 'absolute', width: size.width, height: size.height, left: at(-o!.x, 0), top: at(-o!.y, 0) }
|
|
128
|
+
: fill,
|
|
129
|
+
values && { opacity: values.content },
|
|
130
|
+
]}
|
|
131
|
+
>
|
|
132
|
+
{node}
|
|
133
|
+
</Animated.View>
|
|
134
|
+
</Animated.View>
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<View
|
|
140
|
+
style={[styles.root, style]}
|
|
141
|
+
onLayout={(e) => {
|
|
142
|
+
const { width, height } = e.nativeEvent.layout;
|
|
143
|
+
if (width !== size.width || height !== size.height) setSize({ width, height });
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
{previous ? layer(previous.key, previous.node, change?.exit ?? null, true) : null}
|
|
147
|
+
{layer(current.key, children, previous ? (change?.enter ?? null) : null, false)}
|
|
148
|
+
</View>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const fill: ViewStyle = { position: 'absolute', top: 0, right: 0, bottom: 0, left: 0 };
|
|
153
|
+
const styles = StyleSheet.create({
|
|
154
|
+
root: { flex: 1, overflow: 'hidden' },
|
|
155
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './theme.js';
|
|
2
|
+
export * from './primitives.js';
|
|
3
|
+
export * from './ExpressiveCard.js';
|
|
4
|
+
export * from './Grid.js';
|
|
5
|
+
export * from './Button.js';
|
|
6
|
+
export * from './Fab.js';
|
|
7
|
+
export * from './Progress.js';
|
|
8
|
+
export * from './List.js';
|
|
9
|
+
export * from './Inputs.js';
|
|
10
|
+
export * from './Navigation.js';
|
|
11
|
+
export * from './Sheets.js';
|
|
12
|
+
export * from './Dialogs.js';
|
|
13
|
+
export * from './Menu.js';
|
|
14
|
+
export * from './Chips.js';
|
|
15
|
+
export * from './Fields.js';
|
|
16
|
+
export * from './Carousel.js';
|
|
17
|
+
export * from './Transition.js';
|
|
18
|
+
export * from './Search.js';
|
|
19
|
+
export * from './Toolbar.js';
|
|
20
|
+
export * from './Pickers.js';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createContext, useContext, useRef } from 'react';
|
|
2
|
+
import { Animated, Text, View, type StyleProp, type TextProps, type TextStyle, type ViewStyle } from 'react-native';
|
|
3
|
+
import Svg, { Path } from 'react-native-svg';
|
|
4
|
+
import { avatarTone, initialOf, shapePath, toneRoles, type ConcreteShape } from '@expressive-ui/core';
|
|
5
|
+
import { tokens, type ColorRole, type TypeScaleToken } from '@expressive-ui/tokens';
|
|
6
|
+
import { useExpressiveTheme } from './theme.js';
|
|
7
|
+
|
|
8
|
+
export function typeStyle(token: TypeScaleToken, emphasized = false): TextStyle {
|
|
9
|
+
const t = tokens.typography.scale[token];
|
|
10
|
+
const group = token.replace(/(Large|Medium|Small)$/, '') as keyof typeof tokens.typography.emphasizedWeight;
|
|
11
|
+
const weight = emphasized ? tokens.typography.emphasizedWeight[group] : t.weight;
|
|
12
|
+
return { fontSize: t.size, lineHeight: t.lineHeight, letterSpacing: t.tracking, fontWeight: String(weight) as TextStyle['fontWeight'] };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function T({
|
|
16
|
+
variant = 'bodyMedium',
|
|
17
|
+
emphasized,
|
|
18
|
+
color = 'onSurface',
|
|
19
|
+
style,
|
|
20
|
+
...props
|
|
21
|
+
}: TextProps & { variant?: TypeScaleToken; emphasized?: boolean; color?: ColorRole }) {
|
|
22
|
+
const { colors } = useExpressiveTheme();
|
|
23
|
+
return <Text {...props} style={[typeStyle(variant, emphasized), { color: colors[color] }, style]} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let warned = false;
|
|
27
|
+
export function Icon({
|
|
28
|
+
name,
|
|
29
|
+
size = 24,
|
|
30
|
+
color = 'onSurface',
|
|
31
|
+
tint,
|
|
32
|
+
filled = false,
|
|
33
|
+
}: {
|
|
34
|
+
name: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
color?: ColorRole;
|
|
37
|
+
/** Cor já resolvida (ex.: com alfa do estado desabilitado); tem prioridade sobre `color`. */
|
|
38
|
+
tint?: string;
|
|
39
|
+
filled?: boolean;
|
|
40
|
+
}) {
|
|
41
|
+
const { colors, renderIcon } = useExpressiveTheme();
|
|
42
|
+
if (renderIcon) return <>{renderIcon(name, { size, color: tint ?? colors[color], filled })}</>;
|
|
43
|
+
if (!warned && __DEV__) {
|
|
44
|
+
warned = true;
|
|
45
|
+
console.warn('[expressive-ui] Passe renderIcon ao ExpressiveThemeProvider para exibir ícones.');
|
|
46
|
+
}
|
|
47
|
+
return <View style={{ width: size, height: size }} />;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function Shape({ shape, size, color, style }: { shape: ConcreteShape; size: number; color: ColorRole; style?: StyleProp<ViewStyle> }) {
|
|
51
|
+
const { colors } = useExpressiveTheme();
|
|
52
|
+
return (
|
|
53
|
+
<View pointerEvents="none" style={[{ width: size, height: size }, style]}>
|
|
54
|
+
<Svg width={size} height={size} viewBox="0 0 100 100">
|
|
55
|
+
<Path d={shapePath(shape)} fill={colors[color]} />
|
|
56
|
+
</Svg>
|
|
57
|
+
</View>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 0 em repouso, 1 com o card pressionado/em hover. Fornecido pelo CardSurface. */
|
|
62
|
+
export const CardEmphasisContext = createContext<Animated.Value | null>(null);
|
|
63
|
+
|
|
64
|
+
/** Ícone sobre forma expressiva; a forma gira 30° quando o card que a contém é pressionado. */
|
|
65
|
+
export function ShapeIcon({
|
|
66
|
+
shape,
|
|
67
|
+
icon,
|
|
68
|
+
size = 44,
|
|
69
|
+
container,
|
|
70
|
+
content,
|
|
71
|
+
}: {
|
|
72
|
+
shape: ConcreteShape;
|
|
73
|
+
icon: string;
|
|
74
|
+
size?: number;
|
|
75
|
+
container: ColorRole;
|
|
76
|
+
content: ColorRole;
|
|
77
|
+
}) {
|
|
78
|
+
const emphasis = useContext(CardEmphasisContext);
|
|
79
|
+
const idle = useRef(new Animated.Value(0)).current;
|
|
80
|
+
const rotate = (emphasis ?? idle).interpolate({ inputRange: [0, 1], outputRange: ['0deg', '30deg'] });
|
|
81
|
+
return (
|
|
82
|
+
<View style={{ width: size, height: size, alignItems: 'center', justifyContent: 'center' }}>
|
|
83
|
+
<Animated.View style={{ position: 'absolute', transform: [{ rotate }] }}>
|
|
84
|
+
<Shape shape={shape} size={size} color={container} />
|
|
85
|
+
</Animated.View>
|
|
86
|
+
<Icon name={icon} size={Math.round(size * 0.5)} color={content} filled />
|
|
87
|
+
</View>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Cor com opacidade (#rrggbb → #rrggbbaa). Outros formatos voltam como estão. */
|
|
92
|
+
export function withAlpha(color: string, opacity: number) {
|
|
93
|
+
if (opacity >= 1) return color;
|
|
94
|
+
const hex = /^#([0-9a-f]{6})$/i.exec(color);
|
|
95
|
+
return hex ? `#${hex[1]}${Math.round(opacity * 255).toString(16).padStart(2, '0')}` : color;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Inicial do nome sobre um tom estável (tone1–4 pelo hash do nome), como no mobile-app-rhosse. */
|
|
99
|
+
export function Avatar({ name, size = 40 }: { name: string; size?: number }) {
|
|
100
|
+
const { colors } = useExpressiveTheme();
|
|
101
|
+
const roles = toneRoles(avatarTone(name));
|
|
102
|
+
return (
|
|
103
|
+
<View
|
|
104
|
+
importantForAccessibility="no"
|
|
105
|
+
style={{ width: size, height: size, borderRadius: size / 2, backgroundColor: colors[roles.container], alignItems: 'center', justifyContent: 'center' }}
|
|
106
|
+
>
|
|
107
|
+
<Text style={{ color: colors[roles.onContainer], fontSize: size * 0.42, fontWeight: '500' }}>{initialOf(name)}</Text>
|
|
108
|
+
</View>
|
|
109
|
+
);
|
|
110
|
+
}
|