reflex_behaviors
v0.0.10
Published
Pre-built easy to use reactive TurboReflex behaviors for Rails/Hotwire apps.
Downloads
16
Readme
Pre-built easy to use reactive TurboReflex behaviors for Rails/Hotwire apps.
Table of Contents
Sponsors
Dependencies
- ruby
>=2.7.3
- rails
>=6.1
- turbo-rails
>=1.1
- @hotwired/turbo
>=7.2.0
- @hotwired/turbo-rails
>=7.2.0
- turbo_ready
>=0.1.2
- turbo_reflex
>=0.0.28
Installation
Be sure to install the same version for each libary.
bundle add "reflex_behaviors --version VERSION"
yarn add "reflex_behaviors@VERSION --exact"
Setup
Import and intialize ReflexBehaviors in your application.
# Gemfile
gem "turbo-rails", ">= 1.1", "< 2"
+gem "reflex_behaviors", "~> VERSION"
# package.json
"dependencies": {
"@hotwired/turbo-rails": ">=7.2",
+ "reflex_behaviors": "^VERSION"
# app/javascript/application.js
import '@hotwired/turbo-rails'
+import 'reflex_behaviors'
Behaviors
Toggle
Toggle content via conditional rendering.
This example will re-render the post
partial and toggle the form
section.
<!-- app/views/posts/_post.html.erb -->
<%= tag.div id: dom_id(post) do %>
<!-- content -->
<%= toggle_trigger_tag renders: current_partial_path, morphs: dom_id(post),
controls: dom_id(post, :form), locals: local_assigns, assigns: { post: @post }) do %>
<% if toggle_target_collapsed? dom_id(post, :form) %>
<%= link_to "Edit Post Inline", request.path %>
<% else %>
<%= link_to "Cancel Editing Post", request.path %>
<% end %>
<% end %>
<%= toggle_target_tag dom_id(post, :form) do %>
<%= render "posts/form", post: post %>
<% end %>
<!-- content -->
<% end %>
Tag Helpers
toggle_trigger_tag
renders
- REQUIRED, the partial path to rendermorphs
- REQUIRED,dom_id
of the partial's outermost containing elementcontrols
- REQUIRED,dom_id
of the toggle targetassigns
-{}
,assigns
required to render the partial i.e. instance variableslocals
-{}
,local_assigns
required to render the paritalcollapse_selector
-nil
, CSS selector for other targets to collapse when the target is expandedfocus_selector
-nil
, CSS selector for the element to focus when the target is expandedmethod
-:toggle
, reflex method to inovke (:show, :hide, :toggle)disabled
-false
, disable the triggerremember
-false
, remember state between requestskwargs
- generic support for additional element attributes likeclass
etc.&block
- a Ruby block that emits the rendered content
toggle_target_tag
id
- REQUIRED, thedom_id
for the elementcollapse_on
-[]
, list of events that trigger collapsecollapse_selector
-nil
, CSS selector for other targets to collapse when this target is expandedexpanded
-false
, override to force expansionfocus_selector
-nil
, CSS selector for the element to focus when content is expandedkwargs
- generic support for additional element attributes likeclass
etc.&block
- a Ruby block that emits the rendered content
Releasing
- Run
yarn
andbundle
to pick up the latest - Bump version number at
lib/reflex_behaviors/version.rb
. Pre-release versions use.preN
- Run
rake build
andyarn build
- Run
bin/standardize
- Commit and push changes to GitHub
- Run
rake release
- Run
yarn publish --no-git-tag-version
- Yarn will prompt you for the new version. Pre-release versions use
-preN
- Commit and push changes to GitHub
- Create a new release on GitHub (here) and generate the changelog for the stable release for it
License
The gem is available as open source under the terms of the MIT License.