Components › Components
Demos show your theme.
Avatar
A round picture of someone, or their initials.
Usage #
tscl
@import uiAvatar from './avatar.tscl'
<div class="demo">
<uiAvatar src="/logo.svg" alt="clarusjs" />
<uiAvatar alt="Ada Lovelace" fallback="AL" />
</div>
<style scoped>
:scope {
display: flex;
gap: 12px;
padding: 24px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-bg);
color: var(--ui-fg);
}
</style>Source #
Copy it into your components folder (next to the others) as avatar.tscl.
tscl
{{-- Avatar: a round picture of someone, or their initials when there's no picture. alt names them either way. --}}
@input parts: { image?: Record<string, string | boolean>; fallback?: Record<string, string | boolean> } = {}
@input src: string = ''
@input alt: string
@input fallback: string = ''
<span data-part="avatar">
@if (src) {
<img [...]="parts.image ?? {}" [src]="src" [alt]="alt" data-part="avatar-image" />
} @else {
<span [...]="parts.fallback ?? {}" role="img" [aria-label]="alt" data-part="avatar-fallback">{{ fallback }}</span>
}
</span>
<style scoped>
@layer theme, base, components, utilities;
@layer components {
:where(:scope) {
display: inline-flex;
width: 40px;
height: 40px;
overflow: hidden;
border-radius: 50%;
background: var(--ui-accent-soft);
color: var(--ui-fg);
font: 600 var(--ui-font-size) var(--ui-font);
}
:where([data-part='avatar-image']) {
width: 100%;
height: 100%;
object-fit: cover;
}
:where([data-part='avatar-fallback']) {
display: grid;
place-items: center;
width: 100%;
}
}
</style>Styling #
- On the root:
class,style,id,aria-*anddata-*written on the tag land on its root element;classandstylemerge with its own. - Inner pieces:
partstakes an object of attributes (class,style,data-*) for each ofimage,fallback, spread on that piece:[parts]="{ image: { class: 'my-image' } }". - Selectors:
data-partnamesavatar,avatar-image,avatar-fallback. - Your rules win: every rule here has zero specificity (
:where()) and sits in@layer components, so your own CSS and Tailwind utilities override it.
Needs #
- theme.css, once per project