Skip to content

Commit

Permalink
Merge pull request #85 from damianricobelli/lint-and-fix-ci
Browse files Browse the repository at this point in the history
chore: lint and fix ci
  • Loading branch information
damianricobelli authored Jan 7, 2025
2 parents f8943d8 + 752f9a6 commit 5f499a0
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 129 deletions.
9 changes: 9 additions & 0 deletions .changeset/young-eggs-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@stepperize/core": patch
"@stepperize/react": patch
"@stepperize/solid": patch
"@stepperize/svelte": patch
"@stepperize/vue": patch
---

chore: lint and fix ci
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build the Package
run: pnpm build
working-directory: packages/react
- name: Build @stepperize/react
run: pnpm turbo run build --filter=packages/react

- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1
Expand Down
4 changes: 1 addition & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "0.0.1",
"private": false,
"sideEffects": false,
"files": [
"dist"
],
"files": ["dist"],
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
123 changes: 57 additions & 66 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,66 @@
import type { Step, Stepper, Get, Utils } from "./types";
import type { Get, Step, Stepper, Utils } from "./types";

export function generateStepperUtils<const Steps extends Step[]>(
...steps: Steps
) {
return {
getAll() {
return steps;
},
get: (id) => {
const step = steps.find((step) => step.id === id);
return step as Get.StepById<Steps, typeof id>;
},
getIndex: (id) => steps.findIndex((step) => step.id === id),
getByIndex: (index) => steps[index],
getFirst() {
return steps[0];
},
getLast() {
return steps[steps.length - 1];
},
getNext(id) {
return steps[steps.findIndex((step) => step.id === id) + 1];
},
getPrev(id) {
return steps[steps.findIndex((step) => step.id === id) - 1];
},
getNeighbors(id) {
const index = steps.findIndex((step) => step.id === id);
return {
prev: index > 0 ? steps[index - 1] : null,
next: index < steps.length - 1 ? steps[index + 1] : null,
};
},
} satisfies Utils<Steps>;
export function generateStepperUtils<const Steps extends Step[]>(...steps: Steps) {
return {
getAll() {
return steps;
},
get: (id) => {
const step = steps.find((step) => step.id === id);
return step as Get.StepById<Steps, typeof id>;
},
getIndex: (id) => steps.findIndex((step) => step.id === id),
getByIndex: (index) => steps[index],
getFirst() {
return steps[0];
},
getLast() {
return steps[steps.length - 1];
},
getNext(id) {
return steps[steps.findIndex((step) => step.id === id) + 1];
},
getPrev(id) {
return steps[steps.findIndex((step) => step.id === id) - 1];
},
getNeighbors(id) {
const index = steps.findIndex((step) => step.id === id);
return {
prev: index > 0 ? steps[index - 1] : null,
next: index < steps.length - 1 ? steps[index + 1] : null,
};
},
} satisfies Utils<Steps>;
}

export function getInitialStepIndex<Steps extends Step[]>(
steps: Steps,
initialStep?: Get.Id<Steps>
) {
return Math.max(
steps.findIndex((step) => step.id === initialStep),
0
);
export function getInitialStepIndex<Steps extends Step[]>(steps: Steps, initialStep?: Get.Id<Steps>) {
return Math.max(
steps.findIndex((step) => step.id === initialStep),
0,
);
}

export function generateCommonStepperUseFns<const Steps extends Step[]>(
steps: Steps,
currentStep: Steps[number],
stepIndex: number
steps: Steps,
currentStep: Steps[number],
stepIndex: number,
) {
return {
switch(when) {
const whenFn = when[currentStep.id as keyof typeof when];
return whenFn?.(
currentStep as Get.StepById<typeof steps, (typeof currentStep)["id"]>
);
},
when(id, whenFn, elseFn) {
const currentStep = steps[stepIndex];
const matchesId = Array.isArray(id)
? currentStep.id === id[0] && id.slice(1).every(Boolean)
: currentStep.id === id;
return {
switch(when) {
const whenFn = when[currentStep.id as keyof typeof when];
return whenFn?.(currentStep as Get.StepById<typeof steps, (typeof currentStep)["id"]>);
},
when(id, whenFn, elseFn) {
const currentStep = steps[stepIndex];
const matchesId = Array.isArray(id)
? currentStep.id === id[0] && id.slice(1).every(Boolean)
: currentStep.id === id;

return matchesId
? whenFn?.(currentStep as any)
: elseFn?.(currentStep as any);
},
match(state, matches) {
const matchFn = matches[state as keyof typeof matches];
return matchFn?.(state as any);
},
} as Pick<Stepper<Steps>, "switch" | "when" | "match">;
return matchesId ? whenFn?.(currentStep as any) : elseFn?.(currentStep as any);
},
match(state, matches) {
const matchFn = matches[state as keyof typeof matches];
return matchFn?.(state as any);
},
} as Pick<Stepper<Steps>, "switch" | "when" | "match">;
}
4 changes: 1 addition & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
},
"homepage": "https://stepperize.vercel.app",
"sideEffects": false,
"files": [
"dist"
],
"files": ["dist"],
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
9 changes: 4 additions & 5 deletions packages/react/src/define-stepper.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { generateCommonStepperUseFns, generateStepperUtils, getInitialStepIndex, Step, Stepper, Get } from "@stepperize/core";
import type { Get, Step, Stepper } from "@stepperize/core";
import type { ScopedProps, StepperReturn } from "./types";

import * as React from "react";

import { generateCommonStepperUseFns, generateStepperUtils, getInitialStepIndex } from "@stepperize/core";

export const defineStepper = <const Steps extends Step[]>(...steps: Steps): StepperReturn<Steps> => {
const Context = React.createContext<Stepper<Steps> | null>(null);

const utils = generateStepperUtils(...steps);

const useStepper = (initialStep?: Get.Id<Steps>) => {
const initialStepIndex = React.useMemo(
() => getInitialStepIndex(steps, initialStep),
[initialStep],
);
const initialStepIndex = React.useMemo(() => getInitialStepIndex(steps, initialStep), [initialStep]);

const [stepIndex, setStepIndex] = React.useState(initialStepIndex);

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Types
export type { Step, Stepper, Get } from '@stepperize/core'
export type { Step, Stepper, Get } from "@stepperize/core";

// Define Stepper
export * from "./define-stepper";
64 changes: 32 additions & 32 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import type { Step, Stepper, Get, Utils } from "@stepperize/core";
import type { Get, Step, Stepper, Utils } from "@stepperize/core";

export type ScopedProps<Steps extends Step[]> = React.PropsWithChildren<{
/** The initial step to display. */
initialStep?: Get.Id<Steps>;
/** The initial step to display. */
initialStep?: Get.Id<Steps>;
}>;

export type StepperReturn<Steps extends Step[]> = {
/** The steps of the stepper. */
steps: Steps;
/**
* `utils` provides helper functions to interact with steps in the stepper.
* These functions allow you to get steps by their ID or index, get the first and last steps,
* and navigate through the steps by retrieving neighbors or adjacent steps.
*
* @returns An object containing utility methods to interact with the steps
*/
utils: Utils<Steps>;
/**
* `Scoped` component is a wrapper that provides the stepper context to its children.
* It uses the `Context` to pass the stepper instance to the children.
*
* @param props - The props object containing `initialStep` and `children`.
* @param props.initialStep - The ID of the step to start with (optional).
* @param props.children - The child elements to be wrapped by the `Scoped` component.
* @returns A React element that wraps the children with the stepper context.
*/
Scoped: (props: ScopedProps<Steps>) => React.ReactElement;
/**
* `useStepper` hook returns an object that manages the current step in the stepper.
* You can use this hook to get the current step, navigate to the next or previous step,
* and reset the stepper to the initial state.
*
* @param initialStep - The ID of the step to start with (optional).
* @returns An object containing properties and methods to interact with the stepper.
*/
useStepper: (initialStep?: Get.Id<Steps>) => Stepper<Steps>;
/** The steps of the stepper. */
steps: Steps;
/**
* `utils` provides helper functions to interact with steps in the stepper.
* These functions allow you to get steps by their ID or index, get the first and last steps,
* and navigate through the steps by retrieving neighbors or adjacent steps.
*
* @returns An object containing utility methods to interact with the steps
*/
utils: Utils<Steps>;
/**
* `Scoped` component is a wrapper that provides the stepper context to its children.
* It uses the `Context` to pass the stepper instance to the children.
*
* @param props - The props object containing `initialStep` and `children`.
* @param props.initialStep - The ID of the step to start with (optional).
* @param props.children - The child elements to be wrapped by the `Scoped` component.
* @returns A React element that wraps the children with the stepper context.
*/
Scoped: (props: ScopedProps<Steps>) => React.ReactElement;
/**
* `useStepper` hook returns an object that manages the current step in the stepper.
* You can use this hook to get the current step, navigate to the next or previous step,
* and reset the stepper to the initial state.
*
* @param initialStep - The ID of the step to start with (optional).
* @returns An object containing properties and methods to interact with the stepper.
*/
useStepper: (initialStep?: Get.Id<Steps>) => Stepper<Steps>;
};
9 changes: 2 additions & 7 deletions packages/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
"skipLibCheck": true,
"strict": true
},
"include": [
"."
],
"exclude": [
"node_modules",
"dist"
]
"include": ["."],
"exclude": ["node_modules", "dist"]
}
4 changes: 1 addition & 3 deletions packages/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
}
},
"sideEffects": false,
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
Expand Down
4 changes: 1 addition & 3 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
}
},
"sideEffects": false,
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
Expand Down
4 changes: 1 addition & 3 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
}
},
"sideEffects": false,
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
Expand Down

0 comments on commit 5f499a0

Please sign in to comment.