@marktiderman/genesis-ui-native 3.6.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +48 -1
  2. package/dist/{chunk-NDXNSSM6.js → chunk-DHONOH6K.js} +24 -211
  3. package/dist/chunk-DHONOH6K.js.map +1 -0
  4. package/dist/{chunk-6PGLX6ET.js → chunk-FGIIBON3.js} +334 -24
  5. package/dist/chunk-FGIIBON3.js.map +1 -0
  6. package/dist/{chunk-ZRQAFFTN.js → chunk-FOJJB6AB.js} +2 -2
  7. package/dist/{chunk-ZRQAFFTN.js.map → chunk-FOJJB6AB.js.map} +1 -1
  8. package/dist/{chunk-SEJ6RBP7.js → chunk-JZ7RAGDQ.js} +117 -60
  9. package/dist/chunk-JZ7RAGDQ.js.map +1 -0
  10. package/dist/chunk-PWS2HLDE.js +137 -0
  11. package/dist/chunk-PWS2HLDE.js.map +1 -0
  12. package/dist/{chunk-AGTBABAH.js → chunk-PWYMRUAK.js} +43 -30
  13. package/dist/chunk-PWYMRUAK.js.map +1 -0
  14. package/dist/{chunk-FUMSL7VZ.js → chunk-T7FEVT62.js} +53 -12
  15. package/dist/chunk-T7FEVT62.js.map +1 -0
  16. package/dist/{chunk-2Z72MYHB.js → chunk-UZCJDMGE.js} +353 -19
  17. package/dist/chunk-UZCJDMGE.js.map +1 -0
  18. package/dist/components/index.d.ts +275 -24
  19. package/dist/components/index.js +5 -5
  20. package/dist/data/index.d.ts +2 -1
  21. package/dist/data/index.js +7 -12
  22. package/dist/data/index.js.map +1 -1
  23. package/dist/hooks/index.d.ts +36 -3
  24. package/dist/hooks/index.js +2 -2
  25. package/dist/icons/lucide.d.ts +1 -1
  26. package/dist/icons/lucide.js +13 -3
  27. package/dist/icons/lucide.js.map +1 -1
  28. package/dist/{inbox-page-B7_Oi2fS.d.ts → inbox-page-BGqR_cBs.d.ts} +4 -1
  29. package/dist/index.d.ts +4 -4
  30. package/dist/index.js +8 -8
  31. package/dist/layouts/index.d.ts +12 -3
  32. package/dist/layouts/index.js +5 -5
  33. package/dist/{native-modules-Cl3zw3kh.d.ts → native-modules-CeAaO2Dh.d.ts} +55 -3
  34. package/package.json +73 -2
  35. package/src/__tests__/doctor-rules.test.ts +27 -0
  36. package/src/__tests__/native-modules-lists.test.tsx +1 -0
  37. package/src/components/__tests__/bulk-bar.test.tsx +36 -0
  38. package/src/components/__tests__/button-haptic.test.tsx +74 -0
  39. package/src/components/__tests__/composer-bar.test.tsx +140 -1
  40. package/src/components/__tests__/gallery-grid.test.tsx +2 -2
  41. package/src/components/__tests__/library-round-5.test.tsx +121 -0
  42. package/src/components/__tests__/share-sheet.test.tsx +47 -0
  43. package/src/components/__tests__/swipe-row-context-menu.test.tsx +215 -0
  44. package/src/components/__tests__/tab-bar.test.tsx +43 -0
  45. package/src/components/__tests__/thread-list.test.tsx +200 -0
  46. package/src/components/__tests__/tier-badge.test.tsx +57 -0
  47. package/src/components/__tests__/whats-new-sheet.test.tsx +29 -0
  48. package/src/components/bulk-bar.tsx +91 -0
  49. package/src/components/button.tsx +81 -25
  50. package/src/components/choice-card.tsx +104 -0
  51. package/src/components/composer-bar.tsx +104 -25
  52. package/src/components/context-menu.tsx +101 -0
  53. package/src/components/gallery-grid.tsx +10 -4
  54. package/src/components/index.ts +19 -2
  55. package/src/components/inline-alert.tsx +36 -1
  56. package/src/components/input.tsx +3 -0
  57. package/src/components/progress.tsx +24 -2
  58. package/src/components/rating.tsx +35 -16
  59. package/src/components/share-sheet.tsx +127 -0
  60. package/src/components/sheet.tsx +9 -1
  61. package/src/components/swipe-row.tsx +74 -0
  62. package/src/components/tab-bar.tsx +133 -0
  63. package/src/components/tabs.tsx +2 -0
  64. package/src/components/text.tsx +3 -0
  65. package/src/components/textarea.tsx +3 -0
  66. package/src/components/thread-list.tsx +78 -23
  67. package/src/components/tier-badge.tsx +74 -0
  68. package/src/components/whats-new-sheet.tsx +89 -0
  69. package/src/data/resource-view/NativeRecordView.tsx +3 -8
  70. package/src/data/resource-view/use-native-resource-view.ts +2 -2
  71. package/src/hooks/__tests__/use-haptics.test.tsx +146 -0
  72. package/src/hooks/index.ts +3 -1
  73. package/src/hooks/use-haptics.ts +64 -0
  74. package/src/hooks/use-press-feedback.ts +87 -0
  75. package/src/hooks/use-theme-roles.ts +3 -0
  76. package/src/icon-names.ts +12 -2
  77. package/src/icons/lucide.ts +27 -7
  78. package/src/layouts/__tests__/inbox-page.test.tsx +26 -7
  79. package/src/layouts/__tests__/thread-page.test.tsx +89 -2
  80. package/src/layouts/inbox-page.tsx +28 -12
  81. package/src/layouts/thread-page.tsx +69 -8
  82. package/src/native-modules.tsx +20 -0
  83. package/dist/chunk-2Z72MYHB.js.map +0 -1
  84. package/dist/chunk-4OQOJ2OC.js +0 -80
  85. package/dist/chunk-4OQOJ2OC.js.map +0 -1
  86. package/dist/chunk-6PGLX6ET.js.map +0 -1
  87. package/dist/chunk-AGTBABAH.js.map +0 -1
  88. package/dist/chunk-FUMSL7VZ.js.map +0 -1
  89. package/dist/chunk-NDXNSSM6.js.map +0 -1
  90. package/dist/chunk-SEJ6RBP7.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { useState } from "react";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { describe, expect, it } from "vitest";
