Components › Components
Demos show your theme.
Alert dialog
A dialog that asks before something can't be undone.
Usage #
tscl
@import './dialog.css'
@import uiAlertDialog from './alert-dialog.tscl'
@import uiDialogTrigger from '@clarusjs/ui-primitives/dialog-trigger.tscl'
@import uiDialogClose from '@clarusjs/ui-primitives/dialog-close.tscl'
<div class="demo">
<uiDialogTrigger target="demo-delete">Delete project…</uiDialogTrigger>
<uiAlertDialog id="demo-delete">
@slot('title') {
Delete this project?
}
Its files and history go with it. This can't be undone.
@slot('actions') {
<uiDialogClose target="demo-delete">Cancel</uiDialogClose>
<uiDialogClose target="demo-delete">Delete</uiDialogClose>
}
</uiAlertDialog>
</div>
<style scoped>
:scope {
display: grid;
gap: 12px;
justify-items: start;
padding: 24px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-bg);
color: var(--ui-fg);
}
p {
margin: 0;
}
</style>Source #
Copy it next to your components as alert-dialog.tscl.
tscl
{{-- Alert dialog: a Dialog that asks before something can't be undone. A click outside never closes it; Escape
and Cancel do (as cancel). Put the cancel and the action in the actions slot, each a dialog-close. --}}
@import uiDialog from '@clarusjs/ui-primitives/dialog.tscl'
@input id: string
<uiDialog [id]="id" role="alertdialog" [dismissible]="false" [aria-describedby]="id + '-description'">
@slot('title') {
<slot name="title" />
}
<div [id]="id + '-description'" data-part="alert-dialog-description"><slot /></div>
<div data-part="alert-dialog-actions"><slot name="actions" /></div>
</uiDialog>
<style global>
@layer theme, base, components, utilities;
@layer components {
:where([data-part='alert-dialog-description']) {
color: var(--ui-muted);
}
:where([data-part='alert-dialog-actions']) {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
margin-top: 16px;
}
}
</style>Styling #
- On the root:
class,style,id,aria-*anddata-*written on the tag land on its root element;classandstylemerge with its own. - Selectors:
data-partnamesalert-dialog-description,alert-dialog-actions. - 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
-
@clarusjs/ui-primitives≥ 0.1.0: dialog.tscl, dialog-trigger.tscl, dialog-close.tscl - Dialog, copied next to it