@multiplatform.one/components 8.4.0 → 8.6.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/dist/cjs/SheetModal/detents.cjs +11 -37
- package/dist/cjs/SheetModal/detents.native.js +11 -43
- package/dist/cjs/SheetModal/detents.native.js.map +1 -1
- package/dist/cjs/SheetModal/index.cjs +3 -0
- package/dist/cjs/SheetModal/index.native.js +7 -6
- package/dist/cjs/SheetModal/index.native.js.map +1 -1
- package/dist/cjs/views/ListRow.cjs +101 -19
- package/dist/cjs/views/ListRow.native.js +104 -20
- package/dist/cjs/views/ListRow.native.js.map +1 -1
- package/dist/esm/SheetModal/detents.mjs +2 -32
- package/dist/esm/SheetModal/detents.mjs.map +1 -1
- package/dist/esm/SheetModal/detents.native.js +2 -38
- package/dist/esm/SheetModal/detents.native.js.map +1 -1
- package/dist/esm/SheetModal/index.mjs +3 -0
- package/dist/esm/SheetModal/index.mjs.map +1 -1
- package/dist/esm/SheetModal/index.native.js +8 -7
- package/dist/esm/SheetModal/index.native.js.map +1 -1
- package/dist/esm/views/List.mjs.map +1 -1
- package/dist/esm/views/ListRow.mjs +102 -20
- package/dist/esm/views/ListRow.mjs.map +1 -1
- package/dist/esm/views/ListRow.native.js +105 -21
- package/dist/esm/views/ListRow.native.js.map +1 -1
- package/dist/jsx/SheetModal/detents.mjs +2 -32
- package/dist/jsx/SheetModal/detents.mjs.map +1 -1
- package/dist/jsx/SheetModal/detents.native.js +11 -43
- package/dist/jsx/SheetModal/detents.native.js.map +1 -1
- package/dist/jsx/SheetModal/index.mjs +3 -0
- package/dist/jsx/SheetModal/index.mjs.map +1 -1
- package/dist/jsx/SheetModal/index.native.js +7 -6
- package/dist/jsx/SheetModal/index.native.js.map +1 -1
- package/dist/jsx/views/List.mjs.map +1 -1
- package/dist/jsx/views/List.native.js.map +1 -1
- package/dist/jsx/views/ListRow.mjs +102 -20
- package/dist/jsx/views/ListRow.mjs.map +1 -1
- package/dist/jsx/views/ListRow.native.js +104 -20
- package/dist/jsx/views/ListRow.native.js.map +1 -1
- package/package.json +7 -7
- package/src/SheetModal/SheetModal.detentLayout.spec.tsx +65 -1
- package/src/SheetModal/SheetModal.spec.tsx +8 -3
- package/src/SheetModal/SheetModal.stories.tsx +17 -0
- package/src/SheetModal/detents.ts +25 -78
- package/src/SheetModal/index.native.tsx +13 -9
- package/src/SheetModal/index.tsx +19 -5
- package/src/index.gnome.ts +1 -1
- package/src/views/List.tsx +1 -0
- package/src/views/ListRow.spec.tsx +10 -11
- package/src/views/ListRow.stories.tsx +112 -0
- package/src/views/ListRow.tone.spec.tsx +221 -0
- package/src/views/ListRow.tsx +151 -20
- package/types/SheetModal/detents.d.ts +9 -54
- package/types/SheetModal/detents.d.ts.map +1 -1
- package/types/SheetModal/index.d.ts +18 -5
- package/types/SheetModal/index.d.ts.map +1 -1
- package/types/SheetModal/index.native.d.ts +1 -1
- package/types/SheetModal/index.native.d.ts.map +1 -1
- package/types/index.gnome.d.ts +1 -1
- package/types/index.gnome.d.ts.map +1 -1
- package/types/views/List.d.ts +1 -1
- package/types/views/List.d.ts.map +1 -1
- package/types/views/ListRow.d.ts +33 -3
- package/types/views/ListRow.d.ts.map +1 -1
|
@@ -29,6 +29,7 @@ import { DangerSection } from "../actions/DangerSection";
|
|
|
29
29
|
import { DestructiveAction } from "../actions/DestructiveAction";
|
|
30
30
|
import { HeaderActions } from "../actions/HeaderActions";
|
|
31
31
|
import { OverlayHeader } from "../actions/StandardAction";
|
|
32
|
+
import { sheetDetent } from "./detents";
|
|
32
33
|
import { SheetModal } from "./index";
|
|
33
34
|
import { Paragraph, SizableText } from "../Text";
|
|
34
35
|
|
|
@@ -41,10 +42,12 @@ const projectOptions = ["Inbox", "Launch", "Backlog", "Archive"].map((label) =>
|
|
|
41
42
|
function Harness({
|
|
42
43
|
scrollable = false,
|
|
43
44
|
snapPoint,
|
|
45
|
+
detents,
|
|
44
46
|
startOpen = false,
|
|
45
47
|
}: {
|
|
46
48
|
scrollable?: boolean;
|
|
47
49
|
snapPoint?: number;
|
|
50
|
+
detents?: number[];
|
|
48
51
|
startOpen?: boolean;
|
|
49
52
|
}) {
|
|
50
53
|
const [open, setOpen] = useState(startOpen);
|
|
@@ -60,6 +63,7 @@ function Harness({
|
|
|
60
63
|
onOpenChange={setOpen}
|
|
61
64
|
scrollable={scrollable}
|
|
62
65
|
{...(snapPoint === undefined ? {} : { snapPoint })}
|
|
66
|
+
{...(detents === undefined ? {} : { detents })}
|
|
63
67
|
header={
|
|
64
68
|
<OverlayHeader
|
|
65
69
|
title="Move to project"
|
|
@@ -134,6 +138,19 @@ export const TallDetent: Story = {
|
|
|
134
138
|
render: () => <Harness snapPoint={92} />,
|
|
135
139
|
};
|
|
136
140
|
|
|
141
|
+
export const Detents: Story = {
|
|
142
|
+
name: "Detents",
|
|
143
|
+
parameters: {
|
|
144
|
+
docs: {
|
|
145
|
+
description: {
|
|
146
|
+
story:
|
|
147
|
+
"`detents` is a SET of percents, the way `UISheetPresentationController.detents` holds `[.medium(), .large()]`. This sheet opens at 65 and a finger on the grabber drags it to full or down to 40; released below 40 it dismisses, and released anywhere above that it snaps to the nearest rung rather than closing (LC-21). Before FZ-455 a caller could name one percent, and the web twin resolved it to a single snap point, so the grabber moved and the sheet did not.",
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
render: () => <Harness detents={[sheetDetent.large, 65, 40]} snapPoint={65} startOpen />,
|
|
152
|
+
};
|
|
153
|
+
|
|
137
154
|
export const OpenOnMount: Story = {
|
|
138
155
|
name: "Open",
|
|
139
156
|
render: () => <Harness startOpen />,
|
|
@@ -1,83 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SheetModal detent geometry
|
|
3
|
-
* without standing up a React Native renderer.
|
|
2
|
+
* SheetModal detent geometry.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* and `
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/** Smallest height a native sheet is ever laid out at. */
|
|
11
|
-
export const minSheetHeight = 180;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Half-open detent for a sheet that owns a scrollport, as a fraction of its
|
|
15
|
-
* full height. Mirrors FloatingPanel so both native sheets drag alike.
|
|
16
|
-
*/
|
|
17
|
-
export const mediumDetent = 0.55;
|
|
18
|
-
|
|
19
|
-
export interface ResolveSheetDetentsOptions {
|
|
20
|
-
/** Full (expanded) height of the sheet, in points. */
|
|
21
|
-
travel: number;
|
|
22
|
-
/** The sheet owns a scrollport, so a half-open rest is meaningful. */
|
|
23
|
-
scrollable?: boolean;
|
|
24
|
-
/** Percent detent from the caller — the same prop the web Sheet takes. */
|
|
25
|
-
snapPoint?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The heights the sheet is allowed to rest at, largest first.
|
|
30
|
-
*
|
|
31
|
-
* MPO-68: `snapPoint` is a percent on the web Sheet (`snapPoints={[snapPoint]}`).
|
|
32
|
-
* Native honours the same prop by turning that percent into a detent, so a
|
|
33
|
-
* caller that writes `snapPoint={85}` gets an 85%-height rest on both twins
|
|
34
|
-
* rather than the prop being silently dropped on device.
|
|
4
|
+
* The implementation moved to `@multiplatform.one/forms`
|
|
5
|
+
* (`shared/sheetDetents.ts`) in FZ-455, because FloatingPanel's sheet face
|
|
6
|
+
* needs the same geometry and `forms` is the lower layer. Keeping a second
|
|
7
|
+
* copy here is what let MPO-71 rewrite one of them from a stale version and
|
|
8
|
+
* drop the `snapPoint` push for a month.
|
|
35
9
|
*
|
|
36
|
-
*
|
|
37
|
-
* rests below that is indistinguishable from a dismissed one. A sheet whose
|
|
38
|
-
* full height is already under the floor keeps its own height, otherwise it
|
|
39
|
-
* would have no detents at all.
|
|
10
|
+
* This file stays as the path SheetModal and its specs already import.
|
|
40
11
|
*/
|
|
41
|
-
export function resolveSheetDetents({
|
|
42
|
-
travel,
|
|
43
|
-
scrollable,
|
|
44
|
-
snapPoint,
|
|
45
|
-
}: ResolveSheetDetentsOptions): number[] {
|
|
46
|
-
const points = [travel];
|
|
47
|
-
if (scrollable) {
|
|
48
|
-
points.push(Math.round(travel * mediumDetent));
|
|
49
|
-
}
|
|
50
|
-
if (typeof snapPoint === "number" && Number.isFinite(snapPoint) && snapPoint > 0) {
|
|
51
|
-
points.push(Math.round(travel * (Math.min(snapPoint, 100) / 100)));
|
|
52
|
-
}
|
|
53
|
-
const floor = Math.min(minSheetHeight, travel);
|
|
54
|
-
return Array.from(new Set(points.filter((h) => h >= floor))).sort((a, b) => b - a);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** The large detent: the tallest a content-sized sheet grows, as a fraction of the window. */
|
|
58
|
-
export const largeDetentRatio = 0.85;
|
|
59
|
-
|
|
60
|
-
/** Percent rest of a `fill` sheet with no `snapPoint`: it has no intrinsic height to fit. */
|
|
61
|
-
export const fillSnapPoint = 60;
|
|
62
12
|
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
if (snapPoint === undefined && !fill) return { snapPointsMode: "fit" };
|
|
82
|
-
return { snapPointsMode: "percent", snapPoints: [snapPoint ?? fillSnapPoint] };
|
|
83
|
-
}
|
|
13
|
+
export {
|
|
14
|
+
fillSnapPoint,
|
|
15
|
+
largeDetentRatio,
|
|
16
|
+
mediumDetent,
|
|
17
|
+
minSheetHeight,
|
|
18
|
+
openingDetentIndex,
|
|
19
|
+
resolveDetentPercents,
|
|
20
|
+
resolveSheetDetents,
|
|
21
|
+
resolveWebSnap,
|
|
22
|
+
sheetDetent,
|
|
23
|
+
sheetDismissThreshold,
|
|
24
|
+
} from "@multiplatform.one/forms";
|
|
25
|
+
export type {
|
|
26
|
+
DetentSetOptions,
|
|
27
|
+
ResolveSheetDetentsOptions,
|
|
28
|
+
ResolveWebSnapOptions,
|
|
29
|
+
WebSnap,
|
|
30
|
+
} from "@multiplatform.one/forms";
|
|
@@ -56,7 +56,12 @@ import {
|
|
|
56
56
|
} from "react-native";
|
|
57
57
|
import { SafeAreaInsetsContext, initialWindowMetrics } from "react-native-safe-area-context";
|
|
58
58
|
|
|
59
|
-
import {
|
|
59
|
+
import {
|
|
60
|
+
largeDetentRatio,
|
|
61
|
+
minSheetHeight,
|
|
62
|
+
resolveSheetDetents,
|
|
63
|
+
sheetDismissThreshold,
|
|
64
|
+
} from "./detents";
|
|
60
65
|
import { useTranslation } from "../shared/i18n";
|
|
61
66
|
import { useKeyboardInset } from "../shared/useKeyboardInset";
|
|
62
67
|
import { View, YStack } from "tamagui";
|
|
@@ -70,8 +75,6 @@ export type { SheetModalProps } from "./index";
|
|
|
70
75
|
const bottomInset = Platform.OS === "ios" ? 24 : 16;
|
|
71
76
|
// Backdrop left visible above the sheet, so the scrim stays tappable.
|
|
72
77
|
const backdropStrip = 48;
|
|
73
|
-
// Released more than this far below the smallest detent, the sheet dismisses.
|
|
74
|
-
const dismissThreshold = 56;
|
|
75
78
|
const IN_DIALOG_REGION = { inDialogRegion: true } as const;
|
|
76
79
|
/*
|
|
77
80
|
* MPO-299 fill: an owned viewport bootstraps from zero unless EVERY link
|
|
@@ -96,6 +99,7 @@ export function SheetModal({
|
|
|
96
99
|
header: headerContent,
|
|
97
100
|
headerActions,
|
|
98
101
|
snapPoint,
|
|
102
|
+
detents,
|
|
99
103
|
scrollable,
|
|
100
104
|
fill = false,
|
|
101
105
|
flush = false,
|
|
@@ -163,9 +167,9 @@ export function SheetModal({
|
|
|
163
167
|
*/
|
|
164
168
|
const [measuredHeight, setMeasuredHeight] = useState(0);
|
|
165
169
|
const travel = measuredHeight || maxHeight;
|
|
166
|
-
const
|
|
167
|
-
() => resolveSheetDetents({ travel, scrollable, snapPoint }),
|
|
168
|
-
[travel, scrollable, snapPoint],
|
|
170
|
+
const detentHeights = useMemo(
|
|
171
|
+
() => resolveSheetDetents({ travel, detents, scrollable, snapPoint }),
|
|
172
|
+
[travel, detents, scrollable, snapPoint],
|
|
169
173
|
);
|
|
170
174
|
|
|
171
175
|
/*
|
|
@@ -184,9 +188,9 @@ export function SheetModal({
|
|
|
184
188
|
const translateY = useRef(new Animated.Value(travel)).current;
|
|
185
189
|
const restRef = useRef(travel);
|
|
186
190
|
const travelRef = useRef(travel);
|
|
187
|
-
const detentsRef = useRef(
|
|
191
|
+
const detentsRef = useRef(detentHeights);
|
|
188
192
|
travelRef.current = travel;
|
|
189
|
-
detentsRef.current =
|
|
193
|
+
detentsRef.current = detentHeights;
|
|
190
194
|
|
|
191
195
|
// Async callbacks belong to one committed presentation, never its successor.
|
|
192
196
|
const presentationRef = useRef(0);
|
|
@@ -316,7 +320,7 @@ export function SheetModal({
|
|
|
316
320
|
const current = Math.max(0, restRef.current + g.dy);
|
|
317
321
|
const projected = current + g.vy * 120;
|
|
318
322
|
const smallestRest = tvl - points[points.length - 1];
|
|
319
|
-
if (projected > smallestRest +
|
|
323
|
+
if (projected > smallestRest + sheetDismissThreshold || g.vy > 1.1) {
|
|
320
324
|
dismiss(g.vy);
|
|
321
325
|
return;
|
|
322
326
|
}
|
package/src/SheetModal/index.tsx
CHANGED
|
@@ -47,12 +47,25 @@ export interface SheetModalProps {
|
|
|
47
47
|
*/
|
|
48
48
|
headerActions?: ReactNode;
|
|
49
49
|
/**
|
|
50
|
-
* Percent
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* Percent rest. The web twin OPENS there; the native twin opens at full
|
|
51
|
+
* height and takes it as a detent to drag to, which is the twins' one
|
|
52
|
+
* remaining disagreement (FZ-455). Omitted: the sheet opens at its
|
|
53
|
+
* content's height, capped at the large detent (HIG: a sheet as tall as
|
|
54
|
+
* what it holds). A `fill` sheet has no intrinsic height, so it falls back
|
|
55
|
+
* to 60%. With `detents`, it names which of them the web twin opens at.
|
|
54
56
|
*/
|
|
55
57
|
snapPoint?: number;
|
|
58
|
+
/**
|
|
59
|
+
* The rest positions the sheet may settle at, as percents of its full
|
|
60
|
+
* height, the way `UISheetPresentationController.detents` takes an array
|
|
61
|
+
* (FZ-455). A finger on the grabber drags between them and releases onto
|
|
62
|
+
* the nearest; a release below the smallest dismisses (LC-21). Order does
|
|
63
|
+
* not matter, `sheetDetent.medium` / `.large` name the HIG rungs, and
|
|
64
|
+
* `snapPoint` names which one the web twin opens at. Omitted, the set is the sheet's
|
|
65
|
+
* full height plus `snapPoint` and the half-open rest of a `scrollable`
|
|
66
|
+
* sheet, so no existing sheet changes shape.
|
|
67
|
+
*/
|
|
68
|
+
detents?: number[];
|
|
56
69
|
/** Wrap children in the sheet's scroll container. */
|
|
57
70
|
scrollable?: boolean;
|
|
58
71
|
/**
|
|
@@ -149,6 +162,7 @@ export function SheetModal({
|
|
|
149
162
|
header: headerContent,
|
|
150
163
|
headerActions,
|
|
151
164
|
snapPoint,
|
|
165
|
+
detents,
|
|
152
166
|
scrollable,
|
|
153
167
|
fill = false,
|
|
154
168
|
flush = false,
|
|
@@ -163,7 +177,7 @@ export function SheetModal({
|
|
|
163
177
|
titleId={headerActions && !overlayHeader ? titleId : undefined}
|
|
164
178
|
/>
|
|
165
179
|
) : null;
|
|
166
|
-
const snap = resolveWebSnap({ snapPoint, fill });
|
|
180
|
+
const snap = resolveWebSnap({ snapPoint, detents, scrollable, fill });
|
|
167
181
|
const { height: windowHeight, width: windowWidth } = useWindowDimensions();
|
|
168
182
|
const regular = overlaySizeClass(windowWidth) === "regular";
|
|
169
183
|
const { knobProps } = useResolvedKnobs();
|
package/src/index.gnome.ts
CHANGED
|
@@ -75,7 +75,7 @@ export {
|
|
|
75
75
|
listRowTouchProps,
|
|
76
76
|
useListItemState,
|
|
77
77
|
} from "./views/ListRow";
|
|
78
|
-
export type { ListItemState, ListRowProps } from "./views/ListRow";
|
|
78
|
+
export type { ListItemState, ListRowProps, ListRowTone } from "./views/ListRow";
|
|
79
79
|
export { ListGroup, ListGroupItem } from "./views/ListGroup";
|
|
80
80
|
export type { ListGroupItemProps, ListGroupProps, ListGroupVariant } from "./views/ListGroup";
|
|
81
81
|
export {
|
package/src/views/List.tsx
CHANGED
|
@@ -117,30 +117,29 @@ describe("ListRow loading (LC-187: the spinner stands alone in the trailing slot
|
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
// The ink itself needs the intent sub-themes, which only MPO's own theme
|
|
121
|
+
// config carries: ListRow.tone.spec.tsx proves the colour a destructive row
|
|
122
|
+
// resolves, and that it is the colour `titleTone="error"` resolves.
|
|
120
123
|
describe("ListRow destructive (the row twin of a destructive menu item)", () => {
|
|
121
|
-
const
|
|
122
|
-
String(screen.getByText(text).className)
|
|
123
|
-
.split(/\s+/)
|
|
124
|
-
.find((name) => name.startsWith("_col-"));
|
|
124
|
+
const toneOf = (text: string) => screen.getByText(text).getAttribute("data-list-tone");
|
|
125
125
|
|
|
126
|
-
it("
|
|
126
|
+
it("carries the error tone on the title alone, and marks the row", () => {
|
|
127
127
|
const { container } = renderWithProviders(
|
|
128
128
|
<>
|
|
129
129
|
<ListRow title="Rename" />
|
|
130
130
|
<ListRow title="Delete account" subtitle="This can't be undone" destructive />
|
|
131
131
|
</>,
|
|
132
132
|
);
|
|
133
|
-
expect(
|
|
134
|
-
expect(
|
|
135
|
-
expect(
|
|
133
|
+
expect(toneOf("Delete account")).toBe("error");
|
|
134
|
+
expect(toneOf("Rename")).toBeNull();
|
|
135
|
+
expect(toneOf("This can't be undone")).toBeNull();
|
|
136
136
|
expect(container.querySelectorAll("[data-destructive]")).toHaveLength(1);
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
-
it("hands the error
|
|
139
|
+
it("hands the error tone to the leading glyph", () => {
|
|
140
140
|
const { container } = renderWithProviders(
|
|
141
141
|
<ListRow icon={<svg data-testid="glyph" />} title="Sign out" destructive />,
|
|
142
142
|
);
|
|
143
|
-
|
|
144
|
-
expect(String(icon.className)).toMatch(/(^|\s)_col-red11(\s|$)/);
|
|
143
|
+
expect(slot(container, "icon")!.getAttribute("data-list-tone")).toBe("error");
|
|
145
144
|
});
|
|
146
145
|
});
|
|
@@ -2,8 +2,15 @@ import { action } from "@multiplatform.one/storybook";
|
|
|
2
2
|
import type { Meta, StoryObj } from "@storybook/react-native-web-vite";
|
|
3
3
|
import {
|
|
4
4
|
AirplaneTiltIcon,
|
|
5
|
+
ArrowSquareOutIcon,
|
|
5
6
|
ArrowsClockwiseIcon,
|
|
6
7
|
BellIcon,
|
|
8
|
+
CertificateIcon,
|
|
9
|
+
CubeIcon,
|
|
10
|
+
FolderIcon,
|
|
11
|
+
HeartbeatIcon,
|
|
12
|
+
KeyIcon,
|
|
13
|
+
PlugsConnectedIcon,
|
|
7
14
|
SignOutIcon,
|
|
8
15
|
TrashIcon,
|
|
9
16
|
WifiHighIcon,
|
|
@@ -109,3 +116,108 @@ export const Destructive: Story = {
|
|
|
109
116
|
</YStack>
|
|
110
117
|
),
|
|
111
118
|
};
|
|
119
|
+
|
|
120
|
+
export const Tone: Story = {
|
|
121
|
+
render: () => (
|
|
122
|
+
<YStack width="100%" maxWidth={390} gap="$4">
|
|
123
|
+
<ListGroup aria-label="Machine" title="arrakis">
|
|
124
|
+
<ListGroupItem onPress={action("row:health")}>
|
|
125
|
+
<ListRow
|
|
126
|
+
icon={<HeartbeatIcon />}
|
|
127
|
+
title="Unreachable"
|
|
128
|
+
titleTone="error"
|
|
129
|
+
subtitle="Last seen 3 days ago"
|
|
130
|
+
disclosure
|
|
131
|
+
/>
|
|
132
|
+
</ListGroupItem>
|
|
133
|
+
<ListGroupItem onPress={action("row:certificate")}>
|
|
134
|
+
<ListRow
|
|
135
|
+
icon={<CertificateIcon />}
|
|
136
|
+
title="Certificate expiring"
|
|
137
|
+
titleTone="warning"
|
|
138
|
+
subtitle="In 3 days"
|
|
139
|
+
disclosure
|
|
140
|
+
/>
|
|
141
|
+
</ListGroupItem>
|
|
142
|
+
<ListGroupItem onPress={action("row:tunnel")}>
|
|
143
|
+
<ListRow
|
|
144
|
+
icon={<PlugsConnectedIcon />}
|
|
145
|
+
title="Tunnel up"
|
|
146
|
+
titleTone="success"
|
|
147
|
+
subtitle="Since 09:12"
|
|
148
|
+
/>
|
|
149
|
+
</ListGroupItem>
|
|
150
|
+
<ListGroupItem onPress={action("row:run")}>
|
|
151
|
+
<ListRow icon={<ArrowSquareOutIcon />} title="Latest run" titleTone="accent" disclosure />
|
|
152
|
+
</ListGroupItem>
|
|
153
|
+
</ListGroup>
|
|
154
|
+
<ListGroup
|
|
155
|
+
aria-label="Sessions"
|
|
156
|
+
title="Sessions"
|
|
157
|
+
footer="A tone on the line that reports it."
|
|
158
|
+
>
|
|
159
|
+
<ListGroupItem onPress={action("row:session-failed")}>
|
|
160
|
+
<ListRow
|
|
161
|
+
title="nightly-sweep"
|
|
162
|
+
subtitle="Failed after 4 minutes"
|
|
163
|
+
subtitleTone="error"
|
|
164
|
+
meta="02:14"
|
|
165
|
+
/>
|
|
166
|
+
</ListGroupItem>
|
|
167
|
+
<ListGroupItem onPress={action("row:session-stale")}>
|
|
168
|
+
<ListRow
|
|
169
|
+
title="batch-69"
|
|
170
|
+
subtitle="Queued 41 minutes"
|
|
171
|
+
subtitleTone="warning"
|
|
172
|
+
meta="09:33"
|
|
173
|
+
/>
|
|
174
|
+
</ListGroupItem>
|
|
175
|
+
<ListGroupItem onPress={action("row:session-done")}>
|
|
176
|
+
<ListRow title="spec-appends" subtitle="Merged" subtitleTone="success" meta="11:02" />
|
|
177
|
+
</ListGroupItem>
|
|
178
|
+
</ListGroup>
|
|
179
|
+
<ListGroup aria-label="Danger">
|
|
180
|
+
<ListGroupItem onPress={action("row:delete-machine")}>
|
|
181
|
+
<ListRow icon={<TrashIcon />} title="Delete machine" destructive />
|
|
182
|
+
</ListGroupItem>
|
|
183
|
+
</ListGroup>
|
|
184
|
+
</YStack>
|
|
185
|
+
),
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export const MachineText: Story = {
|
|
189
|
+
render: () => (
|
|
190
|
+
<YStack width="100%" maxWidth={390}>
|
|
191
|
+
<ListGroup aria-label="Machine text" title="Machine text" footer="An id reads as written.">
|
|
192
|
+
<ListGroupItem onPress={action("row:key")}>
|
|
193
|
+
<ListRow
|
|
194
|
+
icon={<KeyIcon />}
|
|
195
|
+
title="SHA256:9f2b7c1e4a"
|
|
196
|
+
titleMono
|
|
197
|
+
subtitle="Signing key"
|
|
198
|
+
disclosure
|
|
199
|
+
/>
|
|
200
|
+
</ListGroupItem>
|
|
201
|
+
<ListGroupItem onPress={action("row:store")}>
|
|
202
|
+
<ListRow
|
|
203
|
+
icon={<FolderIcon />}
|
|
204
|
+
title="Session store"
|
|
205
|
+
subtitle="~/.drover/state/sessions"
|
|
206
|
+
subtitleMono
|
|
207
|
+
disclosure
|
|
208
|
+
/>
|
|
209
|
+
</ListGroupItem>
|
|
210
|
+
<ListGroupItem onPress={action("row:digest")}>
|
|
211
|
+
<ListRow
|
|
212
|
+
icon={<CubeIcon />}
|
|
213
|
+
title="sha256:0ab41d"
|
|
214
|
+
titleMono
|
|
215
|
+
subtitle="Missing from registry"
|
|
216
|
+
subtitleTone="error"
|
|
217
|
+
disclosure
|
|
218
|
+
/>
|
|
219
|
+
</ListGroupItem>
|
|
220
|
+
</ListGroup>
|
|
221
|
+
</YStack>
|
|
222
|
+
),
|
|
223
|
+
};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FZ-10733: a settings row marks state in the line that carries it, so
|
|
3
|
+
* `titleTone` / `subtitleTone` name an intent and the row resolves the ink.
|
|
4
|
+
*
|
|
5
|
+
* A semantic tone resolves on the intent's own hue sub-theme (`light_error`,
|
|
6
|
+
* `light_warning`, `light_success`), and those themes exist only in MPO's own
|
|
7
|
+
* config: rendered under the stock test config a tone would resolve on the
|
|
8
|
+
* base ramp and a green spec here would prove nothing. So every case renders
|
|
9
|
+
* under MPO's theme, and the ink is read from the theme ACTIVE AT THE RUN
|
|
10
|
+
* rather than from a class name — a tone whose sub-theme never applied paints
|
|
11
|
+
* grey while emitting exactly the same `_col-color11` class.
|
|
12
|
+
*
|
|
13
|
+
* That the intent ink step itself clears AA on every page surface in both
|
|
14
|
+
* schemes is theme's own sweep (`colorRules.spec.ts`), not repeated here.
|
|
15
|
+
*/
|
|
16
|
+
import { cleanup, screen } from "@testing-library/react";
|
|
17
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
18
|
+
import { createDefaultThemeConfig } from "@multiplatform.one/theme";
|
|
19
|
+
import type { ReactElement } from "react";
|
|
20
|
+
import { TamaguiProvider, useTheme } from "tamagui";
|
|
21
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
22
|
+
import { ListGroup, ListGroupItem, ListRow, type ListRowProps } from "./List";
|
|
23
|
+
|
|
24
|
+
const config = createDefaultThemeConfig({});
|
|
25
|
+
|
|
26
|
+
afterEach(cleanup);
|
|
27
|
+
|
|
28
|
+
function renderMpo(ui: ReactElement) {
|
|
29
|
+
return renderWithProviders(
|
|
30
|
+
<TamaguiProvider config={config.tamagui} defaultTheme="light">
|
|
31
|
+
{ui}
|
|
32
|
+
</TamaguiProvider>,
|
|
33
|
+
{ tamagui: false },
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Renders the intent ink the theme at this point in the tree resolves. */
|
|
38
|
+
function InkProbe() {
|
|
39
|
+
const theme = useTheme() as unknown as Record<string, { val?: unknown } | undefined>;
|
|
40
|
+
return <>{String(theme.color11?.val ?? "")}</>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The ink a title run resolves, read through the probe standing in its slot. */
|
|
44
|
+
function titleInk(props: Omit<ListRowProps, "title">): string {
|
|
45
|
+
const view = renderMpo(<ListRow title={<InkProbe />} {...props} />);
|
|
46
|
+
const ink = view.container.textContent ?? "";
|
|
47
|
+
view.unmount();
|
|
48
|
+
return ink;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function colorAtom(el: Element): string | undefined {
|
|
52
|
+
return String((el as HTMLElement).className || "")
|
|
53
|
+
.split(/\s+/)
|
|
54
|
+
.find((name) => name.startsWith("_col-"));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Every style atom but the ink: what a tone must leave exactly as it was. */
|
|
58
|
+
function styleAtoms(el: Element): string[] {
|
|
59
|
+
return String((el as HTMLElement).className || "")
|
|
60
|
+
.split(/\s+/)
|
|
61
|
+
.filter((name) => name.startsWith("_") && !name.startsWith("_col-"))
|
|
62
|
+
.sort();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function voice(el: Element): string {
|
|
66
|
+
return String((el as HTMLElement).className || "") + (el.getAttribute("style") ?? "");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe("ListRow tone (FZ-10733: the title and subtitle report their own state)", () => {
|
|
70
|
+
it("resolves each semantic tone on its own hue, and an untoned run on the base ink", () => {
|
|
71
|
+
const base = titleInk({});
|
|
72
|
+
const inks = {
|
|
73
|
+
base,
|
|
74
|
+
error: titleInk({ titleTone: "error" }),
|
|
75
|
+
warning: titleInk({ titleTone: "warning" }),
|
|
76
|
+
success: titleInk({ titleTone: "success" }),
|
|
77
|
+
};
|
|
78
|
+
expect(base).not.toBe("");
|
|
79
|
+
expect(new Set(Object.values(inks)).size).toBe(4);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("leaves an accent tone on the base theme, where the accent ramp tracks the tint", () => {
|
|
83
|
+
expect(titleInk({ titleTone: "accent" })).toBe(titleInk({}));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("paints a toned run at the intent ink step and publishes the tone it took", () => {
|
|
87
|
+
renderMpo(
|
|
88
|
+
<ListRow
|
|
89
|
+
title="Unreachable"
|
|
90
|
+
titleTone="error"
|
|
91
|
+
subtitle="last seen 3 days ago"
|
|
92
|
+
subtitleTone="warning"
|
|
93
|
+
/>,
|
|
94
|
+
);
|
|
95
|
+
const title = screen.getByText("Unreachable");
|
|
96
|
+
const subtitle = screen.getByText("last seen 3 days ago");
|
|
97
|
+
expect(title.getAttribute("data-list-tone")).toBe("error");
|
|
98
|
+
expect(colorAtom(title)).toBe("_col-color11");
|
|
99
|
+
expect(subtitle.getAttribute("data-list-tone")).toBe("warning");
|
|
100
|
+
expect(colorAtom(subtitle)).toBe("_col-color11");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("takes the shared accent-on-surface ink for an accent tone, not the intent step", () => {
|
|
104
|
+
renderMpo(<ListRow title="Open run" titleTone="accent" />);
|
|
105
|
+
const title = screen.getByText("Open run");
|
|
106
|
+
expect(title.getAttribute("data-list-tone")).toBe("accent");
|
|
107
|
+
expect(colorAtom(title)).not.toBe("_col-color11");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("tones one run without touching the other", () => {
|
|
111
|
+
renderMpo(<ListRow title="arrakis" titleTone="error" subtitle="healthy" />);
|
|
112
|
+
expect(screen.getByText("arrakis").getAttribute("data-list-tone")).toBe("error");
|
|
113
|
+
expect(screen.getByText("healthy").getAttribute("data-list-tone")).toBeNull();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("changes the ink and nothing else: a toned run keeps every other style atom", () => {
|
|
117
|
+
const plain = renderMpo(<ListRow title="arrakis" />);
|
|
118
|
+
const atoms = styleAtoms(screen.getByText("arrakis"));
|
|
119
|
+
plain.unmount();
|
|
120
|
+
renderMpo(<ListRow title="arrakis" titleTone="warning" />);
|
|
121
|
+
expect(styleAtoms(screen.getByText("arrakis"))).toEqual(atoms);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("ListRow tone and destructive (one path from a state to an ink)", () => {
|
|
126
|
+
it("resolves destructive to the very ink titleTone error resolves, so the two can't drift", () => {
|
|
127
|
+
const destructiveInk = titleInk({ destructive: true });
|
|
128
|
+
expect(destructiveInk).toBe(titleInk({ titleTone: "error" }));
|
|
129
|
+
expect(destructiveInk).not.toBe(titleInk({}));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("publishes the error tone for a destructive row, on the title and the leading glyph", () => {
|
|
133
|
+
const { container } = renderMpo(
|
|
134
|
+
<ListRow
|
|
135
|
+
icon={<svg data-testid="glyph" />}
|
|
136
|
+
title="Delete machine"
|
|
137
|
+
subtitle="This can't be undone"
|
|
138
|
+
destructive
|
|
139
|
+
/>,
|
|
140
|
+
);
|
|
141
|
+
const title = screen.getByText("Delete machine");
|
|
142
|
+
expect(title.getAttribute("data-list-tone")).toBe("error");
|
|
143
|
+
expect(colorAtom(title)).toBe("_col-color11");
|
|
144
|
+
expect(container.querySelector('[data-list-slot="icon"]')!.getAttribute("data-list-tone")).toBe(
|
|
145
|
+
"error",
|
|
146
|
+
);
|
|
147
|
+
expect(screen.getByText("This can't be undone").getAttribute("data-list-tone")).toBeNull();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("lets destructive win over a title tone: the row's action outranks one line's report", () => {
|
|
151
|
+
renderMpo(<ListRow title="Delete machine" titleTone="warning" destructive />);
|
|
152
|
+
expect(screen.getByText("Delete machine").getAttribute("data-list-tone")).toBe("error");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("still tones the subtitle under destructive, which claims the title alone", () => {
|
|
156
|
+
renderMpo(
|
|
157
|
+
<ListRow
|
|
158
|
+
title="Delete machine"
|
|
159
|
+
subtitle="19 sessions go with it"
|
|
160
|
+
subtitleTone="warning"
|
|
161
|
+
destructive
|
|
162
|
+
/>,
|
|
163
|
+
);
|
|
164
|
+
expect(screen.getByText("19 sessions go with it").getAttribute("data-list-tone")).toBe(
|
|
165
|
+
"warning",
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe("ListRow tone precedence (a row reads as its strongest state)", () => {
|
|
171
|
+
it("drops both tones on a done row, which reads finished rather than toned", () => {
|
|
172
|
+
renderMpo(
|
|
173
|
+
<ListRow
|
|
174
|
+
title="Book the venue"
|
|
175
|
+
titleTone="warning"
|
|
176
|
+
subtitle="was due Friday"
|
|
177
|
+
subtitleTone="error"
|
|
178
|
+
done
|
|
179
|
+
/>,
|
|
180
|
+
);
|
|
181
|
+
expect(screen.getByText("Book the venue").getAttribute("data-list-tone")).toBeNull();
|
|
182
|
+
expect(screen.getByText("was due Friday").getAttribute("data-list-tone")).toBeNull();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("keeps the selection ink over a tone, so a selected row stays one colour", () => {
|
|
186
|
+
renderMpo(
|
|
187
|
+
<ListGroup>
|
|
188
|
+
<ListGroupItem selected onPress={() => {}}>
|
|
189
|
+
<ListRow title="arrakis" titleTone="error" />
|
|
190
|
+
</ListGroupItem>
|
|
191
|
+
</ListGroup>,
|
|
192
|
+
);
|
|
193
|
+
expect(screen.getByText("arrakis").getAttribute("data-list-tone")).toBeNull();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("ListRow mono (LC-221: machine text reads as written)", () => {
|
|
198
|
+
it("renders a mono run in the mono family and leaves the other run in the body voice", () => {
|
|
199
|
+
renderMpo(
|
|
200
|
+
<ListRow title="/var/log/drover.log" titleMono subtitle="12 KB, read by two sessions" />,
|
|
201
|
+
);
|
|
202
|
+
const title = screen.getByText("/var/log/drover.log");
|
|
203
|
+
const subtitle = screen.getByText("12 KB, read by two sessions");
|
|
204
|
+
expect(voice(title)).toMatch(/mono/i);
|
|
205
|
+
expect(voice(subtitle)).not.toMatch(/mono/i);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("renders a mono subtitle in the mono family, with the title left alone", () => {
|
|
209
|
+
renderMpo(<ListRow title="Session store" subtitle="~/.drover/state/sessions" subtitleMono />);
|
|
210
|
+
expect(voice(screen.getByText("~/.drover/state/sessions"))).toMatch(/mono/i);
|
|
211
|
+
expect(voice(screen.getByText("Session store"))).not.toMatch(/mono/i);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("carries a tone and the mono family on the same run", () => {
|
|
215
|
+
renderMpo(<ListRow title="sha256:9f2b" titleMono titleTone="error" />);
|
|
216
|
+
const title = screen.getByText("sha256:9f2b");
|
|
217
|
+
expect(voice(title)).toMatch(/mono/i);
|
|
218
|
+
expect(title.getAttribute("data-list-tone")).toBe("error");
|
|
219
|
+
expect(colorAtom(title)).toBe("_col-color11");
|
|
220
|
+
});
|
|
221
|
+
});
|