-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb71907
commit a993fb8
Showing
11 changed files
with
140 additions
and
37 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,5 @@ | ||
--- | ||
"@zag-js/avatar": patch | ||
--- | ||
|
||
Improve image load check to use `naturalWidth|Height` instead of `currentSrc` |
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
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,31 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + TS</title> | ||
</head> | ||
<body style="padding: 40px"> | ||
<h1>Accordion</h1> | ||
|
||
<div class="accordion"> | ||
<div class="accordion-item" data-value="a"> | ||
<button class="accordion-trigger">First Button</button> | ||
<div class="accordion-content">First Content</div> | ||
</div> | ||
|
||
<div class="accordion-item" data-value="b"> | ||
<button class="accordion-trigger">Second Button</button> | ||
<div class="accordion-content">Second Content</div> | ||
</div> | ||
|
||
<div class="accordion-item" data-value="c"> | ||
<button class="accordion-trigger">Third Button</button> | ||
<div class="accordion-content">Third Content</div> | ||
</div> | ||
</div> | ||
|
||
<script type="module" src="./accordion.ts"></script> | ||
</body> | ||
</html> |
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,9 @@ | ||
import "@zag-js/shared/src/style.css" | ||
|
||
import { Accordion } from "../src/accordion" | ||
import { nanoid } from "nanoid" | ||
|
||
document.querySelectorAll<HTMLElement>(".accordion").forEach((rootEl) => { | ||
const accordion = new Accordion(rootEl, { id: nanoid(), multiple: true }) | ||
accordion.init() | ||
}) |
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,24 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + TS</title> | ||
</head> | ||
<body style="padding: 40px"> | ||
<h1>Avatar</h1> | ||
|
||
<div class="avatar"> | ||
<span class="avatar-fallback">PA</span> | ||
<img | ||
class="avatar-image" | ||
alt="Naruto" | ||
referrerpolicy="no-referrer" | ||
src="https://static.wikia.nocookie.net/naruto/images/d/d6/Naruto_Part_I.png/revision/latest/top-crop/width/200/height/150?cb=20210223094656" | ||
/> | ||
</div> | ||
|
||
<script type="module" src="./avatar.ts"></script> | ||
</body> | ||
</html> |
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,9 @@ | ||
import "@zag-js/shared/src/style.css" | ||
|
||
import { Avatar } from "../src/avatar" | ||
import { nanoid } from "nanoid" | ||
|
||
document.querySelectorAll<HTMLElement>(".avatar").forEach((rootEl) => { | ||
const avatar = new Avatar(rootEl, { id: nanoid() }) | ||
avatar.init() | ||
}) |
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,45 @@ | ||
import * as avatar from "@zag-js/avatar" | ||
import { normalizeProps } from "./normalize-props" | ||
import { spreadProps } from "./spread-props" | ||
|
||
export class Avatar { | ||
rootEl: HTMLElement | ||
service: ReturnType<typeof avatar.machine> | ||
api: avatar.Api<any> | ||
|
||
constructor(rootEl: HTMLElement | null, context: avatar.Context) { | ||
if (!rootEl) throw new Error("Root element not found") | ||
this.rootEl = rootEl | ||
|
||
this.service = avatar.machine(context) | ||
this.api = avatar.connect(this.service.state, this.service.send, normalizeProps) | ||
} | ||
|
||
private disposable = new Map<HTMLElement, VoidFunction>() | ||
|
||
init = () => { | ||
const { service } = this | ||
this.render() | ||
this.service.subscribe(() => { | ||
this.api = avatar.connect(service.state, service.send, normalizeProps) | ||
this.render() | ||
}) | ||
|
||
this.service.start() | ||
} | ||
|
||
destroy = () => { | ||
this.service.stop() | ||
} | ||
|
||
render = () => { | ||
const rootEl = this.rootEl | ||
this.disposable.set(rootEl, spreadProps(this.rootEl, this.api.rootProps)) | ||
|
||
const imageEl = rootEl.querySelector<HTMLElement>(".avatar-image") | ||
if (imageEl) this.disposable.set(imageEl, spreadProps(imageEl, this.api.imageProps)) | ||
|
||
const fallbackEl = rootEl.querySelector<HTMLElement>(".avatar-fallback") | ||
if (fallbackEl) this.disposable.set(fallbackEl, spreadProps(fallbackEl, this.api.fallbackProps)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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