@graupl/icons 1.0.0-beta.24 → 1.0.0-beta.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +1,174 @@
1
- // @gruapl/icons icon component styles.
1
+ // @graupl/icons icon component styles.
2
+ //
3
+ // This module provides the icon component styles and theming hooks.
4
+ //
5
+ // The following selectors are generated by default:
6
+ // - `.icon`: Base icon element.
7
+ // - `.icon-before`: Pseudo-style helper for adding icons before content.
8
+ // - `.icon-after`: Pseudo-style helper for adding icons after content.
9
+ //
10
+ // The following custom properties can be used to customize the icon component:
11
+ // | Property | Description | Default Value |
12
+ // | ----------------------- | -------------------------------------------- | --------------------------- |
13
+ // | `--graupl-icon-display` | Display value applied to the icon. | `inline-block` |
14
+ // | `--graupl-icon-size` | Base size for the icon box. | `1.25em` |
15
+ // | `--graupl-icon-width` | Width of the icon. | `var(--graupl-icon-size)` |
16
+ // | `--graupl-icon-height` | Height of the icon. | `var(--graupl-icon-size)` |
17
+ // | `--graupl-icon-color` | Color applied to the icon fill/mask. | `var(--graupl-color)` |
18
+ // | `--graupl-icon` | Source for the icon (mask-image/background). | `none` |
19
+ // | `--graupl-icon-spacer` | Spacer size used when placing the icon. | `var(--graupl-spacer-2)` |
20
+ //
21
+ // The following sass variables can be used to customize the generation of the icon component:
22
+ // | Variable | Description | Default Value |
23
+ // | -------------------------------- | ------------------------------------------------------------------- | ------------------------- |
24
+ // | `$selector-base` | Selector base for the component. | `"."` |
25
+ // | `$modifier-selector-base` | Selector base for component modifiers. | `"."` |
26
+ // | `$generate-base-theme-map` | Flag to generate base theme maps for icon variants. | `true` |
27
+ // | `$themeable` | Flag to generate theme modifiers. | `true` |
28
+ // | `$icon-selector-base` | Selector base for the icon element. | `$selector-base` |
29
+ // | `$icon-selector` | Selector for the icon element. | `"icon"` |
30
+ // | `$icon-before-selector` | Selector for the before helper. | `"icon-before"` |
31
+ // | `$icon-after-selector` | Selector for the after helper. | `"icon-after"` |
32
+ // | `$icon-theme-selector-base` | Selector base used for theme modifiers. | `$modifier-selector-base` |
33
+ // | `$icon-theme-selector-prefix` | Selector prefix used for theme modifiers. | `""` |
34
+ // | `$icon-prefix-selector-base` | Selector base for icon name modifiers. | `$modifier-selector-base` |
35
+ // | `$icon-prefix-selector` | Selector used for icon name modifiers. | `""` |
36
+ // | `$icon-display` | Default display value applied to icons. | `inline-block` |
37
+ // | `$icon-size` | Default size used for icon width/height. | `1.25em` |
38
+ // | `$icons` | Map of icon names to their SVG data/URLs. | `()` |
39
+ // | `$icon-theme-mappings` | Map of properties and color shades used to generate icon variants. | `()` |
40
+ // | `$icon-theme-map` | Resolved map of properties, colors, and shades for icon variants. | `()` |
41
+ //
42
+ // ## Using `$icon-theme-mappings`
43
+ //
44
+ // `$icon-theme-mappings` is a 1-level map of properties and shade values.
45
+ //
46
+ // e.g.
47
+ // ```scss
48
+ // $icon-theme-mappings: (
49
+ // color: 700,
50
+ // );
51
+ // ```
52
+ //
53
+ // This directly maps to all icon variants, telling them what shade to use for the given property.
54
+ // All icon variants will use the following based on the example above:
55
+ // - Primary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--primary--700`,
56
+ // - Secondary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--secondary--700`, and
57
+ // - Tertiary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--tertiary--700`.
58
+ //
59
+ // You can use this to customize _all_ icon variants in the same way.
60
+ //
61
+ // For example:
62
+ // ```scss
63
+ // $icon-theme-mappings: (
64
+ // color: 500,
65
+ // );
66
+ // ```
67
+ //
68
+ // All icon variants will use the following:
69
+ // - Primary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--primary--500`,
70
+ // - Secondary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--secondary--500`, and
71
+ // - Tertiary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--tertiary--500`.
72
+ //
73
+ // [1] `$icon-theme-mappings` gets parsed into a larger, more explicit map: `$icon-theme-map`.
74
+ //
75
+ // Using `$icon-theme-map`
76
+ //
77
+ // `$icon-theme-map` is a multi-level map of properties, colors, and shade values.
78
+ //
79
+ // e.g.
80
+ // ```scss
81
+ // $icon-theme-map: (
82
+ // primary: (
83
+ // color: (
84
+ // color: primary,
85
+ // shade: 700
86
+ // ),
87
+ // ),
88
+ // secondary: (
89
+ // color: (
90
+ // color: secondary,
91
+ // shade: 700
92
+ // ),
93
+ // ),
94
+ // tertiary: (
95
+ // color: (
96
+ // color: tertiary,
97
+ // shade: 700
98
+ // ),
99
+ // ),
100
+ // )
101
+ // ```
102
+ //
103
+ // This directly maps to all icon variants, telling them what shade to use for said property.
104
+ // The icon variants will use the following based on the example above:
105
+ // - Primary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--primary--700`,
106
+ // - Secondary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--secondary--700`, and
107
+ // - Tertiary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--tertiary--700`.
108
+ //
109
+ // You can use this to customize icon variants individually.
110
+ //
111
+ // For example, if you use the following map:
112
+ //
113
+ // ```scss
114
+ // $icon-theme-map: (
115
+ // primary: (
116
+ // color: (
117
+ // color: secondary,
118
+ // shade: 700
119
+ // ),
120
+ // ),
121
+ // secondary: (
122
+ // color: (
123
+ // color: secondary,
124
+ // shade: 700
125
+ // ),
126
+ // ),
127
+ // tertiary: (
128
+ // color: (
129
+ // color: secondary,
130
+ // shade: 700
131
+ // ),
132
+ // ),
133
+ // )
134
+ // ```
135
+ //
136
+ // The icon variants will use the following:
137
+ // - Primary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--secondary--700`,
138
+ // - Secondary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--secondary--700`, and
139
+ // - Tertiary icons will have their `--graupl-icon-color` property set to `--graupl-theme-active--secondary--700`.
140
+
141
+ // @example
142
+ // <span class="icon icon-search" aria-hidden="true"></span>
2
143
 
