Stimulus

Stimulus is installed and configurd and ready to use in your app.

Stimulus controllers are located in /source/javascripts/controllers/

There is one controller already set up and working, this is the search_controller.js which powers the search in Ruby Static Pro (View search demo)

Tailwind Stimulus Components

Ruby Static Pro also comes with Tailwind Stimulus Components pre-installed. This library includes utitilies to help with:

  • Alerts
  • AutoSaving
  • Color Preview
  • Dropdowns
  • Modals
  • Popovers
  • Slideovers
  • Tabs
  • Toggles

See the component documentation for demos of each component.

The Toggle component is already enabled. To enable more, simply open the /source/javascripts/controllers/index.js and import the additional components and register them with the application. Just follow the same pattern that is alreayd in place for the Toggle component.

Adding a New Stimulus Controller

To add a new custom stimulus controller …

  1. Add the new controller file to /source/javascripts/controllers/
    • Lets call it stats_controller.js and assume its used to fetch stats from some AIP/etc.
  2. Open the /source/javascripts/controllers/index.js file
  3. Add an import for your controller:
import StatsController from "./stats_controller"
  1. Register your controller with the application object:
application.register("stats", StatsController)
  1. Your Stats controller is now ready to be used anywhere in your site.