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
115 changes: 115 additions & 0 deletions addon-test-support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { render } from '@ember/test-helpers';

/**
* Test helpers for the canvas layout (`Layout::Canvas` and the pieces that
* float over it). Import from `@fleetbase/ember-ui/test-support`.
*
* The shell's colours are CSS variables from `styles/tokens.css`, switched by
* the nearest `data-theme` attribute. These helpers set that attribute on
* <body> (where the console sets it) and put it back afterwards, so a test can
* render the same template in both themes without leaking a theme into the
* next test.
*
* @example
* import { setupShellTheme, renderShell, eachShellTheme, shellToken } from '@fleetbase/ember-ui/test-support';
*
* module('Integration | Component | my-chrome', function (hooks) {
* setupRenderingTest(hooks);
* setupShellTheme(hooks);
*
* eachShellTheme((theme) => {
* test(`it renders in ${theme}`, async function (assert) {
* const canvas = await renderShell(hbs`<Layout::Canvas />`, { theme });
* assert.strictEqual(shellToken('canvas-bg', canvas), theme === 'dark' ? '#0b1220' : '#eef1f5');
* });
* });
* });
*/

/** The themes the shell supports, in the order tests should cover them. */
export const SHELL_THEMES = Object.freeze(['light', 'dark']);

/**
* Sets the shell theme on <body>.
*
* @param {'light'|'dark'} theme
* @throws {Error} for anything other than a supported theme, so a typo fails loudly instead of rendering light
*/
export function setShellTheme(theme) {
if (!SHELL_THEMES.includes(theme)) {
throw new Error(`Unknown shell theme "${theme}"; expected one of: ${SHELL_THEMES.join(', ')}`);
}

document.body.setAttribute('data-theme', theme);
}

/**
* Records <body>'s current `data-theme` and returns a function that restores
* it exactly, removing the attribute if there was none.
*
* @returns {() => void}
*/
export function snapshotShellTheme() {
const previous = document.body.getAttribute('data-theme');

return function restoreShellTheme() {
if (previous === null) {
document.body.removeAttribute('data-theme');
} else {
document.body.setAttribute('data-theme', previous);
}
};
}

/**
* Restores <body>'s `data-theme` after every test in the module.
*
* @param {object} hooks QUnit module hooks
*/
export function setupShellTheme(hooks) {
let restore;

hooks.beforeEach(function () {
restore = snapshotShellTheme();
});

hooks.afterEach(function () {
restore();
});
}

/**
* Calls `callback` once per supported theme. Use it to declare one test per
* theme, so a failure names the theme it happened in.
*
* @param {(theme: 'light'|'dark') => void} callback
*/
export function eachShellTheme(callback) {
SHELL_THEMES.forEach((theme) => callback(theme));
}

/**
* Sets the theme, renders `template` and returns the rendered canvas root
* (`.fb-canvas`), or `null` when the template renders no canvas.
*
* @param {object} template a compiled template (`hbs`...``)
* @param {{theme?: 'light'|'dark'}} [options]
* @returns {Promise<HTMLElement|null>}
*/
export async function renderShell(template, { theme = 'light' } = {}) {
setShellTheme(theme);
await render(template);

return document.querySelector('#ember-testing .fb-canvas');
}

