Skip to content

Commit

Permalink
issue-#1, #2 - Updated colors generation script to use simpler output…
Browse files Browse the repository at this point in the history
… css prop. names, library sources also updated to use these new names; E.g., '--x-theme-...' is now '--x-color...', '--x-{name}-hsl-...' is now '-x-{name}-color-...', and '--x-...-hsla-...' is now '--x-...-color-with-alpha-...'.
  • Loading branch information
elycruz committed Apr 28, 2023
1 parent 18a9b0f commit a62806c
Show file tree
Hide file tree
Showing 12 changed files with 484 additions and 563 deletions.
34 changes: 17 additions & 17 deletions css/base/html-body-base.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
html, body {
--x-font-family: Arial, Verdana, Helvetica, Sans-Serif;
--x-focus-ring-color: currentColor;

margin: 0;
padding: 0;
font: normal 1rem var(--x-font-family);
}

@media (prefers-color-scheme: dark) {
html, body {
--x-focus-ring-color: Field;

background: var(--x-neutral-hsl-1);
color: var(--x-neutral-hsl-5);
}
}
html, body {
--x-font-family: Arial, Verdana, Helvetica, Sans-Serif;
--x-focus-ring-color: currentColor;

margin: 0;
padding: 0;
font: normal 1rem var(--x-font-family);
}

@media (prefers-color-scheme: dark) {
html, body {
--x-focus-ring-color: Field;

background: var(--x-neutral-color-1);
color: var(--x-neutral-color-5);
}
}
758 changes: 337 additions & 421 deletions css/modules/colors/index.css

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions css/modules/material-design/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
* ------------------- */
:where(.x-button, .x-btn):not(.x-filled) {
background: transparent;
color: var(--x-theme-4);
color: var(--x-color-4);
}

/** Ripple styles **/
:where(.x-button, .x-btn):not(.x-filled) x-ripple::after,
:where(.x-button, .x-btn):not(.x-filled) x-ripple::before {
background: var(--x-theme-7);
background: var(--x-color-7);
}

/**
Expand Down Expand Up @@ -57,21 +57,21 @@
*/

:where(.x-button, .x-btn).x-filled {
background-color: var(--x-theme-4);
border-color: var(--x-theme-4);
background-color: var(--x-color-4);
border-color: var(--x-color-4);
color: var(--x-field);
}

:where(.x-button, .x-btn).x-filled:focus-visible {
--x-focus-ring-color: var(--x-theme-3);
--x-focus-ring-color: var(--x-color-3);

border-color: var(--x-theme-3);
border-color: var(--x-color-3);
}

:where(.x-button, .x-btn).x-outlined {
border-color: var(--x-theme-4);
border-color: var(--x-color-4);
}

:where(.x-button, .x-btn):where(.x-outlined, .x-raised):not(.x-filled):hover {
color: var(--x-theme-4);
color: var(--x-color-4);
}
2 changes: 1 addition & 1 deletion css/modules/material-design/checkbox.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.x-checkbox,
.x-radio {
--x-input-highlight-color: var(--x-theme-4, var(--x-neutral-hsl-4));
--x-input-highlight-color: var(--x-color-4, var(--x-neutral-color-4));
}

