-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from damianricobelli/lint-and-fix-ci
chore: lint and fix ci
- Loading branch information
Showing
12 changed files
with
112 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters