@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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/Button.d.ts +48 -0
  4. package/dist/Button.d.ts.map +1 -0
  5. package/dist/Button.js +122 -0
  6. package/dist/Button.js.map +1 -0
  7. package/dist/Carousel.d.ts +13 -0
  8. package/dist/Carousel.d.ts.map +1 -0
  9. package/dist/Carousel.js +52 -0
  10. package/dist/Carousel.js.map +1 -0
  11. package/dist/Chips.d.ts +35 -0
  12. package/dist/Chips.d.ts.map +1 -0
  13. package/dist/Chips.js +138 -0
  14. package/dist/Chips.js.map +1 -0
  15. package/dist/Dialogs.d.ts +42 -0
  16. package/dist/Dialogs.d.ts.map +1 -0
  17. package/dist/Dialogs.js +115 -0
  18. package/dist/Dialogs.js.map +1 -0
  19. package/dist/ExpressiveCard.d.ts +20 -0
  20. package/dist/ExpressiveCard.d.ts.map +1 -0
  21. package/dist/ExpressiveCard.js +71 -0
  22. package/dist/ExpressiveCard.js.map +1 -0
  23. package/dist/Fab.d.ts +16 -0
  24. package/dist/Fab.d.ts.map +1 -0
  25. package/dist/Fab.js +104 -0
  26. package/dist/Fab.js.map +1 -0
  27. package/dist/Fields.d.ts +90 -0
  28. package/dist/Fields.d.ts.map +1 -0
  29. package/dist/Fields.js +211 -0
  30. package/dist/Fields.js.map +1 -0
  31. package/dist/Grid.d.ts +8 -0
  32. package/dist/Grid.d.ts.map +1 -0
  33. package/dist/Grid.js +16 -0
  34. package/dist/Grid.js.map +1 -0
  35. package/dist/Inputs.d.ts +33 -0
  36. package/dist/Inputs.d.ts.map +1 -0
  37. package/dist/Inputs.js +172 -0
  38. package/dist/Inputs.js.map +1 -0
  39. package/dist/List.d.ts +20 -0
  40. package/dist/List.d.ts.map +1 -0
  41. package/dist/List.js +222 -0
  42. package/dist/List.js.map +1 -0
  43. package/dist/Menu.d.ts +26 -0
  44. package/dist/Menu.d.ts.map +1 -0
  45. package/dist/Menu.js +117 -0
  46. package/dist/Menu.js.map +1 -0
  47. package/dist/Navigation.d.ts +34 -0
  48. package/dist/Navigation.d.ts.map +1 -0
  49. package/dist/Navigation.js +80 -0
  50. package/dist/Navigation.js.map +1 -0
  51. package/dist/Pickers.d.ts +16 -0
  52. package/dist/Pickers.d.ts.map +1 -0
  53. package/dist/Pickers.js +100 -0
  54. package/dist/Pickers.js.map +1 -0
  55. package/dist/Progress.d.ts +20 -0
  56. package/dist/Progress.d.ts.map +1 -0
  57. package/dist/Progress.js +93 -0
  58. package/dist/Progress.js.map +1 -0
  59. package/dist/Search.d.ts +50 -0
  60. package/dist/Search.d.ts.map +1 -0
  61. package/dist/Search.js +121 -0
  62. package/dist/Search.js.map +1 -0
  63. package/dist/Sheets.d.ts +44 -0
  64. package/dist/Sheets.d.ts.map +1 -0
  65. package/dist/Sheets.js +128 -0
  66. package/dist/Sheets.js.map +1 -0
  67. package/dist/Toolbar.d.ts +13 -0
  68. package/dist/Toolbar.d.ts.map +1 -0
  69. package/dist/Toolbar.js +38 -0
  70. package/dist/Toolbar.js.map +1 -0
  71. package/dist/Transition.d.ts +34 -0
  72. package/dist/Transition.d.ts.map +1 -0
  73. package/dist/Transition.js +93 -0
  74. package/dist/Transition.js.map +1 -0
  75. package/dist/index.d.ts +21 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +21 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/primitives.d.ts +41 -0
  80. package/dist/primitives.d.ts.map +1 -0
  81. package/dist/primitives.js +55 -0
  82. package/dist/primitives.js.map +1 -0
  83. package/dist/theme.d.ts +57 -0
  84. package/dist/theme.d.ts.map +1 -0
  85. package/dist/theme.js +89 -0
  86. package/dist/theme.js.map +1 -0
  87. package/package.json +53 -4
  88. package/src/Button.tsx +347 -0
  89. package/src/Carousel.tsx +108 -0
  90. package/src/Chips.tsx +292 -0
  91. package/src/Dialogs.tsx +252 -0
  92. package/src/ExpressiveCard.tsx +205 -0
  93. package/src/Fab.tsx +187 -0
  94. package/src/Fields.tsx +556 -0
  95. package/src/Grid.tsx +29 -0
  96. package/src/Inputs.tsx +290 -0
  97. package/src/List.tsx +295 -0
  98. package/src/Menu.tsx +238 -0
  99. package/src/Navigation.tsx +198 -0
  100. package/src/Pickers.tsx +151 -0
  101. package/src/Progress.tsx +192 -0
  102. package/src/Search.tsx +351 -0
  103. package/src/Sheets.tsx +273 -0
  104. package/src/Toolbar.tsx +88 -0
  105. package/src/Transition.tsx +155 -0
  106. package/src/index.ts +20 -0
  107. package/src/primitives.tsx +110 -0
  108. package/src/theme.tsx +125 -0