3
144
  @use "defaults";
4
145
  @use "pkg:@graupl/core/src/defaults" as root-defaults;
5
- @use "pkg:@graupl/core/src/functions/theme";
6
- @use "pkg:@graupl/core/src/theme/color/variables" as color;
7
146
  @use "pkg:@graupl/core/src/mixins/layer" as *;
8
147
  @use "mixins" as *;
9
148
  @use "sass:map";
10
149
 
11
150
  @include layer(component) {
151
+ // .icon
12
152
  #{defaults.$icon-selector-base}#{defaults.$icon-selector} {
13
153
  @include apply-component;
14
154
  }
15
155
 
156
+ // .icon-before
16
157
  #{defaults.$icon-selector-base}#{defaults.$icon-before-selector} {
17
158
  @include apply-component("before");
18
159
  }
19
160
 
161
+ // .icon-after
20
162
  #{defaults.$icon-selector-base}#{defaults.$icon-after-selector} {
21
163
  @include apply-component("after");
22
164
  }
23
165
 
166
+ // .icon, .icon-before, .icon-after
24
167
  #{defaults.$icon-selector-base}#{defaults.$icon-selector},
25
168
  #{defaults.$icon-selector-base}#{defaults.$icon-before-selector},
26
169
  #{defaults.$icon-selector-base}#{defaults.$icon-after-selector} {
27
170
  @each $name, $icon in defaults.$icons {
171
+ // &.[icon-name]
28
172
  &#{defaults.$icon-prefix-selector-base}#{defaults.$icon-prefix-selector}#{$name} {
29
173
  --#{root-defaults.$prefix}icon: #{$icon};
30
174
  }
@@ -33,35 +177,18 @@
33
177
  }
34
178
 
35
179
  @include layer(theme) {
180
+ // .icon
36
181
  #{defaults.$icon-selector-base}#{defaults.$icon-selector} {
37
182
  @include apply-theme;
38
183
  }
39
184
 
185
+ // .icon-before
40
186
  #{defaults.$icon-selector-base}#{defaults.$icon-before-selector} {
41
187
  @include apply-theme("before");
42
188
  }
43
189
 
190
+ // .icon-after
44
191
  #{defaults.$icon-selector-base}#{defaults.$icon-after-selector} {
45
192
  @include apply-theme("after");
46
193
  }
47
-
48
- #{defaults.$icon-selector-base}#{defaults.$icon-selector},
49
- #{defaults.$icon-selector-base}#{defaults.$icon-before-selector},
50
- #{defaults.$icon-selector-base}#{defaults.$icon-after-selector} {
51
- @each $color, $map in theme.get-colors() {
52
- @each $shade, $value in $map {
53
- $name: null;
54
-
55
- @if $shade == "_default" {
56
- $name: #{$color};
57
- } @else {
58
- $name: #{$color}-#{$shade};
59
- }
60
-
61
- &#{defaults.$icon-color-prefix-selector-base}#{defaults.$icon-color-prefix-selector}#{$name} {
62
- --#{root-defaults.$prefix}icon-color: #{$value};
63
- }
64
- }
65
- }
66
- }
67
194
  }
