Skip to content

Commit c59e8f4

Browse files
feat(tag): respect type prop for filter tag (#5382)
* feat(tag): respect type prop for filter tag * feat(tag): add support for dark theme colors * fix(tag): import css vars helper * fix(tag): expose tag colors in themes * fix(tag): fix prettier issues * fix(tag): use correct focus color for filterable tag * fix(tag): build new component tokens structure * fix: identify theme for component-tokens * fix: use emit-component-tokens in react stroybook style * fix(tag): emit component tokens on carbon--theme mixin * fix(themes): only emit component tokens if they exist * chore(themes): satisfy prettier issue * fix: roll back to $carbon--theme comparison, remove $theme-identifier * fix: simplify storybook theme mixin * refactor: revert obsolete changes * chore(storybook): revert obsolete explicit theme for component tokens * fix(tag): apply component tokens to default tag Co-authored-by: Lauren Rice <43969356+laurenmrice@users.noreply.github.com>
1 parent 5bda297 commit c59e8f4

File tree

9 files changed

+1075
-56
lines changed

9 files changed

+1075
-56
lines changed

packages/components/docs/sass.md

Lines changed: 125 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
- [❌custom-property [mixin]](#custom-property-mixin)
132132
- [❌should-emit [function]](#should-emit-function)
133133
- [✅carbon--theme [mixin]](#carbon--theme-mixin)
134+
- [❌emit-component-tokens [mixin]](#emit-component-tokens-mixin)
134135
- [✅carbon--theme--g10 [variable]](#carbon--theme--g10-variable)
135136
- [✅carbon--theme--g90 [variable]](#carbon--theme--g90-variable)
136137
- [✅carbon--theme--g100 [variable]](#carbon--theme--g100-variable)
@@ -1826,6 +1827,7 @@ $prefix: 'bx';
18261827
- [select [mixin]](#select-mixin)
18271828
- [slider [mixin]](#slider-mixin)
18281829
- [tabs [mixin]](#tabs-mixin)
1830+
- [tag-theme [mixin]](#tag-theme-mixin)
18291831
- [tags [mixin]](#tags-mixin)
18301832
- [text-area [mixin]](#text-area-mixin)
18311833
- [text-input [mixin]](#text-input-mixin)
@@ -4062,6 +4064,7 @@ $custom-property-prefix: 'cds';
40624064
- **Group**: [@carbon/themes](#carbonthemes)
40634065
- **Used by**:
40644066
- [carbon--theme [mixin]](#carbon--theme-mixin)
4067+
- [emit-component-tokens [mixin]](#emit-component-tokens-mixin)
40654068
- [custom-properties [mixin]](#custom-properties-mixin)
40664069

40674070
### ❌custom-property [mixin]
@@ -6023,6 +6026,57 @@ Define theme variables from a map of tokens
60236026
- [icon-size-02 [variable]](#icon-size-02-variable)
60246027
- [custom-property-prefix [variable]](#custom-property-prefix-variable)
60256028

6029+
### ❌emit-component-tokens [mixin]
6030+
6031+
<details>
6032+
<summary>Source code</summary>
6033+
6034+
```scss
6035+
@mixin emit-component-tokens($tokens, $theme) {
6036+
@if type-of($tokens) == 'map' {
6037+
@each $key, $options in $tokens {
6038+
@each $option in $options {
6039+
$theme: map-get($option, 'theme');
6040+
6041+
@if ($theme == $carbon--theme) {
6042+
$value: map-get($option, 'value');
6043+
6044+
--#{$custom-property-prefix}-#{$key}: #{$value};
6045+
}
6046+
}
6047+
}
6048+
} @else {
6049+
@error 'Unable to find map';
6050+
}
6051+
}
6052+
```
6053+
6054+
</details>
6055+
6056+
- **Parameters**:
6057+
6058+
| Name | Description | Type | Default value |
6059+
| --------- | ----------------------- | -------- | ------------- |
6060+
| `$tokens` | Map of component tokens | `Map` | — |
6061+
| `$theme` | Theme identifier | `String` | — |
6062+
6063+
**Example**:
6064+
6065+
<details>
6066+
<summary>Example code</summary>
6067+
6068+
```scss
6069+
@include emit-component-tokens($component-tokens);
6070+
```
6071+
6072+
</details>
6073+
6074+
- **Group**: [@carbon/themes](#carbonthemes)
6075+
- **Requires**:
6076+
- [tokens [variable]](#tokens-variable)
6077+
- [carbon--theme [variable]](#carbon--theme-variable)
6078+
- [custom-property-prefix [variable]](#custom-property-prefix-variable)
6079+
60266080
### ✅carbon--theme--g10 [variable]
60276081

60286082
Carbon's g10 color theme
@@ -6423,6 +6477,7 @@ $carbon--theme: (
64236477
- **Type**: `Map`
64246478
- **Used by**:
64256479
- [carbon--theme [mixin]](#carbon--theme-mixin)
6480+
- [emit-component-tokens [mixin]](#emit-component-tokens-mixin)
64266481

64276482
### ✅interactive-01 [variable]
64286483

@@ -7224,7 +7279,6 @@ $inverse-01: if(
72247279
- [inline-notifications [mixin]](#inline-notifications-mixin)
72257280
- [toast-notifications [mixin]](#toast-notifications-mixin)
72267281
- [progress-indicator [mixin]](#progress-indicator-mixin)
7227-
- [tags [mixin]](#tags-mixin)
72287282
- [tooltip--icon [mixin]](#tooltip--icon-mixin)
72297283
- [tooltip--definition--legacy [mixin]](#tooltip--definition--legacy-mixin)
72307284
- [tooltip [mixin]](#tooltip-mixin)
@@ -7256,7 +7310,6 @@ $inverse-02: if(
72567310
- [listbox [mixin]](#listbox-mixin)
72577311
- [inline-notifications [mixin]](#inline-notifications-mixin)
72587312
- [toast-notifications [mixin]](#toast-notifications-mixin)
7259-
- [tags [mixin]](#tags-mixin)
72607313
- [tooltip--icon [mixin]](#tooltip--icon-mixin)
72617314
- [tooltip--definition--legacy [mixin]](#tooltip--definition--legacy-mixin)
72627315
- [tooltip [mixin]](#tooltip-mixin)
@@ -7573,6 +7626,7 @@ $focus: if(
75737626
- [modal [mixin]](#modal-mixin)
75747627
- [radio-button [mixin]](#radio-button-mixin)
75757628
- [search [mixin]](#search-mixin)
7629+
- [tags [mixin]](#tags-mixin)
75767630
- [toggle [mixin]](#toggle-mixin)
75777631

75787632
### ✅inverse-focus-ui [variable]
@@ -7599,7 +7653,6 @@ $inverse-focus-ui: if(
75997653
- [carbon--theme [mixin]](#carbon--theme-mixin)
76007654
- [inline-notifications [mixin]](#inline-notifications-mixin)
76017655
- [toast-notifications [mixin]](#toast-notifications-mixin)
7602-
- [tags [mixin]](#tags-mixin)
76037656
- [tooltip [mixin]](#tooltip-mixin)
76047657

76057658
### ✅hover-primary [variable]
@@ -7965,7 +8018,6 @@ $inverse-hover-ui: if(
79658018
- **Used by**:
79668019
- [carbon--theme [mixin]](#carbon--theme-mixin)
79678020
- [inline-notifications [mixin]](#inline-notifications-mixin)
7968-
- [tags [mixin]](#tags-mixin)
79698021

79708022
### ✅hover-danger [variable]
79718023

@@ -8097,6 +8149,7 @@ $disabled-01: if(
80978149
- [content-switcher [mixin]](#content-switcher-mixin)
80988150
- [file-uploader [mixin]](#file-uploader-mixin)
80998151
- [slider [mixin]](#slider-mixin)
8152+
- [tags [mixin]](#tags-mixin)
81008153
- [text-input [mixin]](#text-input-mixin)
81018154
- [toggle [mixin]](#toggle-mixin)
81028155

@@ -13091,6 +13144,7 @@ $tokens: (
1309113144
- **Group**: [@carbon/type](#carbontype)
1309213145
- **Type**: `Map`
1309313146
- **Used by**:
13147+
- [emit-component-tokens [mixin]](#emit-component-tokens-mixin)
1309413148
- [carbon--type-classes [mixin]](#carbon--type-classes-mixin)
1309513149
- [carbon--type-style [mixin]](#carbon--type-style-mixin)
1309613150

@@ -23141,12 +23195,24 @@ Tabs styles
2314123195
@mixin tag-theme() {
2314223196
background-color: $bg-color;
2314323197
color: $text-color;
23198+
23199+
.#{$prefix}--tag__close-icon {
23200+
&:hover {
23201+
background-color: $filter-hover-color;
23202+
}
23203+
23204+
svg {
23205+
fill: $text-color;
23206+
}
23207+
}
2314423208
}
2314523209
```
2314623210

2314723211
</details>
2314823212

2314923213
- **Group**: [tag](#tag)
23214+
- **Requires**:
23215+
- [prefix [variable]](#prefix-variable)
2315023216
- **Used by**:
2315123217
- [tags [mixin]](#tags-mixin)
2315223218

@@ -23185,48 +23251,88 @@ Tag styles
2318523251
}
2318623252

2318723253
.#{$prefix}--tag--red {
23188-
@include tag-theme($ibm-color__red-20, $ibm-color__red-70);
23254+
@include tag-theme(
23255+
get-token-value($tag-colors, 'tag-background-red'),
23256+
get-token-value($tag-colors, 'tag-color-red'),
23257+
get-token-value($tag-colors, 'tag-hover-red')
23258+
);
2318923259
}
2319023260

2319123261
.#{$prefix}--tag--magenta {
23192-
@include tag-theme($ibm-color__magenta-20, $ibm-color__magenta-70);
23262+
@include tag-theme(
23263+
get-token-value($tag-colors, 'tag-background-magenta'),
23264+
get-token-value($tag-colors, 'tag-color-magenta'),
23265+
get-token-value($tag-colors, 'tag-hover-magenta')
23266+
);
2319323267
}
2319423268

2319523269
.#{$prefix}--tag--purple {
23196-
@include tag-theme($ibm-color__purple-20, $ibm-color__purple-70);
23270+
@include tag-theme(
23271+
get-token-value($tag-colors, 'tag-background-purple'),
23272+
get-token-value($tag-colors, 'tag-color-purple'),
23273+
get-token-value($tag-colors, 'tag-hover-purple')
23274+
);
2319723275
}
2319823276

2319923277
.#{$prefix}--tag--blue {
23200-
@include tag-theme($ibm-color__blue-20, $ibm-color__blue-70);
23278+
@include tag-theme(
23279+
get-token-value($tag-colors, 'tag-background-blue'),
23280+
get-token-value($tag-colors, 'tag-color-blue'),
23281+
get-token-value($tag-colors, 'tag-hover-blue')
23282+
);
2320123283
}
2320223284

2320323285
.#{$prefix}--tag--cyan {
23204-
@include tag-theme($ibm-color__cyan-20, $ibm-color__cyan-70);
23286+
@include tag-theme(
23287+
get-token-value($tag-colors, 'tag-background-cyan'),
23288+
get-token-value($tag-colors, 'tag-color-cyan'),
23289+
get-token-value($tag-colors, 'tag-hover-cyan')
23290+
);
2320523291
}
2320623292

2320723293
.#{$prefix}--tag--teal {
23208-
@include tag-theme($ibm-color__teal-20, $ibm-color__teal-70);
23294+
@include tag-theme(
23295+
get-token-value($tag-colors, 'tag-background-teal'),
23296+
get-token-value($tag-colors, 'tag-color-teal'),
23297+
get-token-value($tag-colors, 'tag-hover-teal')
23298+
);
2320923299
}
2321023300

2321123301
.#{$prefix}--tag--green {
23212-
@include tag-theme($ibm-color__green-20, $ibm-color__green-70);
23302+
@include tag-theme(
23303+
get-token-value($tag-colors, 'tag-background-green'),
23304+
get-token-value($tag-colors, 'tag-color-green'),
23305+
get-token-value($tag-colors, 'tag-hover-green')
23306+
);
2321323307
}
2321423308

2321523309
.#{$prefix}--tag--gray {
23216-
@include tag-theme($ibm-color__gray-20, $ibm-color__gray-100);
23310+
@include tag-theme(
23311+
get-token-value($tag-colors, 'tag-background-gray'),
23312+
get-token-value($tag-colors, 'tag-color-gray'),
23313+
get-token-value($tag-colors, 'tag-hover-gray')
23314+
);
2321723315
}
2321823316

2321923317
.#{$prefix}--tag--cool-gray {
23220-
@include tag-theme($ibm-color__cool-gray-20, $ibm-color__cool-gray-100);
23318+
@include tag-theme(
23319+
get-token-value($tag-colors, 'tag-background-cool-gray'),
23320+
get-token-value($tag-colors, 'tag-color-cool-gray'),
23321+
get-token-value($tag-colors, 'tag-hover-cool-gray')
23322+
);
2322123323
}
2322223324

2322323325
.#{$prefix}--tag--warm-gray {
23224-
@include tag-theme($ibm-color__warm-gray-20, $ibm-color__warm-gray-100);
23326+
@include tag-theme(
23327+
get-token-value($tag-colors, 'tag-background-warm-gray'),
23328+
get-token-value($tag-colors, 'tag-color-warm-gray'),
23329+
get-token-value($tag-colors, 'tag-hover-warm-gray')
23330+
);
2322523331
}
2322623332

2322723333
.#{$prefix}--tag--disabled,
2322823334
.#{$prefix}--tag--filter.#{$prefix}--tag--disabled {
23229-
@include tag-theme($ibm-color__gray-10, $ibm-color__gray-30);
23335+
@include tag-theme($disabled-01, $disabled-02);
2323023336

2323123337
&:hover {
2323223338
cursor: not-allowed;
@@ -23242,7 +23348,7 @@ Tag styles
2324223348

2324323349
// tags used for filtering
2324423350
.#{$prefix}--tag--filter {
23245-
@include tag-theme($inverse-02, $inverse-01);
23351+
cursor: pointer;
2324623352
padding-right: rem(2px);
2324723353

2324823354
&:focus,
@@ -23261,19 +23367,11 @@ Tag styles
2326123367
background-color: transparent;
2326223368
border-radius: 50%;
2326323369
cursor: pointer;
23264-
23265-
&:hover {
23266-
background-color: $inverse-hover-ui;
23267-
}
23268-
}
23269-
23270-
.#{$prefix}--tag__close-icon svg {
23271-
fill: $inverse-01;
2327223370
}
2327323371

2327423372
.#{$prefix}--tag__close-icon:focus {
2327523373
outline: none;
23276-
box-shadow: inset 0 0 0 2px $inverse-focus-ui;
23374+
box-shadow: inset 0 0 0 2px $focus;
2327723375
border-radius: 50%;
2327823376
}
2327923377

@@ -23306,11 +23404,9 @@ Tag styles
2330623404
- [carbon--spacing-02 [variable]](#carbon--spacing-02-variable)
2330723405
- [ui-03 [variable]](#ui-03-variable)
2330823406
- [text-01 [variable]](#text-01-variable)
23309-
- [inverse-02 [variable]](#inverse-02-variable)
23310-
- [inverse-01 [variable]](#inverse-01-variable)
23311-
- [inverse-hover-ui [variable]](#inverse-hover-ui-variable)
23312-
- [inverse-focus-ui [variable]](#inverse-focus-ui-variable)
23407+
- [disabled-01 [variable]](#disabled-01-variable)
2331323408
- [disabled-02 [variable]](#disabled-02-variable)
23409+
- [focus [variable]](#focus-variable)
2331423410

2331523411
## text-area
2331623412

packages/components/src/components/tag/_mixins.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77

88
/// @access private
99
/// @group tag
10-
@mixin tag-theme($bg-color, $text-color) {
10+
@mixin tag-theme($bg-color, $text-color, $filter-hover-color: $bg-color) {
1111
background-color: $bg-color;
1212
color: $text-color;
13+
14+
.#{$prefix}--tag__close-icon {
15+
&:hover {
16+
background-color: $filter-hover-color;
17+
}
18+
19+
svg {
20+
fill: $text-color;
21+
}
22+
}
1323
}

0 commit comments

Comments
 (0)