Skip to content

Commit

Permalink
Merge pull request #35 from damianricobelli/jon/update-types
Browse files Browse the repository at this point in the history
Rewire API for maximum extendability
  • Loading branch information
damianricobelli authored Aug 20, 2024
2 parents ffc1964 + ef8d71e commit 3c148d7
Show file tree
Hide file tree
Showing 23 changed files with 815 additions and 528 deletions.
6 changes: 6 additions & 0 deletions .changeset/curvy-apricots-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"docs": major
"@stepperize/react": major
---

Rewire API for maximum extendability
6 changes: 5 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"organizeImports": {
"enabled": true
},
"formatter": {
"lineWidth": 120
},
"linter": {
"enabled": true,
"rules": {
Expand All @@ -31,7 +34,8 @@
},
"correctness": {
"noUnusedVariables": "error",
"noUnusedImports": "error"
"noUnusedImports": "error",
"useExhaustiveDependencies": "off"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/components/features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
const features = [
{
title: "Lightweight",
description: "It's only 5kb in size and has no dependencies.",
description: "It's only ~1kb in size and has no dependencies.",
icon: Expand,
},
{
Expand Down
67 changes: 25 additions & 42 deletions docs/examples/first-stepper.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,49 @@
import { Button } from "@/components/ui/button";
import { Stepper, defineSteps, useStepper } from "@stepperize/react";
import { Button } from "@/components/ui/button"
import { defineStepper } from "@stepperize/react"

const steps = defineSteps(
{ id: "first" },
{ id: "second" },
{ id: "third" },
{ id: "last" },
);

type Steps = typeof steps;
const { useStepper } = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" },
{ id: "third", title: "Third" },
{ id: "last", title: "Last" },
)

export const MyFirstStepper = () => {
return (
<Stepper steps={steps}>
<MySteps />
</Stepper>
);
};

const MySteps = () => {
const {
when,
goToNextStep,
goToPrevStep,
isLastStep,
reset,
isFirstStep,
currentStep,
} = useStepper<Steps>();
const stepper = useStepper()

return (
<div className="flex flex-col gap-4 bg-gray-3 p-4 my-4 rounded-md">
{when("first").render((step) => (
<p>This is the {step.id}</p>
{stepper.when("first", (step) => (
<p>This is the {step.title} step.</p>
))}

{when("second").render((step) => (
<p>This is the {step.id}</p>
{stepper.when("second", (step) => (
<p>This is the {step.title} step.</p>
))}

{when("third").render((step) => (
<p>This is the {step.id}</p>
{stepper.when("third", (step) => (
<p>This is the {step.title} step.</p>
))}

{when("last").render(() => (
<p>You have reached the end of the stepper</p>
{stepper.when("last", (step) => (
<p>You have reached the {step.title} step.</p>
))}

{!isLastStep ? (
{!stepper.isLastStep ? (
<div className="flex items-center gap-2">
<Button onClick={goToPrevStep} disabled={isFirstStep}>
<Button onClick={stepper.goToPrevStep} disabled={stepper.isFirstStep}>
Previous
</Button>
<Button onClick={goToNextStep}>
{currentStep.id === "third" ? "Finish" : "Next"}

<Button onClick={stepper.goToNextStep}>
{stepper.when("third", () => "Finish", () => "Next")}
</Button>
</div>
) : (
<div className="flex items-center gap-2">
<Button onClick={reset}>Reset</Button>
<Button onClick={stepper.reset}>Reset</Button>
</div>
)}
</div>
);
};
)
}
116 changes: 116 additions & 0 deletions docs/examples/multi-scoped-stepper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { Button } from "@/components/ui/button";
import { defineStepper } from "@stepperize/react";

const GlobalStepper = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" },
{ id: "last", title: "Last" },
);

const LocalStepper = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" },
{ id: "last", title: "Last" },
);

export const MyMultiScopedStepper = () => {
return (
<GlobalStepper.Scoped>
<MySteps />
<MyActions />
</GlobalStepper.Scoped>
);
};

const MySteps = () => {
const stepper = GlobalStepper.useStepper();

return (
<div className="flex flex-col gap-4 bg-gray-3 p-4 my-4 rounded-md">
{stepper.when("first", (step) => (
<p>This is the global {step.id} step. So it begins.</p>
))}

<MyLocalStepper />

{stepper.when("last", (step) => (
<p>This is the {step.id} step. So it ends.</p>
))}
</div>
);
};

const MyLocalStepper = () => {
const globalStepper = GlobalStepper.useStepper();
const localStepper = LocalStepper.useStepper();

return (
<>
{globalStepper.when("second", (step) => (
<div className="flex flex-col gap-4">
<p>This is the global {step.id} step.</p>
<div className="flex flex-col gap-4 border p-4 rounded-md">
{localStepper.when("first", (step) => (
<p>This is the local {step.id} step.</p>
))}
{localStepper.when("second", (step) => (
<p>This is the local {step.id} step.</p>
))}
{localStepper.when("last", (step) => (
<p>This is the local {step.id} step.</p>
))}
<MyLocalActions />
</div>
</div>
))}
</>
);
};

const MyActions = () => {
const stepper = GlobalStepper.useStepper();

return !stepper.isLastStep ? (
<div className="flex items-center gap-2">
<Button onClick={stepper.goToPrevStep} disabled={stepper.isFirstStep}>
Previous
</Button>

<Button onClick={stepper.goToNextStep}>
{stepper.when(
"second",
() => "Finish",
() => "Next",
)}
</Button>
</div>
) : (
<div className="flex items-center gap-2">
<Button onClick={stepper.reset}>Reset</Button>
</div>
);
};

const MyLocalActions = () => {
const stepper = LocalStepper.useStepper();

return !stepper.isLastStep ? (
<div className="flex items-center gap-2">
<Button onClick={stepper.goToPrevStep} disabled={stepper.isFirstStep}>
Previous
</Button>

<Button onClick={stepper.goToNextStep}>
{stepper.when(
"second",
() => "Finish",
() => "Next",
)}
</Button>
</div>
) : (
<div className="flex items-center gap-2">
<Button onClick={stepper.reset}>Reset</Button>
</div>
);
};
68 changes: 68 additions & 0 deletions docs/examples/scoped-stepper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Button } from "@/components/ui/button";
import { defineStepper } from "@stepperize/react";

const { useStepper, Scoped } = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" },
{ id: "third", title: "Third" },
{ id: "last", title: "Last" },
);

export const MyScopedStepper = () => {
return (
<div className="flex flex-col gap-4 bg-gray-3 p-4 my-4 rounded-md">
<Scoped>
<MySteps />
<MyActions />
</Scoped>
</div>
);
};

const MySteps = () => {
const stepper = useStepper();

return (
<>
{stepper.when("first", (step) => (
<p>This is the {step.id} step. So it begins.</p>
))}

{stepper.when("second", (step) => (
<p>This is the {step.id} step.</p>
))}

{stepper.when("third", (step) => (
<p>This is the {step.id} step.</p>
))}

{stepper.when("last", (step) => (
<p>This is the {step.id} step. So it ends.</p>
))}
</>
);
};

const MyActions = () => {
const stepper = useStepper();

return !stepper.isLastStep ? (
<div className="flex items-center gap-2">
<Button onClick={stepper.goToPrevStep} disabled={stepper.isFirstStep}>
Previous
</Button>

<Button onClick={stepper.goToNextStep}>
{stepper.when(
"third",
() => "Finish",
() => "Next",
)}
</Button>
</div>
) : (
<div className="flex items-center gap-2">
<Button onClick={stepper.reset}>Reset</Button>
</div>
);
};
1 change: 1 addition & 0 deletions docs/pages/docs/_meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"introduction": "Introduction",
"migrating-from-v1-to-v2": "Migrating from v1 to v2",
"getting-started": "Getting started",
"examples": "Examples"
}
2 changes: 1 addition & 1 deletion docs/pages/docs/examples/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"forms": "Forms",
"dialog": "Dialogs",
"forms": "Forms",
"query-params": "Query params",
"shareable-data": "Shareable data"
}
4 changes: 2 additions & 2 deletions docs/pages/docs/getting-started/_meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"installation": "Installation",
"creating-steps": "Creating steps",
"stepper": "Stepper",
"define-stepper": "Define Stepper",
"use-stepper": "useStepper()",
"scoped-stepper": "Scoped stepper",
"our-first-stepper": "Our first stepper"
}
39 changes: 0 additions & 39 deletions docs/pages/docs/getting-started/creating-steps.mdx

This file was deleted.

Loading

0 comments on commit 3c148d7

Please sign in to comment.