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

70 lines
1.5 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 { fn } from "@storybook/test";
import { useStepperReducer } from "../src/components/Stepper/useStepperReducer";
import { useEffect } from "react";
import "./Stepper.stories.css";
2024-08-20 13:57:58 +00:00
const meta = {
title: "Advanced/Stepper",
component: Stepper,
parameters: {
layout: "fullscreen",
},
tags: ["autodocs"],
argTypes: {},
args: { onNextStep: fn() },
2024-08-20 13:57:58 +00:00
} satisfies Meta<typeof Stepper>;
export default meta;
type Props = {
onNextStep: (s: number) => void | Promise<void>;
};
const Template = (p: Props) => {
2024-09-26 15:00:53 +00:00
const { state, dispatch } = useStepperReducer();
2024-08-20 13:57:58 +00:00
useEffect(() => {
dispatch({
type: "toggle-buttons",
isNextEnable: true,
isBackEnable: true,
});
}, [dispatch]);
2024-08-20 13:57:58 +00:00
const titles = ["Hello world", "Hello world 2", "Hello world 3"];
const title = titles[state.step];
const onNextStep = async (step: number) => {
p.onNextStep(step);
2024-08-20 13:57:58 +00:00
dispatch({
type: "toggle-buttons",
isNextEnable: true,
isBackEnable: true,
});
dispatch({
step,
type: "next",
});
2024-08-20 13:57:58 +00:00
};
return (
<div style={{ padding: "6rem" }}>
<Stepper
titles={titles}
state={state}
dispatch={dispatch}
onNextStep={onNextStep}
className="stepper-padding"
>
<div>{title}</div>
</Stepper>
</div>
2024-08-20 13:57:58 +00:00
);
};
export const Default = Template.bind({});