From fc0e376df8bc31ed41dc48c3a5bcde5549fd360e Mon Sep 17 00:00:00 2001 From: Gabriel20xx Date: Thu, 27 Aug 2026 13:32:13 +0200 Subject: [PATCH] feat: add NotificationStack component and notify API for toast notifications --- .changeset/shared-notifications.md | 5 + .../web-ui/src/lib/components/AppShell.svelte | 3 + packages/web-ui/src/lib/index.ts | 3 + packages/web-ui/src/lib/styles.css | 80 ++++ scripts/sync-consumers.ps1 | 1 + shared-styles.css | 358 +++++++++++++++++- 6 files changed, 441 insertions(+), 9 deletions(-) create mode 100644 .changeset/shared-notifications.md diff --git a/.changeset/shared-notifications.md b/.changeset/shared-notifications.md new file mode 100644 index 0000000..b47dbca --- /dev/null +++ b/.changeset/shared-notifications.md @@ -0,0 +1,5 @@ +--- +"@gabriel20xx/web-ui": minor +--- + +Add a shared `NotificationStack` component and `notify` API (`notify.success/error/warning/info`) for toast-style action feedback. `AppShell` now mounts `NotificationStack` automatically, so any application using `AppShell` gets it without further wiring. diff --git a/packages/web-ui/src/lib/components/AppShell.svelte b/packages/web-ui/src/lib/components/AppShell.svelte index 64ae198..7abcd0f 100644 --- a/packages/web-ui/src/lib/components/AppShell.svelte +++ b/packages/web-ui/src/lib/components/AppShell.svelte @@ -2,6 +2,7 @@ import type { Snippet } from 'svelte'; import type { NavItem } from '../types'; import Header from './Header.svelte'; + import NotificationStack from './NotificationStack.svelte'; import PageHeader from './PageHeader.svelte'; let { @@ -54,6 +55,8 @@
+ +
item.label.toLowerCase() === 'about')?.href ?? '/about'} {brand} diff --git a/packages/web-ui/src/lib/index.ts b/packages/web-ui/src/lib/index.ts index f7358cc..6b57a3f 100644 --- a/packages/web-ui/src/lib/index.ts +++ b/packages/web-ui/src/lib/index.ts @@ -7,11 +7,14 @@ export { default as Button } from './components/Button.svelte'; export { default as Card } from './components/Card.svelte'; export { default as Dialog } from './components/Dialog.svelte'; export { default as Header } from './components/Header.svelte'; +export { default as NotificationStack } from './components/NotificationStack.svelte'; export { default as PageHeader } from './components/PageHeader.svelte'; export { default as ProfileDialog } from './components/ProfileDialog.svelte'; export { default as SettingsDialog } from './components/SettingsDialog.svelte'; export { default as TotpSettings } from './components/TotpSettings.svelte'; export { default as UserManagement } from './components/UserManagement.svelte'; +export { notifications, notify } from './notifications.svelte'; +export type { NotificationEntry, NotificationVariant } from './notifications.svelte'; export type { AboutLink, AsyncAction, diff --git a/packages/web-ui/src/lib/styles.css b/packages/web-ui/src/lib/styles.css index de4cfd3..f76eea9 100644 --- a/packages/web-ui/src/lib/styles.css +++ b/packages/web-ui/src/lib/styles.css @@ -717,6 +717,86 @@ color: var(--sc-fg); } +.sc-notification-stack { + position: fixed; + z-index: 200; + top: 1rem; + right: 1rem; + display: grid; + gap: 0.625rem; + width: min(100% - 2rem, 24rem); + pointer-events: none; +} + +.sc-notification { + display: flex; + align-items: flex-start; + gap: 0.625rem; + padding: 0.875rem 1rem; + color: var(--sc-fg); + background: var(--sc-surface-raised); + border: 1px solid var(--sc-border); + border-radius: var(--sc-radius-md); + box-shadow: var(--sc-shadow-lg); + pointer-events: auto; +} + +.sc-notification-icon { + flex: 0 0 auto; + margin-top: 0.125rem; + color: var(--sc-muted-fg); +} + +.sc-notification[data-variant="success"] .sc-notification-icon { + color: var(--sc-success); +} + +.sc-notification[data-variant="error"] .sc-notification-icon { + color: var(--sc-danger); +} + +.sc-notification[data-variant="warning"] .sc-notification-icon { + color: var(--sc-warning); +} + +.sc-notification[data-variant="info"] .sc-notification-icon { + color: var(--sc-primary); +} + +.sc-notification-message { + flex: 1 1 auto; + margin: 0; + font-size: 0.875rem; + line-height: 1.45; +} + +.sc-notification-close { + display: grid; + flex: 0 0 auto; + width: 1.5rem; + height: 1.5rem; + place-items: center; + color: var(--sc-muted-fg); + background: transparent; + border: 0; + border-radius: var(--sc-radius-sm); + cursor: pointer; +} + +.sc-notification-close:hover { + color: var(--sc-fg); + background: var(--sc-surface-hover); +} + +@media (max-width: 30rem) { + .sc-notification-stack { + top: 0.75rem; + right: 0.75rem; + left: 0.75rem; + width: auto; + } +} + .sc-dialog-backdrop { position: fixed; z-index: 100; diff --git a/scripts/sync-consumers.ps1 b/scripts/sync-consumers.ps1 index 1895c21..5f816f7 100644 --- a/scripts/sync-consumers.ps1 +++ b/scripts/sync-consumers.ps1 @@ -13,6 +13,7 @@ if ($Push -and -not $Commit) { } $consumerProjects = @( + 'Original/AutoCode', 'Original/SimpleCollection', 'Original/CollabTable', 'Original/GameStream', diff --git a/shared-styles.css b/shared-styles.css index c1e4a0a..2176eb9 100644 --- a/shared-styles.css +++ b/shared-styles.css @@ -1,5 +1,7 @@ @import './packages/design-tokens/theme.css'; +@import "@gabriel20xx/design-tokens/theme.css"; + :where(.sc-root, .sc-root *) { box-sizing: border-box; } @@ -62,6 +64,7 @@ } .sc-brand-mark { + overflow: hidden; display: grid; width: 2rem; height: 2rem; @@ -73,6 +76,18 @@ font-weight: 800; } +.sc-brand-icon { + /* Fixed instead of percentage-based: the icon isn't wrapped in a sized container (unlike + .sc-brand-mark, which this rule mirrors), and .sc-brand's own width is content-driven, so + a percentage here has no definite box to resolve against and lets the image render at + whatever intrinsic size its source happens to have. */ + width: 2rem; + height: 2rem; + padding: 0.25rem; + object-fit: contain; + border-radius: var(--sc-radius-md); +} + .sc-nav { display: flex; flex: 1 1 auto; @@ -85,7 +100,17 @@ .sc-icon-button { border: 1px solid transparent; border-radius: var(--sc-radius-md); - transition: color 140ms ease, background 140ms ease, border-color 140ms ease; + transition: + color 140ms ease, + background 140ms ease, + border-color 140ms ease; +} + +.sc-nav-link, +.sc-profile-button { + display: inline-flex; + align-items: center; + gap: 0.4rem; } .sc-nav-link { @@ -96,7 +121,7 @@ } .sc-nav-link:hover, -.sc-nav-link[data-active='true'] { +.sc-nav-link[data-active="true"] { color: var(--sc-fg); background: var(--sc-surface-hover); border-color: var(--sc-border); @@ -129,6 +154,54 @@ font-size: 0.875rem; } +.sc-profile-menu { + position: relative; +} + +.sc-profile-dropdown { + position: absolute; + top: calc(100% + 0.5rem); + right: 0; + z-index: 20; + display: grid; + min-width: 11rem; + gap: 0.125rem; + padding: 0.375rem; + background: var(--sc-surface); + border: 1px solid var(--sc-border); + border-radius: var(--sc-radius-md); + box-shadow: var(--sc-shadow-lg); +} + +.sc-profile-menu-item { + display: flex; + width: 100%; + align-items: center; + gap: 0.5rem; + padding: 0.625rem 0.75rem; + color: var(--sc-muted-fg); + background: transparent; + border: 0; + border-radius: var(--sc-radius-sm); + font: inherit; + font-size: 0.875rem; + text-align: left; + text-decoration: none; + cursor: pointer; +} + +/* The About item falls back to an when no onAbout handler is wired, unlike the other + button-based items - without this, the browser's default a:visited color (higher specificity + than the class color above) makes it drift from the other dropdown items' color once clicked. */ +.sc-profile-menu-item:visited { + color: var(--sc-muted-fg); +} + +.sc-profile-menu-item:hover { + color: var(--sc-fg); + background: var(--sc-surface-hover); +} + .sc-icon-button:hover, .sc-profile-button:hover { color: var(--sc-fg); @@ -146,6 +219,11 @@ justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; + padding: 1rem 1.25rem; + background: var(--sc-surface); + border: 1px solid var(--sc-border); + border-radius: var(--sc-radius-lg); + box-shadow: var(--sc-shadow-sm); } .sc-page-header h1, @@ -209,19 +287,19 @@ font-weight: 650; } -.sc-badge[data-variant='success'] { +.sc-badge[data-variant="success"] { color: var(--sc-success-fg); background: var(--sc-success); border-color: transparent; } -.sc-badge[data-variant='warning'] { +.sc-badge[data-variant="warning"] { color: var(--sc-warning-fg); background: var(--sc-warning); border-color: transparent; } -.sc-badge[data-variant='danger'] { +.sc-badge[data-variant="danger"] { color: var(--sc-danger-fg); background: var(--sc-danger); border-color: transparent; @@ -240,7 +318,11 @@ font-weight: 650; line-height: 1; cursor: pointer; - transition: color 140ms ease, background 140ms ease, border-color 140ms ease, opacity 140ms ease; + transition: + color 140ms ease, + background 140ms ease, + border-color 140ms ease, + opacity 140ms ease; } .sc-button:hover:not(:disabled) { @@ -255,6 +337,7 @@ .sc-button:focus-visible, .sc-icon-button:focus-visible, .sc-profile-button:focus-visible, +.sc-profile-menu-item:focus-visible, .sc-nav-link:focus-visible, .sc-dialog-close:focus-visible { outline: 3px solid color-mix(in srgb, var(--sc-ring) 45%, transparent); @@ -335,6 +418,66 @@ font-weight: 400; } +.sc-totp-settings { + display: grid; + gap: 0.75rem; + margin-top: 1.5rem; + padding-top: 1.25rem; + border-top: 1px solid var(--sc-border); +} + +.sc-totp-heading { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 1rem; +} + +.sc-totp-heading h3 { + margin: 0; + font-size: 0.95rem; +} + +.sc-totp-heading p { + margin: 0.25rem 0 0; +} + +.sc-totp-status { + flex: 0 0 auto; + border: 1px solid var(--sc-border); + border-radius: 999px; + padding: 0.2rem 0.55rem; + color: var(--sc-muted-fg); + font-size: 0.75rem; + font-weight: 600; +} + +.sc-totp-status.sc-totp-enabled { + border-color: var(--sc-success); + color: var(--sc-success); +} + +.sc-totp-secret { + display: grid; + gap: 0.5rem; + color: var(--sc-muted-fg); + font-size: 0.8rem; + overflow-wrap: anywhere; +} + +.sc-totp-secret p { + margin: 0; +} + +.sc-totp-secret code { + display: block; + border-radius: 0.4rem; + background: var(--sc-input-bg); + padding: 0.6rem; + color: var(--sc-fg); + font-size: 0.7rem; +} + .sc-input, .sc-select, .sc-textarea { @@ -346,7 +489,9 @@ border: 1px solid var(--sc-border); border-radius: var(--sc-radius-md); outline: none; - transition: border-color 140ms ease, box-shadow 140ms ease; + transition: + border-color 140ms ease, + box-shadow 140ms ease; } .sc-textarea { @@ -388,6 +533,109 @@ color: var(--sc-success); } +.sc-user-management { + display: grid; + gap: 1rem; + margin-top: 1.5rem; + padding-top: 1.5rem; + border-top: 1px solid var(--sc-border); +} + +.sc-user-management-header, +.sc-user-row, +.sc-user-edit-row { + display: flex; + align-items: center; + gap: 0.75rem; +} + +.sc-user-management-header { + justify-content: space-between; +} + +.sc-user-management-header h3 { + margin: 0; +} + +.sc-user-management-header p { + margin: 0.25rem 0 0; +} + +.sc-user-form, +.sc-user-list { + display: grid; + gap: 0.75rem; +} + +.sc-user-form { + padding: 0.9rem; + border: 1px solid var(--sc-border); + border-radius: 0.6rem; + background: var(--sc-surface-raised); +} + +.sc-user-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 0.6rem; +} + +.sc-user-row { + min-width: 0; + justify-content: space-between; + padding: 0.7rem 0; + border-bottom: 1px solid var(--sc-border); +} + +.sc-user-row > div:first-child { + display: grid; + min-width: 0; +} + +.sc-user-row > div:first-child span { + overflow: hidden; + color: var(--sc-muted-fg); + text-overflow: ellipsis; + white-space: nowrap; +} + +.sc-user-role { + color: var(--sc-muted-fg); + font-size: 0.8rem; + text-transform: capitalize; +} + +.sc-user-actions { + display: flex; + flex-shrink: 0; + gap: 0.4rem; +} + +.sc-user-edit-row { + align-items: stretch; + flex-wrap: wrap; +} + +.sc-user-edit-row .sc-input { + flex: 1 1 10rem; + min-width: 8rem; +} + +@media (max-width: 620px) { + .sc-user-grid { + grid-template-columns: 1fr; + } + + .sc-user-row { + align-items: flex-start; + flex-wrap: wrap; + } + + .sc-user-actions { + width: 100%; + } +} + .sc-auth-page { display: grid; min-height: 100vh; @@ -395,7 +643,11 @@ padding: 1.5rem; color: var(--sc-fg); background: - radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--sc-primary) 18%, transparent), transparent 35%), + radial-gradient( + circle at 15% 10%, + color-mix(in srgb, var(--sc-primary) 18%, transparent), + transparent 35% + ), var(--sc-bg); } @@ -416,6 +668,14 @@ font-weight: 750; } +.sc-auth-brand-icon { + display: block; + width: 2rem; + height: 2rem; + object-fit: contain; + border-radius: var(--sc-radius-md); +} + .sc-auth-card h1 { font-size: 1.7rem; } @@ -459,6 +719,86 @@ color: var(--sc-fg); } +.sc-notification-stack { + position: fixed; + z-index: 200; + top: 1rem; + right: 1rem; + display: grid; + gap: 0.625rem; + width: min(100% - 2rem, 24rem); + pointer-events: none; +} + +.sc-notification { + display: flex; + align-items: flex-start; + gap: 0.625rem; + padding: 0.875rem 1rem; + color: var(--sc-fg); + background: var(--sc-surface-raised); + border: 1px solid var(--sc-border); + border-radius: var(--sc-radius-md); + box-shadow: var(--sc-shadow-lg); + pointer-events: auto; +} + +.sc-notification-icon { + flex: 0 0 auto; + margin-top: 0.125rem; + color: var(--sc-muted-fg); +} + +.sc-notification[data-variant="success"] .sc-notification-icon { + color: var(--sc-success); +} + +.sc-notification[data-variant="error"] .sc-notification-icon { + color: var(--sc-danger); +} + +.sc-notification[data-variant="warning"] .sc-notification-icon { + color: var(--sc-warning); +} + +.sc-notification[data-variant="info"] .sc-notification-icon { + color: var(--sc-primary); +} + +.sc-notification-message { + flex: 1 1 auto; + margin: 0; + font-size: 0.875rem; + line-height: 1.45; +} + +.sc-notification-close { + display: grid; + flex: 0 0 auto; + width: 1.5rem; + height: 1.5rem; + place-items: center; + color: var(--sc-muted-fg); + background: transparent; + border: 0; + border-radius: var(--sc-radius-sm); + cursor: pointer; +} + +.sc-notification-close:hover { + color: var(--sc-fg); + background: var(--sc-surface-hover); +} + +@media (max-width: 30rem) { + .sc-notification-stack { + top: 0.75rem; + right: 0.75rem; + left: 0.75rem; + width: auto; + } +} + .sc-dialog-backdrop { position: fixed; z-index: 100; @@ -584,7 +924,7 @@ padding-bottom: 0.25rem; } - .sc-nav[data-open='true'] { + .sc-nav[data-open="true"] { display: flex; }