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: changed some variables to make the button great again #122

Merged
merged 4 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"build:style-dictionary": "node style-dictionary.js && npm run copy:scss",
"build:patternlab-css": "sass source/css/patternlab.scss:out/css/patternlab.css --style=compressed --embed-sources --load-path=node_modules",
"build:tailwind": "node scripts/tailwind-config-generator.mjs false true && cpr scripts/tailwind-config-generator.mjs build/tailwind/tailwind-config-generator.mjs -o",
"build-test:css": "sass build/scss/_db-ui-base.scss:build/css/db-ui-base.css --load-path=node_modules",
"build-test:base-css": "sass build/scss/_db-ui-base.scss:build/css/db-ui-base.css --load-path=node_modules",
"build-test:color-css": "sass build/scss/_color-classes.scss:build/css/color-classes.css --load-path=node_modules",
nmerget marked this conversation as resolved.
Show resolved Hide resolved
"build": "npm-run-all copy:assets build:* pl:build",
"clean": "rm -rf build",
"lint": "npm-run-all -p lint:*",
Expand Down
27 changes: 1 addition & 26 deletions scripts/color-classes-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,8 @@ const generateBGVariants = (value, index) => {
@extend %${prefix}-bg-${value}-${index}-ia;
}

a {
@extend %${prefix}-bg-${value}-${index}-text-ia;
}

