diff --git a/packages/ui/package.json b/packages/ui/package.json index 489dc08..4f9003a 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "@4bits/ui", - "version": "1.14.45", + "version": "1.14.46", "private": false, "main": "dist/index.js", "module": "dist/esm/index.js", diff --git a/packages/ui/src/components/ui/stepper.tsx b/packages/ui/src/components/ui/stepper.tsx new file mode 100644 index 0000000..ba9220a --- /dev/null +++ b/packages/ui/src/components/ui/stepper.tsx @@ -0,0 +1,112 @@ +import { + LucideCircle, + LucideCircleCheckBig, + LucideCircleDashed, +} from "lucide-react"; +import { cn } from "../../lib/utils"; +import type { HTMLProps } from "react"; + +export interface Step { + label: string; +} + +export type StepperRootProps = HTMLProps & { + steps: Step[]; + currentStepIndex: number; + /** + * @default "vertical" + */ + direction?: "horizontal" | "vertical"; + enumerate?: boolean; +}; + +export function Stepper({ + steps, + currentStepIndex, + direction = "vertical", + enumerate, + ...props +}: StepperRootProps) { + function handleSteps(index: number) { + if (currentStepIndex === index) { + if (enumerate) { + return ( +
+ +
+ {index + 1} +
+
+ ); + } + return ; + } + if (currentStepIndex < index) { + if (enumerate) { + return ( +
+ +
+ {index + 1} +
+
+ ); + } + return ; + } + if (currentStepIndex > index) { + if (enumerate) { + return ( +
+ +
+ {index + 1} +
+
+ ); + } + return ; + } + } + + return ( +
+
+ {steps.map(({ label }, index) => ( + <> + {index > 0 && ( +
+ )} +
+ {handleSteps(index)} + {label} +
+ + ))} +
+
+ ); +} diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts index cd34555..cbf1ac8 100644 --- a/packages/ui/src/index.ts +++ b/packages/ui/src/index.ts @@ -13,6 +13,7 @@ export { Tooltip } from "./components/ui/tooltip"; export { Separator } from "./components/ui/separator"; export { Dialog } from "./components/ui/dialog"; export { Dropdown } from "./components/ui/dropdown"; +export { Stepper } from "./components/ui/stepper"; export { Tabs } from "./components/ui/tabs"; export { Card } from "./components/ui/card"; export { Table } from "./components/ui/table"; diff --git a/packages/ui/src/stories/stepper.stories.tsx b/packages/ui/src/stories/stepper.stories.tsx new file mode 100644 index 0000000..1f91a20 --- /dev/null +++ b/packages/ui/src/stories/stepper.stories.tsx @@ -0,0 +1,24 @@ +import type { Meta } from "@storybook/react"; +import { Stepper } from "src/components/ui/stepper"; + +export default { + title: "Stepper", + component: Stepper, +} satisfies Meta; + +export const Default = () => { + return ( + + ); +};