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

refactor(themes): use igniteui-theming package when generating themes #454

Merged
merged 45 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4b7d249
refactor(themes): use theming package for global themes
simeonoff Jul 27, 2022
359b976
refactor(themes): replace type-category with type-style
simeonoff Jul 27, 2022
f3bcae2
refactor(themes): revert color usage
simeonoff Jul 27, 2022
85b6e1f
build(styles): use compile function for scss files
simeonoff Jul 27, 2022
6ccacd3
refactor(themes): remove utils
simeonoff Jul 27, 2022
c64b277
build(themes): use compile to build scss files
simeonoff Jul 27, 2022
13ff1c7
build(styles): refactor build and watcher
simeonoff Jul 27, 2022
b24983a
npm(package.json): update styles watcher script
simeonoff Jul 27, 2022
a4a8a9e
Merge branch 'master' into igniteui-theming
simeonoff Jul 27, 2022
cc4af85
refactor(themes): optimize imports
simeonoff Jul 28, 2022
2c2c5dc
refactor(themes): update components themes from accordion to dropdown…
didimmova Jul 28, 2022
ae36c14
refactor(themes): forward all igniteui-theming modules
simeonoff Jul 28, 2022
9b3f223
refactor(*): update prefix (#457)
SisIvanova Jul 28, 2022
60e9edc
refactor(watchers): do not rebuild stories on CSS changes
simeonoff Jul 28, 2022
4b7dbb6
deps(theming): bump to beta 5
simeonoff Jul 28, 2022
ee08e69
update theme vars for typography and elevations (#458)
desig9stein Jul 28, 2022
17efcb1
Merge branch 'master' into igniteui-theming
simeonoff Jul 28, 2022
8160813
deps(theming): bump version
simeonoff Aug 1, 2022
bd1198a
Merge branch 'master' into igniteui-theming
simeonoff Aug 15, 2022
8c84aea
npm(igniteui-theming): bump to latest beta
simeonoff Aug 16, 2022
766b19e
Merge branch 'master' into igniteui-theming
simeonoff Aug 16, 2022
89f3b38
npm(theming): bump version
simeonoff Aug 17, 2022
5ec91de
Merge branch 'master' into igniteui-theming
simeonoff Aug 17, 2022
cea3ec3
Merge branch 'master' into igniteui-theming
simeonoff Aug 19, 2022
f25f0dc
npm(theming): bump version
simeonoff Aug 19, 2022
04b8ac3
npm(theming): bump to latest version
simeonoff Aug 25, 2022
875e4b2
Merge branch 'master' into igniteui-theming
simeonoff Aug 30, 2022
db626db
refactor(select): replace type-category with type-style
simeonoff Aug 30, 2022
2ef54ec
npm(theming): bump version
simeonoff Aug 30, 2022
5723579
feat(themes): add grid dark themes
simeonoff Aug 31, 2022
12e401f
refactor(themes): remove grid dg prefix
simeonoff Aug 31, 2022
d85954f
Merge branch 'master' into igniteui-theming
simeonoff Sep 13, 2022
995eb24
npm(theming): bump to latest beta
simeonoff Sep 13, 2022
9bf1f72
refactor(dialog): migrate to theming package typography mixins
simeonoff Sep 13, 2022
3d122c4
Merge branch 'master' into igniteui-theming
simeonoff Sep 16, 2022
c880d21
Merge branch 'master' into igniteui-theming
simeonoff Sep 28, 2022
07eb026
refactor(themes): size component using CSS vars (#484)
simeonoff Sep 29, 2022
a00b242
Merge branch 'master' into igniteui-theming
simeonoff Sep 29, 2022
853a126
lint(styles): fix errors
simeonoff Sep 29, 2022
ec8e354
refactor(themes): update dark grid selector
simeonoff Oct 3, 2022
8ed4830
Merge branch 'master' into igniteui-theming
simeonoff Oct 10, 2022
59bdfed
build(theming): bump version
simeonoff Oct 11, 2022
ef1fab8
refactor(scrollbar): class igc-scrollbar to ig-scrollbar
simeonoff Oct 11, 2022
c83001f
refactor(themes): rename igc-theme to ig-theme
simeonoff Oct 13, 2022
1125e81
refactor(themes): rename igc-scrollbar to ig-scrollbar
simeonoff Oct 13, 2022
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
21 changes: 21 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ export const globalTypes = {
showName: 'True',
},
},
size: {
name: 'Size',
description: 'Component size',
defaultValue: 'attribute',
toolbar: {
icon: 'grow',
items: ['attribute', 'small', 'medium', 'large'],
showName: 'True',
},
}
};

export const parameters = {
Expand All @@ -65,6 +75,16 @@ const getTheme = (themeName, variant) => {
return Themes[`${themeName}_${variant}`];
};

const getSize = (size) => {
if(size === 'attribute') {
return;
}

return `:root {
--ig-size: var(--ig-size-${size});
}`;
};

const themeProvider = (Story, context) => {
const theme = getTheme(context.globals.theme, context.globals.variant);

Expand All @@ -75,6 +95,7 @@ const themeProvider = (Story, context) => {
const styles = htmlNoMin`
<style>
${theme.default}
${getSize(context.globals.size)}
</style>`;

return html` ${styles} ${Story()} `;
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"build:docs:vscode-schema": "web-component-analyzer src --format vscode --outFile vscode-html-custom-data.json",
"build:meta": "node scripts/build-stories.js",
"watch-meta": "node scripts/stories-watcher.js ",
"watch-scss": "node scripts/styles-watcher.js",
"watch-scss": "node scripts/styles-watcher.mjs",
"watch-ts": "tsc --watch --preserveWatchOutput",
"check": "madge --circular --warning --no-spinner dist/src/index.js",
"clean": "npm run clean:dist && npm run clean:styles && npm run clean:docs",
Expand Down Expand Up @@ -74,6 +74,7 @@
"eslint-config-prettier": "^8.5.0",
"globby": "^13.1.2",
"husky": "^8.0.1",
"igniteui-theming": "^1.0.0-release",
"igniteui-typedoc-theme": "^3.1.0",
"keep-a-changelog": "^2.1.0",
"lint-staged": "^13.0.3",
Expand Down
39 changes: 3 additions & 36 deletions scripts/build-styles.mjs
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
import path from 'path';
import { promisify } from 'util';
import { readFile, writeFile } from 'fs/promises';
import { globby } from 'globby';
import sass from 'sass';
import autoprefixer from 'autoprefixer';
import postcss from 'postcss';
import report from './report.js';

const renderSass = promisify(sass.render);

async function sassToCss(sassFile) {
const result = await renderSass({
file: sassFile,
outputStyle: 'compressed',
});

let cssStr = result.css.toString();

cssStr = await postcss([autoprefixer]).process(cssStr).css;

// Strip BOM if any
if (cssStr.charCodeAt(0) === 0xfeff) {
cssStr = cssStr.substring(1);
}
return cssStr;
}

async function sassRender(sourceFile, templateFile, outputFile) {
const regex = /<%\s*content\s*%>/;
const template = await readFile(templateFile, 'utf-8');
const replacement = await sassToCss(sourceFile);
const newContent = template.replace(regex, replacement);

return writeFile(outputFile, newContent, 'utf-8');
}
import { sassRender, template } from './sass.mjs';

(async () => {
const template = path.resolve(process.argv[1], '../styles.tmpl');
const startTime = new Date();
const paths = await globby([
'src/components/**/*.base.scss',
'src/components/**/*.material.scss',
Expand All @@ -52,5 +19,5 @@ async function sassRender(sourceFile, templateFile, outputFile) {
process.exit(-1);
});
}
report.success('Styles generation finished');
report.success(`Styles generated in ${Math.round((Date.now() - startTime) / 1000)}s`);
})();
17 changes: 8 additions & 9 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import path from 'path';
import autoprefixer from 'autoprefixer';
import { exec as _exec } from 'child_process';
import { mkdirSync as makeDir } from 'fs';
import { copyFile, writeFile } from 'fs/promises';
import { exec as _exec } from 'child_process';
import { promisify } from 'util';
import { fileURLToPath } from 'url';
import { globby } from 'globby';
import sass from 'sass';
import path from 'path';
import postcss from 'postcss';
import autoprefixer from 'autoprefixer';
import sass from 'sass';
import { fileURLToPath } from 'url';
import { promisify } from 'util';

const exec = promisify(_exec);
const renderSass = promisify(sass.render);
const renderSass = sass.compile;
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const DEST_DIR = path.join.bind(null, path.resolve(__dirname, '../dist'));
Expand All @@ -20,8 +20,7 @@ async function buildThemes() {
const paths = await globby(`${THEMES_PATH}/{light,dark}/*.scss`);

for (const sassFile of paths) {
const result = await renderSass({
file: sassFile,
const result = renderSass(sassFile, {
outputStyle: 'compressed',
});

Expand Down
32 changes: 32 additions & 0 deletions scripts/sass.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import autoprefixer from 'autoprefixer';
import { readFile, writeFile } from 'fs/promises';
import path from 'path';
import postcss from 'postcss';
import sass from 'sass';

export const template = path.resolve(process.argv[1], '../styles.tmpl');
const renderSass = sass.compile;

async function sassToCss(sassFile) {
const result = renderSass(sassFile, {
outputStyle: 'compressed'
});

let cssStr = result.css.toString();
cssStr = await postcss([autoprefixer]).process(cssStr).css;

// Strip BOM if any
if (cssStr.charCodeAt(0) === 0xfeff) {
cssStr = cssStr.substring(1);
}
return cssStr;
}

export async function sassRender(sourceFile, templateFile, outputFile) {
const regex = /<%\s*content\s*%>/;
const template = await readFile(templateFile, 'utf-8');
const replacement = await sassToCss(sourceFile);
const newContent = template.replace(regex, replacement);

return writeFile(outputFile, newContent, 'utf-8');
}
2 changes: 1 addition & 1 deletion scripts/stories-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const exec = promisify(require('child_process').exec);
const watchOptions = {
recursive: true,
filter: (path) => {
return /^((?!\.spec\.).)*\.ts$/.test(path);
return /^((?!\.spec|.css\.).)*\.ts$/.test(path);
},
};

Expand Down
38 changes: 0 additions & 38 deletions scripts/styles-watcher.js

This file was deleted.

34 changes: 34 additions & 0 deletions scripts/styles-watcher.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import watch from 'node-watch';
import report from './report.js';
import { sassRender, template } from './sass.mjs';

const watchOptions = {
recursive: true,
filter: (path) => {
return /.(?:scss)$/.test(path);
},
};

watch(['src'], watchOptions, function(_event, fileName) {
addToQueue(fileName);
});

let updating = false;

async function addToQueue(fileName) {
const output = fileName.replace(/\.scss$/, '.css.ts');
if (updating) {
return;
}
report.warn(`Change detected: ${fileName}`);
updating = true;
console.log('Rebuilding styles...');

await sassRender(fileName, template, output).catch((err) => {
report.error(err);
});
report.success('Styles rebuilt 🎨');
updating = false;
}

console.log('Styles watcher started...');
16 changes: 9 additions & 7 deletions src/components/avatar/themes/avatar.base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
@use '../../../styles/utilities' as *;

:host {
--size: #{sizable(rem(40px), rem(64px), rem(88px))};

display: inline-block;
}

Expand All @@ -17,7 +19,7 @@
outline-style: none;
flex-shrink: 0;
overflow: hidden;
font-family: var(--igc-font-family);
font-family: var(--ig-font-family);
width: var(--size);
height: var(--size);

Expand All @@ -40,16 +42,16 @@ img {
text-transform: uppercase;
}

:host([size='large']) [part='base'] {
--size: #{rem(88px)};
:host([size='large']) {
--component-size: var(--ig-size, var(--ig-size-large));
}

:host([size='medium']) [part='base'] {
--size: #{rem(64px)};
:host([size='medium']) {
--component-size: var(--ig-size, var(--ig-size-medium));
}

:host([size='small']) [part='base'] {
--size: #{rem(40px)};
:host([size='small']) {
--component-size: var(--ig-size, var(--ig-size-small));
}

:host([shape='rounded']) [part='base'] {
Expand Down
4 changes: 2 additions & 2 deletions src/components/badge/themes/light/badge.base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ span {
align-items: center;
overflow: hidden;
white-space: nowrap;
font-family: var(--igc-font-family);
font-size: var(--igc-subtitle-1-font-size);
font-family: var(--ig-font-family);
font-size: var(--ig-subtitle-1-font-size);
font-weight: inherit;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/badge/themes/light/badge.bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

:host {
--size: #{rem(18px)};
--igc-subtitle-1-font-size: #{rem(12px)};
--ig-subtitle-1-font-size: #{rem(12px)};

font-weight: 700;
}
Expand Down
Loading