-
Notifications
You must be signed in to change notification settings - Fork 4
feat: generate color utilities #51
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d89a6f4
feat: generate color utilities
annsch 11da3f9
feat: utilities for neutral variants
annsch 8ec922a
feat: generate color utilities
annsch 3089be2
feat: utilities for neutral variants
annsch e8a4531
refactor: removed unused properties
annsch 81fea5a
fix: resolve conflicts
annsch 5d8d991
fix: add color for child elements
annsch 57f97e6
feat: color utilities generator
annsch 36a9759
fix: remove console logs
annsch ee75c8f
fix: merged with v3
annsch 3389a89
fix: removed comments
annsch e7987a3
fix: included pr feedback
annsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,100 @@ | ||
| /** | ||
| * Generate Color Utilities (Classes and SCSS Placeholders) for color dependencies | ||
| * according to definitions made by DB UI v3 | ||
| */ | ||
|
|
||
| const prefix = 'db'; | ||
|
|
||
| /** | ||
| * backgrounds have more than one variant with the same color for text (on-color) | ||
| * e.g. neutral with variants 1-6 or transparent-full and transparent-semi | ||
| */ | ||
|
|
||
| const generateBGVariants = (value, index) => { | ||
| return ` | ||
| .${prefix}-bg-${value}-${index} { | ||
| @extend %${prefix}-bg-${value}-${index}; | ||
|
|
||
| &-ia, | ||
| &[data-variant="ia"] { | ||
| @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; | ||
| } | ||
| } | ||
| } | ||
| `; | ||
| }; | ||
|
|
||
| /** | ||
| * generates color utility classes and scss placeholders for non-interactive and interactive variants | ||
| * of color combination (background-color and color) based on definitions made by DB UI v3 | ||
| * | ||
| * @param {*} colorToken scss transform obj generated by styleDictionary | ||
| * @returns scss string | ||
| */ | ||
| exports.generateColorUtilitityClasses = (colorToken) => { | ||
| let output = ''; | ||
|
|
||
| Object.keys(colorToken).forEach((value, index) => { | ||
| output += `/** | ||
| * ${value.toUpperCase()} - Utility Classes | ||
| **/ | ||
| `; | ||
| // 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}; | ||
|
|
||
| &-ia, | ||
| &[data-variant="ia"] { | ||
| @extend %${prefix}-bg-${value}-ia; | ||
| } | ||
|
|
||
| a { | ||
| @extend %${prefix}-bg-${value}-text-ia; | ||
| } | ||
| }`; | ||
| } | ||
|
|
||
| Object.keys(colorToken[value].bg).forEach((variant) => { | ||
| if (colorToken[value].bg[variant].enabled) { | ||
| output += generateBGVariants(value, variant); | ||
| } else { | ||
| Object.keys(colorToken[value].bg[variant]).forEach( | ||
| (childVariant) => { | ||
| output += generateBGVariants( | ||
| value, | ||
| variant + '-' + childVariant | ||
| ); | ||
| } | ||
| ); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| return output; | ||
| }; | ||
This file contains hidden or 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,128 @@ | ||
| /** | ||
| * Generate Color Utilities (Classes and SCSS Placeholders) for color dependencies | ||
| * according to definitions made by DB UI v3 | ||
| */ | ||
|
|
||
| const prefix = 'db'; | ||
|
|
||
| const generateInteractiveVariants = (currentColorObj, cssProp) => { | ||
| return ` | ||
| &:hover { | ||
| ${cssProp}: $${prefix}-${currentColorObj.hover.name}; | ||
| } | ||
|
|
||
| &:active { | ||
| ${cssProp}: $${prefix}-${currentColorObj.pressed.name}; | ||
| } | ||
| `; | ||
| }; | ||
|
|
||
| /** | ||
| * backgrounds have more than one variant with the same color for text (on-color) | ||
| * e.g. neutral with variants 1-6 or transparent-full or transparent-semi | ||
| */ | ||
|
|
||
| const generateBGVariants = (value, index, currentColorObj, baseColorObj) => { | ||
| return ` | ||
| %${prefix}-bg-${value}-${index} { | ||
| background-color: $${prefix}-${currentColorObj.enabled.name}; | ||
| color: $${prefix}-${baseColorObj.enabled.name}; | ||
|
|
||
| &-ia, | ||
| &[data-variant="ia"] { | ||
| @extend %${prefix}-bg-${value}-${index}; | ||
| ${generateInteractiveVariants(currentColorObj, 'background-color')} | ||
| } | ||
|
|
||
| &-text-ia, | ||
| &[data-variant="text-ia"] { | ||
| color: $${prefix}-${baseColorObj.enabled.name}; | ||
| ${generateInteractiveVariants(baseColorObj, 'color')} | ||
| } | ||
|
|
||
| %weak { | ||
| color: $${prefix}-${baseColorObj.weak.enabled.name}; | ||
|
|
||
| &-ia, | ||
| &[data-variant="ia"] { | ||
| color: $${prefix}-${baseColorObj.weak.enabled.name}; | ||
| ${generateInteractiveVariants(baseColorObj.weak, 'color')} | ||
| } | ||
| } | ||
| } | ||
| `; | ||
| }; | ||
|
|
||
| /** | ||
| * generates color utility classes and scss placeholders for non-interactive and interactive variants | ||
| * of color combination (background-color and color) based on definitions made by DB UI v3 | ||
| * | ||
| * @param {*} colorToken scss transform obj generated by styleDictionary | ||
| * @returns scss string | ||
| */ | ||
| exports.generateColorUtilitityPlaceholder = (colorToken) => { | ||
| let output = ''; | ||
|
|
||
| Object.keys(colorToken).forEach((value, index) => { | ||
| output += `/** | ||
| * ${value.toUpperCase()} - Placeholder Utilities | ||
| **/ | ||
| `; | ||
| // 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')} | ||
| } | ||
| }`; | ||
| } | ||
|
|
||
| Object.keys(colorToken[value].bg).forEach((variant) => { | ||
| if (colorToken[value].bg[variant].enabled) { | ||
| output += generateBGVariants( | ||
| value, | ||
| variant, | ||
| colorToken[value].bg[variant], | ||
| colorToken[value].on.bg | ||
| ); | ||
| } else { | ||
| Object.keys(colorToken[value].bg[variant]).forEach( | ||
| (childVariant) => { | ||
| output += generateBGVariants( | ||
| value, | ||
| variant + '-' + childVariant, | ||
| colorToken[value].bg[variant][childVariant], | ||
| colorToken[value].on.bg | ||
| ); | ||
| } | ||
| ); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| return output; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| .DO-NOT-COPY-THIS-CLASS-example-spacing { | ||
| height: 8px; | ||
| background-color: $db-colors-primary-bg-enabled; | ||
| background-color: $db-colors-primary-bg-light-enabled; | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.