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

Update README.md #1158

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions packages/element/README.md
Original file line number Diff line number Diff line change
@@ -45,7 +45,8 @@ export class MyElement extends HTMLElement {
## HTML and CSS

HTML templates can be applied by passing the result of the `html` tag to the shaodw list.
CSS can be applied by passing the result of the `css` tag to the shadow list.
CSS can be applied by passing the result of the `css` tag to the shadow list.
Any new tagged template literal that returns a `ShadowResult` can be used.

```ts
@element({
@@ -94,7 +95,7 @@ export class MyElement extends HTMLElement {
}
```

## Queries
## Query

The `query` function will query for a particular element and allow you to easily patch that element with new properties.

@@ -119,8 +120,36 @@ export class MyElement extends HTMLElement {

@effect()
onChange() {
const input = this.#input();
input.value = this.value;
const input = this.#input({ value: this.value});
}
}
```

## QueryAll

The `queryAll` function will get all elements that match the given query. A patching function can be passed to update any or all items in the list

```ts
@element({
tagName: 'my-element',
shadowDom: [
html`
<input id="first" />
<input id="second" />
`
]
})
export class MyElement extends HTMLElement {
@observe()
value: string;

#inputs = queryAll('input');

@effect()
onChange() {
this.#input(() => {
return { value: this.value }
})
}
}
```