.db-weak {
@extend %weak;

&-ia,
&[data-variant="ia"],
a {
@extend %weak-ia;
}
}
}
`;
Expand All @@ -45,7 +35,7 @@ const generateBGVariants = (value, index) => {
* @returns scss string
*/
exports.generateColorUtilitityClasses = (colorToken) => {
let output = '';
let output = '@import "variables";\n@import "color-placeholder";\n';

for (const [, value] of Object.keys(colorToken).entries()) {
output += `/**
Expand All @@ -54,17 +44,6 @@ exports.generateColorUtilitityClasses = (colorToken) => {
`;
// Text colors with interactive variant, e.g. primary
if (colorToken[value].enabled) {
output += `
.${prefix}-text-${value} {
@extend %${prefix}-text-${value};

&-ia,
&[data-variant="ia"],
a {
@extend %${prefix}-text-${value}-ia;
}
}`;

output += `
.${prefix}-bg-${value} {
@extend %${prefix}-bg-${value};
Expand All @@ -73,10 +52,6 @@ exports.generateColorUtilitityClasses = (colorToken) => {
&[data-variant="ia"] {
@extend %${prefix}-bg-${value}-ia;
}

a {
@extend %${prefix}-bg-${value}-text-ia;
}
}`;
}

Expand Down
98 changes: 48 additions & 50 deletions scripts/color-placeholders-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ const prefix = 'db';

const generateInteractiveVariants = (currentColorObject, cssProp) => {
return `
&:hover {
${cssProp}: $${prefix}-${currentColorObject.hover.name};
}
&:not(:disabled) {
&:hover {
${cssProp}: $${prefix}-${currentColorObject.hover.name};
--db-current-${cssProp}: #{$${prefix}-${currentColorObject.hover.name}};
}

&:active {
${cssProp}: $${prefix}-${currentColorObject.pressed.name};
&:active {
${cssProp}: $${prefix}-${currentColorObject.pressed.name};
--db-current-${cssProp}: #{$${prefix}-${currentColorObject.pressed.name}};
}
}
`;
};
Expand All @@ -24,38 +28,54 @@ const generateInteractiveVariants = (currentColorObject, cssProp) => {

const generateBGVariants = (
value,
index,
variant,
currentColorObject,
baseColorObject
) => {
return `
%${prefix}-bg-${value}-${index} {
const placeholderName = `${prefix}-bg-${value}${
variant ? `-${variant}` : ''
}`;
let result = `
%${placeholderName}-ia-states {
${generateInteractiveVariants(currentColorObject, 'background-color')}
}
%${placeholderName} {
background-color: $${prefix}-${currentColorObject.enabled.name};
color: $${prefix}-${baseColorObject.enabled.name};

&-ia,
&[data-variant="ia"] {
@extend %${prefix}-bg-${value}-${index};
${generateInteractiveVariants(currentColorObject, 'background-color')}
--db-current-background-color: #{$${prefix}-${
currentColorObject.enabled.name
}};
--db-current-color: #{$${prefix}-${baseColorObject.enabled.name}};

&-ia, &[data-variant="ia"] {
@extend %${placeholderName};
@extend %${placeholderName}-ia-states;
}

&-text-ia,
&[data-variant="text-ia"] {
color: $${prefix}-${baseColorObject.enabled.name};
${generateInteractiveVariants(baseColorObject, 'color')}
button {
@extend %${placeholderName}-ia-states;
}

a {
${generateInteractiveVariants(baseColorObject, 'color')}
}

`;
if (baseColorObject.weak) {
result += `
%weak {
color: $${prefix}-${baseColorObject.weak.enabled.name};

&-ia,
&[data-variant="ia"] {
color: $${prefix}-${baseColorObject.weak.enabled.name};
${generateInteractiveVariants(baseColorObject.weak, 'color')}
}
a {
${generateInteractiveVariants(baseColorObject.weak, 'color')}
}
}
}
`;
}

result += `}`;
return result;
};

/**
Expand All @@ -75,35 +95,13 @@ exports.generateColorUtilitityPlaceholder = (colorToken) => {
`;
// Text colors with interactive variant, e.g. primary
if (colorToken[value].enabled) {
output += `%${prefix}-text-${value} {
color: $${prefix}-${colorToken[value].enabled.name};

&-ia,
&[data-variant="ia"] {
color: $${prefix}-${colorToken[value].enabled.name};
${generateInteractiveVariants(colorToken[value], 'color')}
}
}
`;

// Text and background colors
output += `
%${prefix}-bg-${value} {
background-color: $${prefix}-${colorToken[value].enabled.name};
color: $${prefix}-${colorToken[value].on.enabled.name};

&-ia,
&[data-variant="ia"] {
@extend %${prefix}-bg-${value};
${generateInteractiveVariants(colorToken[value], 'background-color')}
}

&-text-ia,
&[data-variant="text-ia"] {
color: $${prefix}-${colorToken[value].on.enabled.name};
${generateInteractiveVariants(colorToken[value].on, 'color')}
}
}`;
output += generateBGVariants(
value,
undefined,
colorToken[value],
colorToken[value].on
);
}

for (const variant of Object.keys(colorToken[value].bg)) {
Expand Down
43 changes: 32 additions & 11 deletions scripts/scss-typography-generator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const prefix = 'db';

const fileHeader =
'\n' +
'@use "sass:math";\n' +
'// Do not edit directly\n' +
'// Generated on ' +
new Date().toString() +
Expand Down Expand Up @@ -54,8 +54,8 @@ const getUtilityClass = (utility, scale, textType, size) => {
${utility ? '.' : '%'}${prefix}-${scale}-${textType}-${getShortSize(size)}{
`;
result += `
\tline-height: $${prefix}-typography-${scale}-mobile-${textType}-${size}-line-height;
\tfont-size: $${prefix}-typography-${scale}-mobile-${textType}-${size}-font-size;
line-height: $${prefix}-typography-${scale}-mobile-${textType}-${size}-line-height;
font-size: $${prefix}-typography-${scale}-mobile-${textType}-${size}-font-size;
`;

if (isHeadline) {
Expand All @@ -65,20 +65,41 @@ ${utility ? '.' : '%'}${prefix}-${scale}-${textType}-${getShortSize(size)}{
font-weight: 300;
}
`;
} else {
result += `
--db-base-icon-font-size: #{$${prefix}-typography-${scale}-mobile-${textType}-${size}-font-size};
--db-base-icon-font-family: #{"icons-" + (math.div($${prefix}-typography-${scale}-mobile-${textType}-${size}-font-size, 1rem)
* 16 * $${prefix}-typography-${scale}-mobile-${textType}-${size}-line-height) + "-outline"},"missing-icons" !important;
`;
}

result += `
\t@media only screen and (min-width: $db-screens-md) {
\t\tline-height: $${prefix}-typography-${scale}-tablet-${textType}-${size}-line-height;
\t\tfont-size: $${prefix}-typography-${scale}-tablet-${textType}-${size}-font-size;
\t}\n`;
@media only screen and (min-width: $db-screens-md) {
line-height: $${prefix}-typography-${scale}-tablet-${textType}-${size}-line-height;
font-size: $${prefix}-typography-${scale}-tablet-${textType}-${size}-font-size;`;
if (!isHeadline) {
result += `
--db-base-icon-font-size: #{$${prefix}-typography-${scale}-tablet-${textType}-${size}-font-size};
--db-base-icon-font-family: #{"icons-" + (math.div($${prefix}-typography-${scale}-tablet-${textType}-${size}-font-size, 1rem)
* 16 * $${prefix}-typography-${scale}-tablet-${textType}-${size}-line-height) + "-outline"},"missing-icons" !important;
`;
}

result += `}\n`;

result += `
\t@media only screen and (min-width: $db-screens-lg) {
\t\tline-height: $${prefix}-typography-${scale}-desktop-${textType}-${size}-line-height;
\t\tfont-size: $${prefix}-typography-${scale}-desktop-${textType}-${size}-font-size;
\t}
@media only screen and (min-width: $db-screens-lg) {
line-height: $${prefix}-typography-${scale}-desktop-${textType}-${size}-line-height;
font-size: $${prefix}-typography-${scale}-desktop-${textType}-${size}-font-size;`;
if (!isHeadline) {
result += `
--db-base-icon-font-size: #{$${prefix}-typography-${scale}-desktop-${textType}-${size}-font-size};
--db-base-icon-font-family: #{"icons-" + (math.div($${prefix}-typography-${scale}-desktop-${textType}-${size}-font-size, 1rem)
* 16 * $${prefix}-typography-${scale}-desktop-${textType}-${size}-line-height) + "-outline"},"missing-icons" !important;
`;
}

result += `}`;

result += `
}
Expand Down
61 changes: 39 additions & 22 deletions scss/_db-ui-base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,7 @@
@import "color-placeholder";

:root {
@extend %db-scaling-normal;

$db-sizing-xs: var(--db-sizing-xs);
$db-sizing-sm: var(--db-sizing-sm);
$db-sizing-md: var(--db-sizing-md);
$db-sizing-lg: var(--db-sizing-lg);

$db-spacing-fixed-3xs: var(--db-spacing-fixed-3xs);
$db-spacing-fixed-2xs: var(--db-spacing-fixed-2xs);
$db-spacing-fixed-xs: var(--db-db-spacing-fixed-xs);
$db-spacing-fixed-sm: var(--db-db-spacing-fixed-sm);
$db-spacing-fixed-md: var(--db-spacing-fixed-md);
$db-spacing-fixed-lg: var(--db-spacing-fixed-lg);
$db-spacing-fixed-xl: var(--db-spacing-fixed-xl);

$db-spacing-responsive-xs: var(--db-spacing-responsive-xs);
$db-spacing-responsive-sm: var(--db-spacing-responsive-sm);
$db-spacing-responsive-md: var(--db-spacing-responsive-md);
$db-spacing-responsive-lg: var(--db-spacing-responsive-lg);
$db-spacing-responsive-xl: var(--db-spacing-responsive-xl);
@extend %db-ui-normal;

font-family: $db-font-family-sans;

Expand All @@ -38,15 +19,51 @@
}
}

$db-sizing-xs: var(--db-sizing-xs);
$db-sizing-sm: var(--db-sizing-sm);
$db-sizing-md: var(--db-sizing-md);
$db-sizing-lg: var(--db-sizing-lg);

$db-spacing-fixed-3xs: var(--db-spacing-fixed-3xs);
$db-spacing-fixed-2xs: var(--db-spacing-fixed-2xs);
$db-spacing-fixed-xs: var(--db-spacing-fixed-xs);
$db-spacing-fixed-sm: var(--db-spacing-fixed-sm);
$db-spacing-fixed-md: var(--db-spacing-fixed-md);
$db-spacing-fixed-lg: var(--db-spacing-fixed-lg);
$db-spacing-fixed-xl: var(--db-spacing-fixed-xl);

$db-spacing-responsive-xs: var(--db-spacing-responsive-xs);
$db-spacing-responsive-sm: var(--db-spacing-responsive-sm);
$db-spacing-responsive-md: var(--db-spacing-responsive-md);
$db-spacing-responsive-lg: var(--db-spacing-responsive-lg);
$db-spacing-responsive-xl: var(--db-spacing-responsive-xl);

$db-type-font-size-lg: var(--db-type-body-lg);
$db-type-font-size-md: var(--db-type-body-md);
$db-type-font-size-sm: var(--db-type-body-sm);

@mixin styles($styles...) {
@for $i from 0 to length($styles) {
%db-ui-#{nth($styles, $i + 1)},
.db-ui-#{nth($styles, $i + 1)} {
@extend %db-scaling-#{nth($styles, $i + 1)};

@extend %db-#{nth($styles, $i + 1)}-body-md;
[data-size="large"] {
@extend %db-#{nth($styles, $i + 1)}-body-lg;
}

body,
button,
input,
optgroup,
select,
textarea,
[data-size="medium"] {
@extend %db-#{nth($styles, $i + 1)}-body-md;
}

small {
small,
[data-size="small"] {
@extend %db-#{nth($styles, $i + 1)}-body-sm;
}

Expand Down