diff --git a/CHANGELOG-prerelease.md b/CHANGELOG-prerelease.md
index c230492f5e..cac92af43c 100644
--- a/CHANGELOG-prerelease.md
+++ b/CHANGELOG-prerelease.md
@@ -2,8 +2,8 @@
Tag: [v1.0.0-prerelease.42](https://github.com/patternfly/patternfly-elements/releases/tag/v1.0.0-prerelease.42)
-- [](https://github.com/patternfly/patternfly-elements/commit/) fix: set consistent line-height for pfe-nav triggers (#773)
-
+- [fbc251b](https://github.com/patternfly/patternfly-elements/commit/fbc251b5180684da26a57c0941235d57f961990e) fix: set consistent line-height for pfe-nav triggers (#773)
+- [](https://github.com/patternfly/patternfly-elements/commit/) feat: adding event to pfe-cta component
## Prerelease 41 ( 2020-03-19 )
diff --git a/elements/pfe-cta/README.md b/elements/pfe-cta/README.md
index 4b2c68bc4b..db217e9991 100644
--- a/elements/pfe-cta/README.md
+++ b/elements/pfe-cta/README.md
@@ -131,6 +131,12 @@ If you'd like to checkout how theming is possible using our CSS Var hooks, try a
```
+## Events
+
+### pfe-cta:select
+
+This event is fired when a link is clicked and serves as a way to capture click events if necessary.
+
## Test
npm run test
diff --git a/elements/pfe-cta/demo/demo.css b/elements/pfe-cta/demo/demo.css
index 3db48df844..56a142d9af 100644
--- a/elements/pfe-cta/demo/demo.css
+++ b/elements/pfe-cta/demo/demo.css
@@ -3,11 +3,6 @@ h2 {
margin: 15px 0 10px;
}
-hr {
- border-bottom: 1px solid #ddd;
- width: 100%;
-}
-
pfe-band {
--pfe-band--Padding--horizontal: 60px;
--pfe-band--Width: 100%;
@@ -17,42 +12,91 @@ pfe-band[pfe-color="lightest"] pfe-card[pfe-color="lightest"] {
--pfe-card--Border: 1px solid rgba(45, 45, 45, 0.3);
}
+.default-link-test {
+ display: flex;
+ flex-flow: row nowrap;
+ border: 1px solid #ddd;
+ width: 305px;
+ padding: 10px;
+}
+
.resize {
resize: horizontal;
overflow: auto;
- border: 1px solid #ddd;
- width: 700px;
- padding: 10px;
}
-.resize>pfe-cta:first-child {
+.resize > pfe-cta:first-child {
margin-right: 20px;
}
+.cta-layout,
.card-layout {
display: flex;
flex-flow: row wrap;
- display: grid;
- grid-gap: 10px;
- grid-template-columns: repeat(auto-fit, minmax(100px, max-content));
margin-top: -10px;
margin-left: -20px;
+ @supports (display: grid) {
+ display: grid;
+ grid-row-gap: 10px;
+ grid-column-gap: 20px;
+ grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
+ margin-top: 0;
+ margin-left: 0;
+ }
+}
+
+.cta-layout > *:not([class~="layout"]),
+.card-layout .cta-align > * {
+ margin-top: 10px;
+ margin-left: 20px;
+ @supports (display: grid) {
+ margin-top: 0;
+ margin-left: 0;
+ }
}
-.card-layout>pfe-cta,
-.card-layout .cta-align>pfe-cta {
+.card-layout > *:not([class~="layout"]) {
+ width: min-content;
+ min-width: 350px;
+ flex-grow: 1;
margin-top: 10px;
margin-left: 20px;
}
+.cta-layout {
+ grid-template-columns: repeat(auto-fit, minmax(max-content, 1fr));
+}
+
+.event-registry {
+ flex-grow: 1;
+ display: flex;
+ align-items: center;
+ font-size: var(--pfe-theme--font-size--zeta, 14px);
+}
+
+.event-registry span {
+ display: inline-block;
+ padding: 5px 10px;
+}
+
+.event-registry pfe-icon {
+ --pfe-icon--Color: #444;
+ float: left;
+}
+
+.event-registry pfe-icon:not([on="light"]) {
+ --pfe-icon--Color: #fff;
+ float: left;
+}
+
.custom-dark-band {
- padding: 60px 15px;
+ padding: 15px;
background: #222;
--theme: dark;
}
.custom-saturated-band {
- padding: 60px 15px;
+ padding: 15px;
background: #0c8488;
--theme: saturated;
-}
\ No newline at end of file
+}
diff --git a/elements/pfe-cta/demo/index.html b/elements/pfe-cta/demo/index.html
index c3d885f05e..e9ce3edc6d 100644
--- a/elements/pfe-cta/demo/index.html
+++ b/elements/pfe-cta/demo/index.html
@@ -1,306 +1,325 @@
+
+
+
+ PatternFly Elements: pfe-cta demo
-
-
-
- PatternFly Elements: pfe-cta demo
-
-
-
-
-
+
+
+
-
+
-
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+ <pfe-cta> demo page
+
-
-
- <pfe-cta> demo page
-
+
+ CTAs in light containers
+
+
+ No color attribute
+
+
+
+
+ pfe-color="base"
+
+
+
+
+ pfe-color="accent"
+
+
+
+
+ pfe-color="complement"
+
+
+
+
+
-
- CTAs in light containers
-
-
- No color attribute
-
-
-
- pfe-color="base"
-
-
-
- pfe-color="accent"
-
-
-
- pfe-color="complement"
-
-
-
+
+ CTAs in dark containers
+
+
+ No color attribute
+
+
+
+
+ pfe-color="base"
+
+
+
+
+ pfe-color="accent"
+
+
+
+
+ pfe-color="complement"
+
+
+
+
+
-
-
-
+
+ CTAs in saturated containers
+
+
+ No color attribute
+
+
+
+
+ pfe-color="base"
+
+
+
+
+ pfe-color="accent"
+
+
+
+
+ pfe-color="complement"
+
+
+
+
+
- CTAs in dark containers
-
-
- No color attribute
-
-
-
- pfe-color="base"
-
-
-
- pfe-color="accent"
-
-
-
- pfe-color="complement"
-
-
-
+
+ Force wrap to test arrow line-wrap
+
+
-
-
-
+
+ Link and button styles (displayed inline)
+
+
Link
+
-
CTAs in saturated containers
-
-
- No color attribute
-
-
-
- pfe-color="base"
-
-
-
- pfe-color="accent"
-
-
-
- pfe-color="complement"
-
-
-
-
-
-
-
-
-
Force wrap to test arrow line-wrap
-
+
Link
+
-
-
-
+
Link
+
-
Link and button styles (displayed inline)
-
+
-
Link
-
+
+ Old school testing (custom backgrounds)
- Link
-
+
+
Custom saturated band with broadcast vars
-
Link
-
-
-
+
Color responsive
+
-
-
-
+
-
Old school testing (custom backgrounds)
-
+
Color override
+
+
-
-
Custom saturated band with broadcast vars
+
+
+ Custom dark band with custom broadcast variables
+
-
Color responsive
-
+
Color responsive
+
-
+
-
Color override
-
-
+
Color override
+
+
+
-
-
- Custom dark band with custom broadcast variables
-
+
+
+
diff --git a/elements/pfe-cta/src/pfe-cta.html b/elements/pfe-cta/src/pfe-cta.html
index 26e58a523b..0b7e0777f4 100644
--- a/elements/pfe-cta/src/pfe-cta.html
+++ b/elements/pfe-cta/src/pfe-cta.html
@@ -1,13 +1,4 @@
- ${this.defaultStyle ? ` ` : ``}
+ ${this.isDefault ? ` ` : ``}
diff --git a/elements/pfe-cta/src/pfe-cta.js b/elements/pfe-cta/src/pfe-cta.js
index f8a54f1d43..c368ac3dbf 100644
--- a/elements/pfe-cta/src/pfe-cta.js
+++ b/elements/pfe-cta/src/pfe-cta.js
@@ -17,7 +17,7 @@ class PfeCta extends PFElement {
return "pfe-cta.json";
}
- get defaultStyle() {
+ get isDefault() {
return this.hasAttribute("pfe-priority") ? false : true;
}
@@ -26,10 +26,24 @@ class PfeCta extends PFElement {
return PFElement.PfeTypes.Content;
}
+ static get events() {
+ return {
+ select: `${this.tag}:select`
+ };
+ }
+
static get observedAttributes() {
return ["pfe-priority", "pfe-color", "pfe-variant"];
}
+ click(event) {
+ this.emitEvent(PfeCta.events.select, {
+ detail: Object.assign(this.data, {
+ originEvent: event
+ })
+ });
+ }
+
constructor() {
super(PfeCta);
this.cta = null;
@@ -37,6 +51,8 @@ class PfeCta extends PFElement {
this._init = this._init.bind(this);
this._focusHandler = this._focusHandler.bind(this);
this._blurHandler = this._blurHandler.bind(this);
+ this._clickHandler = this._clickHandler.bind(this);
+ this._keyupHandler = this._keyupHandler.bind(this);
}
connectedCallback() {
@@ -61,6 +77,8 @@ class PfeCta extends PFElement {
if (this.cta) {
this.cta.removeEventListener("focus", this._focusHandler);
this.cta.removeEventListener("blur", this._blurHandler);
+ this.cta.removeEventListener("click", this._clickHandler);
+ this.cta.removeEventListener("keyup", this._keyupHandler);
}
}
@@ -79,26 +97,24 @@ class PfeCta extends PFElement {
// Initialize the component
_init() {
- // Get the first child of the web component (light DOM)
- const firstChild = this.children[0];
const supportedTags = ["a", "button"]; // add input later
let supportedTag = false;
// If the first child does not exist or that child is not a supported tag
- if (firstChild) {
+ if (this.firstElementChild) {
supportedTags.forEach(tag => {
- if (firstChild.tagName.toLowerCase() === tag) {
+ if (this.firstElementChild.tagName.toLowerCase() === tag) {
supportedTag = true;
}
});
}
- if (!firstChild || !supportedTag) {
+ if (!this.firstElementChild || !supportedTag) {
console.warn(
`${PfeCta.tag}: The first child in the light DOM must be a supported call-to-action tag (
,