diff --git a/README.md b/README.md index 7a617c4..57bec3e 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,12 @@ library is part of the [DeployEx][dye] project. See the [installation guide](https://hexdocs.pm/observer_web/installation.html) for details on installing and Configuring. +## Theming + +Colors come from a small set of CSS custom properties in `assets/css/tokens.css`, one block for light mode and one for dark mode. +They're mapped to Tailwind utilities (`bg-primary`, `bg-base-100`, `text-muted`, `bg-success`, and so on) in the `@theme` block of `assets/css/app.css`, so a class built on a token needs no separate `dark:` variant - the underlying variable itself switches with the page's `dark` class. +To change the palette, edit the values in `tokens.css` and rebuild assets; nothing else needs to change. + ## Supported Versions Observer Web follows the same support policy as [DeployEx][dye]: the last two major Erlang/OTP releases, and the last two major Phoenix releases. diff --git a/assets/css/app.css b/assets/css/app.css index ccb0067..04a81cc 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -6,6 +6,7 @@ @import "tailwindcss"; @plugin "@tailwindcss/forms"; +@import "./tokens.css"; @source "../../lib/**/*.*ex"; @@ -16,4 +17,28 @@ --spacing-72: 18rem; --spacing-84: 21rem; --spacing-96: 24rem; + + /* Backed by the CSS variables in tokens.css, which already flip between light and dark - so + classes built on these (bg-primary, text-base-content, etc.) need no separate dark: variant. */ + --color-base-100: var(--dx-base-100); + --color-base-200: var(--dx-base-200); + --color-base-300: var(--dx-base-300); + --color-base-content: var(--dx-base-content); + --color-muted: var(--dx-muted); + + --color-primary: var(--dx-primary); + --color-primary-content: var(--dx-primary-content); + --color-secondary: var(--dx-secondary); + --color-secondary-content: var(--dx-secondary-content); + --color-neutral: var(--dx-neutral); + --color-neutral-content: var(--dx-neutral-content); + + --color-info: var(--dx-info); + --color-info-content: var(--dx-info-content); + --color-success: var(--dx-success); + --color-success-content: var(--dx-success-content); + --color-warning: var(--dx-warning); + --color-warning-content: var(--dx-warning-content); + --color-error: var(--dx-error); + --color-error-content: var(--dx-error-content); } diff --git a/assets/css/tokens.css b/assets/css/tokens.css new file mode 100644 index 0000000..db1dde4 --- /dev/null +++ b/assets/css/tokens.css @@ -0,0 +1,64 @@ +/* Design tokens, adapted from the deployex dashboard's shared token file so the two keep a matching + palette. Plain CSS custom properties, no Tailwind/daisyUI syntax - edit the values here and every + class built on them (in the @theme block in app.css) picks it up, without touching component files. + + The light values apply on :root; .dark overrides them, matching this project's own dark-mode + mechanism (a `dark` class toggled on by the Themer hook), not deployex's `data-theme` attr. */ + +:root { + --dx-base-100: oklch(98.6% 0.006 85); + --dx-base-200: oklch(95% 0.011 80); + --dx-base-300: oklch(88.5% 0.016 75); + --dx-base-content: oklch(23% 0.014 60); + --dx-muted: color-mix(in oklch, var(--dx-base-content) 66%, var(--dx-base-100)); + + --dx-primary: oklch(70% 0.213 47.604); + --dx-primary-content: oklch(98% 0.016 73.684); + --dx-primary-text: oklch(50% 0.16 42); + --dx-secondary: oklch(52% 0.02 60); + --dx-secondary-content: oklch(98.6% 0.006 85); + --dx-neutral: oklch(44% 0.017 60); + --dx-neutral-content: oklch(98.6% 0.006 85); + + --dx-info: oklch(62% 0.214 259.815); + --dx-info-content: oklch(97% 0.014 254.604); + --dx-info-text: oklch(47% 0.17 260); + --dx-success: oklch(70% 0.14 182.503); + --dx-success-content: oklch(98% 0.014 180.72); + --dx-success-text: oklch(44% 0.09 182); + --dx-warning: oklch(66% 0.179 58.318); + --dx-warning-content: oklch(98% 0.022 95.277); + --dx-warning-text: oklch(47% 0.12 58); + --dx-error: oklch(58% 0.253 17.585); + --dx-error-content: oklch(96% 0.015 12.422); + --dx-error-text: oklch(48% 0.19 20); +} + +.dark { + --dx-base-100: oklch(30.33% 0.016 252.42); + --dx-base-200: oklch(25.26% 0.014 253.1); + --dx-base-300: oklch(20.15% 0.012 254.09); + --dx-base-content: oklch(97.807% 0.029 256.847); + --dx-muted: color-mix(in oklch, var(--dx-base-content) 66%, var(--dx-base-100)); + + --dx-primary: oklch(58% 0.233 277.117); + --dx-primary-content: oklch(96% 0.018 272.314); + --dx-primary-text: oklch(80% 0.11 277); + --dx-secondary: oklch(58% 0.233 277.117); + --dx-secondary-content: oklch(96% 0.018 272.314); + --dx-neutral: oklch(37% 0.044 257.287); + --dx-neutral-content: oklch(98% 0.003 247.858); + + --dx-info: oklch(58% 0.158 241.966); + --dx-info-content: oklch(97% 0.013 236.62); + --dx-info-text: oklch(82% 0.09 240); + --dx-success: oklch(60% 0.118 184.704); + --dx-success-content: oklch(98% 0.014 180.72); + --dx-success-text: oklch(82% 0.09 182); + --dx-warning: oklch(66% 0.179 58.318); + --dx-warning-content: oklch(98% 0.022 95.277); + --dx-warning-text: oklch(84% 0.12 72); + --dx-error: oklch(58% 0.253 17.585); + --dx-error-content: oklch(96% 0.015 12.422); + --dx-error-text: oklch(80% 0.12 20); +} diff --git a/assets/js/app.js b/assets/js/app.js index 6d11eaa..ad2a28e 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -10,6 +10,7 @@ import NavOverflow from "./hooks/nav_overflow"; import ScrollBottom from "./hooks/scroll_bottom"; import Themer from "./hooks/themer"; import AutoDismissFlash from "./hooks/auto_dismiss_flash"; +import Countdown from "./hooks/countdown"; const hooks = { LiveMetricsEChart, @@ -19,6 +20,7 @@ const hooks = { ScrollBottom, Themer, AutoDismissFlash, + Countdown, }; // Topbar --- diff --git a/assets/js/hooks/countdown.js b/assets/js/hooks/countdown.js new file mode 100644 index 0000000..a5bf3d7 --- /dev/null +++ b/assets/js/hooks/countdown.js @@ -0,0 +1,27 @@ +// Ticks down to the timestamp in data-expires (ISO 8601), purely client-side so it doesn't need +// a server round-trip every second. The server re-renders data-expires whenever a new session +// starts, which this hook picks up via updated(). +const Countdown = { + mounted() { + this.tick(); + this.timer = setInterval(() => this.tick(), 1000); + }, + + updated() { + this.tick(); + }, + + destroyed() { + clearInterval(this.timer); + }, + + tick() { + const expiresAt = new Date(this.el.dataset.expires).getTime(); + const remainingMs = expiresAt - Date.now(); + const remainingSeconds = Math.max(0, Math.ceil(remainingMs / 1000)); + + this.el.textContent = `${remainingSeconds}s`; + }, +}; + +export default Countdown; diff --git a/lib/web/components/attention.ex b/lib/web/components/attention.ex index 4d4e731..7116d5f 100644 --- a/lib/web/components/attention.ex +++ b/lib/web/components/attention.ex @@ -11,10 +11,10 @@ defmodule Observer.Web.Components.Attention do def content(assigns) do ~H""" -
+