Skip to content

Commit

Permalink
Use collections to generate styles of Alert color variants
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkudrna committed Sep 11, 2024
1 parent 7412ff5 commit 37b5404
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 90 deletions.
3 changes: 2 additions & 1 deletion src/components/Alert/Alert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Alert.propTypes = {
*/
children: PropTypes.node.isRequired,
/**
* [Color variant](/docs/foundation/colors#component-colors) to clarify importance and meaning of the alert.
* Color variant to clarify importance and meaning of the alert. Implements
* [Feedback and Neutral color collections](/docs/foundation/collections#colors).
*/
color: PropTypes.oneOf(['success', 'warning', 'danger', 'help', 'info', 'note', 'light', 'dark']),
/**
Expand Down
40 changes: 9 additions & 31 deletions src/components/Alert/Alert.module.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@use "sass:map";
@use "../../styles/theme/typography";
@use "../../styles/tools/accessibility";
@use "../../styles/tools/collections";
@use "../../styles/tools/reset";
@use "settings";
@use "theme";
@use "tools";

@layer components.alert {
.root {
Expand Down Expand Up @@ -66,35 +66,13 @@
top: -0.1em;
}

.isRootColorSuccess {
@include tools.color(success);
}

.isRootColorWarning {
@include tools.color(warning);
}

.isRootColorDanger {
@include tools.color(danger);
}

.isRootColorHelp {
@include tools.color(help);
}

.isRootColorInfo {
@include tools.color(info);
}

.isRootColorNote {
@include tools.color(note);
}

.isRootColorLight {
@include tools.color(light);
}

.isRootColorDark {
@include tools.color(dark);
@each $color in settings.$colors {
@include collections.generate-properties(
$prefix: "rui-",
$component-name: "Alert",
$variant-name: "color",
$variant-value: $color,
$properties: settings.$themeable-properties,
);
}
}
11 changes: 6 additions & 5 deletions src/components/Alert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ See [API](#api) for all available options.

## Color Variants

All [component colors](/docs/foundation/colors#component-colors) are supported by
alert to cover all possible needs of your project.
To cover all possible needs of your project, Alert is available in colors from
[Feedback and Neutral color collections](/docs/foundation/collections#colors).

### Success

Expand Down Expand Up @@ -208,9 +208,10 @@ convention looks as follows:

Where:

- `<COLOR>` is one of supported
[component colors](/docs/foundation/colors#component-colors)
(see alert [color variants](#color-variants) and [API](#api)),
- `<COLOR>` is a value from supported
[color collections](/docs/foundation/collections#colors)
(check [color variants](#color-variants) and [API](#api) to see which
collections are supported),
- `<PROPERTY>` is one of `color` (color of text), `foreground-color` (color of
border, icon, links, and emphasis), or `background-color`.

Expand Down
5 changes: 5 additions & 0 deletions src/components/Alert/_settings.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
@use "sass:list";
@use "sass:map";
@use "../../styles/settings/collections";
@use "../../styles/theme/typography";
@use "theme";

$font-size: map.get(typography.$font-size-values, 1);
$line-height: typography.$line-height-base;
$min-height: calc(#{$font-size} * #{$line-height} + 2 * #{theme.$padding});

$colors: list.join(collections.$feedback-colors, collections.$neutral-colors);
$themeable-properties: color, foreground-color, background-color;
43 changes: 0 additions & 43 deletions src/components/Alert/_theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,3 @@ $border-width: var(--rui-Alert__border-width);
$border-radius: var(--rui-Alert__border-radius);
$emphasis-font-weight: var(--rui-Alert__emphasis__font-weight);
$stripe-width: var(--rui-Alert__stripe__width);

$colors: (
success: (
color: var(--rui-Alert--success__color),
foreground-color: var(--rui-Alert--success__foreground-color),
background-color: var(--rui-Alert--success__background-color),
),
warning: (
color: var(--rui-Alert--warning__color),
foreground-color: var(--rui-Alert--warning__foreground-color),
background-color: var(--rui-Alert--warning__background-color),
),
danger: (
color: var(--rui-Alert--danger__color),
foreground-color: var(--rui-Alert--danger__foreground-color),
background-color: var(--rui-Alert--danger__background-color),
),
info: (
color: var(--rui-Alert--info__color),
foreground-color: var(--rui-Alert--info__foreground-color),
background-color: var(--rui-Alert--info__background-color),
),
help: (
color: var(--rui-Alert--help__color),
foreground-color: var(--rui-Alert--help__foreground-color),
background-color: var(--rui-Alert--help__background-color),
),
note: (
color: var(--rui-Alert--note__color),
foreground-color: var(--rui-Alert--note__foreground-color),
background-color: var(--rui-Alert--note__background-color),
),
light: (
color: var(--rui-Alert--light__color),
foreground-color: var(--rui-Alert--light__foreground-color),
background-color: var(--rui-Alert--light__background-color),
),
dark: (
color: var(--rui-Alert--dark__color),
foreground-color: var(--rui-Alert--dark__foreground-color),
background-color: var(--rui-Alert--dark__background-color),
),
);
10 changes: 0 additions & 10 deletions src/components/Alert/_tools.scss

This file was deleted.

0 comments on commit 37b5404

Please sign in to comment.