Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API: Update docs guide with new wp-interactivity directive implementation. #59018

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/interactivity/docs/2-api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _Example of directives used in the HTML markup_

```html
<div
data-wp-interactive='{ "namespace": "myPlugin" }'
data-wp-interactive="myPlugin"
data-wp-context='{ "isOpen": false }'
data-wp-watch="callbacks.logIsOpen"
>
Expand All @@ -69,14 +69,25 @@ Directives can also be injected dynamically using the [HTML Tag Processor](https

### List of Directives

With directives, we can directly manage behavior related to things such as side effects, state, event handlers, attributes or content.
With directives, we can directly manage interactions related to things such as side effects, state, event handlers, attributes or content.

#### `wp-interactive`

The `wp-interactive` directive "activates" the interactivity for the DOM element and its children through the Interactivity API (directives and store). It includes a namespace to reference a specific store.
The `wp-interactive` directive "activates" the interactivity for the DOM element and its children through the Interactivity API (directives and store). The directive includes a namespace to reference a specific store, that can be set as a `string` or an `object`.

```html
<!-- Let's make this element and its children interactive and set the namespace -->
<div
data-wp-interactive="myPlugin"
data-wp-context='{ "myColor" : "red", "myBgColor": "yellow" }'
>
<p>I'm interactive now, <span data-wp-style--background-color="context.myBgColor">>and I can use directives!</span></p>
<div>
<p>I'm also interactive, <span data-wp-style--color="context.myColor">and I can also use directives!</span></p>
</div>
</div>
```html
<!-- This is also valid -->
<div
data-wp-interactive='{ "namespace": "myPlugin" }'
data-wp-context='{ "myColor" : "red", "myBgColor": "yellow" }'
Expand Down Expand Up @@ -725,7 +736,7 @@ Note that, by default, references point to properties in the current namespace,
In the example below, we get `state.isPlaying` from `otherPlugin` instead of `myPlugin`:

```html
<div data-wp-interactive='{ "namespace": "myPlugin" }'>
<div data-wp-interactive="myPlugin">
<div data-bind--hidden="otherPlugin::!state.isPlaying" ... >
<iframe ...></iframe>
</div>
Expand Down