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

feat: variables generation #334

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/dist
/dist-ssr
/node_modules
/tokens

# Logs
logs
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"serve": "vite preview",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"build-tokens": "token-transformer ./tokens/tokens.json tokens/transformed-tokens.json && node sd.config.mjs",
"lint:js": "eslint '**/*.{vue,ts}'",
"lint:js:fix": "eslint --fix '**/*.{vue,ts,html}'",
"lint:style": "stylelint '**/*.{css,scss,vue}'",
Expand Down Expand Up @@ -83,8 +84,10 @@
"rollup-plugin-vue": "^6.0.0",
"sass": "^1.51.0",
"sass-loader": "^12.6.0",
"style-dictionary": "^3.7.1",
"style-loader": "^3.3.1",
"stylelint": "^14.8.2",
"token-transformer": "^0.0.25",
"typescript": "^4.6.4",
"vite": "^2.9.8",
"vite-plugin-dts": "^1.1.1",
Expand Down
61 changes: 61 additions & 0 deletions sd.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable import/no-extraneous-dependencies */
import StyleDictionary from "style-dictionary";
/* eslint-disable import/no-extraneous-dependencies */

const createShadowFromTokenValue = (value) => {
const { x, y, blur, spread, color } = value;

const shadowValues = [x, y, blur, spread];

const isShadowValueNone = shadowValues.every(val => !val);

if (isShadowValueNone) return 'none';

return `${shadowValues.join('px ')} ${color}`;
};

const dropShadowTransformer = (token) => {
const tokenValue = token.original.value;
if (!Array.isArray(tokenValue)) return createShadowFromTokenValue(tokenValue);

return token.original.value.reduce((acc, curTokenValue) => {
const shadow = createShadowFromTokenValue(curTokenValue);
acc.push(shadow);

return acc;
}, []).join(', ');

};

StyleDictionary.registerTransform({
type: 'value',
name: 'shadows-value/css',
matcher: (token) => ['dropShadow', 'boxShadow'].includes(token.type),
transformer: dropShadowTransformer
});

StyleDictionary.registerFilter({
name: 'token-set-order/css',
matcher: (token) => !token.attributes.category.includes('tokenSetOrder'),
});

StyleDictionary.extend({
"source": ["tokens/transformed-tokens.json"],
"platforms": {
"css": {
"transformGroup": "css",
"transforms": ["attribute/cti", "name/cti/kebab", "size/px", "color/css", "shadows-value/css"],
"buildPath": "src/",
"files": [
{
"destination": "token-variables.scss",
"format": "css/variables",
"options": {
"showFileHeader": false
},
filter: 'token-set-order/css'
}
]
}
SeregaBB marked this conversation as resolved.
Show resolved Hide resolved
}
}).buildAllPlatforms();
2 changes: 1 addition & 1 deletion src/main.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import './normalize';
@import './vars';
@import './transition';
@import './vars';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

стоит вернуть обратно


