Skip to content

feat: bottom sheet #2548

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions examples/next-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@zag-js/async-list": "workspace:*",
"@zag-js/auto-resize": "workspace:*",
"@zag-js/avatar": "workspace:*",
"@zag-js/bottom-sheet": "workspace:*",
"@zag-js/carousel": "workspace:*",
"@zag-js/checkbox": "workspace:*",
"@zag-js/clipboard": "workspace:*",
Expand Down
63 changes: 63 additions & 0 deletions examples/next-ts/pages/bottom-sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as bottomSheet from "@zag-js/bottom-sheet"
import { normalizeProps, useMachine } from "@zag-js/react"
import { bottomSheetControls } from "@zag-js/shared"
import { TicketPlusIcon } from "lucide-react"
import { useId } from "react"
import { StateVisualizer } from "../components/state-visualizer"
import { Toolbar } from "../components/toolbar"
import { useControls } from "../hooks/use-controls"

export default function Page() {
const controls = useControls(bottomSheetControls)

const service = useMachine(bottomSheet.machine, {
id: useId(),
...controls.context,
})

const api = bottomSheet.connect(service, normalizeProps)

return (
<>
<main className="bottom-sheet">
<button {...api.triggerProps}>Open</button>
<div {...api.backdropProps} />

<div {...api.grabberProps}>
<div {...api.contentProps}>
<div>
<div className="x">
{Array.from({ length: 10 }).map((_, i) => (
<div key={i} className="x-trigger">
<button>
<TicketPlusIcon />
</button>
<span className="x-trigger-text">Whats new</span>
</div>
))}
</div>

<div className="y">
{Array.from({ length: 10 }).map((_, i) => (
<div key={i} className="y-trigger">
<button>
<span>Whats new</span>
<TicketPlusIcon />
</button>
</div>
))}
</div>
</div>
{/* <button {...api.closeTriggerProps}>
<XIcon />
</button> */}
</div>
</div>
</main>

<Toolbar controls={controls.ui} viz>
<StateVisualizer state={service} />
</Toolbar>
</>
)
}
3 changes: 2 additions & 1 deletion examples/nuxt-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@zag-js/async-list": "workspace:*",
"@zag-js/auto-resize": "workspace:*",
"@zag-js/avatar": "workspace:*",
"@zag-js/bottom-sheet": "workspace:*",
"@zag-js/carousel": "workspace:*",
"@zag-js/checkbox": "workspace:*",
"@zag-js/clipboard": "workspace:*",
Expand Down Expand Up @@ -96,4 +97,4 @@
"@types/node": "24.0.3",
"nuxt": "3.17.5"
}
}
}
22 changes: 22 additions & 0 deletions examples/nuxt-ts/pages/bottom-sheet.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script setup lang="ts">
import * as bottomSheet from "@zag-js/bottom-sheet"
import { bottomSheetControls, bottomSheetData } from "@zag-js/shared"
import { normalizeProps, useMachine } from "@zag-js/vue"
import { useId } from "vue"

const service = useMachine(bottomSheet.machine, {
id: useId(),
})

const api = computed(() => bottomSheet.connect(service, normalizeProps))
</script>

<template>
<main className="bottom-sheet">
<div v-bind="api.rootProps"></div>
</main>

<Toolbar>
<StateVisualizer :state="service" />
</Toolbar>
</template>
3 changes: 2 additions & 1 deletion examples/preact-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@zag-js/async-list": "workspace:*",
"@zag-js/auto-resize": "workspace:*",
"@zag-js/avatar": "workspace:*",
"@zag-js/bottom-sheet": "workspace:*",
"@zag-js/carousel": "workspace:*",
"@zag-js/checkbox": "workspace:*",
"@zag-js/clipboard": "workspace:*",
Expand Down Expand Up @@ -95,4 +96,4 @@
"typescript": "5.8.3",
"vite": "6.3.5"
}
}
}
1 change: 1 addition & 0 deletions examples/solid-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@zag-js/async-list": "workspace:*",
"@zag-js/auto-resize": "workspace:*",
"@zag-js/avatar": "workspace:*",
"@zag-js/bottom-sheet": "workspace:*",
"@zag-js/carousel": "workspace:*",
"@zag-js/checkbox": "workspace:*",
"@zag-js/clipboard": "workspace:*",
Expand Down
32 changes: 32 additions & 0 deletions examples/solid-ts/src/routes/bottom-sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as sheet from "@zag-js/bottom-sheet"
import { bottomSheetControls } from "@zag-js/shared"
import { normalizeProps, useMachine } from "@zag-js/solid"
import { createMemo, createUniqueId } from "solid-js"
import { StateVisualizer } from "../components/state-visualizer"
import { Toolbar } from "../components/toolbar"
import { useControls } from "../hooks/use-controls"

