|
| 1 | +/* |
| 2 | + * (c) Copyright 2026 Palantir Technologies Inc. All rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +import type { Meta, StoryObj } from "@storybook/react-vite"; |
| 6 | +import { storybookLayoutDecorator } from "@storybook-common"; |
| 7 | +import type React from "react"; |
| 8 | + |
| 9 | +import { Flex } from "@blueprintjs/labs"; |
| 10 | + |
| 11 | +import { Intent } from "../../common"; |
| 12 | + |
| 13 | +import { Toast } from "./toast"; |
| 14 | + |
| 15 | +const disabledArgs = ["timeout", "className", "action", "onDismiss", "message"] as const satisfies ReadonlyArray< |
| 16 | + keyof React.ComponentProps<typeof Toast> |
| 17 | +>; |
| 18 | + |
| 19 | +const meta: Meta<typeof Toast> = { |
| 20 | + title: "Core/Overlays/Toast", |
| 21 | + component: Toast, |
| 22 | + decorators: [storybookLayoutDecorator], |
| 23 | + args: { |
| 24 | + intent: Intent.NONE, |
| 25 | + icon: undefined, |
| 26 | + isCloseButtonShown: true, |
| 27 | + timeout: 0, |
| 28 | + }, |
| 29 | + argTypes: { |
| 30 | + intent: { |
| 31 | + control: "select", |
| 32 | + options: Object.values(Intent), |
| 33 | + }, |
| 34 | + icon: { |
| 35 | + control: "text", |
| 36 | + }, |
| 37 | + isCloseButtonShown: { |
| 38 | + control: "boolean", |
| 39 | + }, |
| 40 | + ...disabledArgs.reduce( |
| 41 | + (acc, argName) => { |
| 42 | + acc[argName] = { table: { disable: true } }; |
| 43 | + return acc; |
| 44 | + }, |
| 45 | + {} as Record<(typeof disabledArgs)[number], { table: { disable: boolean } }>, |
| 46 | + ), |
| 47 | + }, |
| 48 | +} satisfies Meta<typeof Toast>; |
| 49 | + |
| 50 | +export default meta; |
| 51 | +type Story = StoryObj<typeof meta>; |
| 52 | + |
| 53 | +/** |
| 54 | + * A basic toast with default styling and a close button. |
| 55 | + */ |
| 56 | +export const Default: Story = { |
| 57 | + args: { |
| 58 | + message: "This is a toast message", |
| 59 | + }, |
| 60 | +}; |
| 61 | + |
| 62 | +/** |
| 63 | + * Use the `intent` prop to apply a semantic color that conveys the purpose or status of the toast. |
| 64 | + */ |
| 65 | +export const IntentExample: Story = { |
| 66 | + name: "Intent", |
| 67 | + argTypes: { |
| 68 | + intent: { table: { disable: true } }, |
| 69 | + }, |
| 70 | + render: args => ( |
| 71 | + <Flex flexDirection="column" gap={2}> |
| 72 | + {Object.values(Intent).map(intent => ( |
| 73 | + <Toast |
| 74 | + key={intent} |
| 75 | + {...args} |
| 76 | + intent={intent} |
| 77 | + message={`${intent.charAt(0).toUpperCase() + intent.slice(1)} intent toast`} |
| 78 | + /> |
| 79 | + ))} |
| 80 | + </Flex> |
| 81 | + ), |
| 82 | +}; |
| 83 | + |
| 84 | +/** |
| 85 | + * Use the `icon` prop to render a Blueprint icon before the message. |
| 86 | + */ |
| 87 | +export const IconExample: Story = { |
| 88 | + name: "Icons", |
| 89 | + argTypes: { |
| 90 | + icon: { table: { disable: true } }, |
| 91 | + intent: { table: { disable: true } }, |
| 92 | + }, |
| 93 | + render: args => ( |
| 94 | + <Flex flexDirection="column" gap={2}> |
| 95 | + <Toast {...args} icon="tick-circle" intent="success" message="File saved successfully" /> |
| 96 | + <Toast {...args} icon="warning-sign" intent="warning" message="Connection is unstable" /> |
| 97 | + <Toast {...args} icon="error" intent="danger" message="Failed to save changes" /> |
| 98 | + <Toast {...args} icon="info-sign" intent="primary" message="New update available" /> |
| 99 | + </Flex> |
| 100 | + ), |
| 101 | +}; |
| 102 | + |
| 103 | +/** |
| 104 | + * Use the `action` prop to render an {@link AnchorButton} alongside the message. |
| 105 | + * The action accepts `ActionProps & LinkProps`, supporting text, icons, and links. |
| 106 | + */ |
| 107 | +export const ActionExample: Story = { |
| 108 | + name: "Action", |
| 109 | + argTypes: { |
| 110 | + isCloseButtonShown: { table: { disable: true } }, |
| 111 | + intent: { table: { disable: true } }, |
| 112 | + }, |
| 113 | + render: args => ( |
| 114 | + <Flex flexDirection="column" gap={2}> |
| 115 | + <Toast {...args} message="File deleted" action={{ text: "Undo" }} /> |
| 116 | + <Toast {...args} message="Changes saved" intent="success" action={{ text: "View", icon: "share" }} /> |
| 117 | + <Toast |
| 118 | + {...args} |
| 119 | + message="New version available" |
| 120 | + intent="primary" |
| 121 | + action={{ text: "Release notes", href: "#", icon: "link" }} |
| 122 | + /> |
| 123 | + </Flex> |
| 124 | + ), |
| 125 | +}; |
| 126 | + |
| 127 | +/** |
| 128 | + * Interactive playground for experimenting with toast props. |
| 129 | + */ |
| 130 | +export const Playground: Story = { |
| 131 | + args: { |
| 132 | + message: "Playground toast message", |
| 133 | + icon: "info-sign", |
| 134 | + intent: Intent.PRIMARY, |
| 135 | + isCloseButtonShown: true, |
| 136 | + action: { |
| 137 | + text: "Undo", |
| 138 | + }, |
| 139 | + }, |
| 140 | +}; |
0 commit comments