Skip to content

Commit daf5ca0

Browse files
castastrophekylebuch8
authored andcommitted
pfe-cta bug fixes + open brand styles (#353)
* CTA bug fixes; variable adjustments, remove !importants * Working on tests for pfe-cta * Pull out hide-show component * Update the tests * US212681 added focus state mixin; updated padding * US212681 reset CTA primary and secondary padding * PFE-CTA bug: switched ui-accent color variable. * Update color variable * US212681 pfe-cta focus styles * US212681 removed iconfont from cta, applied logic to display arrow svg for default CTAs * US212681 fixed on dark variants for default, primary and secondary * US212681 fixed primary cta bg hover color, commented out alt styles * US212681 set complement and base styles to map to alt variants * US212681 reverted color var changes * US212681 fixed secondary focus state, fixed default focus and hover states * US212681 refactored color vars for pfe-ctas. * US212681 added alt versions for primary and secondary * US212681 removed on=dark from demo; provided broadcast var overrides * US212681 shifted bg color styles to the host, applied focus-within and hover styles to the host. * US212681 override broadcast variables for secondary cta hover states. * US212681 removed non-default focus outline, applied all padding to slotted a. * US212681 moved before pseudo element to the slotted a on focus-within * US212681 overrode broadcast color var for secondary links when hover is on host and focus is on a. * Playing with how styles are applied * US212681 fixed focus state styles. * US212681 fixed default hover issue: color--hover to slotted(a) on host hover. * US212681 added important flag to hover color custom property * US212681 applied broadcast overrides to fix hover bug * US212681 added the !important flag on link hover, fixed secondary "active" color states. * US212681 set outline on focus states to none !important. * pfe-cta-broadcast-updates - remove function in pfe-band.js and pfe-card.js that adds on=dark to CTAs - set broadcast interruption once in the middle of the CTA color vars map, only to be overridden by color attributes * pfe-cta-broadcast-updates - adjust arrow placement so its inline, and so that it doesnt move things around it on hover * fix layouts * - remove updateContext functions from band & card - set theme-complement as blue inside of pfe-cta in the demo file - more demo file tweaks - remove color="alt" , we are just using color=complement * pfe-cta-broadcast-updates Add docs about broadcasted vars * pfe-cta-broadcast-updates tidy comments * US212681 simplified alt ctas * pfe-cta-broadcast-updates Tidy demo file, update complement hover fallback color to match link blue * pfe-cta-broadcast-updates fix closing paren * remove fallback-only function (unused) * pfe-cta-broadcast-updates - update font family, fix secondary focus color, add primary lightest * US212681 revert alt changes * Update package-lock * Add a focus event and blur event to attach the class to the element * Hardening the approach to attaching the focus state class * updated README documentation * US212681 fix cta test to match warning. * pfe-cta-bug-fixes remove "base" from storybook demos * Add polyfill for the includes statement * Add schema to JS * fixing the connectedCallback so it only runs this._init if there are children * removing the .includes polyfill We need to work on removing the polyfills from our code and start relying them on a more global level. * changing the link property to a cta property For some reason the link property is no longer available. However, using the cta property seems to fix the test. * making the supported tags a bit more readable in the code * Add comments and wrap event listeners in element checks * Remove duplciate event listener attachment * Move the event attachment to the init * Remove this._slot check; no necessito * Add back the attributeChangedCallback * pfe-cta-bug-fixes add support for fallback and legacy styles * pfe-cta-bug-fixes remove spaces, cleanup debug code * pfe-cta-bug-fixes remove unnecessary interpolation syntax, spacing cleanup, and use color function instead of fallback, * pfe-cta-bug-fixes Add support for link in the light dom for edge & ie11, add back interpolation syntax, add IE11 overrides for card & band * pfe-cta-bug-fixes update attributes to have pfe- prefix * update schema with correct values; update transition property so it only applies to padding, update docs, remove lerna version upgrade * Sass cleanup: group hover & focus styles since those colors appear together on the page. Adjusted slotted states + host states * spacing cleanup * ie11 hacks * remove card/band stuff * reset band demo * Update docs * revert dependeny update * updated package-lock * Fix JS reference to pfe-priority (fixes arrow showing up on buttons); switch from using surface colors to ui-colors - this solves our color issue without needing updates to our theme. * Remove deprecated on="dark" * Pull back unnecessary pfe-band.html updates; clean up readme reference * Fix typo in card padding variable name * Tidy up storybook * Resolve typos in pfe-cta--lightdom stylesheet * Comment out unused code from the test file * US212681 set pfe-color attributes to match their theme variable names. * US212681 set secondary color styles to map to ui-complement. * US212681 set secondary hover to surface--lighter * US212681 added secondary pfe-color=lightest variant * US212681 applied pale gray bg to all bg focus states for secondary * US212681 adjusted focus background for alt secondary ctas * pfe-cta-bug-fixes revert package-lock.json * US212681 removed nav and link-list from examples index file * US212678 added base option to pfe-color in storybook. * US212681 added pfe-color="base" cta styles to at a glance. * pfe-cta-bug-fixes revert changes to pfe-cta.js export
1 parent efd115b commit daf5ca0

File tree

20 files changed

+8522
-7180
lines changed

20 files changed

+8522
-7180
lines changed

elements/pfe-band/src/pfe-band.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ class PfeBand extends PFElement {
143143
if (this.imageSrc) {
144144
this._imgSrcChanged("pfe-img-src", "", this.imageSrc);
145145
}
146-
// Initialize the context setting for the children elements
147-
if (this.backgroundColor) {
148-
this._updateContext(this.backgroundColor);
149-
}
146+
150147
}
151148

152149
attributeChangedCallback(attr, oldValue, newValue) {
@@ -169,8 +166,7 @@ class PfeBand extends PFElement {
169166
// Update the color attribute and contexts
170167
_colorChanged(attr, oldValue, newValue) {
171168
this[attr].value = newValue;
172-
// If the new value has a dark background, update children elements
173-
this._updateContext(newValue);
169+
174170
}
175171

176172
// Update the background image
@@ -179,20 +175,7 @@ class PfeBand extends PFElement {
179175
this.style.backgroundImage = newValue ? `url('${newValue}')` : ``;
180176
}
181177

182-
// Set the children's context if parent background is dark
183-
_updateContext(context) {
184-
if (["darkest", "darker", "complement", "accent"].includes(context)) {
185-
["pfe-cta"].forEach(elementName => {
186-
const els = [...this.querySelectorAll(`${elementName}`)];
187-
els.forEach(el => {
188-
const myContainer = el.closest("[pfe-type=container]");
189-
if (myContainer === this || myContainer === null) {
190-
el.setAttribute("on", "dark");
191-
}
192-
});
193-
});
194-
}
195-
}
178+
196179
}
197180

198181
PFElement.create(PfeBand);

elements/pfe-card/demo/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>PFElements: pfe-card Demo</title>
7-
87
<!-- uncomment the es5-adapter if you're using the umd version -->
98
<script src="/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
109
<script src="/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
@@ -78,7 +77,7 @@ <h2 slot="pfe-card--header">Light card</h2>
7877
<a href="#">Learn more</a>
7978
</pfe-cta>
8079
</pfe-card>
81-
80+
8281
<pfe-card>
8382
<h2 slot="pfe-card--header">Default card</h2>
8483
Unwrapped item. This is the default pfe-card and <a href="#">a link</a>.

elements/pfe-card/src/pfe-card.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ class PfeCard extends PFElement {
127127
if (this.imageSrc) {
128128
this._imgSrcChanged("pfe-img-src", "", this.imageSrc);
129129
}
130-
// Initialize the context setting for the children elements
131-
if (this.backgroundColor) {
132-
this._updateContext(this.backgroundColor);
133-
}
134130

135131
this._observer.observe(this, { childList: true });
136132
}
@@ -159,8 +155,7 @@ class PfeCard extends PFElement {
159155
// Update the color attribute and contexts
160156
_colorChanged(attr, oldValue, newValue) {
161157
this[attr].value = newValue;
162-
// If the new value has a dark background, update children elements
163-
this._updateContext(newValue);
158+
164159
}
165160

166161
// Update the background image
@@ -169,22 +164,6 @@ class PfeCard extends PFElement {
169164
this.style.backgroundImage = newValue ? `url('${newValue}')` : ``;
170165
}
171166

172-
// Set the children's context if parent background is dark
173-
_updateContext(context) {
174-
if (
175-
["darkest", "darker", "dark", "complement", "accent"].includes(context)
176-
) {
177-
["pfe-cta"].forEach(elementName => {
178-
const els = [...this.querySelectorAll(`${elementName}`)];
179-
els.forEach(el => {
180-
const myContainer = el.closest("[pfe-type=container]");
181-
if (myContainer === this || myContainer === null) {
182-
el.setAttribute("on", "dark");
183-
}
184-
});
185-
});
186-
}
187-
}
188167
}
189168

190169
PFElement.create(PfeCard);

elements/pfe-cta/README.md

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# WIP 🐣: PFElements CTA Element
1+
# PFElements Call-to-action Element
22

33
`pfe-cta` is a call-to-action (CTA) element, that stands out from regular hypertext links, and is used for linking users to webpages.
44

@@ -10,11 +10,19 @@ _Note: `pfe-cta` is not a button, though it may look like one visually._
1010
<a href="https://github.com/">GitHub</a>
1111
</pfe-cta>
1212

13-
<pfe-cta priority="primary">
13+
<pfe-cta pfe-priority="primary">
1414
<a href="https://pfelements.github.io/">Learn more about PFElements</a>
1515
</pfe-cta>
1616

17-
<pfe-cta priority="secondary">
17+
<pfe-cta pfe-priority="secondary">
18+
<a href="https://redhat.com/">Red Hat</a>
19+
</pfe-cta>
20+
21+
<pfe-cta pfe-priority="primary" pfe-color="lightest">
22+
<a href="https://pfelements.github.io/">Learn more about PFElements</a>
23+
</pfe-cta>
24+
25+
<pfe-cta pfe-priority="secondary" pfe-color="complement">
1826
<a href="https://redhat.com/">Red Hat</a>
1927
</pfe-cta>
2028
```
@@ -25,23 +33,33 @@ _Note: `pfe-cta` is not a button, though it may look like one visually._
2533

2634
We expect an anchor tag, `<a>` with an `href`, to be the first child inside `pfe-cta` element.
2735

28-
## Styling
29-
30-
| Theme Var Hook | Description | Default |
31-
| -------------- | ----------- | ------- |
32-
| `--pfe-theme--color--ui-link` | Link color for default CTA | $pfe-color--ui-link |
33-
| `--pfe-theme--color--ui-link--hover` | Hover color for default CTA | $pfe-color--ui-link--hover |
34-
| `--pfe-theme--color--ui-link--focus` | Focus color for default CTA | $pfe-color--ui-link--focus |
35-
| `--pfe-theme--color--ui-accent` | Color for Primary CTA | $pfe-color--ui-accent |
36-
| `--pfe-theme--color--ui-accent--hover` | Hover color for Primary CTA | $pfe-color--ui-accent--hover |
37-
| `--pfe-theme--color--ui-accent--text` | Text color for Primary CTA | $pfe-color--ui-accent--text |
38-
| `--pfe-theme--color--ui-accent--text--hover` | Hover text color for Primary CTA | $pfe-color--ui-accent--text--hover |
39-
| `--pfe-theme--color--ui-base` | Border & text color for Secondary CTA | $pfe-color--ui-base |
40-
| `--pfe-theme--color--ui-base--hover` | Hover color for Secondary CTA | $pfe-color--ui-base--hover |
41-
| `--pfe-theme--color--ui-base--text` | Background color for Secondary CTA | $pfe-color--ui-base--text |
42-
| `--pfe-theme--color--ui-base--text--hover` | Hover text color for Secondary CTA | $pfe-color--ui-base--text--hover |
43-
| `--pfe-theme--color--text--on-dark` | Link color for default CTA with `on="dark"` | $pfe-color--text--on-dark |
44-
| `--pfe-theme--color--ui-link--on-dark--hover` | Hover color for default CTA with `on="dark"` | $pfe-color--ui-link--on-dark--hover |
36+
## Styling approach
37+
38+
```
39+
// 1. set up local vars equal to theme vars & fallbacks
40+
:host {
41+
--pfe-cta--Color: var(--pfe-theme--ui-link, #06c);
42+
}
43+
44+
// 2. Use color property once, map to local var value
45+
:host(:not([priority]) {
46+
::slotted(a) {
47+
//color: blue; CSS compiler will print this for IE11
48+
color: var(--pfe-cta--Color, blue) !important;
49+
}
50+
}
51+
52+
// 3. Use broadcasted variables as needed, with theme fallback after other declarations
53+
:host {
54+
--pfe-cta--Color: var(--pfe-broadcasted--ui-link, var(--pfe-theme--ui-link, #06c));
55+
}
56+
57+
// 4. Override broadcasted last
58+
[color="accent"] {
59+
--pfe-cta--Color: var(--pfe-theme--ui-accent);
60+
}
61+
```
62+
4563

4664
### Testing Theme Var Hooks
4765

@@ -50,10 +68,9 @@ If you'd like to checkout how theming is possible using our CSS Var hooks, try a
5068
```html
5169
<style>
5270
:root {
53-
--pfe-theme--color--ui-accent: green;
54-
--pfe-theme--color--ui-accent--hover: darkgreen;
55-
--pfe-theme--color--ui-accent--text: white;
56-
--pfe-theme--color--ui-accent--text--hover: white;
71+
--pfe-theme--color--ui-accent: green;
72+
--pfe-theme--color--ui-accent--hover: darkgreen;
73+
--pfe-theme--color--ui-accent--text: white;
5774
}
5875
</style>
5976
```

elements/pfe-cta/demo/demo.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
body {
3+
margin: 0;
4+
}
5+
6+
h1,
7+
h2,
8+
h3,
9+
p {
10+
font-family: var(--pfe-theme--font-family, "Overpass", Overpass, Helvetica, helvetica, arial, sans-serif);
11+
}
12+
13+
h1,
14+
h2 {
15+
margin: 15px 0 10px;
16+
}
17+
18+
pfe-band {
19+
--pfe-band--Padding--horizontal: 60px;
20+
--pfe-band--Width: 100%;
21+
}
22+
23+
pfe-card {
24+
display: grid;
25+
grid-gap: 15px;
26+
--pfe-card--Padding: 10px;
27+
}
28+
29+
pfe-cta {
30+
margin-top: 10px;
31+
margin-left: 20px;
32+
}
33+
34+
.force-wrap {
35+
max-width: 100px;
36+
}
37+
38+
.card-layout {
39+
display: grid;
40+
grid-gap: 10px;
41+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
42+
}
43+
44+
a {
45+
color: #2290ff;
46+
}
47+
48+
.custom-dark-band {
49+
padding: 60px 15px;
50+
background: #222;
51+
--pfe-broadcasted--color--text: var(--pfe-theme--color--text--on-dark, yellow);
52+
--pfe-broadcasted--color--ui-link: var(--pfe-theme--color--ui-link--on-dark, red);
53+
--pfe-broadcasted--color--ui-link--hover: var(--pfe-theme--color--ui-link--on-dark--hover, orange);
54+
--pfe-broadcasted--color--ui-link--visited: var(--pfe-theme--color--ui-link--on-dark--visited, pink);
55+
--pfe-broadcasted--color--ui-link--focus: var(--pfe-theme--color--ui-link--on-dark--focus, orange);
56+
}
57+
58+
.custom-light-band {
59+
padding: 60px 15px;
60+
background: #cce7e8;
61+
}
62+
63+
.custom-on-dark-band {
64+
padding: 30px 15px;
65+
background: #0d053e;
66+
}

0 commit comments

Comments
 (0)