-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PresenceController - A utility controller to wire up other cont…
…rollers when an element comes into or leaves the DOM (#26)
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
id: PresenceController | ||
title: PresenceController | ||
--- | ||
|
||
import NoActions from "../_partials/no-actions.md"; | ||
import NoTargets from "../_partials/no-targets.md"; | ||
import NoClasses from "../_partials/no-classes.md"; | ||
import NoValues from "../_partials/no-values.md"; | ||
|
||
## Purpose | ||
|
||
A utility controller to wire up other stimulus actions when an element comes into or leaves the document. | ||
|
||
|
||
## [Actions](https://stimulus.hotwire.dev/reference/actions) | ||
|
||
<NoActions/> | ||
|
||
## [Targets](https://stimulus.hotwire.dev/reference/targets) | ||
|
||
|
||
<NoTargets/> | ||
|
||
## [Classes](https://stimulus.hotwire.dev/reference/classes) | ||
|
||
|
||
<NoClasses/> | ||
|
||
## [Values](https://stimulus.hotwire.dev/reference/values) | ||
|
||
|
||
<NoValues/> | ||
|
||
## Events | ||
|
||
| Event | When | Dispatched on | `event.detail` | | ||
| --- | --- | --- |--- | | ||
|`presence:added` | When the element enters the DOM | the controller root element | - | | ||
|`presence:removed` | When the element leaves the DOM | the controller root element | - | | ||
|
||
## Side Effects | ||
|
||
None | ||
|
||
## How to Use | ||
|
||
<iframe | ||
src="https://codesandbox.io/embed/presencecontroller-k7qgy?fontsize=14&hidenavigation=1&theme=dark" | ||
style={{width: "100%", height: "500px", border: "0", borderRadius: "4px", overflow: "hidden"}} | ||
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" | ||
/> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {BaseController} from "../../utilities/base_controller"; | ||
|
||
export class PresenceController extends BaseController { | ||
|
||
connect() { | ||
this.dispatch(this.el, "presence:added"); | ||
} | ||
|
||
disconnect() { | ||
this.dispatch(this.el, "presence:removed"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters