Components › Components
Demos show your theme.
Alert
A message box with a title, plain or destructive.
Saved
Your changes are live.
Couldn't publish
The build failed: check the log.
Published
Your site is live.
Almost full
You've used 90% of your storage.
Usage #
tscl
@import uiAlert from './alert.tscl'
<div class="demo">
<uiAlert>
@slot('title') {
Saved
}
Your changes are live.
</uiAlert>
<uiAlert variant="destructive">
@slot('title') {
Couldn't publish
}
The build failed: check the log.
</uiAlert>
<uiAlert variant="success">
@slot('title') {
Published
}
Your site is live.
</uiAlert>
<uiAlert variant="warning">
@slot('title') {
Almost full
}
You've used 90% of your storage.
</uiAlert>
</div>
<style scoped>
:scope {
display: grid;
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 alert.tscl.
tscl
{{-- Alert: a message box with a title. [live]="true" makes it role="alert", for a message that appears after the page loads.
parts takes attributes (class, style, data-*) for its title and description. --}}
@input variant: 'default' | 'destructive' | 'success' | 'warning' = 'default'
@input live: boolean = false
@input parts: { title?: Record<string, string | boolean>; description?: Record<string, string | boolean> } = {}
<div [role]="live ? 'alert' : null" data-part="alert" [data-variant]="variant">
<p [...]="parts.title ?? {}" data-part="alert-title"><slot name="title" /></p>
<div [...]="parts.description ?? {}" data-part="alert-description"><slot /></div>
</div>
<style scoped>
@layer theme, base, components, utilities;
@layer components {
:where(:scope) {
display: grid;
gap: 4px;
padding: 12px 16px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-bg);
color: var(--ui-fg);
font: var(--ui-font-size)/1.5 var(--ui-font);
}
:where(:scope[data-variant='destructive']) {
border-color: var(--ui-danger);
color: var(--ui-danger);
}
:where(:scope[data-variant='success']) {
border-color: var(--ui-success);
color: var(--ui-success);
}
:where(:scope[data-variant='warning']) {
border-color: var(--ui-warning);
color: var(--ui-warning);
}
:where([data-part='alert-title']) {
margin: 0;
font-weight: 600;
}
:where([data-part='alert-title']:empty) {
display: none;
}
}
</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 oftitle,description, spread on that piece:[parts]="{ title: { class: 'my-title' } }". - Selectors:
data-partnamesalert,alert-title,alert-description; state attributesdata-variant. - 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