Skip to content

Commit

Permalink
chore: add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikorin committed Nov 4, 2023
1 parent 7232c66 commit e6b10b1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
42 changes: 42 additions & 0 deletions examples/nuxt-ts/pages/collapsible.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script setup lang="ts">
import * as collapsible from "@zag-js/collapsible"
import { collapsibleControls, collapsibleData } from "@zag-js/shared"
import { normalizeProps, useMachine } from "@zag-js/vue"
const controls = useControls(collapsibleControls)
const [state, send] = useMachine(collapsible.machine({ id: "1" }), {
context: controls.context,
})
const api = computed(() => collapsible.connect(state.value, send, normalizeProps))
</script>

<template>
<main class="collapsible">
<div v-bind="api.rootProps">
<div>
<span>{{ collapsibleData.headline }}</span>
<button v-if="api.isOpen" v-bind="api.triggerProps">Collapse</button>
<button v-if="!api.isOpen" v-bind="api.triggerProps">Expand</button>
</div>

<div>
<span>{{ collapsibleData.visibleItem }}</span>
</div>

<div v-bind="api.contentProps">
<div v-for="item in data" :key="item.id">
<div>{{ item }}</div>
</div>
</div>
</div>
</main>

<Toolbar>
<StateVisualizer :state="state" />
<template #controls>
<Controls :config="controls.config" :state="controls.context" />
</template>
</Toolbar>
</template>
19 changes: 16 additions & 3 deletions examples/solid-ts/src/pages/collapsible.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as collapsible from "@zag-js/collapsible"
import { normalizeProps, useMachine, mergeProps } from "@zag-js/solid"
import { createMemo, createUniqueId } from "solid-js"
import { collapsibleControls, collapsibleData } from "@zag-js/shared"
import { normalizeProps, useMachine } from "@zag-js/solid"
import { Index, createMemo, createUniqueId } from "solid-js"
import { StateVisualizer } from "../components/state-visualizer"
import { Toolbar } from "../components/toolbar"
import { useControls } from "../hooks/use-controls"
Expand All @@ -18,7 +18,20 @@ export default function Page() {
return (
<>
<main class="collapsible">
<div {...api().rootProps}></div>
<div {...api().rootProps}>
<div>
<span>{collapsibleData.headline}</span>
<button {...api().triggerProps}>{api().isOpen ? "Collapse" : "Expand"}</button>
</div>

<div>
<span>{collapsibleData.visibleItem}</span>
</div>

<div {...api().contentProps}>
<Index each={collapsibleData.items}>{(item) => <div>{item()}</div>}</Index>
</div>
</div>
</main>

<Toolbar controls={controls.ui}>
Expand Down
23 changes: 20 additions & 3 deletions examples/vue-ts/src/pages/collapsible.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as collapsible from "@zag-js/collapsible"
import { normalizeProps, useMachine, mergeProps } from "@zag-js/vue"
import { computed, defineComponent, h, Fragment } from "vue"
import { collapsibleControls, collapsibleData } from "@zag-js/shared"
import { normalizeProps, useMachine } from "@zag-js/vue"
import { computed, defineComponent } from "vue"
import { StateVisualizer } from "../components/state-visualizer"
import { Toolbar } from "../components/toolbar"
import { useControls } from "../hooks/use-controls"
Expand All @@ -23,7 +23,24 @@ export default defineComponent({
return (
<>
<main class="collapsible">
<div {...api.rootProps}></div>
<div {...api.rootProps}>
<div>
<span>{collapsibleData.headline}</span>
<button {...api.triggerProps}>{api.isOpen ? "Collapse" : "Expand"}</button>
</div>

<div>
<span>{collapsibleData.visibleItem}</span>
</div>

<div {...api.contentProps}>
{collapsibleData.items.map((item) => (
<div key={item}>
<span>{item}</span>
</div>
))}
</div>
</div>
</main>

<Toolbar controls={controls.ui}>
Expand Down
5 changes: 2 additions & 3 deletions website/data/snippets/vue-sfc/collapsible/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ const api = computed(() => collapsible.connect(state.value, send, normalizeProps

<template>
<div ref="ref" v-bind="api.rootProps">
<button v-bind="api.triggerProps">
{{ state.value === "open" ? "Collapse" : "Expand" }}
</button>
<button v-if="api.isOpen" v-bind="api.triggerProps">Collapse</button>
<button v-if="!api.isOpen" v-bind="api.triggerProps">Expand</button>
<div v-bind="api.contentProps">
<div
v-for="item in data"
Expand Down

0 comments on commit e6b10b1

Please sign in to comment.