Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@import "tailwindcss";
@plugin "@tailwindcss/forms";
@import "./tokens.css";

@source "../../lib/**/*.*ex";

Expand All @@ -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);
}
64 changes: 64 additions & 0 deletions assets/css/tokens.css
Original file line number Diff line number Diff line change
@@ -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 <html> 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);
}
2 changes: 2 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,6 +20,7 @@ const hooks = {
ScrollBottom,
Themer,
AutoDismissFlash,
Countdown,
};

// Topbar ---
Expand Down
27 changes: 27 additions & 0 deletions assets/js/hooks/countdown.js
Original file line number Diff line number Diff line change
@@ -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();
Comment thread
thiagoesteves marked this conversation as resolved.
Resolved
const remainingMs = expiresAt - Date.now();
const remainingSeconds = Math.max(0, Math.ceil(remainingMs / 1000));

this.el.textContent = `${remainingSeconds}s`;
},
};

export default Countdown;
4 changes: 2 additions & 2 deletions lib/web/components/attention.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ defmodule Observer.Web.Components.Attention do

def content(assigns) do
~H"""
<div class="flex items-stretch justify-between bg-gray-200 dark:bg-gray-800 w-full">
<div class="flex items-stretch justify-between bg-base-200 w-full">
<div
id={"live-#{@id}-alert"}
class={["p-2 bg-gray-300 dark:bg-gray-700 border-l-8 rounded-l-lg grow", @class]}
class={["p-2 bg-base-300 border-l-8 rounded-l-lg grow", @class]}
role="alert"
>
<div class="flex items-center">
Expand Down
2 changes: 1 addition & 1 deletion lib/web/components/confirm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Observer.Web.Components.Confirm do
~H"""
<div id={@id}>
<div
class="fixed inset-0 z-20 overflow-y-auto"
class="fixed inset-0 z-50 overflow-y-auto"
phx-window-keydown="confirm-close-modal"
phx-key="escape"
>
Expand Down
30 changes: 26 additions & 4 deletions lib/web/components/core.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Observer.Web.Components.Core do
<div class="px-4 sm:overflow-visible sm:px-0 ">
<div id={"#{@id}-table"} class="block" phx-hook="ScrollBottom">
<table class="items-center w-full border-collapse ">
<thead class="text-xs text-left align-middle leading-6 text-blueGray-500 uppercase sticky top-0 z-10">
<thead class="text-xs text-left align-middle leading-6 bg-base-200 text-muted uppercase sticky top-0 z-10">
<tr>
<th :for={col <- @col} class="p-1 pb-1 pr-6 font-semibold font-normal">
{col[:label]}
Expand All @@ -55,7 +55,7 @@ defmodule Observer.Web.Components.Core do
<tr
:for={row <- @rows}
id={@row_id && @row_id.(row)}
class="group bg-white dark:bg-gray-800 "
class="group bg-base-100"
phx-mounted={
@transition &&
JS.transition(
Expand Down Expand Up @@ -197,7 +197,7 @@ defmodule Observer.Web.Components.Core do
end

~H"""
<div class="px-4 sm:overflow-visible sm:px-0 rounded bg-white dark:bg-gray-800 border border-solid border-blueGray-100">
<div class="px-4 sm:overflow-visible sm:px-0 rounded bg-base-100 border border-solid border-base-300">
<div id={"#{@id}-table"} class="block max-h-[600px]">
<table class="items-center w-full border-collapse">
<div class={[
Expand Down Expand Up @@ -289,7 +289,7 @@ defmodule Observer.Web.Components.Core do
phx-hook="ScrollBottom"
>
<table class="items-center w-full border-collapse">
<thead class="text-xs text-left align-middle leading-6 bg-white bg-blueGray-50 dark:bg-gray-800 text-blueGray-500 dark:text-blueGray-700 uppercase sticky top-0 z-10">
<thead class="text-xs text-left align-middle leading-6 bg-base-200 text-muted uppercase sticky top-0 z-10">
<tr>
<th :for={col <- @col} class="p-1 pb-1 pr-6 font-semibold font-normal">
{col[:label]}
Expand Down Expand Up @@ -551,4 +551,26 @@ defmodule Observer.Web.Components.Core do
instead of each button hand-rolling its own `disabled:` utilities.
"""
def gated_classes, do: "disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"

@doc """
Shared class string for a toolbar's primary CTA button (REFRESH/RUN/UPDATE), so every page's
button stays visually identical without retyping the same Tailwind string at each call site.
"""
def action_button_class,
do:
"phx-submit-loading:opacity-75 rounded-xl bg-success transform active:scale-75 transition-transform hover:opacity-90 ml-auto px-5 py-1.5 shrink-0 flex items-center justify-center text-sm font-semibold text-success-content active:opacity-75"

@doc """
Shared class string for a small stat/status pill. `tone` picks the color: `:info` (default),
`:warning`, or `:neutral`.
"""
def badge_class(tone \\ :info)

def badge_class(:info), do: "px-2 py-1 rounded-full bg-info/10 border border-info text-info"

def badge_class(:warning),
do: "px-2 py-1 rounded-full bg-warning/10 border border-warning text-warning"

def badge_class(:neutral),
do: "px-2 py-1 rounded-full bg-base-200 border border-base-300 text-base-content"
end
104 changes: 104 additions & 0 deletions lib/web/components/details_panel.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
defmodule Observer.Web.Components.DetailsPanel do
@moduledoc """
Bottom-docked panel that slides up to show the details of whatever row/identifier a page's
user just selected (an ETS table, a process, a port, ...), with collapse/expand/close controls.
Each page keeps its own selection state and event names; this component only renders the
shared chrome around whatever content the caller puts in its `inner_block` slot.
"""
use Phoenix.Component

alias Observer.Web.Components.Icons
alias Phoenix.LiveView.JS

attr :id, :string, required: true
attr :expand_id, :string, required: true
attr :collapse_id, :string, required: true
attr :close_id, :string, required: true
attr :collapsed, :boolean, required: true
attr :expanded, :boolean, required: true
attr :expand_event, :string, required: true
attr :collapse_event, :string, required: true
attr :close_event, :string, required: true

slot :title, required: true
slot :inner_block, required: true

def content(assigns) do
~H"""
<div
id={@id}
phx-mounted={
JS.transition(
{"transition-transform duration-300 ease-out", "translate-y-full", "translate-y-0"}
)
}
class={[
"fixed inset-x-0 bottom-0 z-30 flex flex-col bg-base-100 border-t border-base-300 shadow-2xl",
@expanded && "max-h-[92vh]",
!@expanded && "max-h-[70vh]"
]}
>
<div class="flex items-center justify-between px-4 py-2 border-b border-base-300 shrink-0">
<h2 class="text-sm font-semibold text-base-content">
{render_slot(@title)}
</h2>
<div class="flex items-center gap-x-3">
<button
:if={not @collapsed}
id={@expand_id}
type="button"
aria-label={if @expanded, do: "Shrink details panel", else: "Expand details panel"}
title={if @expanded, do: "Shrink", else: "Expand"}
phx-click={@expand_event}
class="inline-flex text-muted focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary focus:text-base-content transition ease-in-out duration-150"
>
<%= if @expanded do %>
<Icons.arrows_pointing_in class="w-5 h-5" />
<% else %>
<Icons.arrows_pointing_out class="w-5 h-5" />
<% end %>
</button>
<button
id={@collapse_id}
type="button"
aria-label={if @collapsed, do: "Restore details panel", else: "Minimize details panel"}
title={if @collapsed, do: "Restore", else: "Minimize"}
phx-click={@collapse_event}
class="inline-flex text-muted focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary focus:text-base-content transition ease-in-out duration-150"
>
<%= if @collapsed do %>
<Icons.chevron_up class="w-5 h-5" />
<% else %>
<Icons.chevron_down class="w-5 h-5" />
<% end %>
</button>
<button
id={@close_id}
type="button"
aria-label="Close details panel"
title="Close"
phx-click={@close_event}
class="inline-flex text-muted focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary focus:text-base-content transition ease-in-out duration-150"
>
<Icons.x_mark class="w-5 h-5" />
</button>
</div>
</div>

<div :if={not @collapsed} class="overflow-y-auto">
{render_slot(@inner_block)}
</div>
</div>
"""
end

@doc """
Bottom padding for the page's root container, so the docked panel never overlaps the page's
own content. Sized to match the panel's own collapsed/expanded height.
"""
def padding_class(shown?, collapsed?, expanded?)
def padding_class(false, _collapsed?, _expanded?), do: nil
def padding_class(true, true, _expanded?), do: "pb-16"
def padding_class(true, false, true), do: "pb-[92vh]"
def padding_class(true, false, false), do: "pb-[70vh]"
end
Loading