codex-marketplace-ui-compon.../stories/Stepper.stories.tsx

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-08-23 13:31:37 +00:00
import type { Meta } from "@storybook/react";
import { Stepper } from "../src/components/Stepper/Stepper";
import React, { useState } from "react";
import { fn } from "@storybook/test";
2024-08-20 13:57:58 +00:00
const meta = {
title: "Advanced/Stepper",
component: Stepper,
parameters: {
layout: "fullscreen",
},
tags: ["autodocs"],
argTypes: {},
args: { onChangeStep: fn() },
2024-08-20 13:57:58 +00:00
} satisfies Meta<typeof Stepper>;
export default meta;
type Props = {
onChangeStep: (s: number, state: "before" | "end") => void | Promise<void>;
};
const Template = (p: Props) => {
2024-08-20 13:57:58 +00:00
const [step, setStep] = useState(0);
const [progress, setProgress] = useState(false);
const titles = ["Hello world", "Hello world 2", "Hello world 3"];
const title = titles[step];
const onChangeStep = (newStep: number, event: "before" | "end") => {
p.onChangeStep(newStep, event);
2024-08-20 13:57:58 +00:00
if (event === "before") {
setProgress(true);
return;
}
setProgress(false);
setStep(newStep);
};
return (
<Stepper
2024-08-23 13:31:37 +00:00
Body={() => React.createElement("div", {}, title)}
2024-08-20 13:57:58 +00:00
titles={titles}
onChangeStep={onChangeStep}
progress={progress}
step={step}
isNextDisable={progress || step === 2}
/>
);
};
export const Default = Template.bind({});