@zag-js/steps 0.0.0-dev-20240630000246
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/index.d.mts +135 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +315 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +284 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
- package/src/index.ts +13 -0
- package/src/steps.anatomy.ts +18 -0
- package/src/steps.connect.ts +186 -0
- package/src/steps.dom.ts +9 -0
- package/src/steps.machine.ts +70 -0
- package/src/steps.props.ts +18 -0
- package/src/steps.types.ts +146 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Machine, StateMachine as S } from "@zag-js/core"
|
|
2
|
+
import type { CommonProperties, DirectionProperty, PropTypes, RequiredBy } from "@zag-js/types"
|
|
3
|
+
|
|
4
|
+
/* -----------------------------------------------------------------------------
|
|
5
|
+
* Callback details
|
|
6
|
+
* -----------------------------------------------------------------------------*/
|
|
7
|
+
|
|
8
|
+
export interface StepChangeDetails {
|
|
9
|
+
step: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* -----------------------------------------------------------------------------
|
|
13
|
+
* Machine context
|
|
14
|
+
* -----------------------------------------------------------------------------*/
|
|
15
|
+
|
|
16
|
+
export interface ElementIds {
|
|
17
|
+
root?: string
|
|
18
|
+
list?: string
|
|
19
|
+
triggerId?(index: number): string
|
|
20
|
+
contentId?(index: number): string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface PublicContext extends DirectionProperty, CommonProperties {
|
|
24
|
+
/**
|
|
25
|
+
* The custom ids for the stepper elements
|
|
26
|
+
*/
|
|
27
|
+
ids?: ElementIds
|
|
28
|
+
/**
|
|
29
|
+
* The current value of the stepper
|
|
30
|
+
*/
|
|
31
|
+
step: number
|
|
32
|
+
/**
|
|
33
|
+
* Callback to be called when the value changes
|
|
34
|
+
*/
|
|
35
|
+
onStepChange?(details: StepChangeDetails): void
|
|
36
|
+
/**
|
|
37
|
+
* Callback to be called when a step is completed
|
|
38
|
+
*/
|
|
39
|
+
onStepComplete?: VoidFunction
|
|
40
|
+
/**
|
|
41
|
+
* If `true`, the stepper will allow you to skip steps
|
|
42
|
+
*/
|
|
43
|
+
skippable?: boolean
|
|
44
|
+
/**
|
|
45
|
+
* The orientation of the stepper
|
|
46
|
+
*/
|
|
47
|
+
orientation?: "horizontal" | "vertical"
|
|
48
|
+
/**
|
|
49
|
+
* The total number of steps
|
|
50
|
+
*/
|
|
51
|
+
count: number
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface PrivateContext {}
|
|
55
|
+
|
|
56
|
+
type ComputedContext = Readonly<{
|
|
57
|
+
percent: number
|
|
58
|
+
hasNextStep: boolean
|
|
59
|
+
hasPrevStep: boolean
|
|
60
|
+
}>
|
|
61
|
+
|
|
62
|
+
export type UserDefinedContext = RequiredBy<PublicContext, "id">
|
|
63
|
+
|
|
64
|
+
export interface MachineContext extends PublicContext, PrivateContext, ComputedContext {}
|
|
65
|
+
|
|
66
|
+
export interface MachineState {
|
|
67
|
+
value: "idle"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type State = S.State<MachineContext, MachineState>
|
|
71
|
+
|
|
72
|
+
export type Send = S.Send<S.AnyEventObject>
|
|
73
|
+
|
|
74
|
+
export type Service = Machine<MachineContext, MachineState, S.AnyEventObject>
|
|
75
|
+
|
|
76
|
+
/* -----------------------------------------------------------------------------
|
|
77
|
+
* Component API
|
|
78
|
+
* -----------------------------------------------------------------------------*/
|
|
79
|
+
|
|
80
|
+
export interface ItemProps {
|
|
81
|
+
index: number
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ItemState {
|
|
85
|
+
index: number
|
|
86
|
+
triggerId: string
|
|
87
|
+
contentId: string
|
|
88
|
+
current: boolean
|
|
89
|
+
completed: boolean
|
|
90
|
+
last: boolean
|
|
91
|
+
first: boolean
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface MachineApi<T extends PropTypes = PropTypes> {
|
|
95
|
+
/**
|
|
96
|
+
* The value of the stepper.
|
|
97
|
+
*/
|
|
98
|
+
value: number
|
|
99
|
+
/**
|
|
100
|
+
* The percentage of the stepper.
|
|
101
|
+
*/
|
|
102
|
+
percent: number
|
|
103
|
+
/**
|
|
104
|
+
* The total number of steps.
|
|
105
|
+
*/
|
|
106
|
+
count: number
|
|
107
|
+
/**
|
|
108
|
+
* Whether the stepper has a next step.
|
|
109
|
+
*/
|
|
110
|
+
hasNextStep: boolean
|
|
111
|
+
/**
|
|
112
|
+
* Whether the stepper has a previous step.
|
|
113
|
+
*/
|
|
114
|
+
hasPrevStep: boolean
|
|
115
|
+
/**
|
|
116
|
+
* Function to set the value of the stepper.
|
|
117
|
+
*/
|
|
118
|
+
setValue(value: number): void
|
|
119
|
+
/**
|
|
120
|
+
* Function to go to the next step.
|
|
121
|
+
*/
|
|
122
|
+
goToNextStep(): void
|
|
123
|
+
/**
|
|
124
|
+
* Function to go to the previous step.
|
|
125
|
+
*/
|
|
126
|
+
goToPrevStep(): void
|
|
127
|
+
/**
|
|
128
|
+
* Function to go to reset the stepper.
|
|
129
|
+
*/
|
|
130
|
+
resetStep(): void
|
|
131
|
+
/**
|
|
132
|
+
* Returns the state of the item at the given index.
|
|
133
|
+
*/
|
|
134
|
+
getItemState(props: ItemProps): ItemState
|
|
135
|
+
|
|
136
|
+
getRootProps(): T["element"]
|
|
137
|
+
getListProps(): T["element"]
|
|
138
|
+
getItemProps(props: ItemProps): T["element"]
|
|
139
|
+
getTriggerProps(props: ItemProps): T["element"]
|
|
140
|
+
getContentProps(props: ItemProps): T["element"]
|
|
141
|
+
getNextTriggerProps(): T["button"]
|
|
142
|
+
getPrevTriggerProps(): T["button"]
|
|
143
|
+
getProgressProps(): T["element"]
|
|
144
|
+
getIndicatorProps(props: ItemProps): T["element"]
|
|
145
|
+
getSeparatorProps(props: ItemProps): T["element"]
|
|
146
|
+
}
|