-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce color dictionaries for generative styling of components
- Loading branch information
1 parent
02a83f7
commit 5cfa505
Showing
6 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Dictionaries | ||
|
||
Dictionaries are collections of predefined values that can be used in various | ||
components. They are useful for ensuring consistency and reducing the likelihood | ||
of errors. | ||
|
||
## Colors | ||
|
||
The following color names are designed for use in components that support the | ||
`color` prop: | ||
|
||
| Category | Available values | | ||
|----------|--------------------------------------------------------| | ||
| Action | `primary`, `secondary`, `selected` | | ||
| Feedback | `success`, `warning`, `danger`, `info`, `help`, `note` | | ||
| Neutral | `light`, `dark` | | ||
|
||
Not all dictionaries are available in all components with the `color` prop. | ||
Refer to the documentation for each component to see which dictionaries are | ||
available. |
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 @@ | ||
$action-colors: primary, secondary, selected; | ||
$feedback-colors: success, warning, danger, info, help, note; | ||
$neutral-colors: light, dark; | ||
|
||
$colors: ( | ||
action: $action-colors, | ||
feedback: $feedback-colors, | ||
neutral: $neutral-colors, | ||
); |
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,49 @@ | ||
@use "sass:list"; | ||
@use "sass:map"; | ||
@use "../settings/dictionaries"; | ||
@use "string" as rui-string; | ||
|
||
@function _get-category-by-value($value, $dictionaries) { | ||
@each $category, $values in $dictionaries { | ||
@if list.index($values, $value) { | ||
@return $category; | ||
} | ||
} | ||
|
||
@error | ||
"Supplied value \"" | ||
+ $value | ||
+ "\" not found in any category (" | ||
+ map.keys(dictionaries.$colors) | ||
+ ")"; | ||
} | ||
|
||
@function _get-text-color-modifier($modifier) { | ||
@if $modifier == "dark" { | ||
@return "light"; | ||
} @else if $modifier == "light" { | ||
@return "dark"; | ||
} | ||
|
||
@return $modifier; | ||
} | ||
|
||
@mixin generate-colors($prefix, $component-name, $modifier, $properties, $inherit-link-color: false) { | ||
.isRootColor#{rui-string.capitalize($modifier)} { | ||
@each $property in $properties { | ||
--#{$prefix}local-#{$property}: | ||
var( | ||
#{"--" + $prefix + $component-name + "--" + $modifier + "__" + $property} | ||
); | ||
} | ||
|
||
@if $inherit-link-color { | ||
$color-category: _get-category-by-value($value: $modifier, $dictionaries: dictionaries.$colors); | ||
$text-modifier: _get-text-color-modifier($modifier); | ||
|
||
--#{$prefix}local-link-color: var(--rui-color-#{$color-category}-#{$text-modifier}); | ||
--#{$prefix}local-link-color-hover: var(--rui-color-#{$color-category}-#{$text-modifier}-hover); | ||
--#{$prefix}local-link-color-active: var(--rui-color-#{$color-category}-#{$text-modifier}-active); | ||
} | ||
} | ||
} |
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