@multiplatform.one/components 8.0.0 → 8.1.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/ChatTurn/index.cjs +105 -0
- package/dist/cjs/ChatTurn/index.native.js +109 -0
- package/dist/cjs/ChatTurn/index.native.js.map +1 -0
- package/dist/cjs/Chip/index.cjs +50 -0
- package/dist/cjs/Chip/index.native.js +52 -1
- package/dist/cjs/Chip/index.native.js.map +1 -1
- package/dist/cjs/DropDownPanel/index.cjs +101 -0
- package/dist/cjs/DropDownPanel/index.native.js +109 -0
- package/dist/cjs/DropDownPanel/index.native.js.map +1 -0
- package/dist/cjs/SwipeDismissRow/index.cjs +137 -0
- package/dist/cjs/SwipeDismissRow/index.native.js +149 -0
- package/dist/cjs/SwipeDismissRow/index.native.js.map +1 -0
- package/dist/cjs/index.cjs +6 -0
- package/dist/cjs/index.native.js +6 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Accordion/index.native.js.map +1 -1
- package/dist/esm/AnimateHeight/index.native.js.map +1 -1
- package/dist/esm/Avatar/getInitials.native.js.map +1 -1
- package/dist/esm/Avatar/index.native.js.map +1 -1
- package/dist/esm/Badge/index.native.js.map +1 -1
- package/dist/esm/Button.native.js.map +1 -1
- package/dist/esm/Carousel/geometry.native.js.map +1 -1
- package/dist/esm/Carousel/index.native.js.map +1 -1
- package/dist/esm/ChatTurn/index.mjs +80 -0
- package/dist/esm/ChatTurn/index.mjs.map +1 -0
- package/dist/esm/ChatTurn/index.native.js +81 -0
- package/dist/esm/ChatTurn/index.native.js.map +1 -0
- package/dist/esm/CheckGlyph/MenuCheckColumn.native.js.map +1 -1
- package/dist/esm/CheckGlyph/index.native.js.map +1 -1
- package/dist/esm/Chip/index.mjs +50 -0
- package/dist/esm/Chip/index.mjs.map +1 -1
- package/dist/esm/Chip/index.native.js +52 -1
- package/dist/esm/Chip/index.native.js.map +1 -1
- package/dist/esm/ChoiceChips/index.native.js.map +1 -1
- package/dist/esm/Collapsible.native.js.map +1 -1
- package/dist/esm/ContextMenu/index.native.js.map +1 -1
- package/dist/esm/CopyField/CopyMenuButton.native.js.map +1 -1
- package/dist/esm/CopyField/index.native.js.map +1 -1
- package/dist/esm/Dialog.native.js.map +1 -1
- package/dist/esm/Diff/diff.native.js.map +1 -1
- package/dist/esm/Diff/index.native.js.map +1 -1
- package/dist/esm/DotIndicator/index.native.js.map +1 -1
- package/dist/esm/DropDownPanel/index.mjs +76 -0
- package/dist/esm/DropDownPanel/index.mjs.map +1 -0
- package/dist/esm/DropDownPanel/index.native.js +81 -0
- package/dist/esm/DropDownPanel/index.native.js.map +1 -0
- package/dist/esm/DropdownMenu/index.native.js.map +1 -1
- package/dist/esm/DropdownMenu/menuSettle.native.js.map +1 -1
- package/dist/esm/ElapsedProgress/index.native.js.map +1 -1
- package/dist/esm/ErrorBoundary/index.native.js.map +1 -1
- package/dist/esm/Heading.native.js.map +1 -1
- package/dist/esm/Kbd/index.native.js.map +1 -1
- package/dist/esm/Kbd/keys.native.js.map +1 -1
- package/dist/esm/Lightbox/MediaControl.native.js.map +1 -1
- package/dist/esm/Lightbox/index.gnome.native.js.map +1 -1
- package/dist/esm/Lightbox/shared.native.js.map +1 -1
- package/dist/esm/Lightbox/useLightbox.native.js.map +1 -1
- package/dist/esm/MachineLiteral/index.native.js.map +1 -1
- package/dist/esm/Material/index.native.js.map +1 -1
- package/dist/esm/Meter/index.native.js.map +1 -1
- package/dist/esm/Meter/meter.native.js.map +1 -1
- package/dist/esm/OverflowRow/index.native.js.map +1 -1
- package/dist/esm/Pagination.native.js.map +1 -1
- package/dist/esm/Popover.native.js.map +1 -1
- package/dist/esm/ProgressSteps/index.native.js.map +1 -1
- package/dist/esm/Quote/index.native.js.map +1 -1
- package/dist/esm/SchemeToggle/index.native.js.map +1 -1
- package/dist/esm/ScrollView/revealFocusedField.native.js.map +1 -1
- package/dist/esm/Separator/index.native.js.map +1 -1
- package/dist/esm/Sheet.native.js.map +1 -1
- package/dist/esm/SheetModal/SheetHeader.native.js.map +1 -1
- package/dist/esm/SheetModal/SheetNavigation.native.js.map +1 -1
- package/dist/esm/SheetModal/detents.native.js.map +1 -1
- package/dist/esm/SheetModal/useSheetFrameFocus.native.js.map +1 -1
- package/dist/esm/Skeleton/index.native.js.map +1 -1
- package/dist/esm/SkipLink/index.native.js.map +1 -1
- package/dist/esm/SortableList/SortableHandle.native.js.map +1 -1
- package/dist/esm/SortableList/index.native.js.map +1 -1
- package/dist/esm/SortableList/useSortableRows.native.js.map +1 -1
- package/dist/esm/SortableList/useUserOrder.native.js.map +1 -1
- package/dist/esm/SwipeDismissRow/index.mjs +110 -0
- package/dist/esm/SwipeDismissRow/index.mjs.map +1 -0
- package/dist/esm/SwipeDismissRow/index.native.js +119 -0
- package/dist/esm/SwipeDismissRow/index.native.js.map +1 -0
- package/dist/esm/Tabs/index.native.js.map +1 -1
- package/dist/esm/Text.native.js.map +1 -1
- package/dist/esm/ThemePresetPicker/index.native.js.map +1 -1
- package/dist/esm/Toast/index.native.js.map +1 -1
- package/dist/esm/Toast/store.native.js.map +1 -1
- package/dist/esm/Tooltip/nativePress.native.js.map +1 -1
- package/dist/esm/Tooltip/tooltipShared.native.js.map +1 -1
- package/dist/esm/TreeSelect/index.native.js.map +1 -1
- package/dist/esm/TreeSelect/treeSelectModel.native.js.map +1 -1
- package/dist/esm/Video/PlayerChrome.native.js.map +1 -1
- package/dist/esm/Video/VideoFrame.native.js.map +1 -1
- package/dist/esm/Video/types.native.js.map +1 -1
- package/dist/esm/Wheel/index.native.js.map +1 -1
- package/dist/esm/Wizard/index.native.js.map +1 -1
- package/dist/esm/actions/ActionBar.native.js.map +1 -1
- package/dist/esm/actions/DangerSection.native.js.map +1 -1
- package/dist/esm/actions/DestructiveAction.native.js.map +1 -1
- package/dist/esm/actions/HeaderActions.native.js.map +1 -1
- package/dist/esm/actions/StandardAction.native.js.map +1 -1
- package/dist/esm/actions/devWarn.native.js.map +1 -1
- package/dist/esm/actions/index.native.js.map +1 -1
- package/dist/esm/actions/severity.native.js.map +1 -1
- package/dist/esm/appShell/AppShell.native.js.map +1 -1
- package/dist/esm/appShell/BottomChromeClearance.native.js.map +1 -1
- package/dist/esm/appShell/Dock.native.js.map +1 -1
- package/dist/esm/appShell/MpoTabHost.native.js.map +1 -1
- package/dist/esm/appShell/ScopeMenu.native.js.map +1 -1
- package/dist/esm/appShell/SettingsSplit.native.js.map +1 -1
- package/dist/esm/appShell/Springboard.native.js.map +1 -1
- package/dist/esm/appShell/SystemBar.native.js.map +1 -1
- package/dist/esm/appShell/TabBar.native.js.map +1 -1
- package/dist/esm/appShell/appTile.native.js.map +1 -1
- package/dist/esm/appShell/bottomChrome.native.js.map +1 -1
- package/dist/esm/appShell/index.native.js.map +1 -1
- package/dist/esm/appShell/systemBarFit.native.js.map +1 -1
- package/dist/esm/charts/Axis.native.js.map +1 -1
- package/dist/esm/charts/BarChart.native.js.map +1 -1
- package/dist/esm/charts/ChartDataView.native.js.map +1 -1
- package/dist/esm/charts/ChartSurface.native.js.map +1 -1
- package/dist/esm/charts/LineChart.native.js.map +1 -1
- package/dist/esm/charts/PieChart.native.js.map +1 -1
- package/dist/esm/charts/Sparkline.native.js.map +1 -1
- package/dist/esm/charts/accessibility.native.js.map +1 -1
- package/dist/esm/charts/chartHeight.native.js.map +1 -1
- package/dist/esm/charts/composeChart.native.js.map +1 -1
- package/dist/esm/charts/index.native.js.map +1 -1
- package/dist/esm/charts/math.native.js.map +1 -1
- package/dist/esm/charts/series.native.js.map +1 -1
- package/dist/esm/charts/svg.native.js.map +1 -1
- package/dist/esm/charts/types.native.js.map +1 -1
- package/dist/esm/charts/useChartTheme.native.js.map +1 -1
- package/dist/esm/code/Code/index.native.js.map +1 -1
- package/dist/esm/code/CodeBlock/index.native.js.map +1 -1
- package/dist/esm/code/HighlightedCode/index.native.js.map +1 -1
- package/dist/esm/code/Highlighter/houseSyntaxTheme.native.js.map +1 -1
- package/dist/esm/code/Highlighter/index.native.js.map +1 -1
- package/dist/esm/code/Highlighter/namedGroupMatchAll.native.js.map +1 -1
- package/dist/esm/code/LogView.native.js.map +1 -1
- package/dist/esm/code/Pre/index.native.js.map +1 -1
- package/dist/esm/code/index.native.js.map +1 -1
- package/dist/esm/componentColors.native.js.map +1 -1
- package/dist/esm/feedback/ConfirmDialog.native.js.map +1 -1
- package/dist/esm/feedback/NotifyHost.native.js.map +1 -1
- package/dist/esm/feedback/copy.native.js.map +1 -1
- package/dist/esm/feedback/index.native.js.map +1 -1
- package/dist/esm/feedback/notify.native.js.map +1 -1
- package/dist/esm/feedback/route.native.js.map +1 -1
- package/dist/esm/feedback/store.native.js.map +1 -1
- package/dist/esm/formLayouts/FormLayouts.native.js.map +1 -1
- package/dist/esm/formLayouts/PreferencePanel.native.js.map +1 -1
- package/dist/esm/formLayouts/index.native.js.map +1 -1
- package/dist/esm/hooks/index.native.js.map +1 -1
- package/dist/esm/hooks/useClipboard.native.js.map +1 -1
- package/dist/esm/hooks/useDocumentTitle.native.js.map +1 -1
- package/dist/esm/hooks/useHoldCue.native.js.map +1 -1
- package/dist/esm/icons/CheckRegular.native.js.map +1 -1
- package/dist/esm/icons/MinusRegular.native.js.map +1 -1
- package/dist/esm/icons/index.native.js.map +1 -1
- package/dist/esm/icons/lucide.native.js.map +1 -1
- package/dist/esm/icons/themed.native.js.map +1 -1
- package/dist/esm/images/Image/ImageFrame.native.js.map +1 -1
- package/dist/esm/images/Image/framing.native.js.map +1 -1
- package/dist/esm/images/Image/mediaRadius.native.js.map +1 -1
- package/dist/esm/images/Image/shared.native.js.map +1 -1
- package/dist/esm/images/Image/types.native.js.map +1 -1
- package/dist/esm/images/index.native.js.map +1 -1
- package/dist/esm/index.gnome.native.js.map +1 -1
- package/dist/esm/index.mjs +5 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +5 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/knobImmuneExports.native.js.map +1 -1
- package/dist/esm/layouts/AsyncBoundary.native.js.map +1 -1
- package/dist/esm/layouts/Debug/index.native.js.map +1 -1
- package/dist/esm/layouts/EmptyState.native.js.map +1 -1
- package/dist/esm/layouts/IdentityPlate.native.js.map +1 -1
- package/dist/esm/layouts/KeyboardAvoidingWrapper/behavior.native.js.map +1 -1
- package/dist/esm/layouts/PageTemplates.native.js.map +1 -1
- package/dist/esm/layouts/PaneScaffold.native.js.map +1 -1
- package/dist/esm/layouts/SafeAreaWrapper/insets.native.js.map +1 -1
- package/dist/esm/layouts/StatusDot.native.js.map +1 -1
- package/dist/esm/layouts/StatusGlyphStrip.native.js.map +1 -1
- package/dist/esm/layouts/ViewSwitcher.native.js.map +1 -1
- package/dist/esm/layouts/asyncFailure.native.js.map +1 -1
- package/dist/esm/layouts/attachments.native.js.map +1 -1
- package/dist/esm/layouts/barTitleSpan.native.js.map +1 -1
- package/dist/esm/layouts/bottomAccessory.native.js.map +1 -1
- package/dist/esm/layouts/breadcrumbs.native.js.map +1 -1
- package/dist/esm/layouts/index.native.js.map +1 -1
- package/dist/esm/layouts/page.native.js.map +1 -1
- package/dist/esm/layouts/pageHeadingScope.native.js.map +1 -1
- package/dist/esm/layouts/screenScroll.native.js.map +1 -1
- package/dist/esm/layouts/shellSidebarSlot.native.js.map +1 -1
- package/dist/esm/layouts/sidebar.native.js.map +1 -1
- package/dist/esm/layouts/tags.native.js.map +1 -1
- package/dist/esm/layouts/timeline.native.js.map +1 -1
- package/dist/esm/layouts/toolbar.native.js.map +1 -1
- package/dist/esm/shared/actionScan.native.js.map +1 -1
- package/dist/esm/shared/i18n.native.js.map +1 -1
- package/dist/esm/shared/restoreRetries.native.js.map +1 -1
- package/dist/esm/shared/t.native.js.map +1 -1
- package/dist/esm/shared/textRidesText.native.js.map +1 -1
- package/dist/esm/shared/useReturnFocusOnClose.native.js.map +1 -1
- package/dist/esm/surfaces.native.js.map +1 -1
- package/dist/esm/tamagui.native.js.map +1 -1
- package/dist/esm/testSetup.native.js.map +1 -1
- package/dist/esm/utils/unwrapText.native.js.map +1 -1
- package/dist/esm/views/Calendar.native.js.map +1 -1
- package/dist/esm/views/CardGrid.native.js.map +1 -1
- package/dist/esm/views/Dashboard.native.js.map +1 -1
- package/dist/esm/views/Gantt.native.js.map +1 -1
- package/dist/esm/views/GanttDateGrip.native.js.map +1 -1
- package/dist/esm/views/ImageGrid.native.js.map +1 -1
- package/dist/esm/views/List.native.js.map +1 -1
- package/dist/esm/views/ListGroup.native.js.map +1 -1
- package/dist/esm/views/ListRow.native.js.map +1 -1
- package/dist/esm/views/Matrix.native.js.map +1 -1
- package/dist/esm/views/ReportBuilder.native.js.map +1 -1
- package/dist/esm/views/ShortcutCard.native.js.map +1 -1
- package/dist/esm/views/TreeView.native.js.map +1 -1
- package/dist/esm/views/calendarMath.native.js.map +1 -1
- package/dist/esm/views/ganttIntervals.native.js.map +1 -1
- package/dist/esm/views/ganttMath.native.js.map +1 -1
- package/dist/esm/views/index.native.js.map +1 -1
- package/dist/esm/views/kanbanDnd.native.js.map +1 -1
- package/dist/esm/views/matrixMath.native.js.map +1 -1
- package/dist/esm/views/sameNameScope.native.js.map +1 -1
- package/dist/esm/views/treeViewDnd.native.js.map +1 -1
- package/dist/esm/views/treeViewLayout.native.js.map +1 -1
- package/dist/esm/views/treeViewMotion.native.js.map +1 -1
- package/dist/esm/views/treeViewReveal.native.js.map +1 -1
- package/dist/esm/views/usePageFlowLoadMore.native.js.map +1 -1
- package/dist/esm/views/widgetChrome.native.js.map +1 -1
- package/dist/jsx/ChatTurn/index.mjs +80 -0
- package/dist/jsx/ChatTurn/index.mjs.map +1 -0
- package/dist/jsx/ChatTurn/index.native.js +109 -0
- package/dist/jsx/ChatTurn/index.native.js.map +1 -0
- package/dist/jsx/Chip/index.mjs +50 -0
- package/dist/jsx/Chip/index.mjs.map +1 -1
- package/dist/jsx/Chip/index.native.js +52 -1
- package/dist/jsx/Chip/index.native.js.map +1 -1
- package/dist/jsx/DropDownPanel/index.mjs +76 -0
- package/dist/jsx/DropDownPanel/index.mjs.map +1 -0
- package/dist/jsx/DropDownPanel/index.native.js +109 -0
- package/dist/jsx/DropDownPanel/index.native.js.map +1 -0
- package/dist/jsx/SwipeDismissRow/index.mjs +110 -0
- package/dist/jsx/SwipeDismissRow/index.mjs.map +1 -0
- package/dist/jsx/SwipeDismissRow/index.native.js +149 -0
- package/dist/jsx/SwipeDismissRow/index.native.js.map +1 -0
- package/dist/jsx/index.js +5 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +5 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/index.native.js +6 -0
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +7 -7
- package/src/ChatTurn/ChatTurn.spec.tsx +75 -0
- package/src/ChatTurn/ChatTurn.stories.tsx +61 -0
- package/src/ChatTurn/index.tsx +91 -0
- package/src/Chip/Chip.stories.tsx +38 -1
- package/src/Chip/Chip.trailingToggle.spec.tsx +99 -0
- package/src/Chip/index.tsx +72 -0
- package/src/DropDownPanel/DropDownPanel.spec.tsx +55 -0
- package/src/DropDownPanel/DropDownPanel.stories.tsx +69 -0
- package/src/DropDownPanel/index.tsx +87 -0
- package/src/SwipeDismissRow/SwipeDismissRow.spec.tsx +48 -0
- package/src/SwipeDismissRow/SwipeDismissRow.stories.tsx +59 -0
- package/src/SwipeDismissRow/index.tsx +150 -0
- package/src/index.ts +6 -0
- package/types/ChatTurn/index.d.ts +29 -0
- package/types/ChatTurn/index.d.ts.map +1 -0
- package/types/Chip/index.d.ts +9 -1
- package/types/Chip/index.d.ts.map +1 -1
- package/types/DropDownPanel/index.d.ts +11 -0
- package/types/DropDownPanel/index.d.ts.map +1 -0
- package/types/SwipeDismissRow/index.d.ts +18 -0
- package/types/SwipeDismissRow/index.d.ts.map +1 -0
- package/types/index.d.ts +6 -0
- package/types/index.d.ts.map +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Spinner } from "@multiplatform.one/forms";
|
|
2
|
+
import { Text, useResolvedKnobs } from "@multiplatform.one/theme";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import { YStack } from "tamagui";
|
|
5
|
+
|
|
6
|
+
export type ChatTurnFrom = "user" | "agent";
|
|
7
|
+
|
|
8
|
+
export interface ChatTurnProps {
|
|
9
|
+
/** Who spoke: the agent's text sits on the page, the user's in a bubble at the trailing edge. */
|
|
10
|
+
from: ChatTurnFrom;
|
|
11
|
+
/**
|
|
12
|
+
* A string is the turn's text. Anything else (an image, a file card) is its
|
|
13
|
+
* own bubble: it keeps its own paint and gets no bubble behind it.
|
|
14
|
+
*/
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* The turn is still in flight. A spinner sits over the turn's picture, or
|
|
18
|
+
* under its text when it carries none. No word is drawn beside it.
|
|
19
|
+
*/
|
|
20
|
+
pending?: boolean;
|
|
21
|
+
/** The spinner's accessible name ("Sending"). Without one it reads as loading. */
|
|
22
|
+
pendingLabel?: string;
|
|
23
|
+
/** Anything else under the turn (reactions, a retry). */
|
|
24
|
+
footer?: ReactNode;
|
|
25
|
+
testID?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* One turn of a conversation. The agent's words sit on the page like a
|
|
30
|
+
* document; the user's words are a bubble on the trailing side, at most four
|
|
31
|
+
* fifths of the column, on the theme's soft selected tint. Media is its own
|
|
32
|
+
* bubble on the same side. A turn in flight shows a spinner and no word.
|
|
33
|
+
*/
|
|
34
|
+
export function ChatTurn({ from, children, pending, pendingLabel, footer, testID }: ChatTurnProps) {
|
|
35
|
+
const { knobProps, state } = useResolvedKnobs({ component: "Card" });
|
|
36
|
+
const mine = from === "user";
|
|
37
|
+
const text = typeof children === "string" || typeof children === "number";
|
|
38
|
+
const align = mine ? "flex-end" : "flex-start";
|
|
39
|
+
const spinnerName = pendingLabel ? { "aria-label": pendingLabel } : undefined;
|
|
40
|
+
|
|
41
|
+
let body: ReactNode;
|
|
42
|
+
if (text && mine) {
|
|
43
|
+
body = (
|
|
44
|
+
<YStack
|
|
45
|
+
data-chat-bubble="text"
|
|
46
|
+
maxWidth="80%"
|
|
47
|
+
{...knobProps.panelPadding}
|
|
48
|
+
{...knobProps.borderRadius}
|
|
49
|
+
{...state.selected.surfaceKnobProps}
|
|
50
|
+
borderColor="transparent"
|
|
51
|
+
>
|
|
52
|
+
<Text {...knobProps.body}>{children}</Text>
|
|
53
|
+
</YStack>
|
|
54
|
+
);
|
|
55
|
+
} else if (text) {
|
|
56
|
+
body = <Text {...knobProps.body}>{children}</Text>;
|
|
57
|
+
} else {
|
|
58
|
+
body = (
|
|
59
|
+
<YStack data-chat-bubble="media" maxWidth="80%" position="relative">
|
|
60
|
+
{children}
|
|
61
|
+
{pending ? (
|
|
62
|
+
<YStack
|
|
63
|
+
data-chat-turn-pending="media"
|
|
64
|
+
position="absolute"
|
|
65
|
+
top={0}
|
|
66
|
+
right={0}
|
|
67
|
+
bottom={0}
|
|
68
|
+
left={0}
|
|
69
|
+
alignItems="center"
|
|
70
|
+
justifyContent="center"
|
|
71
|
+
pointerEvents="none"
|
|
72
|
+
>
|
|
73
|
+
<Spinner {...spinnerName} />
|
|
74
|
+
</YStack>
|
|
75
|
+
) : null}
|
|
76
|
+
</YStack>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<YStack data-chat-turn={from} testID={testID} alignItems={align} {...knobProps.gapSm}>
|
|
82
|
+
{body}
|
|
83
|
+
{pending && text ? (
|
|
84
|
+
<YStack data-chat-turn-pending="text">
|
|
85
|
+
<Spinner size="small" {...spinnerName} />
|
|
86
|
+
</YStack>
|
|
87
|
+
) : null}
|
|
88
|
+
{footer}
|
|
89
|
+
</YStack>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { action } from "@multiplatform.one/storybook";
|
|
2
|
-
import { CheckIcon, LightningIcon, TagIcon } from "@phosphor-icons/react";
|
|
2
|
+
import { ArticleIcon, CheckIcon, GaugeIcon, LightningIcon, TagIcon } from "@phosphor-icons/react";
|
|
3
3
|
import type { Meta, StoryObj } from "@storybook/react-native-web-vite";
|
|
4
4
|
import { useState } from "react";
|
|
5
5
|
import { XStack, YStack } from "tamagui";
|
|
@@ -318,3 +318,40 @@ export const AllStates: Story = {
|
|
|
318
318
|
</YStack>
|
|
319
319
|
),
|
|
320
320
|
};
|
|
321
|
+
|
|
322
|
+
function TrailingToggleDemo() {
|
|
323
|
+
const [readMode, setReadMode] = useState(true);
|
|
324
|
+
return (
|
|
325
|
+
<XStack gap="$2" flexWrap="wrap" alignItems="center">
|
|
326
|
+
<Chip
|
|
327
|
+
icon={<GaugeIcon />}
|
|
328
|
+
aria-label="Model"
|
|
329
|
+
onPress={() => action("onPress")("model")}
|
|
330
|
+
trailingToggle={{
|
|
331
|
+
icon: <ArticleIcon />,
|
|
332
|
+
selectedIcon: <ArticleIcon weight="fill" />,
|
|
333
|
+
selected: readMode,
|
|
334
|
+
onToggle: setReadMode,
|
|
335
|
+
label: "Read mode",
|
|
336
|
+
}}
|
|
337
|
+
>
|
|
338
|
+
Opus 5.5 1M
|
|
339
|
+
</Chip>
|
|
340
|
+
<Chip
|
|
341
|
+
icon={<GaugeIcon />}
|
|
342
|
+
trailingToggle={{
|
|
343
|
+
icon: <ArticleIcon />,
|
|
344
|
+
selected: false,
|
|
345
|
+
onToggle: (next) => action("onToggle")(next),
|
|
346
|
+
label: "Read mode",
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
Off
|
|
350
|
+
</Chip>
|
|
351
|
+
</XStack>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export const TrailingToggle: Story = {
|
|
356
|
+
render: () => <TrailingToggleDemo />,
|
|
357
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FZ-10608: a chip can end in a toggle (the Drover model pill's read mode).
|
|
3
|
+
* The pill and the toggle are two targets in one pill; the toggle reports
|
|
4
|
+
* aria-pressed, swaps to its selected glyph and paints the LC-131 tint.
|
|
5
|
+
*/
|
|
6
|
+
import { fireEvent } from "@testing-library/react";
|
|
7
|
+
import { describe, expect, it, vi } from "vitest";
|
|
8
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
9
|
+
import { ArticleIcon, GaugeIcon } from "@phosphor-icons/react";
|
|
10
|
+
import { Chip } from "./index";
|
|
11
|
+
|
|
12
|
+
function toggle(container: HTMLElement): HTMLElement {
|
|
13
|
+
return container.querySelector("[aria-label='Read mode']") as HTMLElement;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("Chip trailingToggle", () => {
|
|
17
|
+
it("renders a pressable toggle after the label that reports its state", () => {
|
|
18
|
+
const result = renderWithProviders(
|
|
19
|
+
<Chip
|
|
20
|
+
icon={<GaugeIcon />}
|
|
21
|
+
trailingToggle={{
|
|
22
|
+
icon: <ArticleIcon />,
|
|
23
|
+
selected: true,
|
|
24
|
+
onToggle: () => {},
|
|
25
|
+
label: "Read mode",
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
Model
|
|
29
|
+
</Chip>,
|
|
30
|
+
);
|
|
31
|
+
const button = toggle(result.container);
|
|
32
|
+
expect(button).not.toBeNull();
|
|
33
|
+
expect(button.getAttribute("aria-pressed")).toBe("true");
|
|
34
|
+
expect(button.getAttribute("data-chip-toggle")).toBe("on");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("toggling flips the state and never presses the pill", () => {
|
|
38
|
+
const onPress = vi.fn();
|
|
39
|
+
const onToggle = vi.fn();
|
|
40
|
+
const result = renderWithProviders(
|
|
41
|
+
<Chip
|
|
42
|
+
onPress={onPress}
|
|
43
|
+
trailingToggle={{ icon: <ArticleIcon />, selected: false, onToggle, label: "Read mode" }}
|
|
44
|
+
>
|
|
45
|
+
Model
|
|
46
|
+
</Chip>,
|
|
47
|
+
);
|
|
48
|
+
const button = toggle(result.container);
|
|
49
|
+
expect(button.getAttribute("aria-pressed")).toBe("false");
|
|
50
|
+
fireEvent.click(button);
|
|
51
|
+
expect(onToggle).toHaveBeenCalledWith(true);
|
|
52
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("Enter on the focused toggle flips it", () => {
|
|
56
|
+
const onToggle = vi.fn();
|
|
57
|
+
const result = renderWithProviders(
|
|
58
|
+
<Chip
|
|
59
|
+
trailingToggle={{ icon: <ArticleIcon />, selected: true, onToggle, label: "Read mode" }}
|
|
60
|
+
>
|
|
61
|
+
Model
|
|
62
|
+
</Chip>,
|
|
63
|
+
);
|
|
64
|
+
fireEvent.keyDown(toggle(result.container), { key: "Enter" });
|
|
65
|
+
expect(onToggle).toHaveBeenCalledWith(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("a disabled chip's toggle does not fire", () => {
|
|
69
|
+
const onToggle = vi.fn();
|
|
70
|
+
const result = renderWithProviders(
|
|
71
|
+
<Chip
|
|
72
|
+
disabled
|
|
73
|
+
trailingToggle={{ icon: <ArticleIcon />, selected: false, onToggle, label: "Read mode" }}
|
|
74
|
+
>
|
|
75
|
+
Model
|
|
76
|
+
</Chip>,
|
|
77
|
+
);
|
|
78
|
+
fireEvent.click(toggle(result.container));
|
|
79
|
+
expect(onToggle).not.toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("dismiss wins over a toggle, so a pill has one end cap", () => {
|
|
83
|
+
const result = renderWithProviders(
|
|
84
|
+
<Chip
|
|
85
|
+
onDismiss={() => {}}
|
|
86
|
+
trailingToggle={{
|
|
87
|
+
icon: <ArticleIcon />,
|
|
88
|
+
selected: false,
|
|
89
|
+
onToggle: () => {},
|
|
90
|
+
label: "Read mode",
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
Model
|
|
94
|
+
</Chip>,
|
|
95
|
+
);
|
|
96
|
+
expect(toggle(result.container)).toBeNull();
|
|
97
|
+
expect(result.container.querySelector("[aria-label='Remove']")).not.toBeNull();
|
|
98
|
+
});
|
|
99
|
+
});
|
package/src/Chip/index.tsx
CHANGED
|
@@ -66,6 +66,7 @@ export interface ChipProps {
|
|
|
66
66
|
onDismiss?: () => void;
|
|
67
67
|
/** The dismiss button's accessible name, saying what it clears. Defaults to "Remove". */
|
|
68
68
|
dismissLabel?: string;
|
|
69
|
+
trailingToggle?: ChipTrailingToggle;
|
|
69
70
|
disabled?: boolean;
|
|
70
71
|
/** Cap the pill; the label ellipsizes. */
|
|
71
72
|
maxWidth?: number | string;
|
|
@@ -87,6 +88,14 @@ export interface ChipProps {
|
|
|
87
88
|
ref?: Ref<unknown>;
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
export interface ChipTrailingToggle {
|
|
92
|
+
icon: ReactNode;
|
|
93
|
+
selectedIcon?: ReactNode;
|
|
94
|
+
selected: boolean;
|
|
95
|
+
onToggle: (selected: boolean) => void;
|
|
96
|
+
label: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
90
99
|
// ── Color mappings ────────────────────────────────────────────
|
|
91
100
|
|
|
92
101
|
// Ghost/outlined text is small (12px) and must clear ≥4.5:1 on its own tint.
|
|
@@ -398,6 +407,7 @@ export function Chip({
|
|
|
398
407
|
onPress,
|
|
399
408
|
onDismiss,
|
|
400
409
|
dismissLabel,
|
|
410
|
+
trailingToggle,
|
|
401
411
|
disabled,
|
|
402
412
|
maxWidth,
|
|
403
413
|
count,
|
|
@@ -419,6 +429,8 @@ export function Chip({
|
|
|
419
429
|
const isSelected = Boolean(selected);
|
|
420
430
|
const interactive = Boolean(onPress) && !disabled;
|
|
421
431
|
const showDismiss = Boolean(onDismiss) && !disabled;
|
|
432
|
+
const showToggle = trailingToggle != null && !showDismiss;
|
|
433
|
+
const toggleOn = Boolean(trailingToggle?.selected);
|
|
422
434
|
const iconSize = chipIconSize(resolvedSize);
|
|
423
435
|
const RING_INSET = 2;
|
|
424
436
|
const dismissVisual = iconSize + RING_INSET * 2;
|
|
@@ -617,6 +629,66 @@ export function Chip({
|
|
|
617
629
|
{count}
|
|
618
630
|
</ChipText>
|
|
619
631
|
) : null}
|
|
632
|
+
{showToggle ? (
|
|
633
|
+
<DismissButton
|
|
634
|
+
role="button"
|
|
635
|
+
aria-label={trailingToggle.label}
|
|
636
|
+
aria-pressed={toggleOn}
|
|
637
|
+
aria-disabled={disabled ? true : undefined}
|
|
638
|
+
tabIndex={disabled ? -1 : 0}
|
|
639
|
+
data-chip-toggle={toggleOn ? "on" : "off"}
|
|
640
|
+
opacity={1}
|
|
641
|
+
borderRadius={dismissRadius}
|
|
642
|
+
alignSelf="stretch"
|
|
643
|
+
position="relative"
|
|
644
|
+
marginVertical={-frameGeometry.paddingVertical}
|
|
645
|
+
marginRight={-frameGeometry.paddingHorizontal}
|
|
646
|
+
width={dismissSide ?? undefined}
|
|
647
|
+
hitSlop={pressTargetHitSlop(dismissSide ?? dismissVisual)}
|
|
648
|
+
onLayout={(e) => {
|
|
649
|
+
const h = e.nativeEvent.layout.height;
|
|
650
|
+
if (h > 0 && Math.abs((dismissSide ?? 0) - h) > 0.5) setDismissSide(h);
|
|
651
|
+
}}
|
|
652
|
+
onPress={(e) => {
|
|
653
|
+
e.stopPropagation?.();
|
|
654
|
+
if (!disabled) trailingToggle.onToggle(!toggleOn);
|
|
655
|
+
}}
|
|
656
|
+
onKeyDown={
|
|
657
|
+
((e: KeyboardEvent) => {
|
|
658
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
659
|
+
e.preventDefault();
|
|
660
|
+
e.stopPropagation();
|
|
661
|
+
if (!disabled) trailingToggle.onToggle(!toggleOn);
|
|
662
|
+
}
|
|
663
|
+
}) as unknown as () => void
|
|
664
|
+
}
|
|
665
|
+
>
|
|
666
|
+
{dismissHitOutset > 0 ? (
|
|
667
|
+
<View
|
|
668
|
+
position="absolute"
|
|
669
|
+
top={-dismissHitOutset}
|
|
670
|
+
bottom={-dismissHitOutset}
|
|
671
|
+
left={-dismissHitOutset}
|
|
672
|
+
right={-dismissHitOutset}
|
|
673
|
+
/>
|
|
674
|
+
) : null}
|
|
675
|
+
<DismissRing
|
|
676
|
+
className="mp-chip-dismiss-ring"
|
|
677
|
+
borderRadius={dismissRadius}
|
|
678
|
+
{...(toggleOn ? { backgroundColor: selectedBackground } : undefined)}
|
|
679
|
+
>
|
|
680
|
+
<ThemedIconSlot
|
|
681
|
+
icon={normalizeIcon(
|
|
682
|
+
toggleOn
|
|
683
|
+
? (trailingToggle.selectedIcon ?? trailingToggle.icon)
|
|
684
|
+
: trailingToggle.icon,
|
|
685
|
+
iconSize,
|
|
686
|
+
)}
|
|
687
|
+
color={toggleOn ? (state.selected.textKnobProps.color as ColorTokens) : textColor}
|
|
688
|
+
/>
|
|
689
|
+
</DismissRing>
|
|
690
|
+
</DismissButton>
|
|
691
|
+
) : null}
|
|
620
692
|
{showDismiss ? (
|
|
621
693
|
<DismissButton
|
|
622
694
|
role="button"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FZ-10608: the panel drops over a scrim only while open, carries its name,
|
|
3
|
+
* and the scrim and Escape close it.
|
|
4
|
+
*/
|
|
5
|
+
import { fireEvent } from "@testing-library/react";
|
|
6
|
+
import { describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
8
|
+
import { Text } from "tamagui";
|
|
9
|
+
import { DropDownPanel } from "./index";
|
|
10
|
+
|
|
11
|
+
describe("DropDownPanel", () => {
|
|
12
|
+
it("renders nothing while closed", () => {
|
|
13
|
+
const result = renderWithProviders(
|
|
14
|
+
<DropDownPanel open={false} onOpenChange={() => {}} aria-label="Add-ons">
|
|
15
|
+
<Text>Tiles</Text>
|
|
16
|
+
</DropDownPanel>,
|
|
17
|
+
);
|
|
18
|
+
expect(result.container.querySelector("[data-drop-down-panel]")).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("open, it shows a named panel over a scrim", () => {
|
|
22
|
+
const result = renderWithProviders(
|
|
23
|
+
<DropDownPanel open onOpenChange={() => {}} aria-label="Add-ons">
|
|
24
|
+
<Text>Tiles</Text>
|
|
25
|
+
</DropDownPanel>,
|
|
26
|
+
);
|
|
27
|
+
const sheet = result.container.querySelector("[data-drop-down-sheet]") as HTMLElement;
|
|
28
|
+
expect(sheet.getAttribute("aria-label")).toBe("Add-ons");
|
|
29
|
+
expect(sheet.getAttribute("role")).toBe("dialog");
|
|
30
|
+
expect(result.container.querySelector("[data-drop-down-scrim]")).not.toBeNull();
|
|
31
|
+
expect(result.findTextElement("Tiles")).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("a press on the scrim closes it", () => {
|
|
35
|
+
const onOpenChange = vi.fn();
|
|
36
|
+
const result = renderWithProviders(
|
|
37
|
+
<DropDownPanel open onOpenChange={onOpenChange} aria-label="Add-ons">
|
|
38
|
+
<Text>Tiles</Text>
|
|
39
|
+
</DropDownPanel>,
|
|
40
|
+
);
|
|
41
|
+
fireEvent.click(result.container.querySelector("[data-drop-down-scrim]") as HTMLElement);
|
|
42
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("Escape closes it", () => {
|
|
46
|
+
const onOpenChange = vi.fn();
|
|
47
|
+
renderWithProviders(
|
|
48
|
+
<DropDownPanel open onOpenChange={onOpenChange} aria-label="Add-ons">
|
|
49
|
+
<Text>Tiles</Text>
|
|
50
|
+
</DropDownPanel>,
|
|
51
|
+
);
|
|
52
|
+
fireEvent.keyDown(document, { key: "Escape" });
|
|
53
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BugIcon,
|
|
3
|
+
ChartLineUpIcon,
|
|
4
|
+
GitMergeIcon,
|
|
5
|
+
HardDrivesIcon,
|
|
6
|
+
UsersThreeIcon,
|
|
7
|
+
} from "@phosphor-icons/react";
|
|
8
|
+
import type { Meta, StoryObj } from "@storybook/react-native-web-vite";
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import { YStack } from "tamagui";
|
|
11
|
+
import { CardGrid, ShortcutCard } from "../views";
|
|
12
|
+
import { Text } from "../Text";
|
|
13
|
+
import { DropDownPanel } from "./index";
|
|
14
|
+
|
|
15
|
+
const meta: Meta<typeof DropDownPanel> = {
|
|
16
|
+
title: "Components/DropDownPanel",
|
|
17
|
+
component: DropDownPanel,
|
|
18
|
+
parameters: {
|
|
19
|
+
layout: "fullscreen",
|
|
20
|
+
status: { type: "beta" },
|
|
21
|
+
docs: {
|
|
22
|
+
description: {
|
|
23
|
+
component:
|
|
24
|
+
"A panel that drops from the top of its region over a scrim. The scrim and Escape close it.",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export default meta;
|
|
30
|
+
|
|
31
|
+
type Story = StoryObj<typeof DropDownPanel>;
|
|
32
|
+
|
|
33
|
+
const tiles = [
|
|
34
|
+
{
|
|
35
|
+
id: "accounts",
|
|
36
|
+
title: "Accounts",
|
|
37
|
+
subtitle: "1 needs sign-in",
|
|
38
|
+
count: 21,
|
|
39
|
+
icon: <UsersThreeIcon />,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "machines",
|
|
43
|
+
title: "Machines",
|
|
44
|
+
subtitle: "2 offline",
|
|
45
|
+
count: "1/3",
|
|
46
|
+
icon: <HardDrivesIcon />,
|
|
47
|
+
},
|
|
48
|
+
{ id: "mrs", title: "Merge requests", subtitle: "2 ready", count: 5, icon: <GitMergeIcon /> },
|
|
49
|
+
{ id: "reports", title: "Reports", subtitle: "3 new", count: 3, icon: <ChartLineUpIcon /> },
|
|
50
|
+
{ id: "errors", title: "Errors", subtitle: "None today", icon: <BugIcon /> },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
function Demo() {
|
|
54
|
+
const [open, setOpen] = useState(true);
|
|
55
|
+
return (
|
|
56
|
+
<YStack position="relative" height="100vh" padding="$4" gap="$3">
|
|
57
|
+
<Text onPress={() => setOpen(true)}>Sessions list under the panel</Text>
|
|
58
|
+
<DropDownPanel open={open} onOpenChange={setOpen} aria-label="Add-ons">
|
|
59
|
+
<CardGrid maxColumns={2} minCardWidth={150}>
|
|
60
|
+
{tiles.map((tile) => (
|
|
61
|
+
<ShortcutCard key={tile.id} layout="tile" config={{ ...tile, onClick: () => {} }} />
|
|
62
|
+
))}
|
|
63
|
+
</CardGrid>
|
|
64
|
+
</DropDownPanel>
|
|
65
|
+
</YStack>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const Open: Story = { render: () => <Demo /> };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DropDownPanel (FZ-10608): a panel that drops from the top edge of its
|
|
3
|
+
* region over a scrim, the Drover add-ons tray. It fills its positioned
|
|
4
|
+
* parent, so place it in the region under the bar it drops from. A press on
|
|
5
|
+
* the scrim or Escape closes it. Its top edge is flush with the bar; only the
|
|
6
|
+
* bottom corners round.
|
|
7
|
+
*/
|
|
8
|
+
import { overlayScrim, transitionProps, useResolvedKnobs } from "@multiplatform.one/theme";
|
|
9
|
+
import { useOverlayZIndex } from "@multiplatform.one/forms";
|
|
10
|
+
import { useEffect, type ReactNode } from "react";
|
|
11
|
+
import { useTranslation } from "react-i18next";
|
|
12
|
+
import { YStack } from "tamagui";
|
|
13
|
+
|
|
14
|
+
export interface DropDownPanelProps {
|
|
15
|
+
open: boolean;
|
|
16
|
+
onOpenChange: (open: boolean) => void;
|
|
17
|
+
/** The panel's accessible name ("Add-ons"). */
|
|
18
|
+
"aria-label": string;
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
testID?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function DropDownPanel({
|
|
24
|
+
open,
|
|
25
|
+
onOpenChange,
|
|
26
|
+
"aria-label": ariaLabel,
|
|
27
|
+
children,
|
|
28
|
+
testID,
|
|
29
|
+
}: DropDownPanelProps) {
|
|
30
|
+
const { t } = useTranslation();
|
|
31
|
+
const { knobProps } = useResolvedKnobs({ component: "Card" });
|
|
32
|
+
const zIndex = useOverlayZIndex("dropdown");
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!open || typeof document === "undefined") return;
|
|
36
|
+
const onKey = (event: KeyboardEvent) => {
|
|
37
|
+
if (event.key === "Escape") onOpenChange(false);
|
|
38
|
+
};
|
|
39
|
+
document.addEventListener("keydown", onKey);
|
|
40
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
41
|
+
}, [open, onOpenChange]);
|
|
42
|
+
|
|
43
|
+
if (!open) return null;
|
|
44
|
+
return (
|
|
45
|
+
<YStack
|
|
46
|
+
position="absolute"
|
|
47
|
+
top={0}
|
|
48
|
+
left={0}
|
|
49
|
+
right={0}
|
|
50
|
+
bottom={0}
|
|
51
|
+
zIndex={zIndex}
|
|
52
|
+
data-drop-down-panel=""
|
|
53
|
+
testID={testID}
|
|
54
|
+
>
|
|
55
|
+
<YStack
|
|
56
|
+
position="absolute"
|
|
57
|
+
top={0}
|
|
58
|
+
left={0}
|
|
59
|
+
right={0}
|
|
60
|
+
bottom={0}
|
|
61
|
+
backgroundColor={overlayScrim}
|
|
62
|
+
role="button"
|
|
63
|
+
aria-label={t("Close")}
|
|
64
|
+
data-drop-down-scrim=""
|
|
65
|
+
onPress={() => onOpenChange(false)}
|
|
66
|
+
{...transitionProps(knobProps.motion.scrim)}
|
|
67
|
+
enterStyle={{ opacity: 0 }}
|
|
68
|
+
/>
|
|
69
|
+
<YStack
|
|
70
|
+
role="dialog"
|
|
71
|
+
aria-label={ariaLabel}
|
|
72
|
+
position="relative"
|
|
73
|
+
data-drop-down-sheet=""
|
|
74
|
+
{...knobProps.elevatedSurface}
|
|
75
|
+
{...knobProps.containerRadius}
|
|
76
|
+
borderTopLeftRadius={0}
|
|
77
|
+
borderTopRightRadius={0}
|
|
78
|
+
{...knobProps.panelPadding}
|
|
79
|
+
{...knobProps.gap}
|
|
80
|
+
{...transitionProps(knobProps.motion.overlay)}
|
|
81
|
+
enterStyle={{ opacity: 0 }}
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</YStack>
|
|
85
|
+
</YStack>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FZ-10608: a full swipe dismisses, a short one springs back, and the
|
|
3
|
+
* revealed ✕ is a pressable path that never needs the gesture.
|
|
4
|
+
*/
|
|
5
|
+
import { fireEvent } from "@testing-library/react";
|
|
6
|
+
import { describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
8
|
+
import { Text } from "tamagui";
|
|
9
|
+
import { SWIPE_DISMISS_COMMIT, SwipeDismissRow, swipeDismissOutcome } from "./index";
|
|
10
|
+
|
|
11
|
+
describe("swipeDismissOutcome", () => {
|
|
12
|
+
it("a release past the commit share of the width dismisses", () => {
|
|
13
|
+
expect(swipeDismissOutcome(-300 * SWIPE_DISMISS_COMMIT, 300)).toBe("dismiss");
|
|
14
|
+
expect(swipeDismissOutcome(-290, 300)).toBe("dismiss");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("a short swipe, a swipe the other way and an unmeasured row spring back", () => {
|
|
18
|
+
expect(swipeDismissOutcome(-60, 300)).toBe("rest");
|
|
19
|
+
expect(swipeDismissOutcome(200, 300)).toBe("rest");
|
|
20
|
+
expect(swipeDismissOutcome(-200, 0)).toBe("rest");
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("SwipeDismissRow", () => {
|
|
25
|
+
it("at rest shows the row and no action", () => {
|
|
26
|
+
const result = renderWithProviders(
|
|
27
|
+
<SwipeDismissRow onDismiss={() => {}}>
|
|
28
|
+
<Text>Row</Text>
|
|
29
|
+
</SwipeDismissRow>,
|
|
30
|
+
);
|
|
31
|
+
expect(result.findTextElement("Row")).toBeDefined();
|
|
32
|
+
expect(result.container.querySelector("[data-swipe-dismiss-action]")).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("the revealed ✕ is labelled and dismisses on press", () => {
|
|
36
|
+
const onDismiss = vi.fn();
|
|
37
|
+
const result = renderWithProviders(
|
|
38
|
+
<SwipeDismissRow onDismiss={onDismiss} swipeProgress={0.4} dismissLabel="Dismiss item">
|
|
39
|
+
<Text>Row</Text>
|
|
40
|
+
</SwipeDismissRow>,
|
|
41
|
+
);
|
|
42
|
+
const action = result.container.querySelector("[data-swipe-dismiss-action]") as HTMLElement;
|
|
43
|
+
expect(action).not.toBeNull();
|
|
44
|
+
expect(action.getAttribute("aria-label")).toBe("Dismiss item");
|
|
45
|
+
fireEvent.click(action);
|
|
46
|
+
expect(onDismiss).toHaveBeenCalledTimes(1);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { CardsIcon } from "@phosphor-icons/react";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react-native-web-vite";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { YStack } from "tamagui";
|
|
5
|
+
import { ListGroup, ListGroupItem, ListRow, ListRowMeta } from "../views";
|
|
6
|
+
import { SwipeDismissRow } from "./index";
|
|
7
|
+
|
|
8
|
+
const meta: Meta<typeof SwipeDismissRow> = {
|
|
9
|
+
title: "Components/SwipeDismissRow",
|
|
10
|
+
component: SwipeDismissRow,
|
|
11
|
+
parameters: {
|
|
12
|
+
status: { type: "beta" },
|
|
13
|
+
docs: {
|
|
14
|
+
description: {
|
|
15
|
+
component:
|
|
16
|
+
"A list row a full swipe toward the leading edge dismisses; a short swipe springs back. The revealed ✕ is pressable too.",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export default meta;
|
|
22
|
+
|
|
23
|
+
type Story = StoryObj<typeof SwipeDismissRow>;
|
|
24
|
+
|
|
25
|
+
const seed = [
|
|
26
|
+
{ id: "a", title: "Approve the Reports add-on", session: "Add-on admin", time: "2m" },
|
|
27
|
+
{ id: "b", title: "Sign in to the Studio account", session: "Accounts", time: "14m" },
|
|
28
|
+
{ id: "c", title: "Review MR !926", session: "Drover boards", time: "1h" },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
function Demo({ caught }: { caught?: boolean }) {
|
|
32
|
+
const [items, setItems] = useState(seed);
|
|
33
|
+
return (
|
|
34
|
+
<YStack width="100%">
|
|
35
|
+
<ListGroup variant="plain" aria-label="Needs you">
|
|
36
|
+
{items.map((item, index) => (
|
|
37
|
+
<SwipeDismissRow
|
|
38
|
+
key={item.id}
|
|
39
|
+
swipeProgress={caught && index === 0 ? 0.35 : undefined}
|
|
40
|
+
onDismiss={() => setItems((all) => all.filter((x) => x.id !== item.id))}
|
|
41
|
+
>
|
|
42
|
+
<ListGroupItem onPress={() => {}}>
|
|
43
|
+
<ListRow
|
|
44
|
+
icon={<CardsIcon />}
|
|
45
|
+
title={item.title}
|
|
46
|
+
subtitle={item.session}
|
|
47
|
+
meta={<ListRowMeta>{item.time}</ListRowMeta>}
|
|
48
|
+
/>
|
|
49
|
+
</ListGroupItem>
|
|
50
|
+
</SwipeDismissRow>
|
|
51
|
+
))}
|
|
52
|
+
</ListGroup>
|
|
53
|
+
</YStack>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const Default: Story = { render: () => <Demo /> };
|
|
58
|
+
|
|
59
|
+
export const MidSwipe: Story = { render: () => <Demo caught /> };
|