4
+ import { Text } from "react-native";
5
+ import { NativeTabBar, type NativeTabBarItem } from "../tab-bar";
6
+
7
+ const items = (n: number): NativeTabBarItem[] =>
8
+ Array.from({ length: n }, (_, i) => ({ key: `t${i + 1}`, label: `Tab ${i + 1}`, icon: <Text>*</Text> }));
9
+
10
+ function Bar({ n, max }: { n: number; max?: number }) {
11
+ const [value, setValue] = useState("t1");
12
+ return (
13
+ <>
14
+ <Text testID="current">{value}</Text>
15
+ <NativeTabBar items={items(n)} value={value} onChange={setValue} {...(max ? { max } : {})} />
16
+ </>
17
+ );
18
+ }
19
+
20
+ describe("NativeTabBar", () => {
21
+ it("shows up to five tabs and switches between them", () => {
22
+ render(<Bar n={5} />);
23
+ expect(screen.queryByTestId("native-tab-bar-more")).toBeNull();
24
+ fireEvent.click(screen.getByTestId("native-tab-bar-t3"));
25
+ expect(screen.getByTestId("current").textContent).toBe("t3");
26
+ expect(screen.getByTestId("native-tab-bar-t3").getAttribute("aria-selected")).toBe("true");
27
+ });
28
+
29
+ it("past five, the fifth slot is More and its sheet holds the rest", async () => {
30
+ render(<Bar n={7} />);
31
+ expect(screen.queryByTestId("native-tab-bar-t5")).toBeNull();
32
+ fireEvent.click(screen.getByTestId("native-tab-bar-more"));
33
+ fireEvent.click(await screen.findByTestId("native-tab-bar-t7"));
34
+ expect(screen.getByTestId("current").textContent).toBe("t7");
35
+ });
36
+
37
+ it("honours max", () => {
38
+ render(<Bar n={4} max={3} />);
39
+ expect(screen.getByTestId("native-tab-bar-t2")).toBeTruthy();
40
+ expect(screen.queryByTestId("native-tab-bar-t3")).toBeNull();
41
+ expect(screen.getByTestId("native-tab-bar-more")).toBeTruthy();
42
+ });
43
+ });
@@ -124,6 +124,206 @@ describe("NativeThreadList", () => {
124
124
  expect(announce).toHaveBeenCalledWith("second");
125
125
  });
126
126
 
