aboutsummaryrefslogtreecommitdiff
path: root/app/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/controllers/hello_controller.js18
-rw-r--r--app/javascript/controllers/index.js9
-rw-r--r--app/javascript/packs/application.js2
3 files changed, 29 insertions, 0 deletions
diff --git a/app/javascript/controllers/hello_controller.js b/app/javascript/controllers/hello_controller.js
new file mode 100644
index 0000000..28fdb13
--- /dev/null
+++ b/app/javascript/controllers/hello_controller.js
@@ -0,0 +1,18 @@
+// Visit The Stimulus Handbook for more details
+// https://stimulusjs.org/handbook/introduction
+//
+// This example controller works with specially annotated HTML like:
+//
+// <div data-controller="hello">
+// <h1 data-target="hello.output"></h1>
+// </div>
+
+import { Controller } from "stimulus"
+
+export default class extends Controller {
+ static targets = [ "output" ]
+
+ connect() {
+ this.outputTarget.textContent = 'Hello, Stimulus!'
+ }
+}
diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js
new file mode 100644
index 0000000..6f53d84
--- /dev/null
+++ b/app/javascript/controllers/index.js
@@ -0,0 +1,9 @@
+// Load all the controllers within this directory and all subdirectories.
+// Controller files must be named *_controller.js.
+
+import { Application } from "stimulus"
+import { definitionsFromContext } from "stimulus/webpack-helpers"
+
+const application = Application.start()
+const context = require.context("controllers", true, /_controller\.js$/)
+application.load(definitionsFromContext(context))
diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js
index 5512f7f..5e3eec0 100644
--- a/app/javascript/packs/application.js
+++ b/app/javascript/packs/application.js
@@ -14,3 +14,5 @@ require("@rails/activestorage").start()
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
+
+import "controllers"