view design_system/src/styles/components.css @ 253:fdf3816959cb

[ui] Add Sonner-like notification stack Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Tue, 04 Aug 2026 12:21:19 -0700
parents 7a7581f040e8
children 2b6e732087ff
line wrap: on
line source

:where(
  zen-button,
  zen-card,
  zen-alert,
  zen-field,
  zen-stack,
  zen-notifications
) {
  box-sizing: border-box;
  font-family: var(--zen-font-sans);
  color: var(--zen-color-text);
}

zen-button {
  display: inline-flex;
}

zen-button > :where(button, a) {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--zen-space-2);
  min-height: 2.75rem;
  padding: var(--zen-space-2) var(--zen-space-4);
  border: var(--zen-border-width) solid var(--zen-color-border);
  border-radius: var(--zen-radius-md);
  box-shadow: var(--zen-shadow-sm);
  background: var(--zen-color-accent);
  color: #171a21;
  font: 700 var(--zen-font-size-md)/1 var(--zen-font-sans);
  text-decoration: none;
  cursor: pointer;
  transition:
    background var(--zen-motion-fast) ease,
    box-shadow var(--zen-motion-fast) ease,
    transform var(--zen-motion-fast) ease;
}

zen-button > :where(button, a):hover {
  background: var(--zen-color-accent-hover);
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 rgba(23, 26, 33, 0.18);
}

zen-button > :where(button, a):active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

zen-button > :where(button, a):focus-visible,
zen-alert [data-zen-dismiss]:focus-visible,
zen-field :where(input, select, textarea):focus-visible {
  outline: 3px solid var(--zen-color-focus);
  outline-offset: 3px;
}

zen-button[variant="quiet"] > :where(button, a) {
  background: var(--zen-color-surface);
  color: var(--zen-color-text);
}

zen-button[variant="danger"] > :where(button, a) {
  background: var(--zen-color-danger);
  color: var(--zen-color-on-danger);
}

zen-button[disabled] > :where(button, a),
zen-button[loading] > :where(button, a) {
  opacity: 0.55;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

zen-button[loading] > :where(button, a)::before {
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: zen-spin 700ms linear infinite;
}

@keyframes zen-spin {
  to { transform: rotate(1turn); }
}

zen-card {
  display: block;
}

zen-card > :where(article, section) {
  height: 100%;
  padding: var(--zen-space-5);
  border: var(--zen-border-width) solid var(--zen-color-border);
  border-radius: var(--zen-radius-lg);
  box-shadow: var(--zen-shadow-md);
  background: var(--zen-color-surface-raised);
}

zen-card[interactive] > :where(article, section) {
  transition:
    box-shadow var(--zen-motion-fast) ease,
    transform var(--zen-motion-fast) ease;
}

zen-card[interactive] > :where(article, section):hover {
  transform: translate(-2px, -2px);
  box-shadow: 10px 10px 0 rgba(23, 26, 33, 0.18);
}

zen-card :where(h2, h3, p) {
  margin-top: 0;
}

zen-alert {
  display: grid;
  grid-template-columns: 0.35rem minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--zen-space-3);
  padding: var(--zen-space-4);
  border: var(--zen-border-width) solid var(--zen-color-border);
  border-radius: var(--zen-radius-md);
  background: var(--zen-color-surface-raised);
}

zen-alert::before {
  align-self: stretch;
  border-radius: 999px;
  background: var(--zen-color-info);
  content: "";
}

zen-alert[tone="success"]::before { background: var(--zen-color-success); }
zen-alert[tone="warning"]::before { background: var(--zen-color-warning); }
zen-alert[tone="danger"]::before { background: var(--zen-color-danger); }

zen-alert > :where(p, div) {
  margin: 0;
}

zen-alert [data-zen-dismiss] {
  min-width: 2rem;
  min-height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font: 700 1.2rem/1 var(--zen-font-sans);
  cursor: pointer;
}

zen-field {
  display: grid;
  gap: var(--zen-space-2);
}

zen-field > label {
  font-weight: 750;
}

zen-field > :where(input, select, textarea) {
  width: 100%;
  min-height: 2.75rem;
  box-sizing: border-box;
  padding: var(--zen-space-3);
  border: var(--zen-border-width) solid var(--zen-color-border);
  border-radius: var(--zen-radius-md);
  background: var(--zen-color-surface);
  color: var(--zen-color-text);
  font: inherit;
}

zen-field > textarea {
  min-height: 7rem;
  resize: vertical;
}

zen-field > :where(small, [data-help]) {
  color: var(--zen-color-text-muted);
}

zen-field[data-invalid] > :where(input, select, textarea) {
  border-color: var(--zen-color-danger);
}