package/dist/theme.js ADDED
@@ -0,0 +1,89 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { AccessibilityInfo, Animated, Easing, useColorScheme } from 'react-native';
4
+ import { resolveLabels, springConfig, surfaceTiming } from '@expressive-ui/core';
5
+ import { schemes } from '@expressive-ui/tokens';
6
+ const ThemeContext = createContext({
7
+ mode: 'light',
8
+ colors: schemes.light,
9
+ locale: 'pt-BR',
10
+ labels: resolveLabels('pt-BR'),
11
+ reduceMotion: false,
12
+ motion: 'expressive',
13
+ renderIcon: null,
14
+ });
15
+ export const useExpressiveTheme = () => useContext(ThemeContext);
16
+ export function ExpressiveThemeProvider({ mode = 'system', scheme, locale = 'pt-BR', motion = 'expressive', labels, renderIcon, children }) {
17
+ const system = useColorScheme();
18
+ const reduceMotion = useReduceMotion();
19
+ const resolved = mode === 'system' ? (system === 'dark' ? 'dark' : 'light') : mode;
20
+ const value = useMemo(() => ({ mode: resolved, colors: (scheme ?? schemes)[resolved], locale, labels: resolveLabels(locale, labels), reduceMotion, motion, renderIcon: renderIcon ?? null }), [resolved, scheme, locale, labels, reduceMotion, motion, renderIcon]);
21
+ return _jsx(ThemeContext.Provider, { value: value, children: children });
22
+ }
23
+ // Mesmo comportamento do useReduceMotion do mobile-app-rhosse.
24
+ export function useReduceMotion() {
25
+ const [reduce, setReduce] = useState(false);
26
+ useEffect(() => {
27
+ let active = true;
28
+ AccessibilityInfo.isReduceMotionEnabled()
29
+ .then((value) => active && setReduce(value))
30
+ .catch(() => { });
31
+ const sub = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduce);
32
+ return () => {
33
+ active = false;
34
+ sub.remove();
35
+ };
36
+ }, []);
37
+ return reduce;
38
+ }
39
+ /**
40
+ * Valor animado que persegue `target` com a mola do token (driver JS: borderRadius e cores
41
+ * não rodam no driver nativo). Com "reduzir movimento" salta direto para o alvo.
42
+ */
43
+ export function useSpringValue(target, token) {
44
+ const { reduceMotion, motion } = useExpressiveTheme();
45
+ const value = useRef(new Animated.Value(target)).current;
46
+ useEffect(() => {
47
+ const animation = reduceMotion
48
+ ? Animated.timing(value, { toValue: target, duration: 0, useNativeDriver: false })
49
+ : Animated.spring(value, { toValue: target, ...springConfig(token, motion), useNativeDriver: false });
50
+ animation.start();
51
+ return () => animation.stop();
52
+ }, [target, token, reduceMotion, motion, value]);
53
+ return value;
54
+ }
55
+ const exit = surfaceTiming('exit');
56
+ /** Saída de superfície do M3: mais curta que a entrada e acelerando (emphasizedAccelerate). */
57
+ export function exitTiming(value, toValue = 0, useNativeDriver = true) {
58
+ return Animated.timing(value, { toValue, duration: exit.duration, easing: Easing.bezier(...exit.bezier), useNativeDriver });
59
+ }
60
+ /**
61
+ * Presença animada de sobreposições (dialogs, sheets, busca): mantém montado durante a saída.
62
+ * `progress` vai a 1 (aberto) com a mola spatialDefault e volta a 0 com a saída do M3 antes
63
+ * de desmontar; com "reduzir movimento" é instantâneo.
64
+ */
65
+ export function usePresence(open, useNativeDriver = true) {
66
+ const { reduceMotion, motion } = useExpressiveTheme();
67
+ const progress = useRef(new Animated.Value(open ? 1 : 0)).current;
68
+ const opacity = useRef(new Animated.Value(open ? 1 : 0)).current;
69
+ const [mounted, setMounted] = useState(open);
70
+ useEffect(() => {
71
+ if (open)
72
+ setMounted(true);
73
+ const animation = reduceMotion
74
+ ? Animated.timing(progress, { toValue: open ? 1 : 0, duration: 0, useNativeDriver })
75
+ : open
76
+ ? Animated.spring(progress, { toValue: 1, ...springConfig('spatialDefault', motion), useNativeDriver })
77
+ : exitTiming(progress, 0, useNativeDriver);
78
+ const effect = reduceMotion
79
+ ? Animated.timing(opacity, { toValue: open ? 1 : 0, duration: 0, useNativeDriver })
80
+ : open
81
+ ? Animated.spring(opacity, { toValue: 1, ...springConfig('effectsDefault', motion), useNativeDriver })
82
+ : exitTiming(opacity, 0, useNativeDriver);
83
+ const group = Animated.parallel([animation, effect]);
84
+ group.start(({ finished }) => finished && !open && setMounted(false));
85
+ return () => group.stop();
86
+ }, [open, progress, opacity, reduceMotion, motion, useNativeDriver]);
87
+ return { progress, opacity, mounted };
88
+ }
89
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACxG,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAyB,MAAM,qBAAqB,CAAC;AACxG,OAAO,EAAE,OAAO,EAA0F,MAAM,uBAAuB,CAAC;AAcxI,MAAM,YAAY,GAAG,aAAa,CAAkB;IAClD,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,OAAO,CAAC,KAAK;IACrB,MAAM,EAAE,OAAO;IACf,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC;IAC9B,YAAY,EAAE,KAAK;IACnB,MAAM,EAAE,YAAY;IACpB,UAAU,EAAE,IAAI;CACjB,CAAC,CAAC;AACH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0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "homepage": "https://expressive-ui.com",
5
+ "description": "Componentes React Native (Expo) do ExpressiveUI em Material 3 Expressive.",
6
+ "keywords": [
7
+ "material-3",
8
+ "material-you",
9
+ "expressive",
10
+ "design-system",
11
+ "react-native",
12
+ "expo",
13
+ "components",
14
+ "ui"
15
+ ],
16
+ "license": "MIT",
17
+ "author": "Murilo Cunha",
18
+ "type": "module",
19
+ "sideEffects": false,
20
+ "main": "dist/index.js",
21
+ "types": "dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "src"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsc -b"
35
+ },
36
+ "dependencies": {
37
+ "@expressive-ui/core": "0.1.1",
38
+ "@expressive-ui/schema": "0.1.1",
39
+ "@expressive-ui/tokens": "0.1.1"
40
+ },
41
+ "peerDependencies": {
42
+ "react": ">=19",
43
+ "react-native": ">=0.79",
44
+ "react-native-svg": ">=15"
45
+ },
46
+ "devDependencies": {
47
+ "@types/react": "~19.2.0",
48
+ "react": "19.2.3",
49
+ "react-native": "0.86.3",
50
+ "react-native-svg": "15.15.4"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }
package/src/Button.tsx ADDED
@@ -0,0 +1,347 @@
1
+ import { Children, createContext, useContext, useMemo, useState, type ReactNode } from 'react';
2
+ import { Animated, Pressable, StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';
3
+ import {
4
+ ButtonGroupSizeContext,
5
+ buttonGroupGap,
6
+ resolveButton,
7
+ resolveIconButton,
8
+ resolveSegment,
9
+ resolveSplitButton,
10
+ SiblingIndexContext,
11
+ useButtonGroupSize,
12
+ useInteraction,
13
+ useSiblingIndex,
14
+ type ButtonSpec,
15
+ type InteractionState,
16
+ type RuntimeProps,
17
+ } from '@expressive-ui/core';
18
+ import {
19
+ BUTTON_GROUP_DEFAULTS,
20
+ type ButtonData,
21
+ type ButtonGroupData,
22
+ type ButtonSize,
23
+ type IconButtonData,
24
+ type SplitButtonData,
25
+ } from '@expressive-ui/schema';
26
+ import { elevation, tokens } from '@expressive-ui/tokens';
27
+ import { Icon, typeStyle, withAlpha } from './primitives.js';
28
+ import { LoadingIndicator } from './Progress.js';
29
+ import { useExpressiveTheme, useSpringValue } from './theme.js';
30
+
31
+ type ToggleProps = {
32
+ /** Torna o botão um toggle (estado "selected" acessível). undefined = botão comum. */
33
+ selected?: boolean;
34
+ onPress?: () => void;
35
+ style?: StyleProp<ViewStyle>;
36
+ };
37
+
38
+ // Qual filho do ButtonGroup está pressionado. No web isso é :active + :has(); aqui o grupo guarda o índice.
39
+ type GroupPress = { pressed: number | null; setPressed: (index: number | null) => void; count: number };
40
+ const GroupPressContext = createContext<GroupPress | null>(null);
41
+
42
+ /** Cantos por lado (início/fim), para o split button. Sem isso o botão usa o raio uniforme do spec. */
43
+ type Corners = (state: InteractionState) => { start: number; end: number };
44
+
45
+ /** Container, morph de cantos, alargamento no grupo, elevação e camada de estado comuns a todos os botões. */
46
+ function ButtonSurface({
47
+ spec,
48
+ label,
49
+ busy = false,
50
+ onPress,
51
+ corners,
52
+ grouped = true,
53
+ accessibility,
54
+ style,
55
+ children,
56
+ }: {
57
+ spec: ButtonSpec;
58
+ label: string;
59
+ busy?: boolean;
60
+ onPress?: () => void;
61
+ corners?: Corners;
62
+ /** false para as partes do split: o grupo alarga o split como um só item. */
63
+ grouped?: boolean;
64
+ accessibility?: { expanded?: boolean };
65
+ style?: StyleProp<ViewStyle>;
66
+ children: (content: string) => ReactNode;
67
+ }) {
68
+ const { colors, mode } = useExpressiveTheme();
69
+ const { state, handlers } = useInteraction(spec.disabled || busy);
70
+ const group = useContext(GroupPressContext);
71
+ const index = useSiblingIndex();
72
+ const phase = state.pressed ? 'pressed' : state.hovered ? 'hover' : 'rest';
73
+
74
+ const uniform = state.pressed ? spec.radius.pressed : spec.radius.rest;
75
+ const target = corners ? corners(state) : { start: uniform, end: uniform };
76
+ const start = useSpringValue(target.start, 'spatialFast');
77
+ const end = useSpringValue(target.end, 'spatialFast');
78
+ const layer = useSpringValue(phase === 'pressed' ? tokens.state.pressed : phase === 'hover' ? tokens.state.hover : 0, 'effectsDefault');
79
+
80
+ // Pressionado cresce `squish`; cada vizinho encolhe metade, então a linha mantém a largura.
81
+ // Nas pontas só há um vizinho, que cede o valor inteiro.
82
+ const pressedIndex = grouped ? group?.pressed ?? null : null;
83
+ const edge = pressedIndex !== null && group ? pressedIndex === 0 || pressedIndex === group.count - 1 : false;
84
+ const neighbor = Math.abs((pressedIndex ?? -9) - index) === 1;
85
+ const extra = pressedIndex === null ? 0 : pressedIndex === index ? spec.squish : neighbor ? -spec.squish / (edge && group!.count > 1 ? 1 : 2) : 0;
86
+ const width = useSpringValue((spec.width ?? 0) + extra, 'spatialFast');
87
+ const padding = useSpringValue(spec.paddingX + extra / 2, 'spatialFast');
88
+ const pressHandlers = grouped && group
89
+ ? {
90
+ ...handlers,
91
+ onPressIn: () => {
92
+ handlers.onPressIn();
93
+ group.setPressed(index);
94
+ },
95
+ onPressOut: () => {
96
+ handlers.onPressOut();
97
+ group.setPressed(null);
98
+ },
99
+ }
100
+ : handlers;
101
+
102
+ const content = withAlpha(colors[spec.content], spec.contentOpacity);
103
+ const radius = { borderTopLeftRadius: start, borderBottomLeftRadius: start, borderTopRightRadius: end, borderBottomRightRadius: end };
104
+ return (
105
+ <Pressable
106
+ accessibilityRole="button"
107
+ accessibilityLabel={label}
108
+ accessibilityState={{ disabled: spec.disabled, busy, selected: spec.selected ?? undefined, expanded: accessibility?.expanded }}
109
+ disabled={spec.disabled || busy}
110
+ onPress={onPress}
111
+ hitSlop={{ left: spec.hitSlop.x, right: spec.hitSlop.x, top: spec.hitSlop.y, bottom: spec.hitSlop.y }}
112
+ {...pressHandlers}
113
+ >
114
+ {/* Sombra na view externa, recorte dos cantos na interna (como o CardSurface). */}
115
+ <Animated.View style={[{ ...radius, boxShadow: elevation(mode, spec.elevation[phase]) }, style]}>
116
+ <Animated.View
117
+ style={{
118
+ ...radius,
119
+ height: spec.height,
120
+ width: spec.width ? width : undefined,
121
+ paddingHorizontal: spec.width ? 0 : padding,
122
+ gap: spec.gap,
123
+ flexDirection: 'row',
124
+ alignItems: 'center',
125
+ justifyContent: 'center',
126
+ overflow: 'hidden',
127
+ backgroundColor: spec.container ? withAlpha(colors[spec.container], spec.containerOpacity) : 'transparent',
128
+ borderWidth: spec.borderWidth,
129
+ borderColor: spec.border ? withAlpha(colors[spec.border], spec.containerOpacity) : undefined,
130
+ }}
131
+ >
132
+ <Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, { backgroundColor: colors[spec.stateLayer], opacity: layer }]} />
133
+ {children(content)}
134
+ </Animated.View>
135
+ </Animated.View>
136
+ </Pressable>
137
+ );
138
+ }
139
+
140
+ export type ButtonProps = ButtonData &
141
+ RuntimeProps &
142
+ ToggleProps & {
143
+ /** Troca o ícone por um LoadingIndicator e ignora toques, sem esmaecer o botão. */
144
+ loading?: boolean;
145
+ };
146
+
147
+ export function Button({ onPress, onAction, index: _, children: __, selected, loading = false, style, ...data }: ButtonProps) {
148
+ const groupSize = useButtonGroupSize();
149
+ const spec = resolveButton({ ...data, size: data.size ?? groupSize }, { selected });
150
+ const press = onPress ?? (onAction ? () => onAction(data.action) : undefined);
151
+ return (
152
+ <ButtonSurface spec={spec} label={data.action.label} busy={loading} onPress={press} style={style}>
153
+ {(content) => (
154
+ <>
155
+ {loading ? (
156
+ <LoadingIndicator size={spec.iconSize + 4} tint={content} label={data.action.label} />
157
+ ) : data.icon ? (
158
+ <Icon name={data.icon} size={spec.iconSize} tint={content} filled={spec.iconFilled} />
159
+ ) : null}
160
+ <Text numberOfLines={1} style={[typeStyle(spec.type), { color: content }]}>
161
+ {data.action.label}
162
+ </Text>
163
+ </>
164
+ )}
165
+ </ButtonSurface>
166
+ );
167
+ }
168
+
169
+ export type IconButtonProps = IconButtonData & RuntimeProps & ToggleProps;
170
+
171
+ export function IconButton({ onPress, onAction, index: _, children: __, selected, style, ...data }: IconButtonProps) {
172
+ const groupSize = useButtonGroupSize();
173
+ const spec = resolveIconButton({ ...data, size: data.size ?? groupSize }, { selected });
174
+ const press = onPress ?? (onAction ? () => onAction(data.action) : undefined);
175
+ return (
176
+ <ButtonSurface spec={spec} label={data.action.label} onPress={press} style={style}>
177
+ {(content) => <Icon name={data.icon} size={spec.iconSize} tint={content} filled={spec.iconFilled} />}
178
+ </ButtonSurface>
179
+ );
180
+ }
181
+
182
+ const JUSTIFY = { start: 'flex-start', center: 'center', end: 'flex-end', stretch: 'flex-start' } as const;
183
+
184
+ export type ButtonGroupProps = ButtonGroupData & RuntimeProps & { style?: StyleProp<ViewStyle> };
185
+
186
+ /** Button group padrão do M3 Expressive: o pressionado alarga e os vizinhos encolhem. */
187
+ export function ButtonGroup({ size, align = BUTTON_GROUP_DEFAULTS.align, style, children }: ButtonGroupProps) {
188
+ const [pressed, setPressed] = useState<number | null>(null);
189
+ const items = Children.toArray(children);
190
+ const press = useMemo(() => ({ pressed, setPressed, count: items.length }), [pressed, items.length]);
191
+ return (
192
+ <View style={[{ flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: buttonGroupGap(size), justifyContent: JUSTIFY[align] }, style]}>
193
+ <GroupPressContext.Provider value={press}>
194
+ <ButtonGroupSizeContext.Provider value={size}>
195
+ {items.map((child, i) => (
196
+ <SiblingIndexContext.Provider key={i} value={i}>
197
+ {align === 'stretch' ? <View style={{ flexGrow: 1, flexBasis: 0 }}>{child}</View> : child}
198
+ </SiblingIndexContext.Provider>
199
+ ))}
200
+ </ButtonGroupSizeContext.Provider>
201
+ </GroupPressContext.Provider>
202
+ </View>
203
+ );
204
+ }
205
+
206
+ export type SplitButtonProps = SplitButtonData &
207
+ RuntimeProps & {
208
+ onPress?: () => void;
209
+ onMenuPress?: () => void;
210
+ /** Menu aberto: o botão de menu fica circular e a seta gira. */
211
+ menuOpen?: boolean;
212
+ style?: StyleProp<ViewStyle>;
213
+ };
214
+
215
+ export function SplitButton({ onPress, onMenuPress, onAction, index: _, children: __, menuOpen = false, style, ...data }: SplitButtonProps) {
216
+ const groupSize = useButtonGroupSize();
217
+ const spec = resolveSplitButton({ ...data, size: data.size ?? groupSize }, { menuOpen });
218
+ const press = onPress ?? (onAction ? () => onAction(data.action) : undefined);
219
+ const menu = onMenuPress ?? (onAction ? () => onAction(data.menuAction) : undefined);
220
+ const { corners } = spec;
221
+ const inner = (state: InteractionState) => (state.pressed ? corners.innerPressed : state.hovered ? corners.innerHover : corners.inner);
222
+ const turn = useSpringValue(menuOpen ? 1 : 0, 'spatialDefault');
223
+ const rotate = turn.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '180deg'] });
224
+ return (
225
+ <View style={[{ flexDirection: 'row', gap: spec.gap }, style]}>
226
+ <ButtonSurface spec={spec.leading} label={data.action.label} onPress={press} grouped={false} corners={(state) => ({ start: corners.outer, end: inner(state) })}>
227
+ {(content) => (
228
+ <>
229
+ {data.icon ? <Icon name={data.icon} size={spec.leading.iconSize} tint={content} /> : null}
230
+ <Text numberOfLines={1} style={[typeStyle(spec.leading.type), { color: content }]}>
231
+ {data.action.label}
232
+ </Text>
233
+ </>
234
+ )}
235
+ </ButtonSurface>
236
+ <ButtonSurface
237
+ spec={spec.trailing}
238
+ label={data.menuAction.label}
239
+ onPress={menu}
240
+ grouped={false}
241
+ accessibility={{ expanded: menuOpen }}
242
+ corners={(state) => (menuOpen ? { start: corners.open, end: corners.open } : { start: inner(state), end: corners.outer })}
243
+ >
244
+ {(content) => (
245
+ <Animated.View style={{ transform: [{ rotate }] }}>
246
+ <Icon name={spec.menuIcon} size={spec.trailing.iconSize} tint={content} />
247
+ </Animated.View>
248
+ )}
249
+ </ButtonSurface>
250
+ </View>
251
+ );
252
+ }
253
+
254
+ export type ConnectedOption<V extends string> = { value: V; label: string; icon?: string; disabled?: boolean };
255
+
256
+ export type ConnectedButtonGroupProps<V extends string> = {
257
+ options: readonly ConnectedOption<V>[];
258
+ value: V | null;
259
+ onChange?: (value: V) => void;
260
+ label: string;
261
+ size?: Extract<ButtonSize, 'xs' | 'sm' | 'md'>;
262
+ disabled?: boolean;
263
+ style?: StyleProp<ViewStyle>;
264
+ };
265
+
266
+ /** Grupo de botões conectados (escolha única), portado do ConnectedButtonGroup do mobile-app-rhosse. */
267
+ export function ConnectedButtonGroup<V extends string>({ options, value, onChange, label, size = 'sm', disabled, style }: ConnectedButtonGroupProps<V>) {
268
+ return (
269
+ <View accessibilityRole="radiogroup" accessibilityLabel={label} style={[{ flexDirection: 'row', gap: 2, opacity: disabled ? 0.5 : 1 }, style]}>
270
+ {options.map((option, index) => (
271
+ <Segment
272
+ key={option.value}
273
+ option={option}
274
+ size={size}
275
+ selected={option.value === value}
276
+ first={index === 0}
277
+ last={index === options.length - 1}
278
+ disabled={Boolean(disabled || option.disabled)}
279
+ onPress={() => onChange?.(option.value)}
280
+ />
281
+ ))}
282
+ </View>
283
+ );
284
+ }
285
+
286
+ // Ao selecionar, os cantos internos viram pílula; ao pressionar, encolhem. Cor e cantos seguem molas.
287
+ function Segment({
288
+ option,
289
+ size,
290
+ selected,
291
+ first,
292
+ last,
293
+ disabled,
294
+ onPress,
295
+ }: {
296
+ option: ConnectedOption<string>;
297
+ size: ButtonSize;
298
+ selected: boolean;
299
+ first: boolean;
300
+ last: boolean;
301
+ disabled: boolean;
302
+ onPress: () => void;
303
+ }) {
304
+ const { colors } = useExpressiveTheme();
305
+ const seg = resolveSegment(size, selected);
306
+ const { state, handlers } = useInteraction(disabled);
307
+ const inner = selected ? seg.radius.selected : state.pressed ? seg.radius.pressed : seg.radius.inner;
308
+ const start = useSpringValue(first ? seg.radius.outer : inner, 'spatialDefault');
309
+ const end = useSpringValue(last ? seg.radius.outer : inner, 'spatialDefault');
310
+ const on = useSpringValue(selected ? 1 : 0, 'effectsDefault');
311
+ const off = resolveSegment(size, false);
312
+ const background = on.interpolate({ inputRange: [0, 1], outputRange: [colors[off.container], colors[seg.container]] });
313
+ return (
314
+ <Pressable
315
+ accessibilityRole="radio"
316
+ accessibilityLabel={option.label}
317
+ accessibilityState={{ checked: selected, disabled }}
318
+ disabled={disabled}
319
+ onPress={onPress}
320
+ hitSlop={{ top: seg.hitSlop, bottom: seg.hitSlop }}
321
+ style={{ flex: 1 }}
322
+ {...handlers}
323
+ >
324
+ <Animated.View
325
+ style={{
326
+ height: seg.height,
327
+ paddingHorizontal: seg.paddingX,
328
+ gap: seg.gap,
329
+ flexDirection: 'row',
330
+ alignItems: 'center',
331
+ justifyContent: 'center',
332
+ backgroundColor: background,
333
+ borderTopLeftRadius: start,
334
+ borderBottomLeftRadius: start,
335
+ borderTopRightRadius: end,
336
+ borderBottomRightRadius: end,
337
+ opacity: option.disabled ? 0.45 : 1,
338
+ }}
339
+ >
340
+ {selected ? <Icon name="check" size={seg.iconSize} color={seg.content} /> : option.icon ? <Icon name={option.icon} size={seg.iconSize} color={seg.content} /> : null}
341
+ <Text numberOfLines={1} adjustsFontSizeToFit minimumFontScale={0.85} style={[typeStyle(seg.type), { color: colors[seg.content], flexShrink: 1 }]}>
342
+ {option.label}
343
+ </Text>
344
+ </Animated.View>
345
+ </Pressable>
346
+ );
347
+ }
@@ -0,0 +1,108 @@
1
+ import { useMemo, useRef, useState } from 'react';
2
+ import { Animated, Image, Pressable, ScrollView, StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
3
+ import { carouselLayout, carouselMetrics, toneRoles, type CarouselSlot, type RuntimeProps } from '@expressive-ui/core';
4
+ import { CAROUSEL_DEFAULTS, type CarouselData } from '@expressive-ui/schema';
5
+ import { Icon, T } from './primitives.js';
6
+ import { useExpressiveTheme } from './theme.js';
7
+
8
+ export type CarouselProps = CarouselData &
9
+ RuntimeProps & {
10
+ onItemPress?: (id: string) => void;
11
+ style?: StyleProp<ViewStyle>;
12
+ };
13
+
14
+ /**
15
+ * MultiBrowseCarousel do mobile-app-rhosse generalizado: o layout de cada foco vem do core e a
16
+ * rolagem interpola posição e largura de cada item (grande encolhe e sai, o próximo cresce).
17
+ */
18
+ export function Carousel({ items, variant = CAROUSEL_DEFAULTS.variant, height = CAROUSEL_DEFAULTS.height, label, onAction, onItemPress, index: _, children: __, style }: CarouselProps) {
19
+ const { colors } = useExpressiveTheme();
20
+ const [width, setWidth] = useState(0);
21
+ const scrollX = useRef(new Animated.Value(0)).current;
22
+ const count = items.length;
23
+ const m = carouselMetrics(width || 1, count, { variant, height });
24
+
25
+ const animated = useMemo(() => {
26
+ if (!width) return [];
27
+ const layouts = Array.from({ length: count }, (_, focus) => carouselLayout(focus, count, m));
28
+ // interpolate precisa de pelo menos dois pontos.
29
+ const inputRange = count > 1 ? layouts.map((__, focus) => focus * m.step) : [0, 1];
30
+ const series = (pick: (slot: CarouselSlot) => number, i: number) => {
31
+ const values = layouts.map((slots) => pick(slots[i]!));
32
+ return count > 1 ? values : [values[0]!, values[0]!];
33
+ };
34
+ return items.map((__, i) => {
35
+ const at = (pick: (slot: CarouselSlot) => number) => scrollX.interpolate({ inputRange, outputRange: series(pick, i), extrapolate: 'clamp' });
36
+ return {
37
+ width: at((slot) => slot.width),
38
+ left: Animated.add(scrollX, at((slot) => slot.left)),
39
+ shift: at((slot) => (slot.width - m.large) / 2),
40
+ label: at((slot) => (slot.width >= m.medium - 1 ? 1 : 0)),
41
+ focus: at((slot) => (slot.width >= m.large - 1 ? 1 : 0)),
42
+ };
43
+ });
44
+ }, [width, count, variant, height, scrollX]);
45
+
46
+ return (
47
+ <View accessibilityLabel={label} onLayout={(e) => setWidth(e.nativeEvent.layout.width)} style={style}>
48
+ {width ? (
49
+ <ScrollView
50
+ horizontal
51
+ showsHorizontalScrollIndicator={false}
52
+ snapToInterval={m.step}
53
+ decelerationRate="fast"
54
+ disableIntervalMomentum
55
+ scrollEventThrottle={16}
56
+ onScroll={Animated.event([{ nativeEvent: { contentOffset: { x: scrollX } } }], { useNativeDriver: false })}
57
+ contentContainerStyle={{ width: m.scrollWidth, height: m.height }}
58
+ >
59
+ {items.map((item, i) => {
60
+ const a = animated[i];
61
+ if (!a) return null;
62
+ const roles = toneRoles(item.media.tone && item.media.tone !== 'auto' ? item.media.tone : 'primary');
63
+ return (
64
+ <Animated.View
65
+ key={item.id}
66
+ style={{ position: 'absolute', top: 0, height: m.height, left: a.left, width: a.width, borderRadius: m.radius, overflow: 'hidden', backgroundColor: colors[roles.container] }}
67
+ >
68
+ <Pressable
69
+ accessibilityRole="button"
70
+ accessibilityLabel={item.action?.label ?? item.label}
71
+ onPress={() => (onItemPress ? onItemPress(item.id) : item.action && onAction?.(item.action))}
72
+ style={styles.fill}
73
+ >
74
+ {/* Conteúdo com a largura do grande, centralizado: encolher só recorta as bordas. */}
75
+ <Animated.View style={[styles.content, { width: m.large, transform: [{ translateX: a.shift }] }]}>
76
+ {item.media.src ? (
77
+ <Image source={{ uri: item.media.src }} accessibilityLabel={item.media.alt} style={StyleSheet.absoluteFill} resizeMode="cover" />
78
+ ) : item.media.icon ? (
79
+ <Icon name={item.media.icon} size={48} color={roles.onContainer} filled />
80
+ ) : null}
81
+ </Animated.View>
82
+ <Animated.View style={[styles.caption, { opacity: a.label }]}>
83
+ <T variant="titleMedium" emphasized numberOfLines={1} style={{ color: item.media.src ? '#fff' : colors[roles.onContainer] }}>
84
+ {item.label}
85
+ </T>
86
+ {item.supporting ? (
87
+ <Animated.Text numberOfLines={1} style={{ opacity: a.focus, color: item.media.src ? '#fff' : colors[roles.onContainer] }}>
88
+ {item.supporting}
89
+ </Animated.Text>
90
+ ) : null}
91
+ </Animated.View>
92
+ </Pressable>
93
+ </Animated.View>
94
+ );
95
+ })}
96
+ </ScrollView>
97
+ ) : (
98
+ <View style={{ height: m.height }} />
99
+ )}
100
+ </View>
101
+ );
102
+ }
103
+
104
+ const styles = StyleSheet.create({
105
+ fill: { flex: 1 },
106
+ content: { position: 'absolute', top: 0, bottom: 0, left: 0, alignItems: 'center', justifyContent: 'center' },
107
+ caption: { position: 'absolute', left: 16, right: 16, bottom: 14 },
108
+ });