-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(themes): add themes structure (#108)
* feat(themes): add themes structure * fix(themes): fix typo * feat(themes): complete theme structures. add inputs themes * feat(themes): generate pure css & mixins * chore(themes): remove getCSSModuleLocalIdent
- Loading branch information
Showing
19 changed files
with
152 additions
and
42 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const shell = require('shelljs'); | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
// Записывает правила в :root | ||
const toRoot = rules => `:root {${rules}}\n`; | ||
|
||
// Возвращает контент миксина | ||
const extractContentFromMixins = css => { | ||
if ((css.match(/@define-mixin/g) || []).length != 1) { | ||
throw new Error('Theme file should contain exactly one mixin'); | ||
} | ||
|
||
const match = /@define-mixin.*{([\s\S]*?)}/gm.exec(css); | ||
|
||
if (match) return match[1]; | ||
}; | ||
|
||
// Удаляем файл с дефолтной темой, его публиковать не нужно | ||
shell.rm('dist/default.css'); | ||
|
||
// Переходим в папку с мисинами и парсим темы | ||
shell.cd('dist/mixins'); | ||
|
||
const themes = glob.sync('./*.css', {}).map(cssPath => { | ||
return path.basename(cssPath).replace('.css', ''); | ||
}); | ||
|
||
themes.forEach(theme => { | ||
let allVars = ''; | ||
|
||
// Извлекаем переменные из файлов с миксинами и генерируем css-файлы, записывая переменные в :root | ||
glob.sync(`./?*/${theme}.css`, {}).forEach(cssFile => { | ||
const component = path.basename(path.dirname(cssFile)); | ||
const content = fs.readFileSync(cssFile, 'utf-8'); | ||
const vars = extractContentFromMixins(content); | ||
|
||
if (vars) { | ||
shell.mkdir('-p', `../css/${component}`); | ||
fs.writeFileSync(`../css/${component}/${theme}.css`, toRoot(vars)); | ||
|
||
// Собираем переменные компонентов в один файл | ||
allVars += `\n /**\n * === ${component} ===\n */\n${vars}`; | ||
} | ||
}); | ||
|
||
if (allVars.length) { | ||
fs.writeFileSync(`../css/${theme}.css`, toRoot(allVars)); | ||
} | ||
}); | ||
|
||
// Переносим сгенерированные css-файлы в /dist | ||
shell.cd('../'); | ||
shell.cp('-R', './css/.', './'); | ||
shell.rm('-rf', './css'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@import '../../themes/default.css'; | ||
@import '../../themes/src/default.css'; | ||
|
||
:root { | ||
/* primary */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@import '../../themes/default.css'; | ||
@import '../../themes/src/default.css'; | ||
|
||
:root { | ||
/* border */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@alfalab/core-components-themes", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"license": "ISC", | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "dist" | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
packages/themes/default.css → packages/themes/src/default.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/themes/click.css → packages/themes/src/mixins/button/click.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
:root { | ||
@define-mixin button-click { | ||
--button-ghost-hover-color: var(--color-red-brand); | ||
--button-ghost-active-color: var(--color-red-dark); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@import './input/click.css'; | ||
@import './pure-input/click.css'; | ||
@import './button/click.css'; | ||
|
||
@define-mixin theme-click { | ||
@mixin input-click; | ||
@mixin pure-input-click; | ||
@mixin button-click; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@define-mixin input-click { | ||
--input-border-radius: 4px; | ||
--input-border-bottom: 0; | ||
--input-bg-color: var(--color-dark-indigo-07-flat); | ||
|
||
/* paddings */ | ||
--input-paddings: 0 var(--gap-s); | ||
--input-l-paddings: 0 var(--gap-m); | ||
|
||
/* paddings */ | ||
--input-labeled-s-paddings: 23px var(--gap-s) 5px; | ||
--input-labeled-m-paddings: 28px var(--gap-s) 8px; | ||
--input-labeled-l-paddings: 34px var(--gap-m) 14px; | ||
|
||
/* disabled */ | ||
--input-disabled-border-bottom: 0; | ||
--input-disabled-bg-color: var(--color-dark-indigo-07-flat); | ||
|
||
/* focus */ | ||
--input-focus-shadow: none; | ||
--input-focus-border-bottom: 0; | ||
--input-hover-bg-color: var(--color-dark-indigo-07-flat); | ||
|
||
/* error */ | ||
--input-error-shadow: inset 0 0 0 1px var(--input-error-color); | ||
--input-error-border-bottom: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@define-mixin pure-input-click { | ||
--pure-input-border-radius: 4px; | ||
--pure-input-border-bottom: 0; | ||
--pure-input-bg-color: var(--color-dark-indigo-07-flat); | ||
|
||
/* paddings */ | ||
--pure-input-paddings: 0 var(--gap-s); | ||
--pure-input-l-paddings: 0 var(--gap-m); | ||
|
||
/* disabled */ | ||
--pure-input-disabled-border-bottom: 0; | ||
--pure-input-disabled-bg-color: var(--color-dark-indigo-07-flat); | ||
|
||
/* focus */ | ||
--pure-input-focus-shadow: none; | ||
--pure-input-focus-border-bottom: 0; | ||
--pure-input-hover-bg-color: var(--color-dark-indigo-07-flat); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters