Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update snippets for tour and tree view #2001

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/nuxt-ts/components/TreeNode.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { FileIcon, FolderIcon, ChevronRightIcon } from "lucide-vue-next"
import * as tree from "@zag-js/tree-view"
import type { Api } from "@zag-js/tree-view"
import { ChevronRightIcon, FileIcon, FolderIcon } from "lucide-vue-next"

interface Node {
id: string
Expand All @@ -11,7 +11,7 @@ interface Node {
interface Props {
node: Node
indexPath: number[]
api: tree.Api
api: Api
}

const props = defineProps<Props>()
Expand Down
18 changes: 9 additions & 9 deletions examples/nuxt-ts/pages/tour.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script setup lang="ts">
import { ref, onMounted, useId } from "vue"
import * as tour from "@zag-js/tour"
import { tourControls, tourData } from "@zag-js/shared"
import { useMachine, normalizeProps } from "@zag-js/vue"
import * as tour from "@zag-js/tour"
import { normalizeProps, useMachine } from "@zag-js/vue"
import { X } from "lucide-vue-next"
import { useId } from "vue"

const controls = useControls(tourControls)

Expand Down Expand Up @@ -43,21 +43,21 @@ const open = computed(() => api.value.open && api.value.step)
</div>

<Teleport to="body" v-if="open">
<div v-if="api.step.backdrop" v-bind="api.getBackdropProps()" />
<div v-if="api.step?.backdrop" v-bind="api.getBackdropProps()" />
<div v-bind="api.getSpotlightProps()" />
<div v-bind="api.getPositionerProps()">
<div v-bind="api.getContentProps()">
<div v-if="api.step.arrow" v-bind="api.getArrowProps()">
<div v-if="api.step?.arrow" v-bind="api.getArrowProps()">
<div v-bind="api.getArrowTipProps()" />
</div>

<p v-bind="api.getTitleProps()">{{ api.step.title }}</p>
<div v-bind="api.getDescriptionProps()">{{ api.step.description }}</div>
<p v-bind="api.getTitleProps()">{{ api.step?.title }}</p>
<div v-bind="api.getDescriptionProps()">{{ api.step?.description }}</div>
<div v-bind="api.getProgressTextProps()">{{ api.getProgressText() }}</div>

<div v-if="api.step.actions" class="tour button__group">
<div v-if="api.step?.actions" class="tour button__group">
<button
v-for="action in api.step.actions"
v-for="action in api.step?.actions"
:key="action.label"
v-bind="api.getActionTriggerProps({ action })"
>
Expand Down
41 changes: 34 additions & 7 deletions website/data/snippets/vue/tour/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,34 @@
<script setup lang="ts">
import * as tour from "@zag-js/tour"
import { useMachine, normalizeProps } from "@zag-js/vue"
import { ref, onMounted, useId, computed, Teleport } from "vue"
import { useId, computed, Teleport } from "vue"

const steps: tour.StepDetails[] = [
{
type: 'dialog',
id: 'start',
title: 'Ready to go for a ride',
description: "Let's take the tour component for a ride and have some fun!",
actions: [{ label: "Let's go!", action: 'next' }],
},
{
type: 'dialog',
id: 'logic',
title: 'Statechart',
description: `As an engineer, you'll learn about the internal statechart that powers the tour.`,
actions: [
{ label: 'Prev', action: 'prev' },
{ label: 'Next', action: 'next' },
],
},
{
type: 'dialog',
id: 'end',
title: 'Amazing! You got to the end',
description: 'Like what you see? Now go ahead and use it in your project.',
actions: [{ label: 'Finish', action: 'dismiss' }],
},
]

const [state, send] = useMachine(tour.machine({ id: useId(), steps }))

Expand All @@ -17,23 +44,23 @@
</div>

<Teleport to="body" v-if="open">
<div v-if="api.step.backdrop" v-bind="api.getBackdropProps()" />
<div v-if="api.step?.backdrop" v-bind="api.getBackdropProps()" />
<div v-bind="api.getSpotlightProps()" />
<div v-bind="api.getPositionerProps()">
<div v-bind="api.getContentProps()">
<div v-if="api.step.arrow" v-bind="api.getArrowProps()">
<div v-if="api.step?.arrow" v-bind="api.getArrowProps()">
<div v-bind="api.getArrowTipProps()" />
</div>

<p v-bind="api.getTitleProps()">{{ api.step.title }}</p>
<div v-bind="api.getDescriptionProps()">{{ api.step.description }}</div>
<p v-bind="api.getTitleProps()">{{ api.step?.title }}</p>
<div v-bind="api.getDescriptionProps()">{{ api.step?.description }}</div>
<div v-bind="api.getProgressTextProps()">
{{ api.getProgressText() }}
</div>

<div v-if="api.step.actions" class="tour button__group">
<div v-if="api.step?.actions" class="tour button__group">
<button
v-for="action in api.step.actions"
v-for="action in api.step?.actions"
:key="action.label"
v-bind="api.getActionTriggerProps({ action })"
>
Expand Down
14 changes: 3 additions & 11 deletions website/data/snippets/vue/tree-view/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- TreeNode.vue -->
<script setup lang="ts">
import { FileIcon, FolderIcon, ChevronRightIcon } from "lucide-vue-next"
import * as tree from "@zag-js/tree-view"
import type { Api } from "@zag-js/tree-view"

interface Node {
id: string
Expand All @@ -13,7 +13,7 @@
interface Props {
node: Node
indexPath: number[]
api: tree.Api
api: Api
}

const props = defineProps<Props>()
Expand Down Expand Up @@ -57,10 +57,9 @@
```html
<!-- TreeView.vue -->
<script setup lang="ts">
import { treeviewControls } from "@zag-js/shared"
import * as tree from "@zag-js/tree-view"
import { normalizeProps, useMachine } from "@zag-js/vue"
import { useId } from "vue"
import { computed, useId } from "vue"

// 1. Create the tree collection

Expand Down Expand Up @@ -94,12 +93,5 @@
</div>
</div>
</main>

<Toolbar>
<StateVisualizer :state="state" :omit="['collection']" />
<template #controls>
<Controls :control="controls" />
</template>
</Toolbar>
</template>
```
Loading