*,
*::before,
Expand Down
88 changes: 47 additions & 41 deletions src/qComponents/QInput/src/q-input.scss
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
.q-input {
--field-color-base: var(--color-primary-black);
--field-color-placeholder: rgb(var(--color-rgb-gray) / 32%);
--field-color-disabled: rgb(var(--color-rgb-gray) / 64%);
--field-icon-color-base: var(--color-primary-blue);
--field-icon-color-hover: var(--color-primary-black);
--field-icon-color-inactive: rgb(var(--color-rgb-gray) / 64%);
--field-background-color-base: var(--color-tertiary-gray-light);
--field-background-color-hover: var(--color-tertiary-gray);
--field-background-color-focus: var(--color-tertiary-gray-ultra-light);
--field-background-color-disabled: var(--color-tertiary-gray);
--field-box-shadow-base: -1px -1px 3px rgb(var(--color-rgb-white) / 25%),
1px 1px 3px rgb(var(--color-rgb-blue) / 40%),
4px 4px 8px rgb(var(--color-rgb-blue) / 40%),
-4px -4px 12px var(--color-tertiary-white);
--field-box-shadow-hover: -1px -1px 4px rgb(var(--color-rgb-white) / 25%),
1px 1px 4px rgb(var(--color-rgb-blue) / 40%),
4px 4px 8px rgb(var(--color-rgb-blue) / 40%),
-4px -4px 8px rgb(var(--color-rgb-white) / 80%);
--field-box-shadow-focus: -1px -1px 3px rgb(var(--color-rgb-white) / 25%),
1px 1px 3px rgb(var(--color-rgb-blue) / 40%),
inset -1px -1px 1px rgb(var(--color-rgb-white) / 70%),
inset 1px 1px 2px rgb(var(--color-rgb-blue) / 20%);
--field-box-shadow-disabled: -1px -1px 3px rgb(var(--color-rgb-white) / 25%),
1px 1px 3px rgb(var(--color-rgb-blue) / 40%);
@import '@/token-variables';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это не нужно и можно дропнуть алиасы


.q-input {
position: relative;
display: inline-block;
width: 100%;
Expand All @@ -37,11 +14,12 @@
font-size: var(--font-size-base);
font-weight: var(--font-weight-base);
line-height: var(--line-height-base);
color: var(--field-color-base);
background-color: var(--field-background-color-base);
color: var(--input-filled-text-color);
background-color: var(--input-default-background-color);
border: none;
border-radius: var(--border-radius-base);
box-shadow: var(--field-box-shadow-base);
outline: 1px solid var(--input-default-border-color);
box-shadow: var(--input-default-background-shadow);
appearance: textfield;

&::-webkit-outer-spin-button,
Expand All @@ -52,7 +30,7 @@

&::placeholder,
&:placeholder-shown {
color: var(--field-color-placeholder);
color: var(--input-disabled-text-color);
text-overflow: ellipsis;
opacity: 1;
}
Expand All @@ -71,21 +49,26 @@

.q-input_focused &,
&.focus-visible {
background-color: var(--field-background-color-focus);
box-shadow: var(--field-box-shadow-focus);
color: var(--input-focus-filled-text-color);
background-color: var(--input-filled-background-color);
outline: 1px solid var(--input-focus-filled-border-color);
box-shadow: var(--input-focus-background-shadow);
}

&:hover {
background-color: var(--field-background-color-hover);
box-shadow: var(--field-box-shadow-hover);
color: var(--input-hover-filled-text-color);
background-color: var(--input-hover-background-color);
outline: 1px solid var(--input-hover-border-color);
box-shadow: var(--input-hover-background-shadow);
}

.q-input_disabled & {
padding-right: 40px;
color: var(--field-color-disabled);
color: var(--input-disabled-text-color);
cursor: not-allowed;
background-color: var(--field-background-color-disabled);
box-shadow: var(--field-box-shadow-disabled);
background-color: var(--input-disabled-background-color);
outline: 1px solid var(--input-disabled-border-color);
box-shadow: var(--input-disabled-background-shadow);
}

.q-input_suffix & {
Expand All @@ -96,7 +79,10 @@
&,
&.focus-visible {
padding-left: 15px;
border: var(--border-error);
color: var(--input-error-text-color);
background-color: var(--input-error-background-color);
border: 1px solid var(--input-error-border-color);
box-shadow: var(--input-error-background-shadow);
}
}
}
Expand All @@ -116,23 +102,43 @@
width: 40px;
font-size: 24px;
line-height: 40px;
color: var(--field-icon-color-inactive);
color: var(--input-default-icon-color);
text-align: center;

&:not(:last-child) {
display: none;
}

.q-input_disabled & {
color: var(--input-disabled-icon-color);
}

.q-form-item_is-error & {
color: var(--input-error-icon-color);
}

.q-input_focused .q-input__inner &,
.q-input__inner.focus-visible & {
color: var(--input-focus-icon-color);
}

.q-input__inner:hover & {
color: var(--input-hover-icon-color);
}

&.q-icon-close,
&.q-icon-eye,
&.q-icon-eye-close {
color: var(--field-icon-color-base);
color: var(--input-filled-icon-color);
pointer-events: all;
cursor: pointer;

&:hover,
&:hover {
color: var(--input-hover-filled-icon-color);
}

&.focus-visible {
color: var(--field-icon-color-hover);
color: var(--input-focus-filled-icon-color);
}
}
}
Expand Down
Loading