:where(.x-checkbox,
Expand Down
8 changes: 4 additions & 4 deletions css/modules/material-design/properties.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:root {
--x-input-border-width: var(--x-2px);
--x-input-border-color: var(--x-theme-4, var(--x-neutral-hsl-4));
}
:root {
--x-input-border-width: var(--x-2px);
--x-input-border-color: var(--x-color-4, var(--x-neutral-color-4));
}
32 changes: 16 additions & 16 deletions css/modules/properties.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
:root {
--x-highlight-color: var(--x-theme-5, var(--x-neutral-hsl-5));

--x-focus-ring-width: 0.09375rem; /*1.5px;*/
--x-focus-ring-color: currentColor;

--x-border-radius: var(--x-3px);
--x-border-width: var(--x-1px);

--x-input-speed: 0.13s;
--x-input-border-width: var(--x-1px);
--x-input-highlight-color: var(--x-highlight-color);
--x-input-text-color: FieldText /*ButtonText*/;
--x-input-bg-color: Field;
--x-input-border-color: ButtonBorder;
}
:root {
--x-highlight-color: var(--x-color-5, var(--x-neutral-color-5));

--x-focus-ring-width: 0.09375rem; /*1.5px;*/
--x-focus-ring-color: currentColor;

--x-border-radius: var(--x-3px);
--x-border-width: var(--x-1px);

--x-input-speed: 0.13s;
--x-input-border-width: var(--x-1px);
--x-input-highlight-color: var(--x-highlight-color);
--x-input-text-color: FieldText /*ButtonText*/;
--x-input-bg-color: Field;
--x-input-border-color: ButtonBorder;
}
173 changes: 89 additions & 84 deletions scripts/gen-css/colors.mjs
Original file line number Diff line number Diff line change
@@ -1,84 +1,89 @@
/**
* colors.js
*
* Outputs the library's css color properties - Colors are made up of `hsl`, and `hsla` generated colors.
*/
import fs from 'fs';
import * as path from "path";
import url from "url";
import {xThemes} from "../../constants.js";

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

const {log, error} = console,
primary = ['primary', 224],
secondary = ['secondary', 300],
success = ['success', 120],
info = ['info', 180],
warning = ['warning', 30],
danger = ['danger', 0],
neutral = ['neutral', 0],
fileName = 'index.css',

genColorsCss = (outputFilePath = path.join(__dirname, '../../css/modules/colors/', fileName)) => {
const lightnessNums = '.'.repeat(10)
.split('')
.map((_, i) => ((i + 1) * 10) - (i === 9 ? 1 : 0)),

themeColors = [
primary, secondary, success, info,
warning, danger, neutral
]
.flatMap(([c, cN], j) =>
lightnessNums.flatMap((lightness, i) => ([
` --x-${c}-hsl-${i + 1}: ` +
`hsl(${cN}, ${c === 'neutral' ? 0 : 72}%, ${lightness}%);`,
` --x-${c}-hsla-${i + 1}: ` +
`hsla(${cN}, ${c === 'neutral' ? 0 : 89}%, ${lightness}%, ${1 - ((lightness - 1) * .01)});`,
]))
).join('\n'),

themeVars = Object.keys(xThemes).reduce((agg, k, j) => {
const themeName = xThemes[k];

// @todo deprecate --x-theme-{\d} and --x-theme-hsla-{\d} in
// exchange for the '--x-theme-color-*'.
return agg + `
.x-theme-${themeName} {
${lightnessNums.flatMap((_, i) => ([
` --x-theme-${i + 1}: var(--x-${themeName}-hsl-${i + 1});`,
` --x-theme-color-${i + 1}: var(--x-${themeName}-hsl-${i + 1});`,
` --x-theme-hsla-${i + 1}: var(--x-${themeName}-hsla-${i + 1});`,
` --x-theme-color-hsla-${i + 1}: var(--x-${themeName}-hsla-${i + 1});`
]))
.join('\n')}
}\n`
}, '');

return fs.promises.writeFile(outputFilePath, `/**
* colors.css
*
* The library's base colors (tentative).
*/
:root {
${themeColors}
--x-field: Field;
}
@media (prefers-color-scheme: dark) {
:root {
--x-field: var(--x-neutral-hsl-1);
}
}
${themeVars.trim()}
`)
.then(
() => log(`file ${fileName} written successfully`),
error
);
};

export {genColorsCss};
/**
* colors.js
*
* Outputs the library's css color properties - Colors are made up of `hsl`, and `hsla` generated colors.
*/
import fs from 'fs';
import * as path from "path";
import url from "url";
import {xThemes} from "../../constants.js";

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

const {log, error} = console,
primary = ['primary', 256, 72],
secondary = ['secondary', 300, 72],
success = ['success', 120, 72],
info = ['info', 180, 72],
warning = ['warning', 30, 72],
danger = ['danger', 0, 72],
neutral = ['neutral', 0, 0],
fileName = 'index.css',

genColorsCss = (outputFilePath = path.join(__dirname, '../../css/modules/colors/', fileName)) => {
const lightnessNums = new Array(9)
.fill(null, 0, 9)
.map((_, i) => ((i + 1) * 10) - (i === 9 ? 1 : 0))
.concat([95, 99, 100]),

themeColors = [
primary, secondary, success, info,
warning, danger, neutral
]
.flatMap(([name, degree, saturation], j) =>
lightnessNums.flatMap((lightness, i) => {
const alpha = 1 - ((lightness - 1) * .01);

return [
` --x-${name}-color-${i + 1}: ` +
`hsl(${degree}, ${saturation}%, ${lightness}%);`,
` --x-${name}-color-with-alpha-${i + 1}: ` +
`hsla(${degree}, ${saturation}%, ${lightness}%, ${alpha});`,
];
})
).join('\n'),

themeVars = Object.keys(xThemes).reduce((agg, k, j) => {
const themeName = xThemes[k];

// @todo deprecate --x-theme-{\d} and --x-theme-hsla-{\d} in
// exchange for the '--x-theme-color-*'.
return agg + `
.x-theme-${themeName} {
${lightnessNums.flatMap((lightness, i) => {
return [
` --x-color-${i + 1}: var(--x-${themeName}-color-${i + 1});`,
` --x-color-with-alpha-${i + 1}: var(--x-${themeName}-color-with-alpha-${i + 1});`,
];
})
.join('\n')}
}\n`
}, '');

return fs.promises.writeFile(outputFilePath, `/**
* colors.css
*
* The library's base colors (tentative).
*/
:root {
${themeColors}
--x-field: Field;
}
@media (prefers-color-scheme: dark) {
:root {
--x-field: var(--x-neutral-hsl-1);
}
}
${themeVars.trim()}
`)
.then(
() => log(`file ${fileName} written successfully`),
error
);
};

export {genColorsCss};
10 changes: 5 additions & 5 deletions stories/colors.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<style>
.x-color-grid th {
padding: 0.5rem;
background: var(--x-neutral-hsl-8);
background: var(--x-neutral-color-8);
}

.x-color-grid tbody td {
Expand Down Expand Up @@ -51,8 +51,8 @@
<tbody>
${themeRange.map((_, i) => html`
<tr>${themes.map(k => html`
<td style="background: var(--x-${k}-hsl-${i + 1});"
title="--x-${k}-hsl-${i + 1}">&nbsp;
<td style="background: var(--x-${k}-color-${i + 1});"
title="--x-${k}-color-${i + 1}">&nbsp;
</td>
`)}
</tr>
Expand All @@ -72,8 +72,8 @@
<tbody>
${themeRange.map((_, i) => html`
<tr>${themes.map(k => html`
<td style="background: var(--x-${k}-hsla-${i + 1});"
title="--x-${k}-hsla-${i + 1}">&nbsp;
<td style="background: var(--x-${k}-color-with-alpha-${i + 1});"
title="--x-${k}-color-with-alpha-${i + 1}">&nbsp;
</td>
`)}
</tr>
Expand Down
4 changes: 2 additions & 2 deletions stories/css/index.stories.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ body > div > nav {

body > .x-app-footer {
grid-area: app-footer;
border-top: var(--x-border-width) solid var(--x-neutral-hsl-4);
border-top: var(--x-border-width) solid var(--x-neutral-color-4);
}

body > .x-app-content > main iframe {
border: none;
}

body > .x-app-content > main > div {
border-left: 1px solid var(--x-neutral-hsl-4);
border-left: 1px solid var(--x-neutral-color-4);
}

body > .x-app-content > .x-app-nav {
Expand Down
4 changes: 2 additions & 2 deletions stories/spacing.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<style>
.box {
display: inline-block;
background: var(--x-warning-hsl-5);
border: var(--x-2px) solid var(--x-warning-hsl-1);
background: var(--x-warning-color-5);
border: var(--x-2px) solid var(--x-warning-color-1);
margin: var(--x-13px);
}
</style>
Expand Down
2 changes: 1 addition & 1 deletion x-field/x-field.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}

:host .error-message {
color: var(--x-danger-hsl-5);
color: var(--x-danger-color-5);
margin-top: 0.5rem;
}

Expand Down
4 changes: 2 additions & 2 deletions x-ripple/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ x-ripple {
}

x-ripple:not(:empty):hover {
background: var(--x-theme-hsla-9);
background: var(--x-color-with-alpha-9);
}

x-ripple:empty {
Expand Down Expand Up @@ -89,7 +89,7 @@ x-ripple::before {
content: "";
top: 50%;
left: 50%;
background: var(--x-theme-5);
background: var(--x-color-5);
pointer-events: none;
transform-origin: center;
transition: opacity var(--x-ripple-speed),
Expand Down

0 comments on commit a62806c

Please sign in to comment.