export default function Page() {
const controls = useControls(bottomSheetControls)

const service = useMachine(
sheet.machine,
controls.mergeProps({
id: createUniqueId(),
}),
)

const api = createMemo(() => sheet.connect(service, normalizeProps))

return (
<>
<main class="bottom-sheet">
<div {...api().headerProps}></div>
</main>

<Toolbar controls={controls}>
<StateVisualizer state={service} />
</Toolbar>
</>
)
}
3 changes: 2 additions & 1 deletion examples/svelte-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@zag-js/async-list": "workspace:*",
"@zag-js/auto-resize": "workspace:*",
"@zag-js/avatar": "workspace:*",
"@zag-js/bottom-sheet": "workspace:*",
"@zag-js/carousel": "workspace:*",
"@zag-js/checkbox": "workspace:*",
"@zag-js/clipboard": "workspace:*",
Expand Down Expand Up @@ -100,4 +101,4 @@
"vite": "6.3.5",
"vite-tsconfig-paths": "5.1.4"
}
}
}
3 changes: 2 additions & 1 deletion examples/vanilla-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@zag-js/async-list": "workspace:*",
"@zag-js/auto-resize": "workspace:*",
"@zag-js/avatar": "workspace:*",
"@zag-js/bottom-sheet": "workspace:*",
"@zag-js/carousel": "workspace:*",
"@zag-js/checkbox": "workspace:*",
"@zag-js/clipboard": "workspace:*",
Expand Down Expand Up @@ -90,4 +91,4 @@
"match-sorter": "8.0.3",
"nanoid": "^5.1.5"
}
}
}
38 changes: 38 additions & 0 deletions examples/vue-ts/src/pages/bottom-sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as bottomSheet from "@zag-js/bottom-sheet"
import { normalizeProps, useMachine, mergeProps } from "@zag-js/vue"
import { computed, defineComponent, h, Fragment } from "vue"
import { bottomSheetControls, bottomSheetData } from "@zag-js/shared"
import { StateVisualizer } from "../components/state-visualizer"
import { Toolbar } from "../components/toolbar"
import { useControls } from "../hooks/use-controls"

export default defineComponent({
name: "bottom-sheet",
setup() {
const controls = useControls(bottomSheetControls)

const [state, send] = useMachine(bottomSheet.machine({ id: "1" }), {
context: controls.context,
})

const apiRef = computed(() => bottomSheet.connect(state.value, send, normalizeProps))

return () => {
const api = apiRef.value

return (
<>
<main class="bottom-sheet">
<div {...api.rootProps}>

</div>
</main>

<Toolbar controls={controls.ui}>
<StateVisualizer state={state} />
</Toolbar>
</>
)
}
},
})
19 changes: 19 additions & 0 deletions packages/machines/bottom-sheet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @zag-js/bottom-sheet

Core logic for the bottom-sheet widget implemented as a state machine

## Installation

```sh
yarn add @zag-js/bottom-sheet
# or
npm i @zag-js/bottom-sheet
```

## Contribution

Yes please! See the [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md) for details.

## Licence

This project is licensed under the terms of the [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
49 changes: 49 additions & 0 deletions packages/machines/bottom-sheet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@zag-js/bottom-sheet",
"version": "0.0.0",
"description": "Core logic for the bottom-sheet widget implemented as a state machine",
"keywords": [
"js",
"machine",
"xstate",
"statechart",
"component",
"chakra-ui",
"bottom-sheet"
],
"author": "Segun Adebayo <sage@adebayosegun.com>",
"homepage": "https://github.com/chakra-ui/zag#readme",
"license": "MIT",
"main": "src/index.ts",
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/bottom-sheet",
"sideEffects": false,
"files": [
"dist",
"src"
],
"scripts": {
"build": "tsup",
"lint": "eslint src --ext .ts,.tsx",
"typecheck": "tsc --noEmit",
"prepack": "clean-package",
"postpack": "clean-package restore"
},
"publishConfig": {
"access": "public"
},
"bugs": {
"url": "https://github.com/chakra-ui/zag/issues"
},
"dependencies": {
"@zag-js/anatomy": "workspace:*",
"@zag-js/core": "workspace:*",
"@zag-js/dom-query": "workspace:*",
"@zag-js/dom-event": "workspace:*",
"@zag-js/utils": "workspace:*",
"@zag-js/types": "workspace:*"
},
"devDependencies": {
"clean-package": "2.2.0"
},
"clean-package": "../../../clean-package.config.json"
}
14 changes: 14 additions & 0 deletions packages/machines/bottom-sheet/src/bottom-sheet.anatomy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createAnatomy } from "@zag-js/anatomy"

export const anatomy = createAnatomy("bottom-sheet").parts(
"content",
"trigger",
"overlay",
"backdrop",
"header",
"grabber",
"grabberIndicator",
"closeTrigger",
)

export const parts = anatomy.build()
Loading
Loading