@multiplatform.one/components 7.65.0 → 7.65.2

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 (154) hide show
  1. package/dist/cjs/Alert/index.cjs +26 -5
  2. package/dist/cjs/Alert/index.native.js +26 -5
  3. package/dist/cjs/Alert/index.native.js.map +1 -1
  4. package/dist/cjs/images/Image/framing.cjs +29 -0
  5. package/dist/cjs/images/Image/framing.native.js +32 -0
  6. package/dist/cjs/images/Image/framing.native.js.map +1 -0
  7. package/dist/cjs/images/Image/shared.cjs +2 -2
  8. package/dist/cjs/images/Image/shared.native.js +2 -2
  9. package/dist/cjs/images/Image/shared.native.js.map +1 -1
  10. package/dist/cjs/views/Dashboard.cjs +16 -131
  11. package/dist/cjs/views/Dashboard.native.js +16 -131
  12. package/dist/cjs/views/Dashboard.native.js.map +1 -1
  13. package/dist/cjs/views/List.cjs +14 -189
  14. package/dist/cjs/views/List.native.js +14 -193
  15. package/dist/cjs/views/List.native.js.map +1 -1
  16. package/dist/cjs/views/ListGroup.cjs +181 -0
  17. package/dist/cjs/views/ListGroup.native.js +194 -0
  18. package/dist/cjs/views/ListGroup.native.js.map +1 -0
  19. package/dist/cjs/views/ListRow.cjs +266 -0
  20. package/dist/cjs/views/ListRow.native.js +274 -0
  21. package/dist/cjs/views/ListRow.native.js.map +1 -0
  22. package/dist/cjs/views/ShortcutCard.cjs +100 -0
  23. package/dist/cjs/views/ShortcutCard.native.js +104 -0
  24. package/dist/cjs/views/ShortcutCard.native.js.map +1 -0
  25. package/dist/cjs/views/index.cjs +3 -0
  26. package/dist/cjs/views/index.native.js +3 -0
  27. package/dist/cjs/views/index.native.js.map +1 -1
  28. package/dist/cjs/views/widgetChrome.cjs +93 -0
  29. package/dist/cjs/views/widgetChrome.native.js +95 -0
  30. package/dist/cjs/views/widgetChrome.native.js.map +1 -0
  31. package/dist/esm/Alert/index.mjs +27 -6
  32. package/dist/esm/Alert/index.mjs.map +1 -1
  33. package/dist/esm/Alert/index.native.js +27 -6
  34. package/dist/esm/Alert/index.native.js.map +1 -1
  35. package/dist/esm/images/Image/framing.mjs +4 -0
  36. package/dist/esm/images/Image/framing.mjs.map +1 -0
  37. package/dist/esm/images/Image/framing.native.js +4 -0
  38. package/dist/esm/images/Image/framing.native.js.map +1 -0
  39. package/dist/esm/images/Image/shared.mjs +2 -2
  40. package/dist/esm/images/Image/shared.mjs.map +1 -1
  41. package/dist/esm/images/Image/shared.native.js +2 -2
  42. package/dist/esm/images/Image/shared.native.js.map +1 -1
  43. package/dist/esm/views/Dashboard.mjs +6 -121
  44. package/dist/esm/views/Dashboard.mjs.map +1 -1
  45. package/dist/esm/views/Dashboard.native.js +6 -121
  46. package/dist/esm/views/Dashboard.native.js.map +1 -1
  47. package/dist/esm/views/List.mjs +8 -186
  48. package/dist/esm/views/List.mjs.map +1 -1
  49. package/dist/esm/views/List.native.js +8 -190
  50. package/dist/esm/views/List.native.js.map +1 -1
  51. package/dist/esm/views/ListGroup.mjs +144 -0
  52. package/dist/esm/views/ListGroup.mjs.map +1 -0
  53. package/dist/esm/views/ListGroup.native.js +154 -0
  54. package/dist/esm/views/ListGroup.native.js.map +1 -0
  55. package/dist/esm/views/ListRow.mjs +234 -0
  56. package/dist/esm/views/ListRow.mjs.map +1 -0
  57. package/dist/esm/views/ListRow.native.js +239 -0
  58. package/dist/esm/views/ListRow.native.js.map +1 -0
  59. package/dist/esm/views/ShortcutCard.mjs +75 -0
  60. package/dist/esm/views/ShortcutCard.mjs.map +1 -0
  61. package/dist/esm/views/ShortcutCard.native.js +76 -0
  62. package/dist/esm/views/ShortcutCard.native.js.map +1 -0
  63. package/dist/esm/views/index.mjs +2 -2
  64. package/dist/esm/views/index.mjs.map +1 -1
  65. package/dist/esm/views/index.native.js +2 -2
  66. package/dist/esm/views/index.native.js.map +1 -1
  67. package/dist/esm/views/widgetChrome.mjs +66 -0
  68. package/dist/esm/views/widgetChrome.mjs.map +1 -0
  69. package/dist/esm/views/widgetChrome.native.js +65 -0
  70. package/dist/esm/views/widgetChrome.native.js.map +1 -0
  71. package/dist/jsx/Alert/index.mjs +27 -6
  72. package/dist/jsx/Alert/index.mjs.map +1 -1
  73. package/dist/jsx/Alert/index.native.js +26 -5
  74. package/dist/jsx/Alert/index.native.js.map +1 -1
  75. package/dist/jsx/feedback/NotifyHost.native.js +1 -1
  76. package/dist/jsx/formLayouts/PreferencePanel.native.js +1 -1
  77. package/dist/jsx/images/Image/framing.mjs +4 -0
  78. package/dist/jsx/images/Image/framing.mjs.map +1 -0
  79. package/dist/jsx/images/Image/framing.native.js +32 -0
  80. package/dist/jsx/images/Image/framing.native.js.map +1 -0
  81. package/dist/jsx/images/Image/shared.mjs +2 -2
  82. package/dist/jsx/images/Image/shared.mjs.map +1 -1
  83. package/dist/jsx/images/Image/shared.native.js +2 -2
  84. package/dist/jsx/images/Image/shared.native.js.map +1 -1
  85. package/dist/jsx/index.native.js +1 -1
  86. package/dist/jsx/layouts/AsyncBoundary.native.js +1 -1
  87. package/dist/jsx/layouts/AsyncBoundary.native.js.map +1 -1
  88. package/dist/jsx/views/Dashboard.mjs +6 -121
  89. package/dist/jsx/views/Dashboard.mjs.map +1 -1
  90. package/dist/jsx/views/Dashboard.native.js +16 -131
  91. package/dist/jsx/views/Dashboard.native.js.map +1 -1
  92. package/dist/jsx/views/List.mjs +8 -186
  93. package/dist/jsx/views/List.mjs.map +1 -1
  94. package/dist/jsx/views/List.native.js +14 -193
  95. package/dist/jsx/views/List.native.js.map +1 -1
  96. package/dist/jsx/views/ListGroup.mjs +144 -0
  97. package/dist/jsx/views/ListGroup.mjs.map +1 -0
  98. package/dist/jsx/views/ListGroup.native.js +194 -0
  99. package/dist/jsx/views/ListGroup.native.js.map +1 -0
  100. package/dist/jsx/views/ListRow.mjs +234 -0
  101. package/dist/jsx/views/ListRow.mjs.map +1 -0
  102. package/dist/jsx/views/ListRow.native.js +274 -0
  103. package/dist/jsx/views/ListRow.native.js.map +1 -0
  104. package/dist/jsx/views/ShortcutCard.mjs +75 -0
  105. package/dist/jsx/views/ShortcutCard.mjs.map +1 -0
  106. package/dist/jsx/views/ShortcutCard.native.js +104 -0
  107. package/dist/jsx/views/ShortcutCard.native.js.map +1 -0
  108. package/dist/jsx/views/index.mjs +2 -2
  109. package/dist/jsx/views/index.mjs.map +1 -1
  110. package/dist/jsx/views/index.native.js +3 -0
  111. package/dist/jsx/views/index.native.js.map +1 -1
  112. package/dist/jsx/views/widgetChrome.mjs +66 -0
  113. package/dist/jsx/views/widgetChrome.mjs.map +1 -0
  114. package/dist/jsx/views/widgetChrome.native.js +95 -0
  115. package/dist/jsx/views/widgetChrome.native.js.map +1 -0
  116. package/package.json +9 -9
  117. package/src/Alert/Alert.spec.tsx +79 -0
  118. package/src/Alert/Alert.stories.tsx +32 -1
  119. package/src/Alert/index.tsx +54 -5
  120. package/src/images/Image/framing.ts +8 -0
  121. package/src/images/Image/shared.ts +2 -7
  122. package/src/overlayElevation.spec.tsx +3 -1
  123. package/src/views/Dashboard.tsx +5 -146
  124. package/src/views/Kanban.native.spec.tsx +2 -2
  125. package/src/views/List.tsx +22 -237
  126. package/src/views/ListGroup.spec.tsx +220 -0
  127. package/src/views/ListGroup.stories.tsx +83 -0
  128. package/src/views/ListGroup.tsx +189 -0
  129. package/src/views/ListRow.tsx +282 -0
  130. package/src/views/ShortcutCard.spec.tsx +40 -0
  131. package/src/views/ShortcutCard.stories.tsx +50 -1
  132. package/src/views/ShortcutCard.tsx +88 -0
  133. package/src/views/index.ts +6 -0
  134. package/src/views/widgetChrome.tsx +73 -0
  135. package/types/Alert/index.d.ts +9 -0
  136. package/types/Alert/index.d.ts.map +1 -1
  137. package/types/images/Image/framing.d.ts +7 -0
  138. package/types/images/Image/framing.d.ts.map +1 -0
  139. package/types/images/Image/shared.d.ts +1 -6
  140. package/types/images/Image/shared.d.ts.map +1 -1
  141. package/types/views/Dashboard.d.ts +2 -15
  142. package/types/views/Dashboard.d.ts.map +1 -1
  143. package/types/views/List.d.ts +3 -66
  144. package/types/views/List.d.ts.map +1 -1
  145. package/types/views/ListGroup.d.ts +43 -0
  146. package/types/views/ListGroup.d.ts.map +1 -0
  147. package/types/views/ListRow.d.ts +88 -0
  148. package/types/views/ListRow.d.ts.map +1 -0
  149. package/types/views/ShortcutCard.d.ts +26 -0
  150. package/types/views/ShortcutCard.d.ts.map +1 -0
  151. package/types/views/index.d.ts +1 -1
  152. package/types/views/index.d.ts.map +1 -1
  153. package/types/views/widgetChrome.d.ts +72 -0
  154. package/types/views/widgetChrome.d.ts.map +1 -0