127
+ it("goes to a row by its jumpId when that isn't its key, and highlights it", async () => {
128
+ const { List, calls } = recordingList();
129
+ type Sent = { key: string; serverId: string | null; text: string };
130
+ const sent: Sent[] = [
131
+ { key: "c:1", serverId: "m1", text: "first" },
132
+ { key: "c:2", serverId: "m2", text: "second" },
133
+ { key: "d:3", serverId: null, text: "Today" },
134
+ ];
135
+ render(
136
+ <GenesisModulesProvider modules={{ list: List as never }}>
137
+ <NativeThreadList<Sent>
138
+ testID="l"
139
+ data={sent}
140
+ keyExtractor={(r) => r.key}
141
+ jumpId={(r) => r.serverId}
142
+ renderItem={(r, { highlighted }) => <span data-testid={`row-${r.key}`} data-highlighted={String(highlighted)}>{r.text}</span>}
143
+ jumpTo="m2"
144
+ />
145
+ </GenesisModulesProvider>,
146
+ );
147
+ await waitFor(() => expect(calls.scrollToIndex).toHaveBeenCalledWith(expect.objectContaining({ index: 1 })));
148
+ await waitFor(() => expect(screen.getByTestId("row-c:2").getAttribute("data-highlighted")).toBe("true"));
149
+ expect(screen.getByTestId("row-c:1").getAttribute("data-highlighted")).toBe("false");
150
+ });
151
+
152
+ it("doesn't take its own scroll to a row for coming back to the bottom (which would follow the bottom again and leave the row)", async () => {
153
+ const { List, calls } = recordingList();
154
+ const onAtBottomChange = vi.fn();
155
+ render(
156
+ <GenesisModulesProvider modules={{ list: List as never }}>
157
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="a" onAtBottomChange={onAtBottomChange} />
158
+ </GenesisModulesProvider>,
159
+ );
160
+ await waitFor(() => expect(calls.scrollToIndex).toHaveBeenCalled());
161
+ expect(onAtBottomChange).toHaveBeenLastCalledWith(false);
162
+ // The jump's scroll starts where the list was, at the bottom: its first events say so.
163
+ const scroll = calls.props.at(-1)!.onScroll as (e: unknown) => void;
164
+ act(() => scroll({ nativeEvent: { contentOffset: { y: 1500 }, contentSize: { height: 2000 }, layoutMeasurement: { height: 500 } } }));
165
+ expect(onAtBottomChange).not.toHaveBeenCalledWith(true);
166
+ });
167
+
168
+ it("counts the reader's own drag straight away, even while the list is settling from a jump", async () => {
169
+ const { List, calls } = recordingList();
170
+ const onAtBottomChange = vi.fn();
171
+ render(
172
+ <GenesisModulesProvider modules={{ list: List as never }}>
173
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="c" onAtBottomChange={onAtBottomChange} />
174
+ </GenesisModulesProvider>,
175
+ );
176
+ await waitFor(() => expect(calls.scrollToIndex).toHaveBeenCalled());
177
+ const props = calls.props.at(-1)!;
178
+ const scroll = props.onScroll as (e: unknown) => void;
179
+ // Inside the settling window: the list's own movement is ignored...
180
+ act(() => scroll({ nativeEvent: { contentOffset: { y: 1500 }, contentSize: { height: 2000 }, layoutMeasurement: { height: 500 } } }));
181
+ expect(onAtBottomChange).not.toHaveBeenCalledWith(true);
182
+ // ...but a reader who takes hold and reaches the bottom counts at once.
183
+ act(() => (props.onScrollBeginDrag as () => void)());
184
+ act(() => scroll({ nativeEvent: { contentOffset: { y: 1500 }, contentSize: { height: 2000 }, layoutMeasurement: { height: 500 } } }));
185
+ expect(onAtBottomChange).toHaveBeenLastCalledWith(true);
186
+ act(() => scroll({ nativeEvent: { contentOffset: { y: 0 }, contentSize: { height: 2000 }, layoutMeasurement: { height: 500 } } }));
187
+ expect(onAtBottomChange).toHaveBeenLastCalledWith(false);
188
+ });
189
+
190
+ describe("the reader's touch during a jump", () => {
191
+ afterEach(() => vi.useRealTimers());
192
+ const tick = async (ms: number) => act(async () => void (await vi.advanceTimersByTimeAsync(ms)));
193
+
194
+ it("a drag cancels the queued try, so nothing snaps back", async () => {
195
+ vi.useFakeTimers();
196
+ const { List, calls } = recordingList();
197
+ render(
198
+ <GenesisModulesProvider modules={{ list: List as never }}>
199
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="a" />
200
+ </GenesisModulesProvider>,
201
+ );
202
+ await tick(20);
203
+ expect(calls.scrollToIndex).toHaveBeenCalledTimes(1);
204
+ act(() => (calls.props.at(-1)!.onScrollBeginDrag as () => void)());
205
+ await tick(1000);
206
+ expect(calls.scrollToIndex).toHaveBeenCalledTimes(1);
207
+ });
208
+
209
+ it("doesn't take onMomentumScrollBegin for the reader: Android may report the list's own smooth scroll", async () => {
210
+ vi.useFakeTimers();
211
+ const { List, calls } = recordingList();
212
+ render(
213
+ <GenesisModulesProvider modules={{ list: List as never }}>
214
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="a" />
215
+ </GenesisModulesProvider>,
216
+ );
217
+ await tick(20);
218
+ expect(calls.props.at(-1)!.onMomentumScrollBegin).toBeUndefined();
219
+ });
220
+
221
+ it("a drag while a jump is still loading drops it: the row arriving doesn't move the list, and earlier pages load again", async () => {
222
+ vi.useFakeTimers();
223
+ const { List, calls } = recordingList();
224
+ const onLoadEarlier = vi.fn();
225
+ const onJumpFailed = vi.fn();
226
+ let resolve: (v: boolean) => void = () => undefined;
227
+ const onLoadUntil = vi.fn(() => new Promise<boolean>((r) => (resolve = r)));
228
+ const props = { testID: "l", keyExtractor: (r: Row) => r.id, renderItem: renderRow, jumpTo: "old", hasEarlier: true, onLoadEarlier, onLoadUntil, onJumpFailed };
229
+ const { rerender } = render(
230
+ <GenesisModulesProvider modules={{ list: List as never }}>
231
+ <NativeThreadList {...props} data={rows} />
232
+ </GenesisModulesProvider>,
233
+ );
234
+ await tick(20);
235
+ expect(onLoadUntil).toHaveBeenCalledWith("old");
236
+ // Waiting on the load: near the top doesn't load more.
237
+ (calls.props.at(-1)!.onStartReached as () => void)();
238
+ expect(onLoadEarlier).not.toHaveBeenCalled();
239
+ act(() => (calls.props.at(-1)!.onScrollBeginDrag as () => void)());
240
+ (calls.props.at(-1)!.onStartReached as () => void)();
241
+ expect(onLoadEarlier).toHaveBeenCalledTimes(1);
242
+ await act(async () => resolve(true));
243
+ rerender(
244
+ <GenesisModulesProvider modules={{ list: List as never }}>
245
+ <NativeThreadList {...props} data={[{ id: "old", text: "old" }, ...rows]} />
246
+ </GenesisModulesProvider>,
247
+ );
248
+ await tick(1000);
249
+ expect(calls.scrollToIndex).not.toHaveBeenCalled();
250
+ expect(onJumpFailed).not.toHaveBeenCalled();
251
+ });
252
+
253
+ it("cancels the retries of a row FlatList hadn't measured", async () => {
254
+ vi.useFakeTimers();
255
+ const { List, calls } = recordingList();
256
+ render(
257
+ <GenesisModulesProvider modules={{ list: List as never }}>
258
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="a" />
259
+ </GenesisModulesProvider>,
260
+ );
261
+ await tick(20);
262
+ const props = calls.props.at(-1)!;
263
+ const failed = props.onScrollToIndexFailed as (i: { index: number; averageItemLength: number }) => void;
264
+ act(() => failed({ index: 0, averageItemLength: 50 }));
265
+ expect(calls.scrollToOffset).toHaveBeenCalledTimes(1);
266
+ act(() => (props.onScrollBeginDrag as () => void)());
267
+ const before = calls.scrollToIndex.mock.calls.length;
268
+ await tick(1000);
269
+ expect(calls.scrollToIndex).toHaveBeenCalledTimes(before);
270
+ // Too late to help: a failure reported after the touch doesn't move the list either.
271
+ act(() => failed({ index: 0, averageItemLength: 50 }));
272
+ expect(calls.scrollToOffset).toHaveBeenCalledTimes(1);
273
+ });
274
+
275
+ it("cancels the second try at the newest row", async () => {
276
+ vi.useFakeTimers();
277
+ const { List, calls } = recordingList();
278
+ const ref = createRef<NativeThreadListHandle>();
279
+ render(
280
+ <GenesisModulesProvider modules={{ list: List as never }}>
281
+ <NativeThreadList ref={ref} testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} />
282
+ </GenesisModulesProvider>,
283
+ );
284
+ act(() => ref.current!.scrollToEnd({ animated: true }));
285
+ await tick(20);
286
+ expect(calls.scrollToEnd).toHaveBeenCalledTimes(1);
287
+ act(() => (calls.props.at(-1)!.onScrollBeginDrag as () => void)());
288
+ await tick(500);
289
+ expect(calls.scrollToEnd).toHaveBeenCalledTimes(1);
290
+ });
291
+ });
292
+
293
+ describe("following after a jump in a short thread", () => {
294
+ afterEach(() => vi.useRealTimers());
295
+
296
+ it("comes back on when the list never reported a scroll (nothing moved)", async () => {
297
+ vi.useFakeTimers();
298
+ const { List } = recordingList();
299
+ const onAtBottomChange = vi.fn();
300
+ render(
301
+ <GenesisModulesProvider modules={{ list: List as never }}>
302
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="b" onAtBottomChange={onAtBottomChange} />
303
+ </GenesisModulesProvider>,
304
+ );
305
+ await act(async () => void (await vi.advanceTimersByTimeAsync(20)));
306
+ expect(onAtBottomChange).toHaveBeenLastCalledWith(false);
307
+ await act(async () => void (await vi.advanceTimersByTimeAsync(1000)));
308
+ expect(onAtBottomChange).toHaveBeenLastCalledWith(true);
309
+ });
310
+
311
+ it("stays off when the jump left the reader up the thread", async () => {
312
+ vi.useFakeTimers();
313
+ const { List, calls } = recordingList();
314
+ const onAtBottomChange = vi.fn();
315
+ render(
316
+ <GenesisModulesProvider modules={{ list: List as never }}>
317
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="a" onAtBottomChange={onAtBottomChange} />
318
+ </GenesisModulesProvider>,
319
+ );
320
+ await act(async () => void (await vi.advanceTimersByTimeAsync(20)));
321
+ act(() => (calls.props.at(-1)!.onScroll as (e: unknown) => void)({ nativeEvent: { contentOffset: { y: 100 }, contentSize: { height: 2000 }, layoutMeasurement: { height: 500 } } }));
322
+ await act(async () => void (await vi.advanceTimersByTimeAsync(1000)));
323
+ expect(onAtBottomChange).not.toHaveBeenCalledWith(true);
324
+ });
325
+ });
326
+
127
327
  it("loads until a row it doesn't hold, and says when it can't be found", async () => {
128
328
  const { List } = recordingList();
129
329
  const onLoadUntil = vi.fn(async () => false);
@@ -0,0 +1,57 @@
1
+ // @feat:native-components
2
+ /**
3
+ * NativeTierBadge and NativeButton's gradient variant read the brand from the
4
+ * nearest GenesisThemeProvider (`accents`, `gradients.primary`) and fall back
5
+ * to the Genesis roles without one.
6
+ */
7
+ import { render, screen } from "@testing-library/react";
8
+ import { describe, expect, it } from "vitest";
9
+ import { GenesisThemeProvider, genesisBrand, type CanonicalBrand } from "@marktiderman/genesis-design-system";
10
+ import { NativeTierBadge } from "../tier-badge";
11
+ import { NativeButton, buttonVariants, buttonTextVariants } from "../button";
12
+
13
+ const acme: CanonicalBrand = {
14
+ ...genesisBrand,
15
+ name: "acme",
16
+ accents: { gold: "#d4a017" },
17
+ gradients: { primary: { from: "#0f766e", to: "#2563eb" } },
18
+ };
19
+
20
+ const styleOf = (el: HTMLElement) => JSON.parse(el.dataset.style ?? "null") as Record<string, unknown> | null;
21
+
22
+ describe("NativeTierBadge", () => {
23
+ it("takes its tone from the brand's accents", () => {
24
+ render(
25
+ <GenesisThemeProvider brand={acme} mode="light">
26
+ <NativeTierBadge testID="t" label="Gold" tone="gold" />
27
+ </GenesisThemeProvider>,
28
+ );
29
+ const badge = screen.getByTestId("t");
30
+ expect(badge.getAttribute("aria-label")).toBe("Gold");
31
+ expect(styleOf(badge)).toEqual({ borderColor: "#d4a017", backgroundColor: "#d4a01726" });
32
+ });
33
+
34
+ it("is the secondary chip without a provider or a matching accent", () => {
35
+ render(<NativeTierBadge testID="t2" label="Silver" tone="silver" />);
36
+ expect(styleOf(screen.getByTestId("t2"))).toBeNull();
37
+ expect(screen.getByText("Silver")).toBeTruthy();
38
+ });
39
+ });
40
+
41
+ describe("NativeButton variant=gradient", () => {
42
+ it("sits on the primary, so a brand without a gradient gets the default look", () => {
43
+ expect(buttonVariants({ variant: "gradient" })).toContain("bg-primary");
44
+ expect(buttonTextVariants({ variant: "gradient" })).toContain("text-primary-foreground");
45
+ });
46
+
47
+ it("paints the brand's gradient inside a provider, and nothing extra outside one", () => {
48
+ render(
49
+ <GenesisThemeProvider brand={acme} mode="light">
50
+ <NativeButton testID="g" variant="gradient">Start</NativeButton>
51
+ </GenesisThemeProvider>,
52
+ );
53
+ render(<NativeButton testID="plain" variant="gradient">Start</NativeButton>);
54
+ expect(styleOf(screen.getByTestId("g"))).toEqual({ experimental_backgroundImage: "linear-gradient(135deg, #0f766e, #2563eb)" });
55
+ expect(styleOf(screen.getByTestId("plain"))).toBeNull();
56
+ });
57
+ });
@@ -0,0 +1,29 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { NativeWhatsNewSheet } from "../whats-new-sheet";
4
+
5
+ describe("NativeWhatsNewSheet", () => {
6
+ it("lists the notes and closes with Got it", async () => {
7
+ const dismiss = vi.fn();
8
+ render(<NativeWhatsNewSheet notes={[{ key: "1.2.0", title: "Faster sync", body: "Lists load sooner." }]} dismiss={dismiss} />);
9
+ expect(await screen.findByText("What's new")).toBeTruthy();
10
+ expect(screen.getByTestId("native-whats-new-1.2.0").textContent).toContain("Lists load sooner.");
11
+ fireEvent.click(screen.getByTestId("native-whats-new-done"));
12
+ expect(dismiss).toHaveBeenCalled();
13
+ });
14
+
15
+ it("Learn more closes, then opens the note", async () => {
16
+ const calls: string[] = [];
17
+ render(
18
+ <NativeWhatsNewSheet
19
+ notes={[{ key: "n1", title: "Boards", url: "/boards" }, { key: "n2", title: "No link" }]}
20
+ dismiss={() => calls.push("dismiss")}
21
+ onOpenNote={(note) => calls.push(`open ${note.url}`)}
22
+ learnMoreLabel="More"
23
+ />,
24
+ );
25
+ fireEvent.click(await screen.findByTestId("native-whats-new-open-n1"));
26
+ expect(screen.queryByTestId("native-whats-new-open-n2")).toBeNull();
27
+ expect(calls).toEqual(["dismiss", "open /boards"]);
28
+ });
29
+ });
@@ -0,0 +1,91 @@
1
+ /**
2
+ * BulkBar — the selection action bar: how many are selected, select all, the bulk actions,
3
+ * and Clear. The twin of genesis-ui's `DataBulkBar`, with the same props; it renders nothing
4
+ * while nothing is selected. On the phone it sits at the bottom of the screen, above the tab
5
+ * bar: render it after the list, inside the screen (not over the tab bar).
6
+ *
7
+ * @stability Beta
8
+ */
9
+ import { ScrollView, Text, View } from "react-native";
10
+ import type { NativeIconName } from "../icon-names";
11
+ import { cn } from "../utils";
12
+ import { NativeButton, buttonTextVariants } from "./button";
13
+ import { NativeCheckbox } from "./checkbox";
14
+ import { NativeIcon } from "./icon";
15
+
16
+ /** One button in the bar. */
17
+ export interface NativeBulkAction {
18
+ label: string;
19
+ /** A NativeIcon name (the web's `BulkAction` takes a lucide icon). */
20
+ icon: NativeIconName;
21
+ onClick: () => void;
22
+ variant?: "default" | "destructive" | "outline" | "secondary" | "ghost";
23
+ /** Inert while, say, a bulk mutation is in flight. */
24
+ disabled?: boolean;
25
+ /** `testID` on the button (the web's `testId`). */
26
+ testId?: string;
27
+ }
28
+
29
+ export interface NativeBulkBarProps {
30
+ selected: Set<string>;
31
+ totalCount: number;
32
+ onToggleAll: () => void;
33
+ onClearSelection: () => void;
34
+ actions: NativeBulkAction[];
35
+ /** "{count} selected". Default English. */
36
+ selectedLabel?: (count: number) => string;
37
+ /** Default "Clear". */
38
+ clearLabel?: string;
39
+ /** Merged onto the bar. */
40
+ className?: string;
41
+ testID?: string;
42
+ }
43
+
44
+ export function NativeBulkBar({
45
+ selected,
46
+ totalCount,
47
+ onToggleAll,
48
+ onClearSelection,
49
+ actions,
50
+ selectedLabel = (count) => `${count} selected`,
51
+ clearLabel = "Clear",
52
+ className,
53
+ testID = "native-bulk-bar",
54
+ }: NativeBulkBarProps) {
55
+ if (selected.size === 0) return null;
56
+ const all = selected.size === totalCount;
57
+ return (
58
+ <View
59
+ testID={testID}
60
+ accessibilityRole="toolbar"
61
+ className={cn("mx-3 mb-2 flex-row items-center gap-2 rounded-xl border border-border bg-card px-3 py-2 shadow-md", className)}
62
+ >
63
+ <NativeCheckbox checked={all} onCheckedChange={() => onToggleAll()} testID={`${testID}-all`} />
64
+ <Text className="text-sm font-medium text-foreground" accessibilityLiveRegion="polite">
65
+ {selectedLabel(selected.size)}
66
+ </Text>
67
+ <ScrollView horizontal showsHorizontalScrollIndicator={false} className="flex-1" contentContainerClassName="gap-2 px-1">
68
+ {actions.map((action) => {
69
+ const variant = action.variant ?? "outline";
70
+ return (
71
+ <NativeButton
72
+ key={action.label}
73
+ size="sm"
74
+ variant={variant}
75
+ onPress={action.onClick}
76
+ disabled={action.disabled}
77
+ testID={action.testId}
78
+ accessibilityLabel={action.label}
79
+ >
80
+ <NativeIcon name={action.icon} size={16} />
81
+ <Text className={buttonTextVariants({ variant, size: "sm" })}>{action.label}</Text>
82
+ </NativeButton>
83
+ );
84
+ })}
85
+ </ScrollView>
86
+ <NativeButton size="sm" variant="ghost" onPress={onClearSelection} testID={`${testID}-clear`}>
87
+ {clearLabel}
88
+ </NativeButton>
89
+ </View>
90
+ );
91
+ }
@@ -1,10 +1,19 @@
1
1
  /**
2
- * Button — primary touch target. Variants: default, secondary, outline, ghost, destructive.
2
+ * Button — primary touch target. Variants: default, secondary, outline, ghost, destructive,
3
+ * gradient (the brand's `gradients.primary` from the nearest `GenesisThemeProvider`, else the
4
+ * primary).
5
+ * It answers a touch with `usePressFeedback`: what's inside shrinks a little while held (or dims
6
+ * under Reduce Motion), the same as every Genesis pressable. The background stays still. Layout
7
+ * classes in `className` (`justify-start`, `gap-3`, `flex-col`) apply to what's inside.
3
8
  *
4
9
  * @stability Stable
5
10
  */
6
11
  import { type VariantProps, cva } from "class-variance-authority";
7
- import { ActivityIndicator, Pressable, Text, type AccessibilityState } from "react-native";
12
+ import type { ComponentRef, Ref } from "react";
13
+ import { ActivityIndicator, Animated, Pressable, Text, View, type AccessibilityState, type StyleProp, type ViewStyle } from "react-native";
14
+ import { brandGradientCss, useOptionalTheme } from "@marktiderman/genesis-design-system";
15
+ import type { HapticKind } from "../hooks/use-haptics";
16
+ import { usePressFeedback } from "../hooks/use-press-feedback";
8
17
  import { cn } from "../utils";
9
18
 
10
19
  const buttonVariants = cva(
@@ -17,6 +26,7 @@ const buttonVariants = cva(
17
26
  outline: "border border-input bg-transparent",
18
27
  ghost: "bg-transparent",
19
28
  destructive: "bg-destructive",
29
+ gradient: "bg-primary",
20
30
  },
21
31
  size: {
22
32
  sm: "h-9 px-3 gap-1.5",
@@ -39,6 +49,7 @@ const buttonTextVariants = cva("font-medium text-center", {
39
49
  outline: "text-foreground",
40
50
  ghost: "text-foreground",
41
51
  destructive: "text-destructive-foreground",
52
+ gradient: "text-primary-foreground",
42
53
  },
43
54
  size: {
44
55
  sm: "text-sm",
@@ -52,6 +63,19 @@ const buttonTextVariants = cva("font-medium text-center", {
52
63
  },
53
64
  });
54
65
 
66
+ /** How what's inside is laid out: the same gap per size as the button's own. */
67
+ const contentVariants = cva("flex-row items-center justify-center", {
68
+ variants: { size: { sm: "gap-1.5", md: "gap-2", lg: "gap-2" } },
69
+ defaultVariants: { size: "md" },
70
+ });
71
+
72
+ /** A caller's classes that lay out the button's content, which now sits a level inside it. */
73
+ const contentClasses = (className: string | undefined) =>
74
+ className
75
+ ?.split(/\s+/)
76
+ .filter((c) => /^(flex-(row|col)|justify-|items-|gap-)/.test(c))
77
+ .join(" ");
78
+
55
79
  export interface NativeButtonProps
56
80
  extends VariantProps<typeof buttonVariants> {
57
81
  className?: string;
@@ -66,6 +90,15 @@ export interface NativeButtonProps
66
90
  accessibilityHint?: string;
67
91
  /** Merged with the button's own `disabled` and `busy`: `{ selected: true }` for a vote cast, a filter on. */
68
92
  accessibilityState?: AccessibilityState;
93
+ /**
94
+ * A haptic through `GenesisModules.haptics` (`light` for a vote, `success` for a save): it plays
95
+ * when the press counts, except `select`, which ticks on press-in as `usePressFeedback` does. Default none.
96
+ */
97
+ haptic?: HapticKind | undefined;
98
+ /** Styles for the pressable, after the classes: colors or sizes from a theme object. */
99
+ style?: StyleProp<ViewStyle> | undefined;
100
+ /** The pressable (React 19 passes `ref` as a prop). */
101
+ ref?: Ref<ComponentRef<typeof View>> | undefined;
69
102
  }
70
103
 
71
104
  function NativeButton({
@@ -78,9 +111,23 @@ function NativeButton({
78
111
  disabled,
79
112
  loading,
80
113
  accessibilityState,
114
+ haptic,
115
+ style,
81
116
  ...props
82
117
  }: NativeButtonProps) {
83
118
  const isDisabled = disabled || loading;
119
+ const theme = useOptionalTheme();
120
+ // React Native 0.80+ paints a CSS gradient as `experimental_backgroundImage`; older versions
121
+ // ignore it and the `bg-primary` underneath shows.
122
+ const gradient = variant === "gradient" && theme ? brandGradientCss(theme.brand) : undefined;
123
+ const gradientStyle = gradient ? ({ experimental_backgroundImage: gradient } as ViewStyle) : undefined;
124
+ const feedback = usePressFeedback({ haptic: onPress ? (haptic ?? false) : false, disabled: Boolean(isDisabled) });
125
+ const press = onPress
126
+ ? () => {
127
+ feedback.confirm();
128
+ onPress();
129
+ }
130
+ : undefined;
84
131
 
85
132
  return (
86
133
  <Pressable
@@ -89,34 +136,43 @@ function NativeButton({
89
136
  isDisabled && "opacity-50",
90
137
  className
91
138
  )}
92
- onPress={onPress}
139
+ onPress={press}
140
+ onPressIn={feedback.onPressIn}
141
+ onPressOut={feedback.onPressOut}
93
142
  disabled={isDisabled}
94
143
  accessibilityRole="button"
95
- accessibilityState={{ ...accessibilityState, disabled: isDisabled, busy: loading }}
144
+ accessibilityState={{ ...accessibilityState, disabled: isDisabled, busy: loading ?? accessibilityState?.busy }}
96
145
  {...props}
146
+ // The brand gradient under the caller's own style, not replaced by it.
147
+ style={gradientStyle ? (style ? [gradientStyle, style] : gradientStyle) : style}
97
148
  >
98
- {loading ? (
99
- <ActivityIndicator
100
- size="small"
101
- color={
102
- variant === "outline" || variant === "ghost"
103
- ? undefined
104
- : "white"
105
- }
106
- />
107
- ) : null}
108
- {typeof children === "string" ? (
109
- <Text
110
- className={cn(
111
- buttonTextVariants({ variant, size }),
112
- textClassName
149
+ {/* Inside the Pressable, which keeps the button's size and classes: a wrapper would lose a `flex-1`. */}
150
+ <Animated.View style={[{ flexGrow: 1 }, feedback.style]}>
151
+ <View className={cn(contentVariants({ size }), contentClasses(className))}>
152
+ {loading ? (
153
+ <ActivityIndicator
154
+ size="small"
155
+ color={
156
+ variant === "outline" || variant === "ghost"
157
+ ? undefined
158
+ : "white"
159
+ }
160
+ />
161
+ ) : null}
162
+ {typeof children === "string" ? (
163
+ <Text
164
+ className={cn(
165
+ buttonTextVariants({ variant, size }),
166
+ textClassName
167
+ )}
168
+ >
169
+ {children}
170
+ </Text>
171
+ ) : (
172
+ children
113
173
  )}
114
- >
115
- {children}
116
- </Text>
117
- ) : (
118
- children
119
- )}
174
+ </View>
175
+ </Animated.View>
120
176
  </Pressable>
121
177
  );
122
178
  }