BS-003 Apply approved palette and persistent accessible themes
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import AxeBuilder from '@axe-core/playwright'
|
||||
import { expect, test } from '@playwright/test'
|
||||
|
||||
test('dark default and persistent light preference across routes and reload', async ({ page }) => {
|
||||
await page.emulateMedia({ colorScheme: 'light' })
|
||||
await page.goto('/')
|
||||
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', 'dark')
|
||||
await page.getByRole('button', { name: 'Switch to light mode' }).click()
|
||||
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', 'light')
|
||||
await page.reload()
|
||||
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', 'light')
|
||||
await page.goto('/services')
|
||||
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', 'light')
|
||||
await page.getByRole('button', { name: 'Switch to dark mode' }).click()
|
||||
await page.reload()
|
||||
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', 'dark')
|
||||
})
|
||||
|
||||
test('stored light initializes before React is allowed to load', async ({ page }) => {
|
||||
await page.addInitScript(() => localStorage.setItem('bortstack-theme', 'light'))
|
||||
let release
|
||||
const gate = new Promise(resolve => { release = resolve })
|
||||
await page.route('**/src/main.jsx', async route => { await gate; await route.continue() })
|
||||
const navigation = page.goto('/')
|
||||
await page.waitForFunction(() => globalThis.document.documentElement.dataset.bsTheme === 'light')
|
||||
expect(await page.locator('#root').innerHTML()).toBe('')
|
||||
release()
|
||||
await navigation
|
||||
await expect(page.getByRole('button', { name: 'Switch to dark mode' })).toBeVisible()
|
||||
})
|
||||
|
||||
test('storage denied does not break initial page or theme toggle', async ({ page }) => {
|
||||
await page.addInitScript(() => {
|
||||
Object.defineProperty(globalThis, 'localStorage', { get() { throw new DOMException('denied', 'SecurityError') } })
|
||||
})
|
||||
await page.goto('/')
|
||||
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', 'dark')
|
||||
await page.getByRole('button', { name: 'Switch to light mode' }).click()
|
||||
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', 'light')
|
||||
})
|
||||
|
||||
for (const theme of ['dark', 'light']) {
|
||||
test(`${theme} shell contrast and layout`, async ({ page }) => {
|
||||
await page.addInitScript(theme => localStorage.setItem('bortstack-theme', theme), theme)
|
||||
await page.goto('/')
|
||||
expect((await new AxeBuilder({ page }).analyze()).violations).toEqual([])
|
||||
expect(await page.locator('html').evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true)
|
||||
await page.getByRole('button', { name: `Switch to ${theme === 'dark' ? 'light' : 'dark'} mode` }).focus()
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', theme === 'dark' ? 'light' : 'dark')
|
||||
})
|
||||
}
|
||||
+2
-1
@@ -5,7 +5,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="Custom software, websites, APIs, hosting and ongoing maintenance for businesses and research projects." />
|
||||
<meta name="robots" content="index, follow" />
|
||||
<meta name="theme-color" content="#343a40" />
|
||||
<meta name="theme-color" content="#0E1117" />
|
||||
<script src="/theme-init.js"></script>
|
||||
<title>BortStack</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Runs synchronously in <head>, before React/styles paint. Dark is the default.
|
||||
(function () {
|
||||
var theme = 'dark';
|
||||
try {
|
||||
if (window.localStorage.getItem('bortstack-theme') === 'light') theme = 'light';
|
||||
} catch { /* Storage is optional; rendering and the toggle remain available. */ }
|
||||
document.documentElement.dataset.bsTheme = theme;
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
var meta = document.querySelector('meta[name="theme-color"]');
|
||||
if (meta) meta.content = theme === 'light' ? '#F5F7FA' : '#0E1117';
|
||||
}());
|
||||
@@ -1,41 +1,7 @@
|
||||
@use "sass:map";
|
||||
@use "../../styles/colors";
|
||||
|
||||
.footer {
|
||||
padding: 10px;
|
||||
min-height: 70px;
|
||||
background-color: map.get(colors.$theme-colors, "footer-bg");
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.links {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.developerSlot {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 0 auto 0.5rem;
|
||||
|
||||
a {
|
||||
display: inline-flex;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.developerLogo {
|
||||
display: block;
|
||||
width: min(210px, 70vw);
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.copyright {
|
||||
margin: 0;
|
||||
}
|
||||
.footer { border-top: 1px solid var(--site-line); padding-block: 1.75rem; color: var(--site-muted); font-size: .8rem; }
|
||||
.footerRow { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1.4rem; }
|
||||
.links { display: flex; gap: 1.5rem; a { color: var(--site-muted); text-decoration: none; } a:hover { color: var(--site-link); } }
|
||||
.developerSlot { display: inline-flex; border-radius: .2rem; padding: .35rem .6rem; background: #F5F7FA; }
|
||||
.developerLogo { display: block; width: 95px; height: auto; }
|
||||
.copyright { margin: 0; }
|
||||
@media (max-width: 575.98px) { .footerRow { justify-content: center; } .copyright { flex-basis: 100%; text-align: center; } }
|
||||
|
||||
@@ -2,11 +2,12 @@ import { useState } from "react";
|
||||
import { Container, Nav, Navbar } from "react-bootstrap";
|
||||
import { NavLink } from "react-router-dom";
|
||||
import Logo from "../Logo/Logo";
|
||||
import ThemeToggle from "../ThemeToggle/ThemeToggle";
|
||||
import styles from "./Header.module.scss";
|
||||
|
||||
export default function Header() {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
return <Navbar variant="dark" expand="md" expanded={expanded} onToggle={setExpanded} className={styles.header} aria-label="Main navigation">
|
||||
return <Navbar expand="md" expanded={expanded} onToggle={setExpanded} className={styles.header} aria-label="Main navigation">
|
||||
<Container>
|
||||
<Navbar.Brand as="div"><Logo /></Navbar.Brand>
|
||||
<Navbar.Toggle aria-controls="main-navigation" aria-expanded={expanded} />
|
||||
@@ -17,6 +18,7 @@ export default function Header() {
|
||||
))}
|
||||
</Nav>
|
||||
</Navbar.Collapse>
|
||||
<ThemeToggle />
|
||||
</Container>
|
||||
</Navbar>;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
@use "sass:map";
|
||||
@use "../../styles/colors";
|
||||
|
||||
.header {
|
||||
min-height: 70px;
|
||||
padding: 10px;
|
||||
background-color: map.get(colors.$theme-colors, "header-bg");
|
||||
padding-block: 1.3rem;
|
||||
background: var(--site-bg);
|
||||
border-bottom: 1px solid var(--site-line);
|
||||
:global(.navbar-brand) { margin: 0; }
|
||||
:global(.nav-link) { color: var(--site-text); font-size: .9rem; padding: .75rem 1rem !important; }
|
||||
:global(.nav-link:hover), :global(.nav-link.active) { color: var(--site-link); }
|
||||
:global(.navbar-toggler) { border-color: var(--site-line); padding: .65rem; margin-left: auto; margin-right: .8rem; }
|
||||
}
|
||||
|
||||
.navbarCollapse {
|
||||
justify-content: flex-end !important;
|
||||
.navbarCollapse { justify-content: flex-end; margin-right: 1.25rem; }
|
||||
@media (max-width: 767.98px) {
|
||||
.header { padding-block: 1rem; :global(.navbar-collapse) { order: 5; flex-basis: 100%; } }
|
||||
.navbarCollapse { margin: .8rem 0 0; }
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import styles from "./Logo.module.scss";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
function Logo() {
|
||||
return (
|
||||
<Link to="/" className={styles.link}>
|
||||
<span className={styles.logo}>BortStack</span>
|
||||
</Link>
|
||||
);
|
||||
import styles from "./Logo.module.scss";
|
||||
export default function Logo() {
|
||||
return <Link to="/" className={styles.link} aria-label="BortStack home — temporary text, approved logo pending">
|
||||
<span className={styles.logo}>Bort<span>Stack</span></span>
|
||||
<span className={styles.pending}>Logo pending</span>
|
||||
</Link>;
|
||||
}
|
||||
|
||||
export default Logo;
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
.link {
|
||||
text-decoration: none;
|
||||
color: unset;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.link { display: inline-flex; flex-direction: column; text-decoration: none; color: var(--site-text); line-height: 1.15; }
|
||||
.logo { font-size: 1.7rem; font-weight: 750; letter-spacing: -.055em; span { color: var(--site-link); } }
|
||||
.pending { margin-top: .3rem; font-size: .58rem; text-transform: uppercase; letter-spacing: .14em; color: var(--site-muted); }
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useState } from "react";
|
||||
import { FiMoon, FiSun } from "react-icons/fi";
|
||||
|
||||
export default function ThemeToggle() {
|
||||
const [theme, setTheme] = useState(() => document.documentElement.dataset.bsTheme === "light" ? "light" : "dark");
|
||||
function toggle() {
|
||||
const next = theme === "dark" ? "light" : "dark";
|
||||
document.documentElement.dataset.bsTheme = next;
|
||||
document.documentElement.style.colorScheme = next;
|
||||
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", next === "dark" ? "#0E1117" : "#F5F7FA");
|
||||
try { window.localStorage.setItem("bortstack-theme", next); } catch { /* Keep working without storage. */ }
|
||||
setTheme(next);
|
||||
}
|
||||
return <button type="button" className="themeToggle" onClick={toggle} aria-label={`Switch to ${theme === "dark" ? "light" : "dark"} mode`}>
|
||||
{theme === "dark" ? <FiSun aria-hidden="true" /> : <FiMoon aria-hidden="true" />}
|
||||
</button>;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import ThemeToggle from "./ThemeToggle";
|
||||
|
||||
afterEach(() => { vi.restoreAllMocks(); localStorage.clear(); document.documentElement.dataset.bsTheme = "dark"; });
|
||||
describe("theme control", () => {
|
||||
it("toggles both ways and persists the visitor preference", () => {
|
||||
document.documentElement.dataset.bsTheme = "dark";
|
||||
render(<ThemeToggle />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Switch to light mode" }));
|
||||
expect(document.documentElement.dataset.bsTheme).toBe("light");
|
||||
expect(localStorage.getItem("bortstack-theme")).toBe("light");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Switch to dark mode" }));
|
||||
expect(document.documentElement.dataset.bsTheme).toBe("dark");
|
||||
expect(localStorage.getItem("bortstack-theme")).toBe("dark");
|
||||
});
|
||||
it("still changes the visible theme when storage is denied", () => {
|
||||
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => { throw new Error("denied"); });
|
||||
document.documentElement.dataset.bsTheme = "dark";
|
||||
render(<ThemeToggle />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Switch to light mode" }));
|
||||
expect(document.documentElement.dataset.bsTheme).toBe("light");
|
||||
});
|
||||
});
|
||||
+60
-49
@@ -1,55 +1,66 @@
|
||||
@use "./colors";
|
||||
|
||||
.app {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
:root,
|
||||
[data-bs-theme="dark"] {
|
||||
--site-bg: var(--bs-charcoal);
|
||||
--site-surface: var(--bs-midnight);
|
||||
--site-text: #F5F7FA;
|
||||
--site-muted: #B5C5D2;
|
||||
--site-link: var(--bs-cyan);
|
||||
--site-line: #304C60;
|
||||
--site-cta-text: #07151C;
|
||||
--site-cta: var(--bs-cyan);
|
||||
--site-glow: rgba(38, 198, 218, .11);
|
||||
--bs-body-bg: var(--site-bg);
|
||||
--bs-body-color: var(--site-text);
|
||||
--bs-link-color: var(--site-link);
|
||||
--bs-link-hover-color: var(--site-text);
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
.pageContent {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
[data-bs-theme="light"] {
|
||||
--site-bg: #F5F7FA;
|
||||
--site-surface: #E7EFF5;
|
||||
--site-text: #102638;
|
||||
--site-muted: #455E70;
|
||||
--site-link: #086878;
|
||||
--site-line: #B6C8D4;
|
||||
--site-cta-text: #F5F7FA;
|
||||
--site-cta: #086878;
|
||||
--site-glow: rgba(38, 198, 218, .08);
|
||||
--bs-body-bg: var(--site-bg);
|
||||
--bs-body-color: var(--site-text);
|
||||
--bs-link-color: var(--site-link);
|
||||
--bs-link-hover-color: var(--site-text);
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
main {
|
||||
padding: 20px;
|
||||
flex: 1;
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--site-bg);
|
||||
color: var(--site-text);
|
||||
font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
line-height: 1.65;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.skipLink {
|
||||
position: fixed;
|
||||
z-index: 2000;
|
||||
top: 0.5rem;
|
||||
left: 0.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
color: #111;
|
||||
background: #fff;
|
||||
transform: translateY(-200%);
|
||||
.app { display: flex; min-height: 100vh; flex-direction: column; }
|
||||
.pageContent { flex: 1; padding: 0; }
|
||||
a { color: var(--site-link); text-underline-offset: .25em; }
|
||||
a:hover { color: var(--site-text); }
|
||||
h1, h2, h3 { color: var(--site-text); font-weight: 650; line-height: 1.15; letter-spacing: -.035em; }
|
||||
.container { max-width: 1160px; padding-inline: 28px; }
|
||||
.eyebrow { color: var(--site-link); font-size: .75rem; font-weight: 700; letter-spacing: .17em; text-transform: uppercase; }
|
||||
.routePlaceholder { padding-block: clamp(4rem, 10vw, 8rem); max-width: 850px; }
|
||||
.routePlaceholder h1 { font-size: clamp(2rem, 5vw, 3.5rem); }
|
||||
.routePlaceholder > p:not(.eyebrow) { color: var(--site-muted); max-width: 60ch; margin-block: 1.5rem; }
|
||||
.themeToggle {
|
||||
display: inline-grid; place-items: center; flex-shrink: 0;
|
||||
width: 44px; height: 44px; padding: 0;
|
||||
border: 1px solid var(--site-line); border-radius: 50%;
|
||||
background: var(--site-surface); color: var(--site-text); font-size: 1.15rem;
|
||||
}
|
||||
|
||||
.skipLink:focus {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 3px solid colors.$focus-ring;
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
@media (max-width: 575.98px) {
|
||||
main {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.themeToggle:hover { border-color: var(--site-link); color: var(--site-link); }
|
||||
.skipLink { position: fixed; z-index: 2000; top: .5rem; left: .5rem; padding: .75rem 1rem; color: #07151C; background: #26C6DA; transform: translateY(-200%); }
|
||||
.skipLink:focus { transform: translateY(0); }
|
||||
:focus-visible { outline: 3px solid var(--site-link); outline-offset: 4px; }
|
||||
.btn-primary { --bs-btn-bg: var(--site-cta); --bs-btn-border-color: var(--site-cta); --bs-btn-color: var(--site-cta-text); --bs-btn-hover-bg: var(--site-cta); --bs-btn-hover-border-color: var(--site-cta); --bs-btn-hover-color: var(--site-cta-text); --bs-btn-active-bg: var(--site-cta); --bs-btn-active-color: var(--site-cta-text); font-weight: 650; }
|
||||
@media (max-width: 767.98px) { .container { padding-inline: 22px; } }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
scroll-behavior: auto !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
animation-duration: 0.01ms !important;
|
||||
animation-iteration-count: 1 !important;
|
||||
}
|
||||
*, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/* BortStack — approved Logo Concept 2 brand palette (2026-11-03) */
|
||||
:root {
|
||||
--bs-charcoal: #0E1117;
|
||||
--bs-midnight: #0A1B2A;
|
||||
--bs-steel-blue: #3E6B86;
|
||||
--bs-cyan: #26C6DA;
|
||||
|
||||
/* Suggested semantic mappings for a dark-first website */
|
||||
--bs-background: var(--bs-charcoal);
|
||||
--bs-surface: var(--bs-midnight);
|
||||
--bs-muted-accent: var(--bs-steel-blue);
|
||||
--bs-accent: var(--bs-cyan);
|
||||
--bs-text: #F5F7FA; /* readability utility, not a fifth approved brand colour */
|
||||
}
|
||||
@@ -1,20 +1,14 @@
|
||||
$body-bg: #222222;
|
||||
$body-color: white;
|
||||
$primary: #f99c00;
|
||||
$secondary: #005e49;
|
||||
$danger: red;
|
||||
$surface-header: #343a40;
|
||||
$surface-footer: #343a40;
|
||||
$focus-ring: #ffb84d;
|
||||
|
||||
$theme-colors: (
|
||||
"grey-dark": #222222,
|
||||
"grey-light": #d6f0e3,
|
||||
"grey": #343a40,
|
||||
"orange": #f99c00,
|
||||
// Approved BortStack dark palette; semantic light colors are accessibility utilities.
|
||||
$body-bg: #0E1117;
|
||||
$body-color: #F5F7FA;
|
||||
$primary: #26C6DA;
|
||||
$secondary: #3E6B86;
|
||||
$danger: #d74756;
|
||||
$surface-header: #0A1B2A;
|
||||
$surface-footer: #0A1B2A;
|
||||
$focus-ring: #26C6DA;
|
||||
$theme-colors: (
|
||||
"primary": $primary,
|
||||
"secondary": $secondary,
|
||||
"danger": $danger,
|
||||
"header-bg": $surface-header,
|
||||
"footer-bg": $surface-footer
|
||||
"danger": $danger
|
||||
);
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
$danger: colors.$danger,
|
||||
$theme-colors: colors.$theme-colors
|
||||
);
|
||||
@use "./brand-tokens.css";
|
||||
@use "./app";
|
||||
|
||||
Reference in New Issue
Block a user