{"id":51294277,"url":"https://github.com/schappim/stimulus_sheet","last_synced_at":"2026-06-30T13:01:30.057Z","repository":{"id":360603222,"uuid":"1250904159","full_name":"schappim/stimulus_sheet","owner":"schappim","description":"HTML-first bottom-sheet / action-sheet for Stimulus.js (Hotwire). iOS-style half/full snap, drag-to-dismiss, portal-to-body, Hotwire-Native bridge. Built to survive Turbo and TurboNative WKWebView.","archived":false,"fork":false,"pushed_at":"2026-05-27T04:48:23.000Z","size":792,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-27T06:20:42.602Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/schappim/stimulus_sheet","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schappim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-27T04:23:26.000Z","updated_at":"2026-05-27T04:48:27.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/schappim/stimulus_sheet","commit_stats":null,"previous_names":["schappim/stimulus_sheet"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/schappim/stimulus_sheet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schappim%2Fstimulus_sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schappim%2Fstimulus_sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schappim%2Fstimulus_sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schappim%2Fstimulus_sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schappim","download_url":"https://codeload.github.com/schappim/stimulus_sheet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schappim%2Fstimulus_sheet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34967627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-30T02:00:05.919Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-30T13:01:26.864Z","updated_at":"2026-06-30T13:01:30.046Z","avatar_url":"https://github.com/schappim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stimulus_sheet\n\n[![CI](https://github.com/schappim/stimulus_sheet/actions/workflows/ci.yml/badge.svg)](https://github.com/schappim/stimulus_sheet/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/@ninjaai/stimulus_sheet?label=npm)](https://www.npmjs.com/package/@ninjaai/stimulus_sheet)\n[![stimulus_sheet_rails gem](https://img.shields.io/gem/v/stimulus_sheet_rails?label=stimulus_sheet_rails)](https://rubygems.org/gems/stimulus_sheet_rails)\n\nAn **HTML-first bottom-sheet / action-sheet for [Stimulus.js](https://stimulus.hotwired.dev/) (Hotwire)**.\n\niOS-style half/full snap. Drag-to-dismiss. Portal-to-body so the sheet escapes a Turbo frame's stacking context. Optional Hotwire-Native bridge so a tap on a trigger opens a real native sheet on iOS / Android — and falls back to the web sheet on a browser. **Built to survive Turbo navigations and TurboNative WKWebView without crashing the web view.**\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/screenshots/01-basic-open.png\" alt=\"A bottom sheet open in half mode over a phone-shaped viewport\" width=\"320\" /\u003e\n  \u0026nbsp;\n  \u003cimg src=\"docs/screenshots/03-action-list.png\" alt=\"A sectioned iOS-style action sheet with icon rows\" width=\"320\" /\u003e\n\u003c/p\u003e\n\n## What you get\n\n- **iOS-style bottom sheet** — half and full snap states, rounded top corners, safe-area aware, drag handle.\n- **Pointer-event drag** — single code path for touch / mouse / stylus, with a velocity-based snap and a `pull-down-from-the-top-of-the-scroll-area` close gesture.\n- **Portal-to-body** — opt in to lift the sheet out of a transformed ancestor (e.g. a Turbo `\u003cturbo-frame id=\"mobile-screen\"\u003e`) so `position: fixed` and z-index work relative to the viewport. Stale portaled wrappers are evicted on the next render — no zombies.\n- **Trigger registry** — `\u003cbutton data-controller=\"sheet-trigger\" data-sheet-trigger-id-value=\"X\"\u003e` opens any sheet registered by id, anywhere in the DOM, without DOM-id lookups or Stimulus outlets.\n- **Imperative API** — `StimulusSheet.open(id)` / `close(id)` / `toggle(id)` from any JS (Turbo Stream callback, console, third-party widget).\n- **Events** — `sheet:opened`, `sheet:closed`, `sheet:snap`, `sheet:connected`, `sheet:disconnected` bubble off the wrapper. Detail carries `{ id, sheet, state }`.\n- **Hotwire-Native bridge** — opt-in `bridge-sheet` controller dispatches a `hotwire-native:bridge` event the native shell can intercept to render `UIActionSheet` / Android `BottomSheet`. Falls through to the web sheet on a plain browser.\n- **No `body:has(...)`** — a marker class on `\u003cbody\u003e` is toggled in JS instead, so hosts can react to \"any sheet open\" without paying the cost of a `body:has(.ss-sheet-full)` selector that crashes WebKit under load.\n\n## With Rails\n\nPrefer a server-driven version with view helpers? The optional [`stimulus_sheet_rails`](gem/stimulus_sheet_rails) companion ships the JS + CSS bundle, an importmap pin, view partials, and a `render_sheet` / `render_sheet_trigger` helper. See [`RAILS.md`](RAILS.md) for the integration walkthrough.\n\n---\n\n## Install\n\n**Option A — plain `\u003cscript\u003e` (no bundler).** Self-contained IIFE bundle with Stimulus included.\n\n```html\n\u003clink rel=\"stylesheet\" href=\"https://unpkg.com/@ninjaai/stimulus_sheet/dist/stimulus_sheet.css\" /\u003e\n\u003cscript src=\"https://unpkg.com/@ninjaai/stimulus_sheet/dist/stimulus_sheet.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e StimulusSheet.start() \u003c/script\u003e\n```\n\n**Option B — npm + a bundler.** Stimulus is a peer dependency.\n\n```bash\nnpm install @ninjaai/stimulus_sheet @hotwired/stimulus\n```\n\n```js\nimport { Application } from \"@hotwired/stimulus\"\nimport StimulusSheet from \"@ninjaai/stimulus_sheet\"\nimport \"@ninjaai/stimulus_sheet/style.css\"\n\nconst app = Application.start()\nStimulusSheet.start(app)\n```\n\n`StimulusSheet.start(app?)` registers all controllers (`sheet`, `sheet-trigger`, `bridge-sheet`) on the given Stimulus `Application` (or starts a new one) and returns it.\n\n**Option C — Rails / Hotwire (gem from RubyGems).**\n\n```bash\nbundle add stimulus_sheet_rails\n```\n\nFull setup (importmap, stylesheet, view helpers) is in [`RAILS.md`](RAILS.md).\n\n---\n\n## Quick start\n\n```html\n\u003clink rel=\"stylesheet\" href=\"dist/stimulus_sheet.css\" /\u003e\n\n\u003cbutton data-controller=\"sheet-trigger\"\n        data-sheet-trigger-id-value=\"menu\"\n        data-action=\"click-\u003esheet-trigger#open\"\u003e\n  Open menu\n\u003c/button\u003e\n\n\u003cdiv data-controller=\"sheet\" data-sheet-id-value=\"menu\"\u003e\n  \u003cdiv class=\"ss-sheet-backdrop\"\n       data-sheet-target=\"backdrop\"\n       data-action=\"click-\u003esheet#close\"\u003e\u003c/div\u003e\n  \u003cdiv class=\"ss-sheet\" data-sheet-target=\"sheet\"\u003e\n    \u003cdiv class=\"ss-sheet-handle\" data-sheet-target=\"handle\"\u003e\u003c/div\u003e\n    \u003cdiv class=\"ss-sheet-scroll\" data-sheet-target=\"scroll\"\u003e\n      \u003cdiv class=\"ss-section-title\"\u003eMenu\u003c/div\u003e\n      \u003cbutton class=\"ss-item\" data-action=\"click-\u003esheet#close\"\u003eEdit\u003c/button\u003e\n      \u003cbutton class=\"ss-item\" data-action=\"click-\u003esheet#close\"\u003eDuplicate\u003c/button\u003e\n      \u003cbutton class=\"ss-item ss-item-destructive\" data-action=\"click-\u003esheet#close\"\u003eDelete\u003c/button\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n\u003c/div\u003e\n\n\u003cscript src=\"dist/stimulus_sheet.js\"\u003e\u003c/script\u003e\n\u003cscript\u003eStimulusSheet.start()\u003c/script\u003e\n```\n\nThat's it. The sheet opens in half mode, drags up to full, drags down (or tap-backdrop) to close. Try the [`demo/`](demo) directory for portaling, multi-sheet, forms, events, and the Hotwire-Native bridge.\n\n### Half vs full\n\nThe sheet has two snap states. Half is the default — content scrolls inside the sheet, the host page is still partially visible. Full takes the whole viewport (minus the safe-area inset at the top).\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/screenshots/02-half-snap.png\" alt=\"Sheet snapped to half\" width=\"320\" /\u003e\n  \u0026nbsp;\n  \u003cimg src=\"docs/screenshots/02-full-snap.png\" alt=\"Sheet snapped to full\" width=\"320\" /\u003e\n\u003c/p\u003e\n\n---\n\n## Markup contract\n\n### The sheet wrapper\n\n```html\n\u003cdiv data-controller=\"sheet\"\n     data-sheet-id-value=\"myMenu\"\n     data-sheet-portal-value=\"false\"\n     data-sheet-half-offset-value=\"55\"\n     data-sheet-open-on-connect-value=\"false\"\n     data-sheet-initial-expanded-value=\"false\"\u003e\n  \u003cdiv class=\"ss-sheet-backdrop\"\n       data-sheet-target=\"backdrop\"\n       data-action=\"click-\u003esheet#close\"\u003e\u003c/div\u003e\n  \u003cdiv class=\"ss-sheet\" data-sheet-target=\"sheet\"\u003e\n    \u003cdiv class=\"ss-sheet-handle\" data-sheet-target=\"handle\"\u003e\u003c/div\u003e\n    \u003cdiv class=\"ss-sheet-scroll\" data-sheet-target=\"scroll\"\u003e\n      \u003c!-- your content --\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n\n| Value | Default | Meaning |\n| --- | --- | --- |\n| `data-sheet-id-value` | `\"\"` | Lookup id for triggers and `StimulusSheet.open(id)`. |\n| `data-sheet-portal-value` | `false` | Lift the wrapper to `\u003cbody\u003e` on connect; remove on disconnect. |\n| `data-sheet-half-offset-value` | `55` | Half-state offset (percent of sheet height). |\n| `data-sheet-open-on-connect-value` | `false` | Open immediately after Stimulus connects (handy for Turbo Stream replies). |\n| `data-sheet-initial-expanded-value` | `false` | When `open-on-connect` fires (or a trigger calls `#open` without an explicit `expanded`), start in full mode. |\n\n### Targets\n\n| Target | Required? | Notes |\n| --- | --- | --- |\n| `sheet` | yes | The container that animates. Receives `.ss-sheet`, `.ss-sheet-half`, `.ss-sheet-full`. |\n| `backdrop` | recommended | Sits behind the sheet; wire `click-\u003esheet#close` for outside-tap dismiss. |\n| `handle` | recommended | Drag handle. The controller adds `.ss-sheet-handle`; `touch-action: none` is applied so pointer drags don't fight scroll. |\n| `scroll` | recommended | The scrolling content region. Drag in full-mode is only honoured here when `scrollTop === 0`. |\n\n### Triggers\n\n```html\n\u003cbutton data-controller=\"sheet-trigger\"\n        data-sheet-trigger-id-value=\"myMenu\"\n        data-sheet-trigger-expanded-value=\"true\"\n        data-action=\"click-\u003esheet-trigger#open\"\u003e\n  Open\n\u003c/button\u003e\n```\n\n`#open`, `#close`, and `#toggle` are all wired. The trigger looks the sheet up in the in-memory registry the `sheet` controller populates on connect — this works across portaling, multiple Turbo frames, and re-renders.\n\n### Imperative API\n\n```js\nStimulusSheet.open(\"myMenu\", { expanded: true })\nStimulusSheet.close(\"myMenu\")\nStimulusSheet.toggle(\"myMenu\")\nStimulusSheet.isOpen(\"myMenu\")          // → true | false\nStimulusSheet.getSheet(\"myMenu\")        // → the SheetController instance, or null\n```\n\nEach wrapper also exposes a `sheetApi` directly:\n\n```js\nconst wrap = document.querySelector('[data-sheet-id-value=\"myMenu\"]')\nwrap.sheetApi.open({ expanded: true })\nwrap.sheetApi.state()      // 'closed' | 'half' | 'full'\nwrap.sheetApi.isOpen()\n```\n\n### Events\n\n| Event | Detail |\n| --- | --- |\n| `sheet:opened` | `{ id, sheet, state }` |\n| `sheet:closed` | `{ id, sheet }` |\n| `sheet:snap` | `{ id, sheet, state }` |\n| `sheet:connected` / `sheet:disconnected` | `{ id, sheet }` |\n\n```js\ndocument.addEventListener(\"sheet:opened\", (ev) =\u003e {\n  console.log(\"opened\", ev.detail.id, ev.detail.state)\n})\n```\n\n---\n\n## TurboNative considerations\n\nThis library was extracted from a Hotwire-Native iOS/Android app. The following decisions are deliberate; if you're porting to another shell, keep them in mind:\n\n- **Pointer events, not touch+mouse.** A single `pointerdown`/`pointermove`/`pointerup` handler runs everywhere. Registering both touch and mouse listeners on iOS WKWebView causes nondeterministic gesture state.\n- **No `body:has(...)`.** Selectors like `body:has(.ss-sheet-full)` are re-evaluated on every reflow against the whole DOM — known to crash WKWebView under deep DOM. A marker class `body.ss-sheet-open` is toggled in JS instead. Hosts that want to react to \"any sheet open\" should target that class.\n- **No `DOMContentLoaded`.** Controllers do their work on Stimulus connect. Turbo navigations don't re-fire `DOMContentLoaded`, so anything wired to it stops working after the first nav.\n- **Per-sheet portaling.** Each sheet's controller portals its own wrapper on connect and removes its own copy on disconnect, evicting any stale wrapper sharing the same `data-ss-portal-slot` first. No global `turbo:before-frame-render` sweep that can race with concurrent renders.\n- **Body marker is cleared safely.** When a sheet disconnects, the marker is only cleared when no *other* sheet is open — so a Turbo Stream that replaces sheet A with sheet B keeps `body.ss-sheet-open` set throughout.\n- **Pointer capture is best-effort.** Older WKWebViews throw on `setPointerCapture` inside a passive handler; the call is `try`-wrapped so the drag still works.\n\n---\n\n## Theming\n\nAll visual properties are CSS custom properties on `.ss-sheet-wrapper`:\n\n```css\n.ss-sheet-wrapper {\n  --ss-bg: #ffffff;\n  --ss-radius: 16px;\n  --ss-backdrop: rgba(0, 0, 0, 0.35);\n  --ss-handle-bg: #d0d0d0;\n  /* …see src/styles/stimulus_sheet.css for the full list */\n}\n```\n\nOverride on a specific wrapper for a one-off look, or on `:root` for a global re-theme. The library never writes inline colours.\n\n---\n\n## Tests\n\n- `npm test` — vitest (registry, portal, controller wiring) in jsdom.\n- `npm run test:e2e` — Playwright in WebKit + Chromium against the live demo pages. Closest analogue to the iOS WKWebView this library targets.\n\n## Demo gallery\n\nCaptured from the demo pages in WebKit at a 2× retina iPhone viewport, so what you see is what an iOS / Hotwire-Native shell renders.\n\n| Demo | Screenshot |\n| --- | --- |\n| **01 — Basic sheet** ([demo](demo/01-basic.html)) — single sheet, opens half, backdrop tap to close. | \u003cimg src=\"docs/screenshots/01-basic-open.png\" alt=\"01 basic open\" width=\"260\" /\u003e |\n| **02 — Half \u0026amp; full** ([demo](demo/02-half-and-full.html)) — two triggers for one sheet, one opens half, the other goes full. | \u003cimg src=\"docs/screenshots/02-full-snap.png\" alt=\"02 full snap\" width=\"260\" /\u003e |\n| **03 — Action list** ([demo](demo/03-action-list.html)) — sectioned `.ss-section-title` + `.ss-item` rows. | \u003cimg src=\"docs/screenshots/03-action-list.png\" alt=\"03 action list\" width=\"260\" /\u003e |\n| **04 — Multiple sheets** ([demo](demo/04-multiple-sheets.html)) — two independent sheets keyed by id. | \u003cimg src=\"docs/screenshots/04-multiple-sheets.png\" alt=\"04 multiple sheets\" width=\"260\" /\u003e |\n| **06 — Portal to body** ([demo](demo/06-portaled-from-frame.html)) — sheet rendered inside a transformed frame, lifted to `\u003cbody\u003e` on connect. | \u003cimg src=\"docs/screenshots/06-portal.png\" alt=\"06 portaled\" width=\"260\" /\u003e |\n| **08 — Non-dismissable** ([demo](demo/08-non-dismissable.html)) — backdrop has no `#close` action; explicit confirm/cancel required. | \u003cimg src=\"docs/screenshots/08-non-dismissable.png\" alt=\"08 non-dismissable\" width=\"260\" /\u003e |\n| **09 — Form in a sheet** ([demo](demo/09-form-in-sheet.html)) — submit-to-close, Cancel row. | \u003cimg src=\"docs/screenshots/09-form-in-sheet.png\" alt=\"09 form in sheet\" width=\"260\" /\u003e |\n\nRegenerate after editing a demo:\n\n```bash\nnpm run dev                            # in one terminal\nnode scripts/screenshot-demos.mjs      # in another\n```\n\n## Repo layout\n\n```\nsrc/\n  controllers/  sheet, sheet-trigger, bridge-sheet\n  lib/          registry, portal, drag, turbo_safe\n  styles/       stimulus_sheet.css\ndemo/           hand-written HTML demos served by `npm run dev`\ntest/           vitest unit tests\ne2e/            Playwright tests\ngem/            stimulus_sheet_rails Rails companion\nskills/         LLM-facing usage docs (stimulus-sheet-js, stimulus-sheet-rails)\nbin/            sync-rails-assets (vendor built bundle into the gem)\n```\n\n## Licence\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschappim%2Fstimulus_sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschappim%2Fstimulus_sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschappim%2Fstimulus_sheet/lists"}