|
| 1 | +import type { Meta, StoryObj } from "@storybook/react-vite"; |
| 2 | +import { TutorialTooltip, type TutorialStep } from "./TutorialTooltip"; |
| 3 | +import { TutorialProvider } from "@/browser/contexts/TutorialContext"; |
| 4 | +import { TUTORIAL_STATE_KEY, type TutorialState } from "@/common/constants/storage"; |
| 5 | + |
| 6 | +// eslint-disable-next-line @typescript-eslint/no-empty-function |
| 7 | +const noop = () => {}; |
| 8 | + |
| 9 | +const meta = { |
| 10 | + title: "Components/TutorialTooltip", |
| 11 | + component: TutorialTooltip, |
| 12 | + parameters: { |
| 13 | + layout: "centered", |
| 14 | + // Enable tutorials for these stories |
| 15 | + tutorialEnabled: true, |
| 16 | + }, |
| 17 | + tags: ["autodocs"], |
| 18 | + decorators: [ |
| 19 | + (Story) => { |
| 20 | + // Reset tutorial state to not-disabled for these stories |
| 21 | + const enabledState: TutorialState = { |
| 22 | + disabled: false, |
| 23 | + completed: {}, |
| 24 | + }; |
| 25 | + localStorage.setItem(TUTORIAL_STATE_KEY, JSON.stringify(enabledState)); |
| 26 | + |
| 27 | + return ( |
| 28 | + <TutorialProvider> |
| 29 | + <Story /> |
| 30 | + </TutorialProvider> |
| 31 | + ); |
| 32 | + }, |
| 33 | + ], |
| 34 | +} satisfies Meta<typeof TutorialTooltip>; |
| 35 | + |
| 36 | +export default meta; |
| 37 | +type Story = StoryObj<typeof meta>; |
| 38 | + |
| 39 | +// Mock target element for positioning |
| 40 | +const MockTargetWrapper: React.FC<{ |
| 41 | + children: React.ReactNode; |
| 42 | + tutorialTarget: string; |
| 43 | +}> = ({ children, tutorialTarget }) => ( |
| 44 | + <div className="bg-background flex h-[400px] w-[600px] items-center justify-center"> |
| 45 | + <button |
| 46 | + data-tutorial={tutorialTarget} |
| 47 | + className="bg-accent rounded px-4 py-2 text-sm text-white" |
| 48 | + > |
| 49 | + Target Element |
| 50 | + </button> |
| 51 | + {children} |
| 52 | + </div> |
| 53 | +); |
| 54 | + |
| 55 | +const sampleStep: TutorialStep = { |
| 56 | + target: "demo-target", |
| 57 | + title: "Welcome to Mux", |
| 58 | + content: "This is a tutorial tooltip that helps guide users through the application.", |
| 59 | + position: "bottom", |
| 60 | +}; |
| 61 | + |
| 62 | +export const SingleStep: Story = { |
| 63 | + args: { |
| 64 | + step: sampleStep, |
| 65 | + currentStep: 1, |
| 66 | + totalSteps: 1, |
| 67 | + onNext: noop, |
| 68 | + onDismiss: noop, |
| 69 | + onDisableTutorial: noop, |
| 70 | + }, |
| 71 | + render: (args) => ( |
| 72 | + <MockTargetWrapper tutorialTarget="demo-target"> |
| 73 | + <TutorialTooltip {...args} /> |
| 74 | + </MockTargetWrapper> |
| 75 | + ), |
| 76 | +}; |
| 77 | + |
| 78 | +export const MultiStepFirst: Story = { |
| 79 | + args: { |
| 80 | + step: { |
| 81 | + target: "demo-target", |
| 82 | + title: "Choose Your Model", |
| 83 | + content: |
| 84 | + "Select which AI model to use. Different models have different capabilities and costs.", |
| 85 | + position: "bottom", |
| 86 | + }, |
| 87 | + currentStep: 1, |
| 88 | + totalSteps: 4, |
| 89 | + onNext: noop, |
| 90 | + onDismiss: noop, |
| 91 | + onDisableTutorial: noop, |
| 92 | + }, |
| 93 | + render: (args) => ( |
| 94 | + <MockTargetWrapper tutorialTarget="demo-target"> |
| 95 | + <TutorialTooltip {...args} /> |
| 96 | + </MockTargetWrapper> |
| 97 | + ), |
| 98 | +}; |
| 99 | + |
| 100 | +export const MultiStepMiddle: Story = { |
| 101 | + args: { |
| 102 | + step: { |
| 103 | + target: "demo-target", |
| 104 | + title: "Exec vs Plan Mode", |
| 105 | + content: |
| 106 | + "Exec mode lets the AI edit files and run commands. Plan mode is read-only—great for exploring ideas safely.", |
| 107 | + position: "top", |
| 108 | + }, |
| 109 | + currentStep: 2, |
| 110 | + totalSteps: 4, |
| 111 | + onNext: noop, |
| 112 | + onDismiss: noop, |
| 113 | + onDisableTutorial: noop, |
| 114 | + }, |
| 115 | + render: (args) => ( |
| 116 | + <MockTargetWrapper tutorialTarget="demo-target"> |
| 117 | + <TutorialTooltip {...args} /> |
| 118 | + </MockTargetWrapper> |
| 119 | + ), |
| 120 | +}; |
| 121 | + |
| 122 | +export const MultiStepLast: Story = { |
| 123 | + args: { |
| 124 | + step: { |
| 125 | + target: "demo-target", |
| 126 | + title: "Runtime Environment", |
| 127 | + content: "Run locally using git worktrees, or connect via SSH to work on a remote machine.", |
| 128 | + position: "bottom", |
| 129 | + }, |
| 130 | + currentStep: 4, |
| 131 | + totalSteps: 4, |
| 132 | + onNext: noop, |
| 133 | + onDismiss: noop, |
| 134 | + onDisableTutorial: noop, |
| 135 | + }, |
| 136 | + render: (args) => ( |
| 137 | + <MockTargetWrapper tutorialTarget="demo-target"> |
| 138 | + <TutorialTooltip {...args} /> |
| 139 | + </MockTargetWrapper> |
| 140 | + ), |
| 141 | +}; |
| 142 | + |
| 143 | +// Position variants |
| 144 | +const PositionWrapper: React.FC<{ |
| 145 | + children: React.ReactNode; |
| 146 | + tutorialTarget: string; |
| 147 | + position: "center" | "top" | "bottom" | "left" | "right"; |
| 148 | +}> = ({ children, tutorialTarget, position }) => { |
| 149 | + const positionClasses = { |
| 150 | + center: "items-center justify-center", |
| 151 | + top: "items-start justify-center pt-20", |
| 152 | + bottom: "items-end justify-center pb-20", |
| 153 | + left: "items-center justify-start pl-20", |
| 154 | + right: "items-center justify-end pr-20", |
| 155 | + }; |
| 156 | + |
| 157 | + return ( |
| 158 | + <div className={`bg-background flex h-[400px] w-[600px] ${positionClasses[position]}`}> |
| 159 | + <button |
| 160 | + data-tutorial={tutorialTarget} |
| 161 | + className="bg-accent rounded px-4 py-2 text-sm text-white" |
| 162 | + > |
| 163 | + Target |
| 164 | + </button> |
| 165 | + {children} |
| 166 | + </div> |
| 167 | + ); |
| 168 | +}; |
| 169 | + |
| 170 | +export const PositionBottom: Story = { |
| 171 | + args: { |
| 172 | + step: { ...sampleStep, position: "bottom" }, |
| 173 | + currentStep: 1, |
| 174 | + totalSteps: 1, |
| 175 | + onNext: noop, |
| 176 | + onDismiss: noop, |
| 177 | + onDisableTutorial: noop, |
| 178 | + }, |
| 179 | + render: (args) => ( |
| 180 | + <PositionWrapper tutorialTarget="demo-target" position="top"> |
| 181 | + <TutorialTooltip {...args} /> |
| 182 | + </PositionWrapper> |
| 183 | + ), |
| 184 | +}; |
| 185 | + |
| 186 | +export const PositionTop: Story = { |
| 187 | + args: { |
| 188 | + step: { ...sampleStep, position: "top" }, |
| 189 | + currentStep: 1, |
| 190 | + totalSteps: 1, |
| 191 | + onNext: noop, |
| 192 | + onDismiss: noop, |
| 193 | + onDisableTutorial: noop, |
| 194 | + }, |
| 195 | + render: (args) => ( |
| 196 | + <PositionWrapper tutorialTarget="demo-target" position="bottom"> |
| 197 | + <TutorialTooltip {...args} /> |
| 198 | + </PositionWrapper> |
| 199 | + ), |
| 200 | +}; |
| 201 | + |
| 202 | +export const PositionLeft: Story = { |
| 203 | + args: { |
| 204 | + step: { ...sampleStep, position: "left" }, |
| 205 | + currentStep: 1, |
| 206 | + totalSteps: 1, |
| 207 | + onNext: noop, |
| 208 | + onDismiss: noop, |
| 209 | + onDisableTutorial: noop, |
| 210 | + }, |
| 211 | + render: (args) => ( |
| 212 | + <PositionWrapper tutorialTarget="demo-target" position="right"> |
| 213 | + <TutorialTooltip {...args} /> |
| 214 | + </PositionWrapper> |
| 215 | + ), |
| 216 | +}; |
| 217 | + |
| 218 | +export const PositionRight: Story = { |
| 219 | + args: { |
| 220 | + step: { ...sampleStep, position: "right" }, |
| 221 | + currentStep: 1, |
| 222 | + totalSteps: 1, |
| 223 | + onNext: noop, |
| 224 | + onDismiss: noop, |
| 225 | + onDisableTutorial: noop, |
| 226 | + }, |
| 227 | + render: (args) => ( |
| 228 | + <PositionWrapper tutorialTarget="demo-target" position="left"> |
| 229 | + <TutorialTooltip {...args} /> |
| 230 | + </PositionWrapper> |
| 231 | + ), |
| 232 | +}; |
0 commit comments