Skip to content

Commit 84cb0b1

Browse files
authored
fix: #1490: Make pfe-icon set CSS properties instead of overriding local var (#1491)
1 parent 61ad702 commit 84cb0b1

File tree

8 files changed

+89
-26
lines changed

8 files changed

+89
-26
lines changed

CHANGELOG-1.x.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 1.5.0 (TBD)
22

3-
- [](https://github.com/patternfly/patternfly-elements/commit/) feat: Add CSS variable support for typography & background colors on tabs
3+
- [a1e4b67](https://github.com/patternfly/patternfly-elements/commit/a1e4b67ac012f5987e6cddf2cc7b532a135fa989) feat: Add CSS variable support for typography & background colors on tabs
4+
- [](https://github.com/patternfly/patternfly-elements/commit/) fix: Updated CSS to allow CSS custom properties to override dynamically calculated theme context
45

56
# 1.4.0 (2021-03-30)
67

elements/pfe-icon/demo/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@
125125

126126
<style type="text/css" media="screen">
127127
body {
128-
--pfe-icon--color: orange;
129-
--pfe-icon--context: light;
128+
/* Icon overrides for testing */
129+
/* --pfe-icon--color: orange;
130+
--pfe-icon--context: light; */
130131
}
131132

132133
pfe-band {

elements/pfe-icon/src/pfe-icon.scss

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22
@include pfe-contexts;
33

44
$LOCAL: icon;
5+
56
$LOCAL-VARIABLES: (
67
context: light,
78
size: pfe-var(icon-size),
89
spacing: pfe-var(container-spacer),
9-
color: transparent,
1010
Padding: 0,
1111
BackgroundColor: transparent,
1212
BorderWidth: 0,
13+
// Legacy variable for changing icon color
14+
Color: pfe-broadcasted(text),
1315
);
1416

1517
// Nested internal variables (pfe-local calls), maps cannot "self-reference"
1618
$LOCAL-VARIABLES: map-deep-merge($LOCAL-VARIABLES, (
17-
Color: pfe-local(color, $fallback: pfe-broadcasted(text)),
19+
// Current variable for updating icon color
20+
color: pfe-local(Color),
21+
));
22+
23+
// Nested internal variables (pfe-local calls), maps cannot "self-reference"
24+
$LOCAL-VARIABLES: map-deep-merge($LOCAL-VARIABLES, (
1825
BorderColor: pfe-local(color),
1926
));
2027

@@ -31,15 +38,16 @@ $LOCAL-VARIABLES: map-deep-merge($LOCAL-VARIABLES, (
3138
}
3239

3340
:host {
34-
--context: #{pfe-local(context)};
41+
--context: #{pfe-local(context)};
3542

3643
position: relative;
3744
display: inline-block;
3845

39-
// Supports sizing while preserving aspect ratio (despite layout)
40-
max-width: calc(#{pfe-local(size)} + #{pfe-local(Padding)} * 2);
46+
// Content-box model supports sizing while preserving aspect ratio (despite layout)
47+
box-sizing: content-box!important;
48+
max-width: pfe-local(size);
4149
width: fit-content !important;
42-
max-height: calc(#{pfe-local(size)} + #{pfe-local(Padding)} * 2);
50+
max-height: pfe-local(size);
4351
height: fit-content !important;
4452
line-height: 0;
4553

@@ -83,7 +91,7 @@ $LOCAL-VARIABLES: map-deep-merge($LOCAL-VARIABLES, (
8391
}
8492

8593
filter feFlood {
86-
flood-color: pfe-local(Color);
94+
flood-color: pfe-local(color);
8795
}
8896

8997
.pfe-icon--fallback {
@@ -107,13 +115,26 @@ $sizing: (
107115
// @TODO: Sort out sizing
108116
@each $label, $size in $sizing {
109117
:host([size="#{$label}"]) {
110-
--pfe-icon--size: #{$size};
118+
// Respect var if user set CSS var, but fallback to sizing property map
119+
$desired-size: pfe-local(size, $fallback: $size);
120+
max-width: $desired-size;
121+
max-height: $desired-size;
122+
123+
svg {
124+
width: $desired-size;
125+
height: $desired-size;
126+
}
111127
}
112128
}
113129

114130
@each $level in (critical, important, moderate, success, info, default) {
115131
:host([color="#{$level}"]) {
116-
--pfe-icon--color: #{pfe-var(feedback--#{$level})};
132+
filter feFlood {
133+
flood-color: pfe-local(
134+
color,
135+
$fallback: pfe-var(feedback--#{$level})
136+
);
137+
}
117138
@if $level != "moderate" {
118139
--pfe-icon--context: dark;
119140
}
@@ -122,19 +143,48 @@ $sizing: (
122143

123144
@each $color in (lightest, base, darker, darkest, complement, accent) {
124145
:host([color="#{$color}"]) {
125-
--pfe-icon--color: #{pfe-var(surface--#{$color})};
126146
--pfe-icon--context: #{pfe-var(surface--#{$color}--context)};
147+
148+
filter feFlood {
149+
flood-color: pfe-local(
150+
color,
151+
$fallback: pfe-var(surface--#{$color})
152+
);
153+
}
127154
}
128155
}
129156

130157
// May need Feedback Darkest colors too.
131158

132159
:host([circled]:not([circled="false"])) {
133-
--pfe-icon--BackgroundColor: #{pfe-local(color, $fallback: pfe-var(surface--lightest))};
134-
--pfe-icon--Color: #{pfe-broadcasted(text)};
135-
--pfe-icon--Padding: .5em;
136-
--pfe-icon--BorderWidth: #{pfe-var(ui--border-width)};
137-
--pfe-icon--BorderColor: #{pfe-local(color, $fallback: pfe-var(surface--border))};
160+
padding: pfe-local(Padding, $fallback: .5em);
161+
border-width: pfe-local(BorderWidth, $fallback: pfe-var(ui--border-width));
162+
border-color: pfe-local(color, $fallback: pfe-var(surface--border));
163+
background-color: pfe-local(BackgroundColor, pfe-local(color, $fallback: pfe-var(surface--lightest)));
164+
165+
filter feFlood {
166+
flood-color: pfe-local(color);
167+
}
168+
}
169+
170+
/**
171+
* Override circled items with color set to named property
172+
*/
173+
@each $color in (lightest, base, darker, darkest, complement, accent) {
174+
:host([color=#{$color}][circled]:not([circled="false"])) {
175+
// Respect var if user set CSS var, but fallback to property
176+
$desired-color: pfe-local(color, $fallback: pfe-var(surface--#{$color}));
177+
background-color: $desired-color;
178+
border-color: $desired-color;
179+
}
180+
}
181+
@each $level in (critical, important, moderate, success, info, default) {
182+
:host([color="#{$level}"][circled]:not([circled="false"])) {
183+
// Respect var if user set CSS var, but fallback to property
184+
$desired-color: pfe-local(backgroundColor, $fallback: pfe-var(feedback--#{$level}));
185+
background-color: $desired-color;
186+
border-color: $desired-color;
187+
}
138188
}
139189

140190
:host(.load-failed) svg image {

elements/pfe-icon/test/pfe-icon_test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,25 @@ suite("<pfe-icon>", () => {
101101
// CSS variable.
102102
const newColor = "rgb(11, 12, 13)";
103103

104-
icon.style.setProperty("--pfe-icon--Color", newColor);
104+
icon.style.setProperty("--pfe-icon--color", newColor);
105105

106106
const { floodColor } = getComputedStyle(feFlood);
107107

108108
assert.equal(floodColor, newColor);
109+
icon.style.removeProperty("--pfe-broadcasted--text");
110+
});
111+
112+
test("it should change color when pfe-icon's LEGACY color CSS var is changed", () => {
113+
// we can't get the exact color of the image, but we can make sure
114+
// the feFlood element is getting `flood-color` from the appropriate
115+
// CSS variable.
116+
const newColor = "rgb(11, 12, 13)";
117+
118+
icon.style.setProperty("--pfe-icon--Color", newColor);
109119

120+
const { floodColor } = getComputedStyle(feFlood);
121+
122+
assert.equal(floodColor, newColor);
110123
icon.style.removeProperty("--pfe-broadcasted--text");
111124
});
112125

@@ -119,7 +132,6 @@ suite("<pfe-icon>", () => {
119132
icon.style.setProperty("--pfe-broadcasted--text", newColor);
120133

121134
const { floodColor } = getComputedStyle(feFlood);
122-
123135
assert.equal(floodColor, newColor);
124136

125137
icon.style.removeProperty("--pfe-broadcasted--text");
@@ -135,7 +147,6 @@ suite("<pfe-icon>", () => {
135147
await new Promise(resolve => {
136148
flush(() => {
137149
const { width, height } = icon.getBoundingClientRect();
138-
debugger;
139150
assert.isAbove(width, lastSize.width, `size "${size}" should be wider than the size below`);
140151
assert.isAbove(height, lastSize.height, `size "${size}" should be taller than the size below`);
141152
lastSize = { width, height };

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
3.16 KB
Loading
-173 Bytes
Loading
21.9 KB
Loading

0 commit comments

Comments
 (0)