zen-field[data-invalid] > :where(small, [data-help]) {
  color: var(--zen-color-danger);
}

zen-stack {
  display: flex;
  flex-direction: column;
  gap: var(--zen-stack-gap, var(--zen-space-4));
}

zen-stack[direction="row"] {
  flex-flow: row wrap;
  align-items: center;
}

zen-stack[gap="tight"] { --zen-stack-gap: var(--zen-space-2); }
zen-stack[gap="loose"] { --zen-stack-gap: var(--zen-space-6); }

zen-notifications > [data-zen-notification-stack] {
  position: fixed;
  z-index: var(--zen-notification-z-index, 1000);
  inset-inline-end: var(--zen-notification-inset, var(--zen-space-4));
  inset-block-end: var(
    --zen-notification-bottom-inset,
    var(--zen-space-4)
  );
  inline-size: min(24rem, calc(100vi - 2rem));
  height: var(--zen-notification-collapsed-height, 0);
  --zen-notification-gap: 12px;
  pointer-events: auto;
  isolation: isolate;
  transition: height 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

zen-notifications > [data-zen-notification-stack]:is(
  :hover,
  :focus-within
) {
  height: var(--zen-notification-expanded-height, 0);
}

zen-notifications > [data-zen-notification-stack] > article {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr) 2rem;
  align-items: start;
  gap: var(--zen-space-3);
  padding: var(--zen-space-4);
  border: var(--zen-border-width) solid var(--zen-color-border);
  border-radius: var(--zen-radius-lg);
  box-shadow: var(--zen-shadow-md);
  background: var(--zen-color-surface-raised);
  color: var(--zen-color-text);
  opacity: var(--zen-notification-collapsed-opacity, 1);
  pointer-events: none;
  transform:
    translate3d(
      0,
      var(--zen-notification-collapsed-offset, 0),
      0
    )
    scale(var(--zen-notification-scale, 1));
  transform-origin: center bottom;
  transition:
    opacity 180ms ease,
    transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
  animation: zen-notification-enter 160ms ease-out;
}

zen-notifications > [data-zen-notification-stack] > article[data-depth="0"] {
  pointer-events: auto;
}

zen-notifications > [data-zen-notification-stack]:is(
  :hover,
  :focus-within
) > article {
  opacity: 1;
  pointer-events: auto;
  transform:
    translate3d(
      0,
      var(--zen-notification-offset, 0px),
      0
    )
    scale(1);
}

zen-notifications > [data-zen-notification-stack] > article[data-removing] {
  opacity: 0;
  pointer-events: none;
  transform: translate3d(110%, 0, 0) scale(0.96);
}

.zen-notification-tone {
  display: grid;
  width: 1.75rem;
  height: 1.75rem;
  place-items: center;
  border-radius: 50%;
  background: var(--zen-color-info);
  color: var(--zen-color-on-info);
  font-weight: 900;
}

[data-tone="success"] > .zen-notification-tone {
  background: var(--zen-color-success);
  color: var(--zen-color-on-success);
}

[data-tone="warning"] > .zen-notification-tone {
  background: var(--zen-color-warning);
  color: var(--zen-color-on-warning);
}

[data-tone="error"] > .zen-notification-tone {
  background: var(--zen-color-danger);
  color: var(--zen-color-on-danger);
}

.zen-notification-content {
  display: grid;
  gap: var(--zen-space-1);
}

.zen-notification-message,
.zen-notification-description {
  margin: 0;
}

.zen-notification-message {
  font-weight: 800;
}

.zen-notification-description {
  color: var(--zen-color-text-muted);
  font-size: var(--zen-font-size-sm);
}

.zen-notification-action,
.zen-notification-dismiss {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.zen-notification-action {
  justify-self: start;
  margin-top: var(--zen-space-2);
  padding: 0;
  color: var(--zen-color-info);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.zen-notification-dismiss {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1.25rem;
}

.zen-notification-action:focus-visible,
.zen-notification-dismiss:focus-visible {
  outline: 3px solid var(--zen-color-focus);
  outline-offset: 2px;
}

.zen-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

@keyframes zen-notification-enter {
  from {
    opacity: 0;
  }
}

@media (forced-colors: active) {
  zen-notifications > [data-zen-notification-stack] > article,
  .zen-notification-tone {
    border: 1px solid CanvasText;
  }
}

@media (prefers-reduced-motion: reduce) {
  zen-button > :where(button, a),
  zen-card > :where(article, section) {
    transition: none;
  }

  zen-button[loading] > :where(button, a)::before {
    animation-duration: 1400ms;
  }

  zen-notifications > [data-zen-notification-stack] > article {
    animation: none;
    transition: none;
  }

  zen-notifications > [data-zen-notification-stack] {
    transition: none;
  }
}