Avatar
An easily stylable avatar component.
<?phem
use Phem\Attribute\Component;
use Phem\Node;
use function Phem\Ui\{Avatar, AvatarFallback, AvatarImage};
#[Component]
function AvatarHeroDemo(): Node
{
return (
<div className="flex gap-4">
<Avatar>
<AvatarImage src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?w=128&h=128&dpr=2&q=80" width="48" height="48" />
<AvatarFallback delay={{ 600 }}>LT</AvatarFallback>
</Avatar>
<Avatar>LT</Avatar>
</div>
);
}
API reference#
Import the components of the family:
use function Phem\Ui\{Avatar, AvatarImage, AvatarFallback};Avatar#
An image of a user with a fallback, such as the initials: Base UI Avatar.Root, on the phem-avatar controller. The fallback shows while the image is not loaded.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
AvatarImage#
The image. It shows only when it loads.
| Prop | Type | Default |
|---|---|---|
src (required) | string | — |
alt | string | '' |
...rest | mixed | — |
AvatarFallback#
The text that shows while the image is not loaded. With a delay (in ms), it shows only after this time, so a fast image does not show it: the server render has it hidden.
| Prop | Type | Default |
|---|---|---|
delay | int | 0 |
children | ?Html | null |
...rest | mixed | — |
The source of the examples: examples/ui/Avatar.phem.