Skip to content

Commit

Permalink
chore(svelte): add splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed May 20, 2024
1 parent 6dd0f3b commit 8ee1635
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/svelte-ts/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import Select from "./routes/select.svelte"
import SignaturePad from "./routes/signature-pad.svelte"
import Slider from "./routes/slider.svelte"
import Splitter from "./routes/splitter.svelte"
import Switch from "./routes/switch.svelte"
import Tabs from "./routes/tabs.svelte"
import TagsInput from "./routes/tags-input.svelte"
Expand Down Expand Up @@ -73,6 +74,7 @@
{ path: "/rating-group", component: RatingGroup },
{ path: "/segment-control", component: SegmentControl },
{ path: "/select", component: Select },
{ path: "/splitter", component: Splitter },
{ path: "/signature-pad", component: SignaturePad },
{ path: "/slider", component: Slider },
{ path: "/switch", component: Switch },
Expand Down
41 changes: 41 additions & 0 deletions examples/svelte-ts/src/routes/splitter.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script lang="ts">
import { normalizeProps, useMachine } from "@zag-js/svelte"
import { splitterControls } from "@zag-js/shared"
import * as splitter from "@zag-js/splitter"
import { useControls } from "$lib/use-controls.svelte"
import Toolbar from "$lib/components/toolbar.svelte"
import StateVisualizer from "$lib/components/state-visualizer.svelte"
const controls = useControls(splitterControls)
const [snapshot, send] = useMachine(
splitter.machine({
id: "1",
size: [
{ id: "a", size: 50 },
{ id: "b", size: 50 },
],
}),
{
context: controls.context,
},
)
const api = $derived(splitter.connect(snapshot, send, normalizeProps))
</script>

<main class="splitter">
<div {...api.rootProps}>
<div {...api.getPanelProps({ id: "a" })}>
<p>A</p>
</div>
<div {...api.getResizeTriggerProps({ id: "a:b" })}></div>
<div {...api.getPanelProps({ id: "b" })}>
<p>B</p>
</div>
</div>
</main>

<Toolbar {controls} viz>
<StateVisualizer state={snapshot} omit={["previousPanels", "initialSize"]} />
</Toolbar>

0 comments on commit 8ee1635

Please sign in to comment.