-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathAvatar.doc.mjs
More file actions
176 lines (172 loc) · 10.1 KB
/
Copy pathAvatar.doc.mjs
File metadata and controls
176 lines (172 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright (c) Meta Platforms, Inc. and affiliates.
/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
export const docs = {
name: 'Avatar',
displayName: 'Avatar',
group: 'Avatar',
category: 'Content',
keywords: ["avatar","profile","user","photo","thumbnail","initials","gravatar","pfp","userpic"],
usage: {
description:
'Avatar represents a person or team with a profile photo, initials, or a default icon. Use it in comment headers, contact lists, chat messages, user cards, and anywhere you need to identify someone visually.',
bestPractices: [
{guidance: true, description: 'Always pass a name so the avatar can show initials if the photo fails to load, and so screen readers can announce who it represents.'},
{guidance: true, description: 'Pick a size that matches the context: xsm or sm for inline mentions, md or lg for lists and cards, xl for profile headers.'},
{guidance: true, description: 'Add a status dot when knowing someone\'s availability matters, like in chat or team views.'},
{guidance: true, description: 'When wrapping an Avatar in your own Tooltip or HoverCard, set tooltip={false} so the built-in name tooltip does not overlap yours.'},
{guidance: true, description: 'Give every interactive avatar (href or onClick) a name or alt. It is the control\'s accessible name, and it warns in development when it is missing.'},
{guidance: false, description: 'Rely on a status label to name an interactive avatar. "Online" says nothing about where the link goes.'},
{guidance: false, description: 'Use Avatar for logos, product images, or anything that isn\'t a person or team. Use an image or icon instead.'},
{guidance: false, description: 'Force a square or custom shape. Avatars are always circular to stay consistent across the system.'},
],
anatomy: [
{name: 'Photo', required: false, description: 'The profile image, loaded from the src URL. Shown when available.'},
{name: 'Initials', required: false, description: 'One or two letters extracted from the name. Shown when no photo is available.'},
{name: 'Default icon', required: false, description: 'A generic person silhouette. Shown when there is no photo or name.'},
{name: 'Status dot', required: false, description: 'A small indicator in the bottom-right corner showing availability (online, away, busy). Each variant pairs colour with a distinct shape so status does not rely on colour alone.'},
],
},
theming: {
targets: [
{className: 'astryx-avatar', visualProps: ['size']},
{className: 'astryx-avatar-fallback', visualProps: ['size']},
{className: 'astryx-avatar-status-dot', visualProps: ['variant']},
{className: 'astryx-avatar-status-dot-glyph', visualProps: ['shape']},
],
vars: [
{name: '--_avatar-group-overlap', description: 'Negative inline offset applied to every avatar after the first when avatars are stacked in an AvatarGroup. Set from the group size; a more negative value tightens the stack.', default: 'set at runtime from the group avatar size (px)', private: true},
],
},
description: 'Displays a user avatar with image, initials fallback, and optional status indicator.',
props: [
{
name: 'src',
type: 'string',
description: 'Primary image source URL.',
},
{
name: 'fallbackSrc',
type: 'string',
description: 'Fallback image when primary fails.',
},
{
name: 'name',
type: 'string',
description: 'User name for initials and alt text.',
},
{
name: 'alt',
type: 'string',
description: 'Alt text (falls back to name).',
},
{
name: 'size',
type: "'xsm' | 'sm' | 'md' | 'lg' | 'xl' | number",
description: "Avatar size. Use a named size ('xsm' 20px, 'sm' 24px, 'md' 36px, 'lg' 48px, 'xl' 128px) or a numeric pixel value. Avatar shares Icon's abbreviated scale, but its tiers are larger because avatars align with media rather than glyphs. Inside an AvatarGroup the group's size wins and this prop is ignored.",
default: "'md'",
},
{
name: 'status',
type: 'ReactNode',
description: 'Corner content for status indicators. AvatarStatusDot reports its `label` to the avatar, which composes it into the accessible name (e.g. "Jane Doe, Online") so screen readers announce the status. Reporting goes through context, so it still works when the dot sits inside a wrapper component of your own.',
slotElements: [
{
__element: 'AvatarStatusDot',
props: {
variant: 'success',
label: 'Online',
},
},
],
},
{
name: 'tooltip',
type: 'string | boolean',
description:
"Tooltip shown on hover and keyboard focus. Omitted or true shows the avatar's name; a string shows that text instead; false shows no tooltip. Not auto-disabled when wrapped in your own Tooltip/HoverCard. Set tooltip={false} if you supply your own overlay. No tooltip is shown when tooltip is true/omitted and there is no name.",
default: 'true',
},
{
name: 'href',
type: 'string',
description:
'When set, the avatar renders as an interactive link (`<a>` or a custom link component) pointing here. This follows the same element-swap rule as Button. Requires a meaningful accessible name via `alt` or `name`: an interactive avatar without one warns in development. Inside an AvatarGroup, interactive avatars share a single Tab stop and are reached with arrow keys.',
},
{
name: 'as',
type: 'ElementType',
description:
'Custom link component used when `href` is set (e.g. `next/link`). Overrides the provider-level LinkProvider default. Only applies with `href`.',
},
{
name: 'target',
type: 'string',
description: 'Link target attribute. Only applies with `href`.',
},
{
name: 'rel',
type: 'string',
description: 'Link rel attribute. Only applies with `href`.',
},
{
name: 'onClick',
type: '(e: MouseEvent) => void',
description:
'Click handler. When set without `href`, the avatar renders as a focusable `<button type="button">`. Requires a meaningful accessible name via `alt` or `name`: an interactive avatar without one warns in development.',
},
],
components: [
{name: 'AvatarStatusDot'},
],
};
/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
export const docsZh = {
usage: {
description:
'Avatar displays a user or entity\'s profile picture with automatic fallback to initials or a default icon. Use it alongside user information to visually represent people, teams, or entities throughout the interface.',
bestPractices: [
{guidance: true, description: 'Always provide a name prop so the component can generate meaningful initials and alt text when the image fails to load.'},
{guidance: true, description: 'Use the status slot with AvatarStatusDot to indicate online presence or availability when relevant to the context.'},
{guidance: true, description: 'Give every interactive avatar (href or onClick) a name or alt. It is the control\'s accessible name, and it warns in development when it is missing.'},
{guidance: false, description: 'Use Avatar for decorative images or logos that aren\'t representing a person or entity. Use an image or icon component instead.'},
{guidance: false, description: 'Override the circular shape. Avatars are always round to maintain visual consistency across the system.'},
],
},
};
/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
export const docsDense = {
description: 'person/team avatar w/ photo → initials → icon fallback chain',
usage: {
description:
'Avatar represents a person or team with a profile photo, initials, or a default icon. Falls back automatically. Use in comment headers, contact lists, chat, user cards.',
bestPractices: [
{guidance: true, description: 'Always pass a name for initials fallback and screen reader alt text.'},
{guidance: true, description: 'Match size to context: xsm/sm inline, md/lg in lists, xl for profiles.'},
{guidance: true, description: 'Add a status dot in chat or team views where availability matters.'},
{guidance: true, description: 'When wrapping Avatar in your own Tooltip or HoverCard, set tooltip={false} so the built-in name tooltip does not overlap yours.'},
{guidance: true, description: 'Interactive avatars (href/onClick) need name or alt; without one they warn in development.'},
{guidance: false, description: 'Rely on a status label to name an interactive avatar. "Online" says nothing about where the link goes.'},
{guidance: false, description: 'Use for logos or product images. Use an image or icon instead.'},
{guidance: false, description: 'Force a square or custom shape. Avatars are always circular.'},
],
},
propDescriptions: {
src: 'primary image source URL',
fallbackSrc: 'fallback image when primary fails',
name: 'user name for initials and alt text',
alt: 'alt text; falls back to name',
size: "avatar size. Named ('xsm' 20px, 'sm' 24px, 'md' 36px, 'lg' 48px, 'xl' 128px) or numeric px. An AvatarGroup's size overrides it.",
status:
'corner content for status indicators; AvatarStatusDot reports its `label`, composed into the avatar accessible name ("Jane Doe, Online"), at any nesting depth',
tooltip:
"hover/focus tooltip. true/omitted → name; string → that text; false → none. Owns its tooltip; set false when wrapping in your own Tooltip/HoverCard. Default true.",
href: 'renders avatar as a link (<a>/custom). Needs alt/name for an accessible name; warns in development without one. Button-style element swap.',
as: 'custom link component for href (e.g. Next Link). Only with href.',
target: 'link target. Only with href.',
rel: 'link rel. Only with href.',
onClick: 'click handler → renders <button> when no href. Needs alt/name; warns in development without one.',
},
components: [
{name: 'AvatarStatusDot', description: 'size-aware status indicator rendered in the Avatar corner'},
],
};