Skip to content

Commit 3136eb2

Browse files
authored
Add size and muted props to Icon (#1951)
This PR adds two new props to the Icon component: `muted`, which will render the icon slightly opaque, and `size` which will scale the icon to the requested icon size token.
1 parent d866a56 commit 3136eb2

File tree

8 files changed

+110
-21
lines changed

8 files changed

+110
-21
lines changed

.changeset/chilled-frogs-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudfour/patterns": minor
3+
---
4+
5+
Add `size` and `muted` props to Icon

src/components/icon/icon.scss

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@use 'sass:math';
2+
@use '../../compiled/tokens/scss/opacity';
3+
@use '../../compiled/tokens/scss/size';
24
@use '../../mixins/svg';
35
@use '../../mixins/icon';
46

@@ -18,3 +20,27 @@
1820
.c-icon--inline {
1921
@include icon.inline;
2022
}
23+
24+
/**
25+
* Muted modifier
26+
*/
27+
28+
.c-icon--muted {
29+
opacity: opacity.$muted;
30+
}
31+
32+
/**
33+
* Size modifiers
34+
*/
35+
36+
.c-icon--medium {
37+
--icon-size: #{size.$icon-medium};
38+
}
39+
40+
.c-icon--large {
41+
--icon-size: #{size.$icon-large};
42+
}
43+
44+
.c-icon--x-large {
45+
--icon-size: #{size.$icon-x-large};
46+
}

src/components/icon/icon.stories.mdx

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ const iconStory = (args) => {
2020
}
2121
return template(args);
2222
};
23+
const defaultArgs = {
24+
name: { type: 'string' },
25+
fallback: { type: 'string' },
26+
inline: { type: 'boolean' },
27+
class: { type: 'string' },
28+
title: { type: 'string' },
29+
muted: { type: 'boolean' },
30+
size: { type: 'string' },
31+
};
2332

2433
<Meta title="Components/Icon" />
2534

@@ -36,13 +45,62 @@ For a list of available icons, visit [the Icons page](/docs/design-icons--page).
3645
name: 'heart',
3746
inline: false,
3847
}}
39-
argTypes={{
40-
name: { type: { name: 'string' } },
41-
fallback: { type: { name: 'string' } },
42-
inline: { type: { name: 'boolean' } },
43-
class: { type: { name: 'string' } },
44-
title: { type: { name: 'string' } },
48+
argTypes={defaultArgs}
49+
>
50+
{(args) => iconStory(args)}
51+
</Story>
52+
</Canvas>
53+
54+
## Muted
55+
56+
By setting the `muted` property to `true`, the icon will become slightly opaque.
57+
58+
<Canvas>
59+
<Story
60+
name="Muted"
61+
args={{
62+
name: 'heart',
63+
inline: false,
64+
muted: true,
65+
}}
66+
argTypes={defaultArgs}
67+
>
68+
{(args) => iconStory(args)}
69+
</Story>
70+
</Canvas>
71+
72+
## Sizes
73+
74+
By setting the `size` property to the [name of a `size.$icon` token](/docs/design-tokens-size--page), such as `large`, the icon will be scaled to the appropriate size.
75+
76+
<Canvas>
77+
<Story
78+
name="Medium Size"
79+
args={{
80+
name: 'heart',
81+
size: 'medium',
82+
}}
83+
argTypes={defaultArgs}
84+
>
85+
{(args) => iconStory(args)}
86+
</Story>
87+
<Story
88+
name="Large Size"
89+
args={{
90+
name: 'heart',
91+
size: 'large',
92+
}}
93+
argTypes={defaultArgs}
94+
>
95+
{(args) => iconStory(args)}
96+
</Story>
97+
<Story
98+
name="X-Large Size"
99+
args={{
100+
name: 'heart',
101+
size: 'x-large',
45102
}}
103+
argTypes={defaultArgs}
46104
>
47105
{(args) => iconStory(args)}
48106
</Story>
@@ -87,6 +145,8 @@ The component template supports the following unique properties:
87145
- `inline`: When `true`, the inline modifier will be applied.
88146
- `name`: The name of the intended icon [in our library](/docs/design-icons--page).
89147
- `title`: If provided, a `title` element will be prepended to the icon source with the contents of this property. This will also set the `role` to `img` unless it is already specified. ([More info](https://css-tricks.com/accessible-svgs/#aa-example-1-standalone-icon-meaningful))
148+
- `muted`: When `true`, the icon will be displayed in a muted color.
149+
- `size`: The size to display the icon, taken from the `size.$icon` tokens.
90150

91151
Additional SVG properties will be passed to the Twig template for the asset itself:
92152

src/components/icon/icon.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
{% set _class = _class ~ ' c-icon--inline' %}
1212
{% endif %}
1313

14+
{% if size %}
15+
{% set _class = _class ~ ' c-icon--' ~ size %}
16+
{% endif %}
17+
18+
{% if muted %}
19+
{% set _class = _class ~ ' c-icon--muted' %}
20+
{% endif %}
21+
1422
{% if class %}
1523
{% set _class = _class ~ ' ' ~ class %}
1624
{% endif %}

src/prototypes/no-content/example/example.scss

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/prototypes/no-content/example/example.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{% block content %}
4545
{% include '@cloudfour/components/icon/icon.twig' with {
4646
name: 'magnifying-glass',
47-
class: 'large-icon'
47+
class: 'c-icon--x-large c-icon--muted'
4848
} %}
4949
{% include '@cloudfour/components/heading/heading.twig' with {
5050
"level": 2,

src/prototypes/no-content/no-content.stories.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import examplePrototype from './example/example.twig';
2-
import './example/example.scss';
32

43
export default {
54
title: 'Prototypes/No Content',

src/tokens/size/sizing.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ module.exports = {
2121
value: modularEm(2),
2222
comment: 'The large icon size.',
2323
},
24+
'x-large': {
25+
value: modularEm(5),
26+
comment: 'The x-large icon size.',
27+
},
2428
},
2529
width: {
2630
card_column: {

0 commit comments

Comments
 (0)