@@ -0,0 +1,220 @@
1
+ import { cleanup, fireEvent, screen } from "@testing-library/react";
2
+ import { renderWithProviders } from "@multiplatform.one/test-utils";
3
+ import { GroupPositionContext } from "@multiplatform.one/theme";
4
+ import { useContext } from "react";
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+ import { ListGroup, ListGroupItem, ListRow, ListRowFact, useListItemState } from "./List";
7
+ import * as ViewExports from "./index";
8
+
9
+ afterEach(cleanup);
10
+
11
+ function rows(container: HTMLElement): HTMLElement[] {
12
+ return Array.from(container.querySelectorAll<HTMLElement>("[data-list-row]"));
13
+ }
14
+
15
+ describe("ListGroup (LC-175 MPO-ONLY-REUSE: the inset-grouped list apps used to build)", () => {
16
+ it("ships from the views barrel", () => {
17
+ expect(ViewExports).toHaveProperty("ListGroup");
18
+ expect(ViewExports).toHaveProperty("ListGroupItem");
19
+ });
20
+
21
+ it("tells each row its place in the stacked group (LC-72)", () => {
22
+ const { container } = renderWithProviders(
23
+ <ListGroup aria-label="Settings">
24
+ <ListGroupItem>
25
+ <ListRow title="Wi-Fi" />
26
+ </ListGroupItem>
27
+ <ListGroupItem>
28
+ <ListRow title="Bluetooth" />
29
+ </ListGroupItem>
30
+ <ListGroupItem>
31
+ <ListRow title="Cellular" />
32
+ </ListGroupItem>
33
+ </ListGroup>,
34
+ );
35
+ expect(rows(container).map((row) => row.getAttribute("data-group-position"))).toEqual([
36
+ "first",
37
+ "middle",
38
+ "last",
39
+ ]);
40
+ expect(screen.getByRole("list", { name: "Settings" })).toBeTruthy();
41
+ expect(screen.getAllByRole("listitem")).toHaveLength(3);
42
+ });
43
+
44
+ it("draws a hairline between rows only, never above the first", () => {
45
+ const { container } = renderWithProviders(
46
+ <ListGroup>
47
+ <ListGroupItem>
48
+ <ListRow title="One" />
49
+ </ListGroupItem>
50
+ <ListGroupItem>
51
+ <ListRow title="Two" />
52
+ </ListGroupItem>
53
+ </ListGroup>,
54
+ );
55
+ const items = screen.getAllByRole("listitem");
56
+ expect(items[0].children).toHaveLength(1);
57
+ expect(items[1].children).toHaveLength(2);
58
+ expect(rows(container)).toHaveLength(2);
59
+ });
60
+
61
+ it("insets each hairline to the row's text, past a leading icon (iOS inset-grouped)", () => {
62
+ const { container } = renderWithProviders(
63
+ <ListGroup>
64
+ <ListGroupItem>
65
+ <ListRow icon={<span />} title="Wi-Fi" />
66
+ </ListGroupItem>
67
+ <ListGroupItem>
68
+ <ListRow icon={<span />} title="Bluetooth" />
69
+ </ListGroupItem>
70
+ <ListGroupItem>
71
+ <ListRow title="About" />
72
+ </ListGroupItem>
73
+ </ListGroup>,
74
+ );
75
+ const lines = Array.from(container.querySelectorAll("[data-list-hairline]"));
76
+ expect(lines.map((line) => line.getAttribute("data-list-hairline"))).toEqual(["icon", "text"]);
77
+ });
78
+
79
+ it("the inset variant sits on the Card surface; plain paints none", () => {
80
+ const { container, unmount } = renderWithProviders(
81
+ <ListGroup>
82
+ <ListGroupItem>
83
+ <ListRow title="Inset" />
84
+ </ListGroupItem>
85
+ </ListGroup>,
86
+ );
87
+ expect(container.querySelector('[data-tier="content"]')).toBeTruthy();
88
+ unmount();
89
+ const plain = renderWithProviders(
90
+ <ListGroup variant="plain">
91
+ <ListGroupItem>
92
+ <ListRow title="Plain" />
93
+ </ListGroupItem>
94
+ </ListGroup>,
95
+ );
96
+ expect(plain.container.querySelector('[data-tier="content"]')).toBeNull();
97
+ });
98
+
99
+ it("a pressable row is a button that answers press, Enter and Space", () => {
100
+ const onPress = vi.fn();
101
+ renderWithProviders(
102
+ <ListGroup>
103
+ <ListGroupItem onPress={onPress} aria-label="Open Pikachu">
104
+ <ListRow title="Pikachu" />
105
+ </ListGroupItem>
106
+ </ListGroup>,
107
+ );
108
+ const button = screen.getByRole("button", { name: "Open Pikachu" });
109
+ fireEvent.click(button);
110
+ fireEvent.keyDown(button, { key: "Enter" });
111
+ fireEvent.keyDown(button, { key: " " });
112
+ expect(onPress).toHaveBeenCalledTimes(3);
113
+ });
114
+
115
+ it("a row without onPress is not a button", () => {
116
+ renderWithProviders(
117
+ <ListGroup>
118
+ <ListGroupItem>
119
+ <ListRow title="Static" />
120
+ </ListGroupItem>
121
+ </ListGroup>,
122
+ );
123
+ expect(screen.queryByRole("button")).toBeNull();
124
+ });
125
+
126
+ it("the selected row carries data-selected and hands its state to the content", () => {
127
+ let seen: boolean | undefined;
128
+ function Probe() {
129
+ seen = useListItemState().selected;
130
+ return null;
131
+ }
132
+ const { container } = renderWithProviders(
133
+ <ListGroup variant="plain">
134
+ <ListGroupItem selected onPress={() => {}}>
135
+ <Probe />
136
+ </ListGroupItem>
137
+ </ListGroup>,
138
+ );
139
+ expect(rows(container)[0].hasAttribute("data-selected")).toBe(true);
140
+ expect(seen).toBe(true);
141
+ });
142
+
143
+ it("an explicit position wins for rows a virtualized list renders one by one", () => {
144
+ const { container } = renderWithProviders(
145
+ <ListGroupItem groupPosition="last">
146
+ <ListRow title="Alone" />
147
+ </ListGroupItem>,
148
+ );
149
+ expect(rows(container)[0].getAttribute("data-group-position")).toBe("last");
150
+ });
151
+ });
152
+
153
+ describe("ListRow done (a checked to-do)", () => {
154
+ it("marks the row done and strikes the title and subtitle through", () => {
155
+ const { container } = renderWithProviders(
156
+ <ListRow title="Buy milk" subtitle="Two litres" done />,
157
+ );
158
+ expect(container.querySelector("[data-done]")).toBeTruthy();
159
+ for (const text of ["Buy milk", "Two litres"]) {
160
+ const className = String(screen.getByText(text).className);
161
+ // tamagui truncates long atomic class names: _td-line-throug<hash>
162
+ expect(className).toMatch(/_td-line-throug/);
163
+ }
164
+ });
165
+
166
+ it("an open row is neither marked nor struck", () => {
167
+ const { container } = renderWithProviders(<ListRow title="Buy bread" />);
168
+ expect(container.querySelector("[data-done]")).toBeNull();
169
+ expect(String(screen.getByText("Buy bread").className)).not.toMatch(/line-through/);
170
+ });
171
+ });
172
+
173
+ describe("ListGroupItem content", () => {
174
+ it("does not hand its group position to what it holds", () => {
175
+ let seen: unknown = "unset";
176
+ function Probe() {
177
+ seen = useContext(GroupPositionContext);
178
+ return null;
179
+ }
180
+ renderWithProviders(
181
+ <ListGroup>
182
+ <ListGroupItem>
183
+ <Probe />
184
+ </ListGroupItem>
185
+ <ListGroupItem>
186
+ <ListRow title="Two" />
187
+ </ListGroupItem>
188
+ </ListGroup>,
189
+ );
190
+ expect(seen).toBeUndefined();
191
+ });
192
+ });
193
+
194
+ describe("ListRowFact (LC-261 NO-MIDDOT-JOIN)", () => {
195
+ it("puts a count beside its glyph in the trailing meta, named in words, the subtitle left alone", () => {
196
+ const Glyph = () => <svg data-testid="fact-glyph" />;
197
+ const { container } = renderWithProviders(
198
+ <ListGroup>
199
+ <ListGroupItem>
200
+ <ListRow
201
+ title="Button"
202
+ subtitle="Forms"
203
+ meta={
204
+ <ListRowFact icon={Glyph} label="12 stories">
205
+ 12
206
+ </ListRowFact>
207
+ }
208
+ />
209
+ </ListGroupItem>
210
+ </ListGroup>,
211
+ );
212
+ const fact = container.querySelector<HTMLElement>('[data-list-slot="fact"]');
213
+ expect(fact?.getAttribute("aria-label")).toBe("12 stories");
214
+ expect(fact?.textContent).toBe("12");
215
+ expect(fact?.querySelector('[data-testid="fact-glyph"]')).toBeTruthy();
216
+ expect(fact?.closest('[data-list-slot="meta"]')).toBeTruthy();
217
+ expect(screen.getByText("Forms").textContent).toBe("Forms");
218
+ expect(ViewExports).toHaveProperty("ListRowFact");
219
+ });
220
+ });
@@ -0,0 +1,83 @@
1
+ import { action } from "@multiplatform.one/storybook";
2
+ import type { Meta, StoryObj } from "@storybook/react-native-web-vite";
3
+ import { BellIcon, HouseIcon, MoonIcon, WifiHighIcon } from "@phosphor-icons/react";
4
+ import { useState } from "react";
5
+ import { YStack } from "tamagui";
6
+ import { ListGroup, ListGroupItem, ListRow, ListRowFact } from "./List";
7
+
8
+ const meta: Meta<typeof ListGroup> = {
9
+ title: "Components/ListGroup",
10
+ component: ListGroup,
11
+ parameters: {
12
+ status: { type: "stable" },
13
+ docs: {
14
+ description: {
15
+ component:
16
+ "A short, static list of rows drawn as one stacked group: a settings section, a to-do list, a catalog section. `inset` sits on the Card surface; `plain` on the ground it is placed on.",
17
+ },
18
+ },
19
+ },
20
+ };
21
+
22
+ export default meta;
23
+ type Story = StoryObj<typeof ListGroup>;
24
+
25
+ export const Inset: Story = {
26
+ render: () => (
27
+ <YStack width="100%" maxWidth={390}>
28
+ <ListGroup aria-label="Settings">
29
+ <ListGroupItem onPress={action("row:wifi")}>
30
+ <ListRow
31
+ icon={<WifiHighIcon />}
32
+ title="Wi-Fi"
33
+ meta={<ListRowFact icon={HouseIcon} label="Joined the home network" />}
34
+ />
35
+ </ListGroupItem>
36
+ <ListGroupItem onPress={action("row:notifications")}>
37
+ <ListRow icon={<BellIcon />} title="Notifications" subtitle="Banners, sounds" />
38
+ </ListGroupItem>
39
+ <ListGroupItem onPress={action("row:focus")}>
40
+ <ListRow icon={<MoonIcon />} title="Focus" meta="Off" />
41
+ </ListGroupItem>
42
+ </ListGroup>
43
+ </YStack>
44
+ ),
45
+ };
46
+
47
+ export const Plain: Story = {
48
+ render: function PlainStory() {
49
+ const [active, setActive] = useState("primitives");
50
+ const sections = ["primitives", "forms", "layouts", "data"];
51
+ return (
52
+ <YStack width={260} padding="$4">
53
+ <ListGroup variant="plain" aria-label="Sections">
54
+ {sections.map((id) => (
55
+ <ListGroupItem
56
+ key={id}
57
+ selected={id === active}
58
+ aria-current={id === active ? "true" : undefined}
59
+ onPress={() => setActive(id)}
60
+ >
61
+ <ListRow title={id[0].toUpperCase() + id.slice(1)} />
62
+ </ListGroupItem>
63
+ ))}
64
+ </ListGroup>
65
+ </YStack>
66
+ );
67
+ },
68
+ };
69
+
70
+ export const Done: Story = {
71
+ render: () => (
72
+ <YStack width="100%" maxWidth={390}>
73
+ <ListGroup aria-label="To-dos">
74
+ <ListGroupItem>
75
+ <ListRow title="Book the venue" subtitle="Call before Friday" />
76
+ </ListGroupItem>
77
+ <ListGroupItem>
78
+ <ListRow title="Send invitations" subtitle="Forty guests" done />
79
+ </ListGroupItem>
80
+ </ListGroup>
81
+ </YStack>
82
+ ),
83
+ };
@@ -0,0 +1,189 @@
1
+ import { Card } from "../Card";
2
+ import { componentColors } from "../componentColors";
3
+ import {
4
+ GroupPositionContext,
5
+ ensureKeyboardModalityTracking,
6
+ getGroupPosition,
7
+ hairline,
8
+ keyboardFocusRingProps,
9
+ stackRadiusProps,
10
+ transitionProps,
11
+ type GroupPosition,
12
+ useResolvedKnobs,
13
+ useTouchSurface,
14
+ wasKeyboardFocus,
15
+ } from "@multiplatform.one/theme";
16
+ import React, { useContext, useState, type ReactNode } from "react";
17
+ import { View, XStack, YStack, type YStackProps } from "tamagui";
18
+ import {
19
+ ListItemStateContext,
20
+ listLeadingIconSize,
21
+ listRowTouchProps,
22
+ type ListItemState,
23
+ } from "./ListRow";
24
+
25
+ export type ListGroupVariant = "inset" | "plain";
26
+
27
+ export interface ListGroupProps extends Omit<YStackProps, "children"> {
28
+ /**
29
+ * `inset` (default): the rows sit on one Card surface, the iOS inset-grouped
30
+ * table. `plain`: the rows sit on the ground they are placed on, a sidebar or
31
+ * source list.
32
+ */
33
+ variant?: ListGroupVariant;
34
+ /** `ListGroupItem`s; each learns its place in the group from here. */
35
+ children: ReactNode;
36
+ "aria-label"?: string;
37
+ }
38
+
39
+ /**
40
+ * A short, static list of rows drawn as one stacked group (LC-72): a settings
41
+ * section, a to-do list, a catalog section. Use `List` when the rows are data
42
+ * that pages in or needs keyboard selection; use this when the rows are a
43
+ * handful of children an app composes, each a `ListGroupItem` holding a
44
+ * `ListRow` or a form. Outer corners follow the radius knob, interiors stay
45
+ * square, and hairlines sit only between rows, inset to the text.
46
+ */
47
+ export function ListGroup({ variant = "inset", children, ...props }: ListGroupProps) {
48
+ const rows = React.Children.toArray(children).filter(React.isValidElement);
49
+ const body = rows.map((row, index) => (
50
+ <GroupPositionContext.Provider
51
+ key={row.key ?? index}
52
+ value={getGroupPosition(index, rows.length)}
53
+ >
54
+ {row}
55
+ </GroupPositionContext.Provider>
56
+ ));
57
+ if (variant === "plain")
58
+ return (
59
+ <YStack role="list" {...props}>
60
+ {body}
61
+ </YStack>
62
+ );
63
+ return (
64
+ <Card role="list" padding={0} gap={0} overflow="hidden" {...(props as object)}>
65
+ {body}
66
+ </Card>
67
+ );
68
+ }
69
+
70
+ export interface ListGroupItemProps extends Omit<YStackProps, "children" | "onPress"> {
71
+ children: ReactNode;
72
+ /** Makes the row a button: hover and press fills, the 44 floor, Enter and Space. */
73
+ onPress?: () => void;
74
+ /** The current row (a nav list's open page): the LC-131 selection fill and ink. */
75
+ selected?: boolean;
76
+ /**
77
+ * Where the row sits in its group. Inside a `ListGroup` it is read from the
78
+ * group; pass it when a virtualized list renders the rows one by one.
79
+ */
80
+ groupPosition?: GroupPosition;
81
+ }
82
+
83
+ function rowLeading(children: ReactNode): "icon" | "media" | null {
84
+ const row = React.Children.toArray(children).find(React.isValidElement);
85
+ if (!row) return null;
86
+ const props = row.props as { icon?: unknown; media?: unknown };
87
+ if (props.media) return "media";
88
+ return props.icon ? "icon" : null;
89
+ }
90
+
91
+ /**
92
+ * One row of a `ListGroup`: the hairline above it, the row inset, the group's
93
+ * outer corners, and the hover, press, selection and keyboard-focus states.
94
+ * Its child decides the content, usually a `ListRow`.
95
+ */
96
+ export function ListGroupItem({
97
+ children,
98
+ onPress,
99
+ selected = false,
100
+ groupPosition,
101
+ ...props
102
+ }: ListGroupItemProps) {
103
+ const { knobProps } = useResolvedKnobs();
104
+ const touch = useTouchSurface();
105
+ const grouped = useContext(GroupPositionContext);
106
+ const position = groupPosition ?? grouped ?? "only";
107
+ const corners = stackRadiusProps(position, knobProps.borderRadius.borderRadius);
108
+ const [keyboardFocused, setKeyboardFocused] = useState(false);
109
+ if (typeof document !== "undefined") ensureKeyboardModalityTracking();
110
+ const pressable = Boolean(onPress);
111
+ const selectedInk = componentColors.selection.ink;
112
+ const state: ListItemState = { selected, focused: keyboardFocused, selectedInk };
113
+ const first = position === "first" || position === "only";
114
+ const leading = rowLeading(children);
115
+
116
+ return (
117
+ <YStack role="listitem">
118
+ {first ? null : (
119
+ <XStack
120
+ aria-hidden
121
+ paddingLeft={knobProps.panelPadding.padding}
122
+ {...knobProps.gap}
123
+ {...({ "data-list-hairline": leading ?? "text" } as Record<string, unknown>)}
124
+ >
125
+ {leading === "media" ? <View width="$true" flexShrink={0} /> : null}
126
+ {leading === "icon" ? (
127
+ <View width={listLeadingIconSize(knobProps.sizeToken)} flexShrink={0} />
128
+ ) : null}
129
+ <YStack flex={1}>
130
+ <View {...hairline.line} />
131
+ </YStack>
132
+ </XStack>
133
+ )}
134
+ <XStack
135
+ data-group-position={position}
136
+ {...({
137
+ "data-list-row": true,
138
+ ...(selected ? { "data-selected": true } : {}),
139
+ } as Record<string, unknown>)}
140
+ {...listRowTouchProps(touch)}
141
+ paddingHorizontal={knobProps.panelPadding.padding}
142
+ paddingVertical="$2"
143
+ alignItems="center"
144
+ {...knobProps.gap}
145
+ overflow="hidden"
146
+ {...corners}
147
+ backgroundColor={selected ? componentColors.selection.background : "transparent"}
148
+ {...(selected ? { color: selectedInk } : {})}
149
+ {...transitionProps(knobProps.motion.control)}
150
+ {...(pressable
151
+ ? {
152
+ role: "button" as const,
153
+ tabIndex: 0,
154
+ cursor: "pointer",
155
+ hoverStyle: {
156
+ backgroundColor: selected
157
+ ? componentColors.selection.hover
158
+ : componentColors.interactive.background,
159
+ ...corners,
160
+ },
161
+ pressStyle: {
162
+ backgroundColor: selected
163
+ ? componentColors.selection.press
164
+ : componentColors.interactive.hover,
165
+ ...corners,
166
+ },
167
+ outlineWidth: 0,
168
+ focusStyle: { outlineWidth: 0 },
169
+ ...(keyboardFocused ? keyboardFocusRingProps : null),
170
+ onPress,
171
+ onFocus: () => setKeyboardFocused(wasKeyboardFocus()),
172
+ onBlur: () => setKeyboardFocused(false),
173
+ onKeyDown: (event: { key: string; preventDefault: () => void }) => {
174
+ if (event.key === "Enter" || event.key === " ") {
175
+ event.preventDefault();
176
+ onPress?.();
177
+ }
178
+ },
179
+ }
180
+ : null)}
181
+ {...(props as object)}
182
+ >
183
+ <GroupPositionContext.Provider value={undefined}>
184
+ <ListItemStateContext.Provider value={state}>{children}</ListItemStateContext.Provider>
185
+ </GroupPositionContext.Provider>
186
+ </XStack>
187
+ </YStack>
188
+ );
189
+ }