{"id":19555072,"url":"https://github.com/kanety/stimulus-static-actions","last_synced_at":"2025-04-26T22:32:15.890Z","repository":{"id":41137866,"uuid":"403549391","full_name":"kanety/stimulus-static-actions","owner":"kanety","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-27T03:03:46.000Z","size":57,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-28T04:19:42.437Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/kanety.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-06T08:46:51.000Z","updated_at":"2024-09-10T21:52:12.000Z","dependencies_parsed_at":"2023-02-01T01:46:05.781Z","dependency_job_id":null,"html_url":"https://github.com/kanety/stimulus-static-actions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanety%2Fstimulus-static-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanety%2Fstimulus-static-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanety%2Fstimulus-static-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanety%2Fstimulus-static-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanety","download_url":"https://codeload.github.com/kanety/stimulus-static-actions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224048758,"owners_count":17247081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2024-11-11T04:31:32.209Z","updated_at":"2024-11-11T04:31:34.892Z","avatar_url":"https://github.com/kanety.png","language":"JavaScript","readme":"# stimulus-static-actions\n\nA stimulus extension to define actions in controller.\n\n## Dependencies\n\n* @hotwired/stimulus 3.0\n\n## Installation\n\nInstall from npm:\n\n    $ npm install @kanety/stimulus-static-actions --save\n\n## Usage\n\nImport `@kanety/stimulus-static-actions`:\n\n```javascript\nimport '@kanety/stimulus-static-actions';\n```\n\nThen define `actions` as static class properties in a controller:\n\n```javascript\nimport { Controller } from '@hotwired/stimulus';\n\nclass TestController extends Controller {\n  static actions = [\n    ['element', 'click-\u003eshow']\n  ];\n\n  show(e) {\n    // some codes here...\n  }\n}\n```\n\nActions are attached when the controller is connected.\nThey are also attached when target elements are added in the controller.\n\n## Action definition\n\nAction definition takes 3 arguments:\n\n1. target element to attach actions\n2. action description like `data-action` of stimulus\n3. options\n\n### Target element\n\nFollowing kind of target elements could be specified:\n\n* name of stimulus target\n* `element` that is an element of stimulus controller\n\nFor example:\n\n```javascript\nclass TestController extends Controller {\n  static targets = ['button'];\n  static actions = [\n    ['button', 'click-\u003eshow'],  // specify name of stimulus target\n    ['element', 'click-\u003eshow']  // specify element of stimulus controller\n  ];\n```\n\n### Action description\n\nAction description is almost same as `data-action` of stimulus,\nbut identifier of controller is automatically recognized.\n\nFor example:\n\n```javascript\nclass TestController extends Controller {\n  static targets = ['button'];\n  static actions = [\n    ['button', 'show'],  // equal to test#show\n    ['button', 'click-\u003eshow'],  // equal to click-\u003etest#show\n    ['button', ':custom-\u003eshow']  // equal to test:custom-\u003etest#show\n  ];\n```\n\nThis controller attaches `data-action` attribute as follows:\n\n```html\n\u003cdiv data-controller=\"test\"\u003e\n  \u003cbutton data-action=\"click-\u003etest#show test:custom-\u003etest#show\"\u003e\u003c/button\u003e\n\u003c/div\u003e\n```\n\n\n### Options\n\nYou can use `if` option for checking some conditions to attach actions.\nThis option takes a method or a getter of the controller.\nFor example:\n\n```javascript\nclass TestController extends Controller {\n  static actions = [\n    ['element', 'click-\u003eshow', { if: 'isSpecificBrowser'}]\n  ];\n\n  get isSpecificBrowser() {\n    return navigator.userAgent.match(/SpecificBrowser/);\n  }\n}\n```\n\nIn this example, the action is attached only if `userAgent` includes `SpecificBrowser`.\n\n## License\n\nThe library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanety%2Fstimulus-static-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanety%2Fstimulus-static-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanety%2Fstimulus-static-actions/lists"}