Skip to content

Commit feac40f

Browse files
authored
chore: add snippets of steps for svelte (#2905)
2 parents 75b0495 + 9d1d924 commit feac40f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```bash
2+
npm install @zag-js/steps @zag-js/svelte
3+
# or
4+
yarn add @zag-js/steps @zag-js/svelte
5+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
```svelte
2+
<script lang="ts">
3+
import { normalizeProps, useMachine } from "@zag-js/svelte"
4+
import * as steps from "@zag-js/steps"
5+
6+
const stepsData = [
7+
{ title: "Step 1" },
8+
{ title: "Step 2" },
9+
{ title: "Step 3" },
10+
]
11+
12+
const service = useMachine(steps.machine, {
13+
id: "1",
14+
count: stepsData.length,
15+
})
16+
17+
const api = $derived(steps.connect(service, normalizeProps))
18+
</script>
19+
20+
<div {...api.getRootProps()}>
21+
<div {...api.getListProps()}>
22+
{#each stepsData as step, index}
23+
<div {...api.getItemProps({ index })}>
24+
<button {...api.getTriggerProps({ index })}>
25+
<div {...api.getIndicatorProps({ index })}>{index + 1}</div>
26+
<span>{step.title}</span>
27+
</button>
28+
<div {...api.getSeparatorProps({ index })} />
29+
</div>
30+
{/each}
31+
</div>
32+
33+
{#each stepsData as step, index}
34+
<div {...api.getContentProps({ index })}>
35+
{step.title} - {step.description}
36+
</div>
37+
{/each}
38+
39+
<div {...api.getContentProps({ index: stepsData.length })}>
40+
Steps Complete - Thank you for filling out the form!
41+
</div>
42+
43+
<div>
44+
<button {...api.getPrevTriggerProps()}>Back</button>
45+
<button {...api.getNextTriggerProps()}>Next</button>
46+
</div>
47+
</div>
48+
```

0 commit comments

Comments
 (0)