mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 01:49:41 -05:00
Eight themes (nephritis, pumpkin, moderatepink, strongcyan, limegreen, relax, corteza, modern) had white text on an accent at 2.1 to 4.3:1: their accents and hover, selected and emphasis shades are darkened until it reads at 4.5:1. The filter sidebar's headings, the clear themes' quiet text and cleanlight's add-dependency link are darker. A color a member chooses is made legible: a custom theme accent or slide end is darkened under the header's white text, the text color is moved to read on the theme's surfaces and no longer reaches the header, labels and primary buttons, a dependency line is drawn at 3:1, Kanri's tag text is the better of dark and light, and a custom label, card, list or swimlane color already derives its text. All 25 themes show no colour contrast failure on the board, the sidebars, Card Settings, the card and its popups. Thanks to Samunosuke and xet7 !
133 lines
5.8 KiB
JavaScript
133 lines
5.8 KiB
JavaScript
import { readableAccent } from './contrastColor.js';
|
|
|
|
// The accent colour of every named theme — the colour that theme paints its header
|
|
// bar with (docs/Features/General/Theme/Change-Color.md).
|
|
//
|
|
// WeKan's chrome outside a board reads ONE CSS variable, `--theme-accent`: the
|
|
// Admin Panel's selected left-menu row, its buttons, every Save button, the table
|
|
// page's controls. Until now that variable was only set when a user picked a CUSTOM
|
|
// colour for a flat/clear theme, so choosing a named theme like Pumpkin recoloured
|
|
// the header (which has its own `.board-color-pumpkin#header` rule) and left the
|
|
// menu row and the buttons on the stock blue fallback.
|
|
//
|
|
// This map closes that gap: whatever theme is active - the user's own override, a
|
|
// board's colour, or the site theme - its accent is published as `--theme-accent`,
|
|
// and everything that already reads the variable follows along.
|
|
//
|
|
// The values MIRROR client/components/boards/boardColors.css: each is the
|
|
// `background-color` of that theme's `#header` rule. tests/themeAccents.test.cjs
|
|
// parses that stylesheet and fails if the two ever disagree, so a new theme cannot
|
|
// be added in CSS alone and quietly fall back to blue.
|
|
const THEME_ACCENTS = {
|
|
belize: '#2573a7',
|
|
nephritis: '#217d49',
|
|
pomegranate: '#c0392b',
|
|
pumpkin: '#a75919',
|
|
wisteria: '#8e44ad',
|
|
moderatepink: '#bd3a79',
|
|
strongcyan: '#00798d',
|
|
limegreen: '#277c48',
|
|
midnight: '#2c3e50',
|
|
dark: '#2c3e51',
|
|
relax: '#217d4a',
|
|
corteza: '#4a738a',
|
|
appleglasspastel: '#2563eb',
|
|
// The MAIN header bar's colour. It read #2d8ce7 - the quick-access bar's
|
|
// separate, lighter shade - because the guard that derives these matched
|
|
// `#header-quick-access` as well as `#header`. The two bars are one colour
|
|
// now, and it is this one.
|
|
clearblue: '#00798d',
|
|
// The other colour slides. Each publishes the BOTTOM of its own slide, the
|
|
// way clearblue publishes #00798d: a variable holds a colour and a gradient
|
|
// is not one, so what everything outside a board reads is the solid end.
|
|
cleargreen: '#277c48',
|
|
clearorange: '#a75919',
|
|
clearpink: '#bd3a79',
|
|
clearpurple: '#8e44ad',
|
|
clearred: '#c0392b',
|
|
natural: '#596557',
|
|
modern: '#2372a4',
|
|
moderndark: '#2a2a2a',
|
|
exodark: '#222',
|
|
cleandark: '#2E2E39',
|
|
cleanlight: 'rgba(190, 190, 190, 1)',
|
|
};
|
|
|
|
// The accent of one theme, or '' when the name is unknown (which is what an
|
|
// unthemed instance and a bad value both look like).
|
|
function accentOf(color) {
|
|
// hasOwnProperty, not a plain lookup: `THEME_ACCENTS['constructor']` answers
|
|
// with Object's constructor, and 'toString' with a function - so a board whose
|
|
// colour is named after any Object.prototype member would have got a FUNCTION
|
|
// as its accent and written it into a stylesheet. Only the map's own keys are
|
|
// themes.
|
|
if (typeof color !== 'string') return '';
|
|
return Object.prototype.hasOwnProperty.call(THEME_ACCENTS, color)
|
|
? THEME_ACCENTS[color] || ''
|
|
: '';
|
|
}
|
|
|
|
// The accent to publish as `--theme-accent`, given the active theme and whatever
|
|
// custom colours go with it. A custom colour ALWAYS wins: it is the one the user
|
|
// chose on top of the theme.
|
|
//
|
|
// A custom colour is drawn under white text, so it is made readable first
|
|
// (readableAccent: the same hue, darkened until white and the header's #f2f2f2
|
|
// labels are at WCAG AA, 4.5:1). A colour that is not a hex is passed through as
|
|
// it was, and a colour that already reads is not touched.
|
|
function activeAccent(color, customColors) {
|
|
const custom = Array.isArray(customColors) ? customColors : [];
|
|
if (typeof custom[0] === 'string' && custom[0]) return readableAccent(custom[0]);
|
|
return accentOf(color);
|
|
}
|
|
|
|
// The two ends of each colour-slide theme, top first.
|
|
//
|
|
// `--theme-accent` is ONE colour and a gradient is not one, so a slide theme's
|
|
// buttons came out flat while its header slid. This is the other half of the
|
|
// answer: the pair, from which a `background` value can be built.
|
|
//
|
|
// Only the `clear` category has one. Everything else is a flat colour and its
|
|
// fill IS its accent. MIRRORS boardColors.css, and a guard fails if they ever
|
|
// disagree - the same arrangement THEME_ACCENTS has.
|
|
const THEME_SLIDES = {
|
|
clearblue: ['#499bea', '#00798d'],
|
|
cleargreen: ['#8ad59f', '#277c48'],
|
|
clearorange: ['#efab6f', '#a75919'],
|
|
clearpink: ['#df94b8', '#bd3a79'],
|
|
clearpurple: ['#b685ca', '#8e44ad'],
|
|
clearred: ['#d67e75', '#c0392b'],
|
|
};
|
|
|
|
// The slide of a theme, or null when it is a flat one.
|
|
function slideOf(color) {
|
|
const ends = THEME_SLIDES[color];
|
|
return ends ? ends.slice() : null;
|
|
}
|
|
|
|
// What to paint a themed CONTROL with: a full CSS `background` value rather
|
|
// than a colour, so a slide theme's buttons slide like its header.
|
|
//
|
|
// A custom pair wins over the theme's own, the same way a custom colour wins
|
|
// over its accent - a user who chose two colours chose a slide. One custom
|
|
// colour, or a flat theme, answers with that solid colour.
|
|
//
|
|
// An unknown theme answers `''`, which is what accentOf() answers - not null.
|
|
// Either is falsy and the caller's `if (fill)` treats them alike, but the two
|
|
// functions sit beside each other and should not need a reader to remember
|
|
// which one returns which kind of nothing.
|
|
function activeFill(color, customColors) {
|
|
const custom = Array.isArray(customColors) ? customColors : [];
|
|
const [c1, c2] = custom;
|
|
// Text sits across the whole slide, so BOTH ends are made readable.
|
|
if (typeof c1 === 'string' && c1 && typeof c2 === 'string' && c2) {
|
|
return `linear-gradient(180deg, ${readableAccent(c1)} 0%, ${readableAccent(c2)} 100%)`;
|
|
}
|
|
if (typeof c1 === 'string' && c1) return readableAccent(c1);
|
|
const ends = slideOf(color);
|
|
if (ends) return `linear-gradient(180deg, ${ends[0]} 0%, ${ends[1]} 100%)`;
|
|
return accentOf(color);
|
|
}
|
|
|
|
export { THEME_ACCENTS, THEME_SLIDES, accentOf, activeAccent, slideOf, activeFill };
|