Components › Components
Demos show your theme.
Popover
A panel anchored to its trigger, on the popover attribute.
Copy the link, or send it by email.
Usage #
The parts come from @clarusjs/ui-primitives; the look is popover.css, imported once.
tscl
@import './popover.css'
@import uiPopover from '@clarusjs/ui-primitives/popover.tscl'
@import uiPopoverTrigger from '@clarusjs/ui-primitives/popover-trigger.tscl'
<div class="demo">
<uiPopoverTrigger target="demo-popover">Share</uiPopoverTrigger>
<uiPopover id="demo-popover" side="bottom" align="start">
<p>Copy the link, or send it by email.</p>
</uiPopover>
</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 popover.css. It's the same as @clarusjs/ui's rules for these parts, so using both looks the same.
css
/*
Popover: the same rules as @clarusjs/ui's ui.css for popover.tscl, popover-trigger.tscl from @clarusjs/ui-primitives.
Copy it next to your components, @import it once, and change it to change the look.
*/
@layer theme, base, components, utilities;
@layer components {
/* Focus is always visible, on every part and what's inside it. */
:where([data-part]):focus-visible,
:where([data-part]) :focus-visible {
outline: 2px solid var(--ui-ring);
outline-offset: 2px;
}
/* Buttons: triggers and closes. */
:where([data-part='trigger'], [data-part='close']) {
font: 600 var(--ui-font-size) var(--ui-font);
padding: 8px 14px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-bg);
color: var(--ui-fg);
cursor: pointer;
}
:where([data-part='trigger'], [data-part='close']):hover {
border-color: var(--ui-accent);
}
/* Popover: a little gap from its trigger, wherever it's placed. */
:where([data-part='popover']) {
margin: 6px;
padding: 12px 14px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-popover);
color: var(--ui-popover-fg);
color: var(--ui-fg);
box-shadow: var(--ui-shadow);
font: var(--ui-font-size)/1.5 var(--ui-font);
}
@media (prefers-reduced-motion: reduce) {
:where([data-part]),
:where([data-part]) * {
transition: none !important;
}
}
}Styling #
- On the parts:
class,style,id,aria-*anddata-*written on a part's tag (from@clarusjs/ui-primitives) land on its root element, merged with its own. - Selectors:
data-partnamestrigger,close,popover. - 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: popover.tscl, popover-trigger.tscl