Skip to content

Commit 4bc5691

Browse files
authored
Merge pull request #70 from opf/update-documentations-for-using-controller
Change documentations for adding a Catalyst controller to the component
2 parents 0ed1b9e + d6c0d89 commit 4bc5691

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

docs/contributors/adding-components.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ The generator script has several flags:
3434
- `inline` creates a `#call` method instead of generating an ERB template
3535
- `js` can be passed the name of an npm package dependency
3636

37+
### JavaScript controllers
38+
39+
If your component needs a JavaScript controller, you can pass `@github/catalyst` to the `js` flag.
40+
41+
```sh
42+
bundle exec thor component_generator my_component_name --js='@github/catalyst'
43+
```
44+
45+
[Catalyst](https://catalyst.rocks/) is a small library for developing Web Components and is very similar to [Stimulus](https://stimulus.hotwired.dev/).
46+
47+
Catalyst has `controller` and `target` decorators which you have to import from `@github/catalyst` inside `app/components/<status>/<component_name>.ts`. It can then be used like this:
48+
49+
```ts
50+
import {controller, target} from '@github/catalyst';
51+
52+
@controller
53+
class MyComponentNameElement extends HTMLElement {
54+
@target button: HTMLElement
55+
}
56+
```
57+
3758
### Generated files
3859

3960
Running the component generator script creates several files across the codebase:

0 commit comments

Comments
 (0)