stimulus-snippets

Copy-pasteable Stimulus JS controllers for Ruby on Rails. Inspired by shadcn/ui — not an installable package, just files you own.

Accordion

Expand and collapse a set of content panels, with full ARIA disclosure support and optional single-open mode.

Character Count

Show a live character count for a textarea or input, with optional remaining-characters feedback tied to a max length.

Checkbox Required

Require at least a minimum number of checkboxes in a group to be checked before the form can be submitted.

Clipboard

Copy text from a source element to the clipboard on button click, with optional brief feedback.

Dismiss

Click a button to remove or hide the controller element — alerts, flash notices, banners.

File Preview

Show a thumbnail (images) or filename and size (everything else) for files selected in a file input, before the form is submitted.

Form Confirm

Show a `<dialog>`-based confirmation prompt before a form submits or a link/button proceeds, replacing Rails 7's removed `data-confirm` UJS behaviour.

Password Reveal

Toggle a password input between `password` (hidden) and `text` (visible) types, updating show/hide labels in sync.

Password Rules

Show real-time feedback on whether a password satisfies a set of configurable rules. Each rule is a plain HTML element; the controller sets `data-valid="true"` or `data-valid="false"` on it as the user types. Your CSS handles the visual treatment.

Search Filter

Filter a list of items client-side as the user types, with an optional "no results" message.

Slug

Auto-populate a URL slug field from a title or name field as the user types.

Tabs

Show one panel at a time from a set of tab buttons, with full ARIA tablist support and arrow-key navigation.