@marktiderman/genesis-ui-native 3.7.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/{chunk-KH2RVAI5.js → chunk-DHONOH6K.js} +24 -210
- package/dist/chunk-DHONOH6K.js.map +1 -0
- package/dist/{chunk-O4BMDV7I.js → chunk-FGIIBON3.js} +333 -21
- package/dist/chunk-FGIIBON3.js.map +1 -0
- package/dist/{chunk-YWDDDYDI.js → chunk-FOJJB6AB.js} +2 -2
- package/dist/{chunk-YWDDDYDI.js.map → chunk-FOJJB6AB.js.map} +1 -1
- package/dist/{chunk-IXC3LO2K.js → chunk-JZ7RAGDQ.js} +44 -36
- package/dist/chunk-JZ7RAGDQ.js.map +1 -0
- package/dist/{chunk-RTYO24SC.js → chunk-PWS2HLDE.js} +63 -31
- package/dist/chunk-PWS2HLDE.js.map +1 -0
- package/dist/{chunk-3KFUS7O6.js → chunk-PWYMRUAK.js} +43 -30
- package/dist/chunk-PWYMRUAK.js.map +1 -0
- package/dist/{chunk-GBNIBHSU.js → chunk-T7FEVT62.js} +53 -12
- package/dist/chunk-T7FEVT62.js.map +1 -0
- package/dist/{chunk-7NDKIIOT.js → chunk-UZCJDMGE.js} +353 -19
- package/dist/chunk-UZCJDMGE.js.map +1 -0
- package/dist/components/index.d.ts +229 -23
- package/dist/components/index.js +5 -6
- package/dist/data/index.d.ts +2 -1
- package/dist/data/index.js +7 -12
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +7 -3
- package/dist/hooks/index.js +2 -3
- package/dist/icons/lucide.d.ts +1 -1
- package/dist/icons/lucide.js +13 -3
- package/dist/icons/lucide.js.map +1 -1
- package/dist/{inbox-page-B7_Oi2fS.d.ts → inbox-page-BGqR_cBs.d.ts} +4 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +8 -9
- package/dist/layouts/index.d.ts +12 -3
- package/dist/layouts/index.js +5 -6
- package/dist/{native-modules-DEJJQhDx.d.ts → native-modules-CeAaO2Dh.d.ts} +26 -2
- package/package.json +51 -3
- package/src/__tests__/native-modules-lists.test.tsx +1 -0
- package/src/components/__tests__/bulk-bar.test.tsx +36 -0
- package/src/components/__tests__/button-haptic.test.tsx +22 -0
- package/src/components/__tests__/composer-bar.test.tsx +116 -1
- package/src/components/__tests__/gallery-grid.test.tsx +2 -2
- package/src/components/__tests__/library-round-5.test.tsx +121 -0
- package/src/components/__tests__/share-sheet.test.tsx +47 -0
- package/src/components/__tests__/swipe-row-context-menu.test.tsx +215 -0
- package/src/components/__tests__/tab-bar.test.tsx +43 -0
- package/src/components/__tests__/thread-list.test.tsx +137 -0
- package/src/components/__tests__/tier-badge.test.tsx +57 -0
- package/src/components/__tests__/whats-new-sheet.test.tsx +29 -0
- package/src/components/bulk-bar.tsx +91 -0
- package/src/components/button.tsx +74 -35
- package/src/components/choice-card.tsx +104 -0
- package/src/components/composer-bar.tsx +20 -19
- package/src/components/context-menu.tsx +101 -0
- package/src/components/gallery-grid.tsx +10 -4
- package/src/components/index.ts +18 -1
- package/src/components/inline-alert.tsx +36 -1
- package/src/components/input.tsx +3 -0
- package/src/components/progress.tsx +24 -2
- package/src/components/rating.tsx +35 -16
- package/src/components/share-sheet.tsx +127 -0
- package/src/components/sheet.tsx +9 -1
- package/src/components/swipe-row.tsx +74 -0
- package/src/components/tab-bar.tsx +133 -0
- package/src/components/tabs.tsx +2 -0
- package/src/components/text.tsx +3 -0
- package/src/components/textarea.tsx +3 -0
- package/src/components/thread-list.tsx +48 -23
- package/src/components/tier-badge.tsx +74 -0
- package/src/components/whats-new-sheet.tsx +89 -0
- package/src/data/resource-view/NativeRecordView.tsx +3 -8
- package/src/data/resource-view/use-native-resource-view.ts +2 -2
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-theme-roles.ts +3 -0
- package/src/icon-names.ts +12 -2
- package/src/icons/lucide.ts +27 -7
- package/src/layouts/__tests__/inbox-page.test.tsx +26 -7
- package/src/layouts/__tests__/thread-page.test.tsx +89 -2
- package/src/layouts/inbox-page.tsx +28 -12
- package/src/layouts/thread-page.tsx +69 -8
- package/src/native-modules.tsx +16 -0
- package/dist/chunk-3KFUS7O6.js.map +0 -1
- package/dist/chunk-7NDKIIOT.js.map +0 -1
- package/dist/chunk-CAI7LGN6.js +0 -39
- package/dist/chunk-CAI7LGN6.js.map +0 -1
- package/dist/chunk-GBNIBHSU.js.map +0 -1
- package/dist/chunk-IXC3LO2K.js.map +0 -1
- package/dist/chunk-KH2RVAI5.js.map +0 -1
- package/dist/chunk-O4BMDV7I.js.map +0 -1
- package/dist/chunk-RTYO24SC.js.map +0 -1
|
@@ -187,6 +187,143 @@ describe("NativeThreadList", () => {
|
|
|
187
187
|
expect(onAtBottomChange).toHaveBeenLastCalledWith(false);
|
|
188
188
|
});
|
|
189
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
|
+
|
|
190
327
|
it("loads until a row it doesn't hold, and says when it can't be found", async () => {
|
|
191
328
|
const { List } = recordingList();
|
|
192
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,11 +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 {
|
|
8
|
-
import {
|
|
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";
|
|
9
17
|
import { cn } from "../utils";
|
|
10
18
|
|
|
11
19
|
const buttonVariants = cva(
|
|
@@ -18,6 +26,7 @@ const buttonVariants = cva(
|
|
|
18
26
|
outline: "border border-input bg-transparent",
|
|
19
27
|
ghost: "bg-transparent",
|
|
20
28
|
destructive: "bg-destructive",
|
|
29
|
+
gradient: "bg-primary",
|
|
21
30
|
},
|
|
22
31
|
size: {
|
|
23
32
|
sm: "h-9 px-3 gap-1.5",
|
|
@@ -40,6 +49,7 @@ const buttonTextVariants = cva("font-medium text-center", {
|
|
|
40
49
|
outline: "text-foreground",
|
|
41
50
|
ghost: "text-foreground",
|
|
42
51
|
destructive: "text-destructive-foreground",
|
|
52
|
+
gradient: "text-primary-foreground",
|
|
43
53
|
},
|
|
44
54
|
size: {
|
|
45
55
|
sm: "text-sm",
|
|
@@ -53,6 +63,19 @@ const buttonTextVariants = cva("font-medium text-center", {
|
|
|
53
63
|
},
|
|
54
64
|
});
|
|
55
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
|
+
|
|
56
79
|
export interface NativeButtonProps
|
|
57
80
|
extends VariantProps<typeof buttonVariants> {
|
|
58
81
|
className?: string;
|
|
@@ -72,6 +95,10 @@ export interface NativeButtonProps
|
|
|
72
95
|
* when the press counts, except `select`, which ticks on press-in as `usePressFeedback` does. Default none.
|
|
73
96
|
*/
|
|
74
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;
|
|
75
102
|
}
|
|
76
103
|
|
|
77
104
|
function NativeButton({
|
|
@@ -85,18 +112,22 @@ function NativeButton({
|
|
|
85
112
|
loading,
|
|
86
113
|
accessibilityState,
|
|
87
114
|
haptic,
|
|
115
|
+
style,
|
|
88
116
|
...props
|
|
89
117
|
}: NativeButtonProps) {
|
|
90
118
|
const isDisabled = disabled || loading;
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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;
|
|
100
131
|
|
|
101
132
|
return (
|
|
102
133
|
<Pressable
|
|
@@ -106,34 +137,42 @@ function NativeButton({
|
|
|
106
137
|
className
|
|
107
138
|
)}
|
|
108
139
|
onPress={press}
|
|
109
|
-
onPressIn={
|
|
140
|
+
onPressIn={feedback.onPressIn}
|
|
141
|
+
onPressOut={feedback.onPressOut}
|
|
110
142
|
disabled={isDisabled}
|
|
111
143
|
accessibilityRole="button"
|
|
112
|
-
accessibilityState={{ ...accessibilityState, disabled: isDisabled, busy: loading }}
|
|
144
|
+
accessibilityState={{ ...accessibilityState, disabled: isDisabled, busy: loading ?? accessibilityState?.busy }}
|
|
113
145
|
{...props}
|
|
146
|
+
// The brand gradient under the caller's own style, not replaced by it.
|
|
147
|
+
style={gradientStyle ? (style ? [gradientStyle, style] : gradientStyle) : style}
|
|
114
148
|
>
|
|
115
|
-
{
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
|
130
173
|
)}
|
|
131
|
-
>
|
|
132
|
-
|
|
133
|
-
</Text>
|
|
134
|
-
) : (
|
|
135
|
-
children
|
|
136
|
-
)}
|
|
174
|
+
</View>
|
|
175
|
+
</Animated.View>
|
|
137
176
|
</Pressable>
|
|
138
177
|
);
|
|
139
178
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeChoiceCard — one selectable option drawn as a card: an indicator
|
|
3
|
+
* (a radio circle, or a checkbox square with `multiple`), an optional
|
|
4
|
+
* `media` slot (a thumbnail, an icon), a title and a description.
|
|
5
|
+
*
|
|
6
|
+
* The whole card is the press target (at least 44pt high) and reads as one
|
|
7
|
+
* radio or checkbox to VoiceOver and TalkBack, named "title, description".
|
|
8
|
+
* Selected, the border and indicator take the primary colour and the card a
|
|
9
|
+
* light primary wash; `invalid` draws the border in the destructive colour
|
|
10
|
+
* (and says "Needs an answer"). Controlled: the parent owns `selected`.
|
|
11
|
+
*
|
|
12
|
+
* Use a column of them for a question with pictures or explanations per
|
|
13
|
+
* option; for a plain list of words use NativeRadioGroup or NativeChipGroup.
|
|
14
|
+
*
|
|
15
|
+
* @stability Beta
|
|
16
|
+
*/
|
|
17
|
+
import { Pressable, Text, View } from "react-native";
|
|
18
|
+
import { cn } from "../utils";
|
|
19
|
+
|
|
20
|
+
export interface NativeChoiceCardProps {
|
|
21
|
+
title: string;
|
|
22
|
+
/** A second line under the title, muted. */
|
|
23
|
+
description?: string;
|
|
24
|
+
/** Slot left of the text: a thumbnail (NativeImage), an icon. */
|
|
25
|
+
media?: React.ReactNode;
|
|
26
|
+
selected: boolean;
|
|
27
|
+
onPress: () => void;
|
|
28
|
+
/** A checkbox (several can be chosen) rather than a radio. */
|
|
29
|
+
multiple?: boolean;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** The question still needs an answer: a destructive border and hint. */
|
|
32
|
+
invalid?: boolean;
|
|
33
|
+
/** Extra accessibility hint, such as "Option 2 of 4". */
|
|
34
|
+
hint?: string;
|
|
35
|
+
className?: string;
|
|
36
|
+
testID?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function Indicator({ on, multiple, testID }: { on: boolean; multiple: boolean; testID?: string | undefined }) {
|
|
40
|
+
return (
|
|
41
|
+
<View
|
|
42
|
+
testID={testID}
|
|
43
|
+
className={cn(
|
|
44
|
+
"h-5 w-5 items-center justify-center border",
|
|
45
|
+
multiple ? "rounded" : "rounded-full",
|
|
46
|
+
on ? "border-primary" : "border-input",
|
|
47
|
+
on && multiple && "bg-primary",
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
{on ? (
|
|
51
|
+
multiple ? (
|
|
52
|
+
<Text className="text-xs font-bold text-primary-foreground">✓</Text>
|
|
53
|
+
) : (
|
|
54
|
+
<View className="h-2.5 w-2.5 rounded-full bg-primary" />
|
|
55
|
+
)
|
|
56
|
+
) : null}
|
|
57
|
+
</View>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function NativeChoiceCard({
|
|
62
|
+
title,
|
|
63
|
+
description,
|
|
64
|
+
media,
|
|
65
|
+
selected,
|
|
66
|
+
onPress,
|
|
67
|
+
multiple = false,
|
|
68
|
+
disabled = false,
|
|
69
|
+
invalid = false,
|
|
70
|
+
hint,
|
|
71
|
+
className,
|
|
72
|
+
testID = "native-choice-card",
|
|
73
|
+
}: NativeChoiceCardProps) {
|
|
74
|
+
const name = description ? `${title}, ${description}` : title;
|
|
75
|
+
const accessibilityHint = [hint, invalid ? "Needs an answer" : ""].filter(Boolean).join(". ") || undefined;
|
|
76
|
+
return (
|
|
77
|
+
<Pressable
|
|
78
|
+
testID={testID}
|
|
79
|
+
onPress={onPress}
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
accessibilityRole={multiple ? "checkbox" : "radio"}
|
|
82
|
+
accessibilityLabel={name}
|
|
83
|
+
accessibilityHint={accessibilityHint}
|
|
84
|
+
accessibilityState={{ checked: selected, selected, disabled }}
|
|
85
|
+
className={cn(
|
|
86
|
+
"min-h-[44px] flex-row items-center gap-3 rounded-lg border bg-card p-3",
|
|
87
|
+
selected ? "border-primary bg-primary/5" : invalid ? "border-destructive" : "border-border",
|
|
88
|
+
disabled && "opacity-50",
|
|
89
|
+
className,
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
<Indicator on={selected} multiple={multiple} testID={`${testID}-indicator`} />
|
|
93
|
+
{media ? (
|
|
94
|
+
<View testID={`${testID}-media`} accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
|
|
95
|
+
{media}
|
|
96
|
+
</View>
|
|
97
|
+
) : null}
|
|
98
|
+
<View className="flex-1">
|
|
99
|
+
<Text className="text-base text-foreground">{title}</Text>
|
|
100
|
+
{description ? <Text className="mt-0.5 text-sm text-muted-foreground">{description}</Text> : null}
|
|
101
|
+
</View>
|
|
102
|
+
</Pressable>
|
|
103
|
+
);
|
|
104
|
+
}
|