Skip to content

fix(docs): fix and update some examples #612

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions www/commands/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ add <class-ref+ or attribute-ref or object-literal> [to <target-expression>] [wh
The `add` command allows you to add a class (via a [class ref](/expressions/class-reference)), an attribute
(via an [attribute ref](/expressions/attribute-ref)) or CSS attributes (via an object literal) to either the current element or to another element.

**Note:** Hyperscript supports hyphens in object property names, so you can write `add { font-size: '2em' }`. However, double hyphens (`--`) mark comments in hyperscript, so if you need to use them for [CSS Custom Properties][], use quotes -- `add { '--big-font-size': '2em' }`.

The `where` clause allows you filter what elements have the class or property added in the `target`. The expression will be evaluated for
each element in `target` and, if the result is true, the element class or property will be added. If it is false, the class
or property will be removed. The `it` symbol will be set to the current element, allowing you to express conditions against each element
Expand All @@ -27,15 +25,17 @@ in `target`. Note that this clause only works with classes and properties.
```html
<div _="on click add .clicked">Click Me!</div>

<div _="on click add .clacked to #another-div">Click Me!</div>
<div _="on click add .clicked to #another-div">Click Me!</div>

<button _="on click add @disabled='true'">Disable Me!</button>
<button _="on click add @disabled">Disable Me!</button>

<input
type="color"
_="on change add { '--accent-color': my.value } to document.body"
_="on change add { --accent-color: my.value } to document.body"
/>

<button _="on click add @disabled='true' to <button/> when it is not me">Disable Other Buttons</button>
<button _="on click add [@disabled='true'] to <button/> when it is not me">Disable Other Buttons</button>

<button _"on click add .{'-foo-bar'} to #that">Add Class With A Dash Prefix!</button>

```
6 changes: 5 additions & 1 deletion www/expressions/attribute-ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ Attribute references are similar to CSS attribute references, and may or may not
### Examples

```html
<button _="on click add [@disabled]">Disable Me!</button>
<button _="on click add @disabled">Disable Me!</button>

<button _="on click remove [@disabled]">Enable Me!</button>

<button type="button" _="on click add [@type='submit']">Change My Type!</button>

<button type="button" _="on click my @type to 'submit'">Change My Type As Well!</button>
```
6 changes: 4 additions & 2 deletions www/expressions/possessive.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ The possessive expression can also be used to get and set attributes of an eleme
Go to Duck Duck Go
</div>
<div
id="foo"
data-demo="Here is some data..."
_="on click put my attribute data-demo into me"
>
Replace Me w/ Attribute Data
</div>
<button _"on click put #foo's @data-demo into me">
Replace Me w/ Foo's Attribute Data
</button>
```
4 changes: 2 additions & 2 deletions www/features/def.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Functions are typically placed in script tags:

```html
<script type="text/hyperscript">
def delayTheAnswer()
def delayTheAnswer(i)
wait 2s
return 42
return i
end
</script>
```
Expand Down