@ui-sdk/vue 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +561 -0
- package/dist/accordion.js +24 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +7 -0
- package/dist/alert-dialog.d.ts +231 -0
- package/dist/alert-dialog.js +33 -0
- package/dist/async-options.d.ts +18 -0
- package/dist/async-options.js +40 -0
- package/dist/autocomplete.d.ts +384 -0
- package/dist/autocomplete.js +344 -0
- package/dist/avatar.d.ts +40 -0
- package/dist/avatar.js +28 -0
- package/dist/button.d.ts +52 -0
- package/dist/button.js +43 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +7 -0
- package/dist/calendar.d.ts +311 -0
- package/dist/calendar.js +349 -0
- package/dist/carousel.d.ts +236 -0
- package/dist/carousel.js +204 -0
- package/dist/checkbox.d.ts +211 -0
- package/dist/checkbox.js +151 -0
- package/dist/children.d.ts +41 -0
- package/dist/children.js +135 -0
- package/dist/collapsible.d.ts +54 -0
- package/dist/collapsible.js +18 -0
- package/dist/color-picker.d.ts +187 -0
- package/dist/color-picker.js +158 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +21 -0
- package/dist/combobox.d.ts +517 -0
- package/dist/combobox.js +531 -0
- package/dist/command.d.ts +322 -0
- package/dist/command.js +345 -0
- package/dist/controller-target.d.ts +49 -0
- package/dist/controller-target.js +112 -0
- package/dist/create-parts.d.ts +126 -0
- package/dist/create-parts.js +206 -0
- package/dist/date-input.d.ts +133 -0
- package/dist/date-input.js +31 -0
- package/dist/date-picker.d.ts +328 -0
- package/dist/date-picker.js +354 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +59 -0
- package/dist/dialog-parts.d.ts +259 -0
- package/dist/dialog-parts.js +300 -0
- package/dist/dialog.d.ts +251 -0
- package/dist/dialog.js +25 -0
- package/dist/drawer.d.ts +304 -0
- package/dist/drawer.js +373 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +5 -0
- package/dist/field-context.d.ts +26 -0
- package/dist/field-context.js +44 -0
- package/dist/field.d.ts +154 -0
- package/dist/field.js +240 -0
- package/dist/file-input.d.ts +212 -0
- package/dist/file-input.js +255 -0
- package/dist/form-inputs.d.ts +16 -0
- package/dist/form-inputs.js +25 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +15 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +11 -0
- package/dist/hover-card.d.ts +137 -0
- package/dist/hover-card.js +153 -0
- package/dist/image-cropper.d.ts +74 -0
- package/dist/image-cropper.js +36 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +5 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +60 -0
- package/dist/input.d.ts +120 -0
- package/dist/input.js +73 -0
- package/dist/item-icon.d.ts +34 -0
- package/dist/item-icon.js +63 -0
- package/dist/label.d.ts +16 -0
- package/dist/label.js +8 -0
- package/dist/lifecycle.d.ts +11 -0
- package/dist/lifecycle.js +91 -0
- package/dist/list-items.d.ts +38 -0
- package/dist/list-items.js +59 -0
- package/dist/list-text.d.ts +7 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +273 -0
- package/dist/listbox.js +126 -0
- package/dist/menu.d.ts +678 -0
- package/dist/menu.js +607 -0
- package/dist/menubar-context.d.ts +5 -0
- package/dist/menubar-context.js +5 -0
- package/dist/menubar.d.ts +61 -0
- package/dist/menubar.js +48 -0
- package/dist/meter.d.ts +41 -0
- package/dist/meter.js +37 -0
- package/dist/navigation-menu.d.ts +228 -0
- package/dist/navigation-menu.js +195 -0
- package/dist/number-input.d.ts +176 -0
- package/dist/number-input.js +231 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +39 -0
- package/dist/nuxt/entries.json +977 -0
- package/dist/nuxt/module.d.ts +18 -0
- package/dist/nuxt/module.js +31 -0
- package/dist/nuxt/registrations.d.ts +22 -0
- package/dist/nuxt/registrations.js +22 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +7 -0
- package/dist/otp-input.d.ts +142 -0
- package/dist/otp-input.js +130 -0
- package/dist/overlays.d.ts +40 -0
- package/dist/overlays.js +118 -0
- package/dist/pagination.d.ts +201 -0
- package/dist/pagination.js +146 -0
- package/dist/password-input.d.ts +144 -0
- package/dist/password-input.js +134 -0
- package/dist/popover.d.ts +211 -0
- package/dist/popover.js +258 -0
- package/dist/popup.d.ts +60 -0
- package/dist/popup.js +89 -0
- package/dist/preferences.d.ts +44 -0
- package/dist/preferences.js +102 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +11 -0
- package/dist/progress.d.ts +41 -0
- package/dist/progress.js +37 -0
- package/dist/radio.d.ts +164 -0
- package/dist/radio.js +145 -0
- package/dist/rating.d.ts +149 -0
- package/dist/rating.js +146 -0
- package/dist/renderless.d.ts +4 -0
- package/dist/renderless.js +28 -0
- package/dist/resizable.d.ts +54 -0
- package/dist/resizable.js +22 -0
- package/dist/scroll-area.d.ts +72 -0
- package/dist/scroll-area.js +77 -0
- package/dist/segmented-control.d.ts +151 -0
- package/dist/segmented-control.js +110 -0
- package/dist/segmented-input.d.ts +76 -0
- package/dist/segmented-input.js +115 -0
- package/dist/select.d.ts +458 -0
- package/dist/select.js +468 -0
- package/dist/separator.d.ts +14 -0
- package/dist/separator.js +8 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +56 -0
- package/dist/slider.d.ts +65 -0
- package/dist/slider.js +194 -0
- package/dist/switch.d.ts +103 -0
- package/dist/switch.js +71 -0
- package/dist/tabs.d.ts +338 -0
- package/dist/tabs.js +27 -0
- package/dist/text-control.d.ts +89 -0
- package/dist/text-control.js +51 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +7 -0
- package/dist/textarea.d.ts +106 -0
- package/dist/textarea.js +68 -0
- package/dist/time-input.d.ts +131 -0
- package/dist/time-input.js +32 -0
- package/dist/timeline.d.ts +81 -0
- package/dist/timeline.js +30 -0
- package/dist/toast-parts.d.ts +203 -0
- package/dist/toast-parts.js +270 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +21 -0
- package/dist/toggle-props.d.ts +22 -0
- package/dist/toggle-props.js +14 -0
- package/dist/toggle.d.ts +199 -0
- package/dist/toggle.js +129 -0
- package/dist/token-input.d.ts +136 -0
- package/dist/token-input.js +214 -0
- package/dist/toolbar-context.d.ts +7 -0
- package/dist/toolbar-context.js +20 -0
- package/dist/toolbar.d.ts +120 -0
- package/dist/toolbar.js +77 -0
- package/dist/tooltip.d.ts +160 -0
- package/dist/tooltip.js +224 -0
- package/dist/tree.d.ts +300 -0
- package/dist/tree.js +209 -0
- package/dist/trigger-menu.d.ts +452 -0
- package/dist/trigger-menu.js +254 -0
- package/dist/use-primitive.d.ts +132 -0
- package/dist/use-primitive.js +462 -0
- package/dist/waterfall.d.ts +201 -0
- package/dist/waterfall.js +171 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1369 -0
- package/docs/components/alert-dialog.md +799 -0
- package/docs/components/autocomplete.md +1857 -0
- package/docs/components/avatar.md +272 -0
- package/docs/components/button.md +435 -0
- package/docs/components/calendar.md +1589 -0
- package/docs/components/carousel.md +1171 -0
- package/docs/components/checkbox.md +1008 -0
- package/docs/components/collapsible.md +536 -0
- package/docs/components/color-picker.md +706 -0
- package/docs/components/combobox.md +3504 -0
- package/docs/components/command.md +1481 -0
- package/docs/components/date-input.md +536 -0
- package/docs/components/date-picker.md +1244 -0
- package/docs/components/dialog.md +1397 -0
- package/docs/components/drawer.md +1166 -0
- package/docs/components/field.md +538 -0
- package/docs/components/file-input.md +611 -0
- package/docs/components/hover-card.md +505 -0
- package/docs/components/image-cropper.md +556 -0
- package/docs/components/input.md +306 -0
- package/docs/components/label.md +203 -0
- package/docs/components/listbox.md +1004 -0
- package/docs/components/menu.md +1229 -0
- package/docs/components/menubar.md +443 -0
- package/docs/components/meter.md +315 -0
- package/docs/components/navigation-menu.md +1523 -0
- package/docs/components/number-input.md +1029 -0
- package/docs/components/otp-input.md +512 -0
- package/docs/components/pagination.md +613 -0
- package/docs/components/password-input.md +649 -0
- package/docs/components/popover.md +1448 -0
- package/docs/components/preferences.md +208 -0
- package/docs/components/progress.md +423 -0
- package/docs/components/radio.md +785 -0
- package/docs/components/rating.md +416 -0
- package/docs/components/resizable.md +910 -0
- package/docs/components/scroll-area.md +915 -0
- package/docs/components/segmented-control.md +435 -0
- package/docs/components/select.md +2015 -0
- package/docs/components/separator.md +229 -0
- package/docs/components/slider.md +1084 -0
- package/docs/components/switch.md +565 -0
- package/docs/components/tabs.md +944 -0
- package/docs/components/textarea.md +299 -0
- package/docs/components/time-input.md +224 -0
- package/docs/components/timeline.md +654 -0
- package/docs/components/toast.md +1224 -0
- package/docs/components/toggle.md +500 -0
- package/docs/components/token-input.md +953 -0
- package/docs/components/toolbar.md +739 -0
- package/docs/components/tooltip.md +818 -0
- package/docs/components/tree.md +1306 -0
- package/docs/components/trigger-menu.md +1223 -0
- package/docs/components/waterfall.md +717 -0
- package/docs/controllers.md +71 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +89 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +122 -0
- package/docs/installation.md +72 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +122 -0
- package/docs/llms.txt +1502 -0
- package/docs/parts-and-composition.md +85 -0
- package/docs/popups.md +108 -0
- package/docs/rendering.md +56 -0
- package/docs/server-rendering.md +180 -0
- package/docs/state-and-events.md +100 -0
- package/docs/styling-and-animation.md +148 -0
- package/docs/utilities/async-options.md +348 -0
- package/docs/utilities/shortcuts.md +159 -0
- package/package.json +352 -3
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# Avatar
|
|
2
|
+
|
|
3
|
+
Show an image with a fallback while it loads or if it fails.
|
|
4
|
+
|
|
5
|
+
Use an Avatar for a person or a team, like in a comment, a member list or an account menu. It shows initials or an icon until the image loads, and keeps showing them if the image fails.
|
|
6
|
+
|
|
7
|
+
```vue title="basic.vue"
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { Avatar, AvatarFallback, AvatarImage } from "@ui-sdk/vue/avatar"
|
|
10
|
+
|
|
11
|
+
const person = {
|
|
12
|
+
name: "shadcn",
|
|
13
|
+
src: "https://github.com/shadcn.png",
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<div data-slot="row">
|
|
19
|
+
<Avatar>
|
|
20
|
+
<AvatarImage :src="person.src" :alt="person.name" />
|
|
21
|
+
<AvatarFallback
|
|
22
|
+
><span aria-hidden="true">CN</span
|
|
23
|
+
><span data-slot="visually-hidden">shadcn</span></AvatarFallback
|
|
24
|
+
>
|
|
25
|
+
</Avatar>
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The image replaces the initials once it loads. A screen reader can read the person's name in either state.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @ui-sdk/vue @ui-sdk/core
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Composition
|
|
39
|
+
|
|
40
|
+
Use the following composition to build an `Avatar`:
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
Avatar
|
|
44
|
+
├── AvatarImage
|
|
45
|
+
└── AvatarFallback
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- `Avatar` shares the image's loading state with its parts.
|
|
49
|
+
- `AvatarImage` renders the image.
|
|
50
|
+
- `AvatarFallback` shows when no image is loaded.
|
|
51
|
+
|
|
52
|
+
The image is a real `img`, including in server markup. The browser can start fetching it before hydration. The fallback stays visible until the image loads; if loading fails, the fallback remains.
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
Import the parts and put them together:
|
|
57
|
+
|
|
58
|
+
```vue
|
|
59
|
+
<script setup lang="ts">
|
|
60
|
+
import { Avatar, AvatarFallback, AvatarImage } from "@ui-sdk/vue/avatar"
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<template>
|
|
64
|
+
<Avatar>
|
|
65
|
+
<AvatarImage src="/ada.png" alt="Ada Lovelace" />
|
|
66
|
+
<AvatarFallback>AL</AvatarFallback>
|
|
67
|
+
</Avatar>
|
|
68
|
+
</template>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Build Your Own
|
|
72
|
+
|
|
73
|
+
`@ui-sdk/vue/avatar` comes with a ready-made Avatar. If you'd like to build your own, with your own names, start from the `avatar` primitive in `@ui-sdk/core`:
|
|
74
|
+
|
|
75
|
+
```ts title="user-photo.ts"
|
|
76
|
+
import { avatar } from "@ui-sdk/core/avatar"
|
|
77
|
+
import { createParts } from "@ui-sdk/vue/primitive"
|
|
78
|
+
|
|
79
|
+
const {
|
|
80
|
+
Root: UserPhoto,
|
|
81
|
+
Image: UserPhotoImage,
|
|
82
|
+
Fallback: UserPhotoInitials,
|
|
83
|
+
} = createParts(avatar, { root: "span", image: "img", fallback: "span" })
|
|
84
|
+
|
|
85
|
+
export { UserPhoto, UserPhotoImage, UserPhotoInitials }
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```vue
|
|
89
|
+
<template>
|
|
90
|
+
<UserPhoto>
|
|
91
|
+
<UserPhotoImage src="https://github.com/shadcn.png" alt="shadcn" />
|
|
92
|
+
<UserPhotoInitials>CN</UserPhotoInitials>
|
|
93
|
+
</UserPhoto>
|
|
94
|
+
</template>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
These are the same parts the ready-made Avatar is made of, with your names. See [Rendering](../rendering.md) and [Custom Rendering](#custom-rendering) for more.
|
|
98
|
+
|
|
99
|
+
## Fallback Delay
|
|
100
|
+
|
|
101
|
+
<span id="behavior-and-options" />
|
|
102
|
+
|
|
103
|
+
Set `delay` on the fallback to wait before showing it. This avoids flashing initials when an image loads quickly. Without a delay, the fallback appears immediately, including on the server.
|
|
104
|
+
|
|
105
|
+
```vue
|
|
106
|
+
<template>
|
|
107
|
+
<Avatar>
|
|
108
|
+
<AvatarImage src="https://github.com/shadcn.png" alt="shadcn" />
|
|
109
|
+
<AvatarFallback :delay="600">CN</AvatarFallback>
|
|
110
|
+
</Avatar>
|
|
111
|
+
</template>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Image Attributes
|
|
115
|
+
|
|
116
|
+
Pass image attributes such as `srcset`, `crossorigin`, and `referrerpolicy` to the image. They work on the same `img` the browser loads. For avatars farther down a page, use `loading="lazy"`.
|
|
117
|
+
|
|
118
|
+
```vue
|
|
119
|
+
<template>
|
|
120
|
+
<Avatar>
|
|
121
|
+
<AvatarImage
|
|
122
|
+
src="https://github.com/shadcn.png"
|
|
123
|
+
srcset="https://github.com/shadcn.png?size=80 1x, https://github.com/shadcn.png?size=160 2x"
|
|
124
|
+
alt="shadcn"
|
|
125
|
+
crossorigin="anonymous"
|
|
126
|
+
referrerpolicy="no-referrer"
|
|
127
|
+
loading="lazy"
|
|
128
|
+
/>
|
|
129
|
+
<AvatarFallback>CN</AvatarFallback>
|
|
130
|
+
</Avatar>
|
|
131
|
+
</template>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
<span id="render-functions" />
|
|
135
|
+
|
|
136
|
+
## Interactive Avatar
|
|
137
|
+
|
|
138
|
+
Use a button when clicking an avatar performs an action. Give it an accessible name that stays available while the image loads.
|
|
139
|
+
|
|
140
|
+
```vue
|
|
141
|
+
<template>
|
|
142
|
+
<Avatar @click="openProfile">
|
|
143
|
+
<template #render="{ props, children }">
|
|
144
|
+
<button v-bind="props" type="button" aria-label="shadcn">
|
|
145
|
+
<component :is="children" />
|
|
146
|
+
</button>
|
|
147
|
+
</template>
|
|
148
|
+
<AvatarImage src="https://github.com/shadcn.png" alt="" />
|
|
149
|
+
<AvatarFallback aria-hidden="true">CN</AvatarFallback>
|
|
150
|
+
</Avatar>
|
|
151
|
+
</template>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
[Parts and Composition](../parts-and-composition.md) explains how to change the root element in this framework.
|
|
155
|
+
|
|
156
|
+
## Loading Status
|
|
157
|
+
|
|
158
|
+
`@loading-status-change` receives the new status and change details. The possible statuses are `loading`, `loaded`, `error`, and `idle`.
|
|
159
|
+
|
|
160
|
+
```vue
|
|
161
|
+
<template>
|
|
162
|
+
<Avatar
|
|
163
|
+
@loading-status-change="
|
|
164
|
+
(status, details) => {
|
|
165
|
+
if (status === 'error') reportBrokenImage(details.reason)
|
|
166
|
+
}
|
|
167
|
+
"
|
|
168
|
+
>
|
|
169
|
+
<AvatarImage :src="user.image" :alt="user.name" />
|
|
170
|
+
<AvatarFallback>{{ user.initials }}</AvatarFallback>
|
|
171
|
+
</Avatar>
|
|
172
|
+
</template>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
When you replace a loaded image, the browser keeps it visible while the next source loads. A failed replacement shows the fallback. The change details explain why the status changed; see [Reasons](#reasons).
|
|
176
|
+
|
|
177
|
+
## Custom Rendering
|
|
178
|
+
|
|
179
|
+
Use [Parts and Composition](../parts-and-composition.md) to replace an element or read its state. Every part receives the loading status, so the fallback can say something different when the image fails:
|
|
180
|
+
|
|
181
|
+
```vue
|
|
182
|
+
<template>
|
|
183
|
+
<Avatar>
|
|
184
|
+
<AvatarImage :src="user.image" :alt="user.name" />
|
|
185
|
+
<AvatarFallback v-slot="{ state }">
|
|
186
|
+
{{ state.loadingStatus === "error" ? "?" : user.initials }}
|
|
187
|
+
</AvatarFallback>
|
|
188
|
+
</Avatar>
|
|
189
|
+
</template>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Styling
|
|
193
|
+
|
|
194
|
+
Set the root's size and let the image and fallback fill it. The image manages its own hidden styles until it loads; keep those styles intact when changing its element.
|
|
195
|
+
|
|
196
|
+
Each part has a `data-slot`, such as `avatar-fallback`, and shows the loading status through the attributes listed under [Data Attributes](#data-attributes).
|
|
197
|
+
|
|
198
|
+
## Data Attributes
|
|
199
|
+
|
|
200
|
+
### Avatar
|
|
201
|
+
`[data-slot="avatar"]`
|
|
202
|
+
|
|
203
|
+
- `data-loading-status` (`idle`, `loading`, `loaded`, `error`): Where the image is: no image yet, loading, loaded, or failed.
|
|
204
|
+
|
|
205
|
+
### AvatarImage
|
|
206
|
+
`[data-slot="avatar-image"]`
|
|
207
|
+
|
|
208
|
+
- `data-loading-status` (`idle`, `loading`, `loaded`, `error`): Where the image is: no image yet, loading, loaded, or failed.
|
|
209
|
+
|
|
210
|
+
### AvatarFallback
|
|
211
|
+
`[data-slot="avatar-fallback"]`
|
|
212
|
+
|
|
213
|
+
- `data-loading-status` (`idle`, `loading`, `loaded`, `error`): Where the image is: no image yet, loading, loaded, or failed.
|
|
214
|
+
|
|
215
|
+
## API Reference
|
|
216
|
+
|
|
217
|
+
Props are the same as below, and callbacks are events.
|
|
218
|
+
|
|
219
|
+
### Avatar
|
|
220
|
+
|
|
221
|
+
- `@loading-status-change` (`((status: AvatarLoadingStatus, details: ChangeDetails<AvatarLoadingStatusChangeReason>) => void)`): Runs when the image's loading status changes: `"loading"` when it gets a source, `"loaded"`, `"error"`, and `"idle"` when it leaves the page. `details.reason` says why, and `details.event` is the image's `load` or `error` event, or undefined when the status was known at once, like for a cached image.
|
|
222
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
223
|
+
|
|
224
|
+
### AvatarImage
|
|
225
|
+
|
|
226
|
+
The image. Renders a real `img`, so the browser can fetch it before hydration, and accepts its attributes, such as `srcset`, `crossorigin` and `referrerpolicy`.
|
|
227
|
+
|
|
228
|
+
### AvatarFallback
|
|
229
|
+
|
|
230
|
+
- `delay?` (`number`): How long to wait, in milliseconds, before showing the fallback, so a fast image appears without the fallback flashing first. Without one, the fallback shows at once, server markup included.
|
|
231
|
+
|
|
232
|
+
### State
|
|
233
|
+
|
|
234
|
+
What render functions, state-based class names and slots receive. Every part gets the same state.
|
|
235
|
+
|
|
236
|
+
- `loadingStatus` (`AvatarLoadingStatus`): Where the image is: `"idle"`, `"loading"`, `"loaded"` or `"error"`.
|
|
237
|
+
|
|
238
|
+
### Reasons
|
|
239
|
+
|
|
240
|
+
`details.reason` says why the status changed.
|
|
241
|
+
|
|
242
|
+
- `image-load` (`Event | undefined`): An image loaded. No event when it was already in the browser's cache.
|
|
243
|
+
- `image-error` (`Event | undefined`): An image failed to load, or has no source. No event when that was known at once.
|
|
244
|
+
- `src-change` (`none`): An image got a new source, or left the page, so its status starts over.
|
|
245
|
+
|
|
246
|
+
### Events
|
|
247
|
+
|
|
248
|
+
Events get the new status first, then the details.
|
|
249
|
+
|
|
250
|
+
| Binding | On | Receives |
|
|
251
|
+
| ------------------------ | -------- | ----------------------------------------------------------------------------------- |
|
|
252
|
+
| `@loading-status-change` | `Avatar` | `(status, details)`: the image's status, the [reason](#reasons) and `details.event` |
|
|
253
|
+
|
|
254
|
+
## Accessibility
|
|
255
|
+
|
|
256
|
+
Give the image meaningful `alt` text. Include the person's name in the fallback too, using visually hidden text if you only want to show initials.
|
|
257
|
+
|
|
258
|
+
When a visible name beside the avatar already identifies the person, use an empty `alt` and hide decorative fallback content from screen readers.
|
|
259
|
+
|
|
260
|
+
- An image that loads replaces the fallback.
|
|
261
|
+
- An image that fails keeps the fallback.
|
|
262
|
+
- An avatar without an image shows its fallback.
|
|
263
|
+
- A fallback with a delay waits before showing.
|
|
264
|
+
- The image's loading status is reported.
|
|
265
|
+
- Removing the image brings the fallback back.
|
|
266
|
+
- A new source shows its image once it loads.
|
|
267
|
+
- The image is fetched with its own referrer policy.
|
|
268
|
+
- A cached image doesn't flash the fallback when the avatar mounts again.
|
|
269
|
+
- A new source keeps showing the previous image until it loads.
|
|
270
|
+
- The image is fetched once, even when it can't be cached.
|
|
271
|
+
|
|
272
|
+
Runs in React, Vue and web components.
|