Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Admin UI - Colors and Theming #4474

Merged
merged 44 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
271ef26
wip
adrians5j Jan 6, 2025
589e361
wip
adrians5j Jan 6, 2025
8d0be67
wip
adrians5j Jan 7, 2025
e47ed45
wip
adrians5j Jan 7, 2025
bbe79f1
Merge branch 'refs/heads/feat/new-admin-ui-merge-next-2025-01-07' int…
adrians5j Jan 7, 2025
c6ede83
wip
adrians5j Jan 9, 2025
3bd04d3
wip
adrians5j Jan 9, 2025
1badf9a
wip
adrians5j Jan 10, 2025
df38086
wip
adrians5j Jan 10, 2025
32f6a80
wip
adrians5j Jan 10, 2025
badee33
wip
adrians5j Jan 13, 2025
7925b35
wip
adrians5j Jan 13, 2025
8de20fa
wip
adrians5j Jan 13, 2025
e6ae1de
wip: add Plugin wrapper
Pavel910 Jan 13, 2025
563d36c
wip: use state initializer instead of useMemo
Pavel910 Jan 13, 2025
c486c84
fix(app-tenant-manager): remove obsolete mounting checks
Pavel910 Jan 13, 2025
afb2d25
wip: switch primary color based on tenant
Pavel910 Jan 13, 2025
828929d
wip: remove spinners
adrians5j Jan 14, 2025
5e6ae16
Merge remote-tracking branch 'refs/remotes/origin/feat/new-admin-ui' …
adrians5j Jan 15, 2025
fa62360
wip
adrians5j Jan 15, 2025
84bb616
wip
adrians5j Jan 15, 2025
21656d0
wip
adrians5j Jan 15, 2025
d138231
wip
adrians5j Jan 15, 2025
db83d76
wip
adrians5j Jan 15, 2025
2bb2b1b
wip
adrians5j Jan 15, 2025
239dd56
wip
adrians5j Jan 16, 2025
baabbde
wip
adrians5j Jan 16, 2025
bff22d2
wip
adrians5j Jan 16, 2025
43fbaba
wip
adrians5j Jan 16, 2025
fbc9ad4
wip
adrians5j Jan 16, 2025
6379d5a
wip
adrians5j Jan 16, 2025
8da8031
wip
adrians5j Jan 17, 2025
39ec430
wip
adrians5j Jan 17, 2025
121af3c
wip
adrians5j Jan 17, 2025
535af73
wip
adrians5j Jan 17, 2025
65ef5e9
wip
adrians5j Jan 17, 2025
b8d55fd
wip
adrians5j Jan 17, 2025
7922bd9
wip
adrians5j Jan 17, 2025
360a4a7
wip
adrians5j Jan 17, 2025
9bb7a9c
wip
adrians5j Jan 17, 2025
83f8d73
wip
adrians5j Jan 17, 2025
d2aba53
wip
adrians5j Jan 20, 2025
b8cc524
wip
adrians5j Jan 20, 2025
ae271ee
Merge remote-tracking branch 'refs/remotes/origin/feat/new-admin-ui' …
adrians5j Jan 21, 2025
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
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,5 @@ lerna.json
.stormTests
*storybook.log
.normalizedFigmaExport.json

# TODO remove after moving traffic splitting config to WPC
gateway.*.json

