Skip to content

Commit

Permalink
Merge pull request #2 from niconiahi/feat/button-iteration
Browse files Browse the repository at this point in the history
feat(button): add default value
  • Loading branch information
niconiahi authored Jan 19, 2024
2 parents a185034 + 82b4132 commit fe8f399
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": ["@ariabones/playground"]
}
5 changes: 5 additions & 0 deletions .changeset/rotten-mice-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ariabones/button": minor
---

accept default value through data-pressed attribute
10 changes: 3 additions & 7 deletions apps/playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@
<div id="root"></div>
<script type="module" src="/src/main.ts"></script>
<section style="display: grid; grid-template-columns: 1fr; row-gap: 8px">
<button
id="disable-button"
_="on click set @disabled to true"
is="ariabones-button"
>
<button is="ariabones-button" _="on click set @disabled to true">
Disable button
</button>
<button
id="toggle-button"
_type="toggle"
is="ariabones-button"
data-type="toggle"
data-pressed="true"
style="display: flex; align-items: center; justify-content: center"
>
Toggle button
Expand Down
39 changes: 0 additions & 39 deletions apps/playground/src/button.ts

This file was deleted.

15 changes: 11 additions & 4 deletions packages/button/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Button extends HTMLButtonElement {
}

static get observedAttributes(): string[] {
return ["disabled", "_type", "style"]
return ["disabled", "data-type"]
}

attributeChangedCallback(
Expand All @@ -22,11 +22,18 @@ class Button extends HTMLButtonElement {
this.removeAttribute("aria-disabled")
}
}
if (name === "_type") {
if (name === "data-type") {
// toggle
if (newValue === "toggle") {
this.setAttribute("_", "on click if @aria-pressed equals 'false' set @aria-pressed to 'true' else set @aria-pressed to 'false'")
this.setAttribute("aria-pressed", "false")
const pressed = this.getAttribute("data-pressed")
this.setAttribute("aria-pressed", pressed ?? "false")
this.setAttribute("_", `
on click
if @aria-pressed equals 'true'
set @aria-pressed to 'false'
else
set @aria-pressed to 'true'
`)
}

// menu
Expand Down

0 comments on commit fe8f399

Please sign in to comment.