@@ -1,61 +1,67 @@
1
1
  // @graupl/icons icon mixins.
2
2
 
3
+ @use "defaults";
4
+ @use "pkg:@graupl/core/src/defaults" as root-defaults;
5
+ @use "pkg:@graupl/core/src/mixins/state";
6
+ @use "pkg:@graupl/core/src/mixins/theme";
7
+ @use "sass:map";
3
8
  @use "variables" as *;
4
9
 
5
- @mixin _component() {
6
- display: $icon-display;
7
- width: $icon-width;
8
- height: $icon-height;
9
- background-repeat: no-repeat;
10
- background-position: center;
11
- background-size: contain;
12
- vertical-align: sub;
13
- mask-image: $icon;
14
- mask-repeat: no-repeat;
15
- mask-size: contain;
16
- mask-position: center;
17
- }
18
-
19
- @mixin _theme() {
20
- background-color: $icon-color;
21
- }
10
+ $-targets: (
11
+ "self": "&",
12
+ "before": "&::before",
13
+ "after": "&::after",
14
+ );
22
15
 
16
+ /// Mixin to apply component styles for icons.
23
17
  @mixin apply-component($target: "self") {
24
- @if $target == "before" {
25
- &::before {
26
- @include _component;
18
+ #{map.get($-targets, $target)} {
19
+ display: $icon-display;
20
+ width: $icon-width;
21
+ height: $icon-height;
22
+ background-repeat: no-repeat;
23
+ background-position: center;
24
+ background-size: contain;
25
+ vertical-align: sub;
26
+ mask-image: $icon;
27
+ mask-repeat: no-repeat;
28
+ mask-size: contain;
29
+ mask-position: center;
27
30
 
31
+ @if $target == "before" or $target == "after" {
28
32
  content: "";
29
- margin-inline-end: $icon-spacer;
30
33
  }
31
- } @else if $target == "after" {
32
- &::after {
33
- @include _component;
34
-
35
- content: "";
36
- margin-inline-start: $icon-spacer;
37
- }
38
- } @else {
39
- @include _component;
40
-
41
- margin-inline: $icon-spacer $icon-spacer;
42
34
  }
43
35
  }
44
36
 
37
+ /// Mixin to apply theme styles for icons.
45
38
  @mixin apply-theme($target: "self") {
46
- @if $target == "before" {
47
- &::before {
48
- @include _theme;
49
- }
50
- } @else if $target == "after" {
51
- &::after {
52
- @include _theme;
53
- }
54
- } @else {
55
- @include _theme;
39
+ @if root-defaults.$themeable-components and defaults.$themeable {
40
+ @include theme.generate-modifiers(
41
+ defaults.$icon-theme-map,
42
+ defaults.$icon-theme-selector-base,
43
+ defaults.$icon-theme-selector-prefix,
44
+ "icon-"
45
+ );
46
+ }
47
+
48
+ #{map.get($-targets, $target)} {
49
+ background-color: $icon-color;
56
50
  }
57
51
  }
58
52
 
53
+ /// Mixin to bind icon colors to a component.
54
+ ///
55
+ /// @param {CustomProperty} $color - The default color prop for the icon.
56
+ /// @param {Map} $states - A map of states and color props for the icon.
57
+ @mixin bind($color, $states) {
58
+ --#{root-defaults.$prefix}icon-color: #{$color};
59
+
60
+ @include state.generate-modifiers(
61
+ (--#{root-defaults.$prefix}icon-color: $states)
62
+ );
63
+ }
64
+
59
65
  @mixin apply($target: "self") {
60
66
  @include apply-component($target);
61
67
  @include apply-theme($target);
@@ -3,6 +3,17 @@
3
3
  // These values are to be used to directly style components and provide a
4
4
  // cleaner way to reference custom properties.
5
5
 
6
+ // Custom property defaults:
7
+ // | Property | Default |
8
+ // | ------------------------- | ------------------------- |
9
+ // | --graupl-icon-display | inline-block |
10
+ // | --graupl-icon-size | 1.25em |
11
+ // | --graupl-icon-width | var(--graupl-icon-size) |
12
+ // | --graupl-icon-height | var(--graupl-icon-size) |
13
+ // | --graupl-icon-color | var(--graupl-color) |
14
+ // | --graupl-icon | none |
15
+ // | --graupl-icon-spacer | var(--graupl-spacer-2) |
16
+
6
17
  @use "defaults";
7
18
  @use "pkg:@graupl/core/src/defaults" as root-defaults;
8
19
  @use "pkg:@graupl/core/src/theme/color/variables" as color;