Skip to content

Commit 19d3c31

Browse files
authored
feat(styles): simplify the icon mixins (#6836)
## ๐Ÿ“„ Description The PR simplifies the icon mixins removing the need to load icons manually. --- ## ๐Ÿ”ฎ Design review - [ ] Design review done - [x] No design review needed ## ๐Ÿ“ Checklist - โœ… My code follows the style guidelines of this project - ๐Ÿ› ๏ธ I have performed a self-review of my own code - ๐Ÿ“„ I have made corresponding changes to the documentation - โš ๏ธ My changes generate no new warnings or errors - ๐Ÿงช I have added tests that prove my fix is effective or that my feature works - โœ”๏ธ New and existing unit tests pass locally with my changes
1 parent 4a2f01b commit 19d3c31

File tree

10 files changed

+38
-50
lines changed

10 files changed

+38
-50
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@swisspost/design-system-styles': major
3+
'@swisspost/design-system-documentation': patch
4+
---
5+
6+
Refactored the icon mixins so that icons no longer need to be included separately, imports are now handled automatically.
7+
The `custom-property` mixin as therefore be removed entirely.
8+
9+
The `icon` mixin arguments have also been updated: `$height` and `$width` have been replaced with a single `$size` since all icons are square.

โ€Žpackages/components/src/components/post-stepper-item/post-stepper-item.scssโ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
tokens.$default-map: components.$post-stepper;
99

10-
@include icons.custom-property('success-solid');
11-
1210
post-stepper-item {
1311
grid-row: 1;
1412
position: relative;

โ€Žpackages/documentation/.storybook/styles/preview.scssโ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
tokens.$default-map: utilities.$post-spacing;
1414

15-
@include post.custom-property(('chevrondown', 'resizeexpand', 'link', 'code'));
16-
1715
$monospace: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
1816

1917
// Mixin for toolbar button icons

โ€Žpackages/documentation/src/stories/foundations/icons/icon.styles.scssโ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
@use '@swisspost/design-system-styles/core' as post;
22

3-
@include post.custom-property(('accessibility', 'letter'));
4-
53
$resizer-padding: 1rem;
64
$resizer-border-width: 1px;
75
$resizer-border-color: #999;
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
@use '@swisspost/design-system-styles/core' as post;
22

3-
// Load icon(s) at the top of your file
4-
// For a single icon:
5-
@include post.custom-property('accessibility', './path/to/icon/folder');
6-
7-
// For multiple icons in the same file:
8-
@include post.custom-property(('accessibility', 'arrow'), './path/to/icon/folder');
3+
// Icon inheriting the size and color from the surrounding text
4+
.my-inline-icon {
5+
@include post.icon('printer');
6+
}
97

10-
.my-icon {
8+
// Icon with custom color and size
9+
.my-custom-icon {
1110
@include post.icon(
1211
$name: 'accessibility',
13-
// optional
1412
$color: '#fc0',
15-
$width: 1em,
16-
$height: 1em
13+
$size: 1em,
1714
);
1815
}

โ€Žpackages/styles-primeng-workspace/projects/styles-primeng/src/lib/primeng-theme/_icons.scssโ€Ž

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
@use '@swisspost/design-system-styles/core' as post;
22

3-
// Load all icon CSS files used in this component
4-
@include post.custom-property(
5-
(
6-
'plus',
7-
'trash',
8-
'chevrondown',
9-
'filter',
10-
'updown',
11-
'chevronup',
12-
'arrowup',
13-
'arrowdown',
14-
'checkmark',
15-
'closex',
16-
'burger'
17-
)
18-
);
19-
203
@mixin custom-icon($icon) {
214
display: inline-block;
225
height: 1rem;

โ€Žpackages/styles/src/components/card.scssโ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
tokens.$default-map: components.$post-cards;
1111

12-
@include icons-mx.custom-property('arrowright');
13-
1412
.card {
1513
display: flex;
1614
flex-direction: column;

โ€Žpackages/styles/src/components/chip.scssโ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
tokens.$default-map: components.$post-chip;
88

9-
@include icons-mx.custom-property(('closex', 'checkmark'));
10-
119
button.chip-dismissible {
1210
$button-size: tokens.get('close-size', components.$post-close);
1311
$icon-size: tokens.get('close-icon-size', components.$post-close);

โ€Žpackages/styles/src/components/list-check.scssโ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
tokens.$default-map: components.$post-listcheck;
88

9-
@include icons-mx.custom-property('checkmark');
10-
119
ul.list-check {
1210
@include utilities.reset-list;
1311
display: flex;

โ€Žpackages/styles/src/mixins/_icons.scssโ€Ž

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,40 @@
99
@use './../mixins/utilities';
1010
@use './../utilities/env-variables' as icon-version;
1111

12-
@mixin mask-image($name) {
12+
// Default path for icons
13+
$icons-default-path: '../icons/temp';
14+
15+
/**
16+
* Light mixin that applies only the mask image.
17+
*
18+
* Intended for internal use where full control over icon styles is needed.
19+
* Not documented for Design System users.
20+
*/
21+
@mixin mask-image($name, $path: $icons-default-path) {
1322
mask-image: var(--post-icon-#{$name});
1423
background-color: currentColor;
15-
color: currentColor; // Required in this case with usage of forced-color-adjust: preserve-parent-color
16-
forced-color-adjust: preserve-parent-color;
17-
}
1824

19-
@mixin custom-property($names, $path: '../icons/temp') {
20-
@each $name in $names {
25+
// An extra selector is required to avoid having nested rule errors
26+
& {
2127
@at-root {
2228
@include meta.load-css('#{$path}/#{$name}');
2329
}
2430
}
2531
}
2632

27-
@mixin icon($name, $color: inherit, $width: 1em, $height: 1em) {
33+
/**
34+
* Full-featured icon mixin.
35+
*
36+
* Documented for Design System users.
37+
* Use with caution internally as it applies additional styles beyond the mask.
38+
*/
39+
@mixin icon($name, $path: $icons-default-path, $color: inherit, $size: 1em) {
40+
@include mask-image($name, $path);
2841
display: inline-block;
29-
width: $width;
30-
height: $height;
42+
width: $size;
43+
height: $size;
3144
vertical-align: -0.15em;
32-
background-color: currentColor;
3345
color: $color;
34-
mask-image: var(--post-icon-#{$name});
3546
mask-position: center center;
3647
mask-repeat: no-repeat;
3748
mask-size: 100%;

0 commit comments

Comments
ย (0)