.normalizedPrimitivesFigmaExport.json
packages/tasks/tpl/*
13 changes: 10 additions & 3 deletions packages/admin-ui/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ One of the main things we define via the [`tailwind.config.js`](./tailwind.confi
But, do note that all the default theme-values are not actually defined in the `tailwind.config.js` file, but rather in the `tailwind.config.theme.js` file, which is a file that is generated from a Figma export (more on this in the next section).

### Figma To Code
Since manually transferring values from the mentioned Figma file into code has shown to be a very cumbersome process, we've created a script that basically takes a Figma export and generates all the necessary Tailwind CSS configuration. Note that when we say "Figma export", we basically mean an export of Alias tokens, created by this [Export/Import Variables](https://www.figma.com/community/plugin/1256972111705530093/export-import-variables) plugin.
Since manually transferring values from the mentioned Figma file into code has shown to be a very cumbersome process, we've created a script that basically takes a Figma export and generates all the necessary Tailwind CSS configuration.

Once the export is downloaded, we place it in `packages/admin-ui/scripts/importFromFigma/exports/Alias tokens.json`, and then we run the following command from project root:
When we say "Figma export", we basically mean exports of (1) Primitives and (2) Alias tokens, which are created by this [Export/Import Variables](https://www.figma.com/community/plugin/1256972111705530093/export-import-variables) plugin.

The exports need to be downloaded and place into the `packages/admin-ui/scripts/importFromFigma/exports` folder. Ultimately, we should end up with the following two:

1. `packages/admin-ui/scripts/importFromFigma/exports/Alias tokens.json`
2. `packages/admin-ui/scripts/importFromFigma/exports/Primitives.json`

Finally, from project root, we run the following script:

```bash
yarn webiny-admin-import-from-figma
```

This will generate a new `tailwind.config.theme.js` file, which will contain all the necessary Tailwind CSS configuration. On top of that, it will also generate a `src/styles.scss` file, which contains actual values for CSS variables that are referenced in the `tailwind.config.theme.js` file.
First, the script will regenerate the `tailwind.config.theme.js` file, which will contain all the necessary Tailwind CSS configuration. Second, it will also regenerate the `src/styles.scss` file, which contains actual values for CSS variables that are referenced in the `tailwind.config.theme.js` file.
1 change: 0 additions & 1 deletion packages/admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"rimraf": "^5.0.5",
"sass": "1.44.0",
"storybook": "7.6.20",
"tailwindcss": "^3.4.6",
"ttypescript": "^1.5.12",
"typescript": "4.9.5"
},
Expand Down
18 changes: 15 additions & 3 deletions packages/admin-ui/scripts/importFromFigma.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const fs = require("fs");
const { green } = require("chalk");
const path = require("path");
const aliasTokensExport = require("./importFromFigma/exports/Alias tokens.json");
const { normalizeFigmaExport } = require("./importFromFigma/normalizeFigmaExport");
const {
normalizePrimitivesFigmaExport
} = require("./importFromFigma/normalizePrimitivesFigmaExport");
const { createTailwindConfigTheme } = require("./importFromFigma/createTailwindConfigTheme");
const { createThemeScss } = require("./importFromFigma/createThemeScss");
const { formatCode } = require("./importFromFigma/formatCode");
Expand All @@ -13,13 +15,18 @@ const saveFileAndFormat = async (filePath, content) => {
};

(async () => {
const normalizedFigmaExport = normalizeFigmaExport(aliasTokensExport);
const normalizedFigmaExport = normalizeFigmaExport();
const normalizedPrimitivesFigmaExport = normalizePrimitivesFigmaExport();
const tailwindConfigTheme = createTailwindConfigTheme(normalizedFigmaExport);
const stylesScss = createThemeScss(normalizedFigmaExport, tailwindConfigTheme);
const stylesScss = createThemeScss(normalizedFigmaExport, normalizedPrimitivesFigmaExport);

const paths = {
cwd: process.cwd(),
normalizedFigmaExport: path.join(__dirname, "../.normalizedFigmaExport.json"),
normalizedPrimitivesFigmaExport: path.join(
__dirname,
"../.normalizedPrimitivesFigmaExport.json"
),
createTailwindConfigTheme: path.join(__dirname, "../tailwind.config.theme.js"),
stylesScss: path.join(__dirname, "../src/theme.scss")
};
Expand All @@ -42,6 +49,11 @@ const saveFileAndFormat = async (filePath, content) => {
JSON.stringify(normalizedFigmaExport, null, 2)
);

await saveFileAndFormat(
paths.normalizedPrimitivesFigmaExport,
JSON.stringify(normalizedPrimitivesFigmaExport, null, 2)
);

await saveFileAndFormat(
paths.createTailwindConfigTheme,
`module.exports = ${JSON.stringify(tailwindConfigTheme, null, 2)};`
Expand Down
54 changes: 48 additions & 6 deletions packages/admin-ui/scripts/importFromFigma/createThemeScss.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
const fs = require("fs");

const createThemeScss = normalizedFigmaExport => {
// We don't need tokens that end with `-a{one or two numbers}` because they are used for
// alpha colors. We don't need these because we can use the /alpha function in Tailwind CSS.
const isColorWithAlpha = variantName => {
return variantName.match(/^.*-a\d{1,2}$/);
};

const createThemeScss = (normalizedFigmaExport, normalizedPrimitivesFigmaExport) => {
// Generate `theme.scss` file.
let stylesScss = fs.readFileSync(__dirname + "/templates/theme.scss.txt", "utf8");

// 0. Colors
{
let currentBgColorGroup = null;
const bgColors = normalizedPrimitivesFigmaExport
.filter(item => item.type === "colors")
.map(variable => {
const [colorGroup] = variable.variantName.split("-");
const cssVar = `--color-${variable.variantName}: ${variable.hsla.h} ${variable.hsla.s}% ${variable.hsla.l}%;`;

if (!currentBgColorGroup) {
currentBgColorGroup = colorGroup;
return cssVar;
}

if (!currentBgColorGroup || currentBgColorGroup !== colorGroup) {
currentBgColorGroup = colorGroup;
return ["", cssVar];
}
return cssVar;
})
.flat()
.reverse();

stylesScss = stylesScss.replace("{COLORS}", bgColors.join("\n"));
}

// 1. Background color.
{
let currentBgColorGroup = null;
const bgColors = normalizedFigmaExport
.filter(item => item.type === "backgroundColor")
.filter(variable => !isColorWithAlpha(variable.variantName))
.map(variable => {
const [colorGroup] = variable.variantName.split("-");
const cssVar = `--bg-${variable.variantName}: ${variable.hsla.h} ${variable.hsla.s}% ${variable.hsla.l}%;`;
const cssVarName = variable.aliasName.replace("colors/colors-", "color-");
const cssVar = `--bg-${variable.variantName}: var(--${cssVarName});`;

if (!currentBgColorGroup) {
currentBgColorGroup = colorGroup;
Expand All @@ -34,9 +68,11 @@ const createThemeScss = normalizedFigmaExport => {
let currentBorderColor = null;
const borderColors = normalizedFigmaExport
.filter(item => item.type === "borderColor")
.filter(variable => !isColorWithAlpha(variable.variantName))
.map(variable => {
const [colorGroup] = variable.variantName.split("-");
const cssVar = `--border-${variable.variantName}: ${variable.hsla.h} ${variable.hsla.s}% ${variable.hsla.l}%;`;
const cssVarName = variable.aliasName.replace("colors/colors-", "color-");
const cssVar = `--border-${variable.variantName}: var(--${cssVarName});`;

if (!currentBorderColor) {
currentBorderColor = colorGroup;
Expand Down Expand Up @@ -81,9 +117,11 @@ const createThemeScss = normalizedFigmaExport => {
let currentFillColorGroup = null;
const fillColors = normalizedFigmaExport
.filter(item => item.type === "fill")
.filter(variable => !isColorWithAlpha(variable.variantName))
.map(variable => {
const [colorGroup] = variable.variantName.split("-");
const cssVar = `--fill-${variable.variantName}: ${variable.hsla.h} ${variable.hsla.s}% ${variable.hsla.l}%;`;
const cssVarName = variable.aliasName.replace("colors/colors-", "color-");
const cssVar = `--fill-${variable.variantName}: var(--${cssVarName});`;

if (!currentFillColorGroup) {
currentFillColorGroup = colorGroup;
Expand Down Expand Up @@ -139,9 +177,11 @@ const createThemeScss = normalizedFigmaExport => {
let currentRingColorGroup = null;
const ringColors = normalizedFigmaExport
.filter(item => item.type === "ringColor")
.filter(variable => !isColorWithAlpha(variable.variantName))
.map(variable => {
const [colorGroup] = variable.variantName.split("-");
const cssVar = `--ring-${variable.variantName}: ${variable.hsla.h} ${variable.hsla.s}% ${variable.hsla.l}%;`;
const cssVarName = variable.aliasName.replace("colors/colors-", "color-");
const cssVar = `--ring-${variable.variantName}: var(--${cssVarName});`;

if (!currentRingColorGroup) {
currentRingColorGroup = colorGroup;
Expand Down Expand Up @@ -191,9 +231,11 @@ const createThemeScss = normalizedFigmaExport => {
let currentTextColor = null;
const textColors = normalizedFigmaExport
.filter(item => item.type === "textColor")
.filter(variable => !isColorWithAlpha(variable.variantName))
.map(variable => {
const [colorGroup] = variable.variantName.split("-");
const cssVar = `--text-${variable.variantName}: ${variable.hsla.h} ${variable.hsla.s}% ${variable.hsla.l}%;`;
const cssVarName = variable.aliasName.replace("colors/colors-", "color-");
const cssVar = `--text-${variable.variantName}: var(--${cssVarName});`;

if (!currentTextColor) {
currentTextColor = colorGroup;
Expand Down

Large diffs are not rendered by default.

Loading
Loading