Dialog
A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.
View source
import * as Dialog from "@danielfrg/solid-ui/dialog"
import styles from "./index.module.css"
export function DemoDialogHero() {
return (
<Dialog.Root>
<Dialog.Trigger class={styles.button}>View notifications</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay class={styles.overlay} />
<div class={styles.positioner}>
<Dialog.Content class={styles.content}>
<Dialog.Title class={styles.title}>Notifications</Dialog.Title>
<Dialog.Description class={styles.description}>You are all caught up. Good job!</Dialog.Description>
<div class={styles.actions}>
<Dialog.CloseButton class={styles.button}>Close</Dialog.CloseButton>
</div>
</Dialog.Content>
</div>
</Dialog.Portal>
</Dialog.Root>
)
}.button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
height: 2.5rem;
padding: 0 0.875rem;
outline: 0;
border: 1px solid var(--color-gray-200);
border-radius: 0.375rem;
background-color: var(--color-gray-50);
font-family: inherit;
font-size: 1rem;
font-weight: 500;
line-height: 1.5rem;
color: var(--color-gray-900);
user-select: none;
cursor: pointer;
}
@media (hover: hover) {
.button:hover {
background-color: var(--color-gray-100);
}
}
.button:active {
background-color: var(--color-gray-100);
}
.button:focus-visible {
outline: 2px solid var(--color-blue);
outline-offset: -1px;
}
.overlay {
position: fixed;
inset: 0;
z-index: 200;
background-color: rgb(0 0 0 / 0.2);
animation: overlayHide 150ms ease forwards;
}
.overlay[data-expanded] {
animation: overlayShow 150ms ease;
}
@media (prefers-color-scheme: dark) {
.overlay {
background-color: rgb(0 0 0 / 0.7);
}
}
.positioner {
position: fixed;
inset: 0;
z-index: 200;
display: flex;
align-items: center;
justify-content: center;
}
.content {
box-sizing: border-box;
width: 24rem;
max-width: calc(100vw - 3rem);
padding: 1.5rem;
border-radius: 0.5rem;
outline: 1px solid var(--color-gray-200);
background-color: var(--color-gray-50);
color: var(--color-gray-900);
animation: contentHide 150ms ease forwards;
}
.content[data-expanded] {
animation: contentShow 150ms ease;
}
@media (prefers-color-scheme: dark) {
.content {
outline: 1px solid var(--color-gray-300);
}
}
.title {
margin-top: -0.375rem;
margin-bottom: 0.25rem;
font-size: 1.125rem;
line-height: 1.75rem;
letter-spacing: -0.0025em;
font-weight: 500;
}
.description {
font-size: 1rem;
line-height: 1.5rem;
color: var(--color-gray-600);
margin-bottom: 1.5rem;
}
.actions {
display: flex;
justify-content: end;
gap: 1rem;
}
@keyframes overlayShow {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes overlayHide {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
@keyframes contentShow {
from {
opacity: 0;
transform: scale(0.96);
}
to {
opacity: 1;
transform: scale(1);
}
}
@keyframes contentHide {
from {
opacity: 1;
transform: scale(1);
}
to {
opacity: 0;
transform: scale(0.96);
}
}:root {
--color-blue: oklch(45% 50% 264deg);
--color-red: oklch(50% 55% 31deg);
--color-gray-50: oklch(98% 0.25% 264deg);
--color-gray-100: oklch(12% 9.5% 264deg / 5%);
--color-gray-200: oklch(12% 9% 264deg / 7%);
--color-gray-300: oklch(12% 8.5% 264deg / 17%);
--color-gray-400: oklch(12% 8% 264deg / 38%);
--color-gray-500: oklch(12% 7.5% 264deg / 50%);
--color-gray-600: oklch(12% 7% 264deg / 67%);
--color-gray-700: oklch(12% 6% 264deg / 77%);
--color-gray-800: oklch(12% 5% 264deg / 85%);
--color-gray-900: oklch(12% 5% 264deg / 90%);
--color-gray-950: oklch(12% 5% 264deg / 95%);
}
@media (prefers-color-scheme: dark) {
:root {
--color-blue: oklch(69% 50% 264deg);
--color-red: oklch(80% 55% 31deg);
--color-gray-50: oklch(17% 0.25% 264deg);
--color-gray-100: oklch(28% 0.75% 264deg / 65%);
--color-gray-200: oklch(29% 0.75% 264deg / 80%);
--color-gray-300: oklch(35% 0.75% 264deg / 80%);
--color-gray-400: oklch(47% 0.875% 264deg / 80%);
--color-gray-500: oklch(64% 1% 264deg / 80%);
--color-gray-600: oklch(82% 1% 264deg / 80%);
--color-gray-700: oklch(92% 1.125% 264deg / 80%);
--color-gray-800: oklch(93% 0.875% 264deg / 85%);
--color-gray-900: oklch(95% 0.5% 264deg / 90%);
--color-gray-950: oklch(94% 0.375% 264deg / 95%);
}
}