/**
* Reads a shell token's resolved value, e.g. `shellToken('canvas-bg')`.
*
* @param {string} name the token name without the `--fb-` prefix
* @param {Element} [element] where to resolve it; defaults to <body>
* @returns {string} the trimmed value, or '' when the token is not defined
*/
export function shellToken(name, element = document.body) {
return getComputedStyle(element).getPropertyValue(`--fb-${name}`).trim();
}
17 changes: 17 additions & 0 deletions addon/components/layout/canvas.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="fb-canvas" data-theme={{@theme}} ...attributes>
<div class="fb-canvas-backdrop" data-canvas-layer="backdrop">
{{#if (has-block "backdrop")}}
{{yield to="backdrop"}}
{{else}}
<Layout::Canvas::Backdrop::DotGrid />
{{/if}}
</div>
<main class="fb-canvas-content" data-canvas-layer="content">
{{yield}}
</main>
{{#if (has-block "chrome")}}
<div class="fb-canvas-chrome" data-canvas-layer="chrome">
{{yield to="chrome"}}
</div>
{{/if}}
</div>
1 change: 1 addition & 0 deletions addon/components/layout/canvas/backdrop/dot-grid.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fb-canvas-dot-grid" aria-hidden="true" ...attributes></div>
4 changes: 4 additions & 0 deletions addon/styles/addon.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/** Design tokens: CSS variables only, no rules */
@import 'tokens.css';

/** Layout */
@import 'layout/reset.css';
@import "ember-basic-dropdown/vendor/ember-basic-dropdown.css";
Expand All @@ -9,6 +12,7 @@
@import 'layout/utilities.css';
@import 'layout/dark-theme.css';
@import 'layout/light-theme.css';
@import 'layout/canvas.css';

/** Components */
@import 'components/modal.css';
Expand Down
52 changes: 52 additions & 0 deletions addon/styles/layout/canvas.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Layout::Canvas, an opt-in application shell (the existing layout components
* do not use it). Three stacked layers, lowest first: backdrop, content, chrome.
* All colours and geometry come from `styles/tokens.css`.
*/

.fb-canvas {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
isolation: isolate;
background-color: var(--fb-canvas-bg);
color: var(--fb-text);
}

.fb-canvas-backdrop {
position: absolute;
inset: 0;
z-index: 0;
}

.fb-canvas-content {
position: absolute;
top: var(--fb-inset-top);
right: var(--fb-inset-right);
bottom: var(--fb-inset-bottom);
left: var(--fb-inset-left);
z-index: 1;
overflow: auto;
}

/* The chrome layer spans the canvas but never swallows a click meant for the
map or content below; only the chrome pieces themselves take the pointer. */
.fb-canvas-chrome {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
}

.fb-canvas-chrome > * {
pointer-events: auto;
}

.fb-canvas-dot-grid {
position: absolute;
inset: 0;
background-color: var(--fb-canvas-bg);
background-image: radial-gradient(var(--fb-canvas-dot) var(--fb-canvas-dot-size), transparent var(--fb-canvas-dot-size));
background-size: var(--fb-canvas-grid) var(--fb-canvas-grid);
}
106 changes: 106 additions & 0 deletions addon/styles/tokens.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Design tokens for the canvas layout.
*
* Every value the canvas layout needs is a CSS custom property here, so one
* `data-theme` attribute (on <body>, or on any element such as a
* `Layout::Canvas` root) switches the whole subtree between light and dark.
* `tailwind.config.js` maps these into utilities (`bg-surface`, `text-muted`,
* `rounded-chrome`, `shadow-chrome`, ...), so templates never repeat a hex.
*
* The light values also sit on `:root` so a page without `data-theme` still
* resolves every token. All names carry the `--fb-` prefix so they cannot
* collide with host or engine variables. None of the existing components read
* them, so importing this file changes nothing until a component uses them.
*/

:root,
[data-theme='light'] {
/* Surfaces and text */
--fb-surface: #ffffff;
--fb-subtle: #f4f6f9;
--fb-border: #e3e8ef;
--fb-text: #0f172a;
--fb-muted: #526077;
--fb-accent: #2563eb;
--fb-accent-fg: #ffffff;
--fb-focus: #2563eb;

/* Floating chrome (context bar, dock, tray, taskbar) */
--fb-chrome: rgba(255, 255, 255, 0.92);
--fb-chrome-border: rgba(15, 23, 42, 0.09);

/* Status: foreground and its tinted background */
--fb-info: #1d4ed8;
--fb-info-subtle: #e8f0fe;
--fb-warn: #92400e;
--fb-warn-subtle: #fef3c7;
--fb-ok: #166534;
--fb-ok-subtle: #dcfce7;
--fb-critical: #b91c1c;
--fb-critical-subtle: #fee2e2;

/* Map backdrop */
--fb-map-land: #edf0f4;
--fb-map-water: #c9daec;
--fb-map-road: #ffffff;
--fb-map-route: #2563eb;

/* Dot-grid canvas */
--fb-canvas-bg: #eef1f5;
--fb-canvas-dot: #b8c3d1;
--fb-canvas-grid: 22px;
--fb-canvas-dot-size: 1px;

/* Shadows */
--fb-shadow-chrome: 0 8px 24px rgba(15, 23, 42, 0.1);
--fb-shadow-sheet: 0 16px 40px rgba(15, 23, 42, 0.14);
}

[data-theme='dark'] {
--fb-surface: #0f1726;
--fb-subtle: #182235;
--fb-border: #2a3852;
--fb-text: #e7ecf4;
--fb-muted: #9aa7bd;
--fb-accent: #3b82f6;
--fb-accent-fg: #ffffff;
--fb-focus: #60a5fa;

--fb-chrome: rgba(15, 23, 38, 0.9);
--fb-chrome-border: rgba(148, 163, 184, 0.22);

--fb-info: #bfdbfe;
--fb-info-subtle: #172b4d;
--fb-warn: #fde68a;
--fb-warn-subtle: #422006;
--fb-ok: #bbf7d0;
--fb-ok-subtle: #052e16;
--fb-critical: #fecaca;
--fb-critical-subtle: #450a0a;

--fb-map-land: #1b2333;
--fb-map-water: #13233a;
--fb-map-road: #2b3750;
--fb-map-route: #60a5fa;

--fb-canvas-bg: #0b1220;
--fb-canvas-dot: #26344f;

--fb-shadow-chrome: 0 10px 30px rgba(0, 0, 0, 0.45);
--fb-shadow-sheet: 0 18px 44px rgba(0, 0, 0, 0.5);
}

/* Theme-independent: geometry is the same in both themes. */
:root {
/* Radius */
--fb-radius-control: 8px;
--fb-radius-card: 12px;
--fb-radius-chrome: 14px;
--fb-radius-dock: 18px;

/* Content insets: where the content layer sits inside the floating chrome */
--fb-inset-left: 82px;
--fb-inset-top: 64px;
--fb-inset-bottom: 80px;
--fb-inset-right: 12px;
}
1 change: 1 addition & 0 deletions app/components/layout/canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/ember-ui/components/layout/canvas';
1 change: 1 addition & 0 deletions app/components/layout/canvas/backdrop/dot-grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/ember-ui/components/layout/canvas/backdrop/dot-grid';
28 changes: 28 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ module.exports = {
DEFAULT: 'transparent',
},
colors: {
// Design tokens (addon/styles/tokens.css). Each resolves a CSS variable, so
// the same class follows the nearest [data-theme] without a `dark:` variant.
surface: 'var(--fb-surface)',
subtle: 'var(--fb-subtle)',
border: 'var(--fb-border)',
text: 'var(--fb-text)',
muted: 'var(--fb-muted)',
accent: { DEFAULT: 'var(--fb-accent)', fg: 'var(--fb-accent-fg)' },
focus: 'var(--fb-focus)',
chrome: { DEFAULT: 'var(--fb-chrome)', border: 'var(--fb-chrome-border)' },
info: { DEFAULT: 'var(--fb-info)', subtle: 'var(--fb-info-subtle)' },
warn: { DEFAULT: 'var(--fb-warn)', subtle: 'var(--fb-warn-subtle)' },
ok: { DEFAULT: 'var(--fb-ok)', subtle: 'var(--fb-ok-subtle)' },
critical: { DEFAULT: 'var(--fb-critical)', subtle: 'var(--fb-critical-subtle)' },
map: { land: 'var(--fb-map-land)', water: 'var(--fb-map-water)', road: 'var(--fb-map-road)', route: 'var(--fb-map-route)' },
canvas: { DEFAULT: 'var(--fb-canvas-bg)', dot: 'var(--fb-canvas-dot)' },
sky: {
100: '#e6f0fb',
200: '#bad5f5',
Expand Down Expand Up @@ -75,7 +91,15 @@ module.exports = {
850: '#212a38',
},
},
borderRadius: {
control: 'var(--fb-radius-control)',
card: 'var(--fb-radius-card)',
chrome: 'var(--fb-radius-chrome)',
dock: 'var(--fb-radius-dock)',
},
boxShadow: {
chrome: 'var(--fb-shadow-chrome)',
sheet: 'var(--fb-shadow-sheet)',
xs: '0 0 0 1px rgba(0,0,0, 0.05)',
'light-xs': '0 0 0 1px rgba(212,220,236, 0.05)',
'light-sm': '0 1px 2px 0 rgba(212,220,236, 0.05)',
Expand All @@ -102,6 +126,10 @@ module.exports = {
86: '30rem',
},
spacing: {
'canvas-left': 'var(--fb-inset-left)',
'canvas-top': 'var(--fb-inset-top)',
'canvas-bottom': 'var(--fb-inset-bottom)',
'canvas-right': 'var(--fb-inset-right)',
70: '18rem',
74: '22rem',
78: '26rem',
Expand Down
Loading
Loading