-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e57fa17
commit df5d460
Showing
26 changed files
with
1,059 additions
and
610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(function attachShadowRoots(root) { | ||
root.querySelectorAll('template[shadowrootmode]').forEach(template => { | ||
const mode = template.getAttribute('shadowrootmode'); | ||
const shadowRoot = template.parentNode.attachShadow({ mode }); | ||
shadowRoot.appendChild(template.content); | ||
template.remove(); | ||
attachShadowRoots(shadowRoot); | ||
}); | ||
})(document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
<link rel="stylesheet" href="https://static.redhat.com/libs/redhat/redhat-font/4/webfonts/red-hat-font.min.css"> | ||
<link rel="stylesheet" href="https://static.redhat.com/libs/redhat/redhat-theme/6/advanced-theme.css"> | ||
<link rel="stylesheet" href="demo.css"> | ||
<link rel="stylesheet" href="/assets/prism.css"> | ||
|
||
<script type="module" src="rh-cta.js"></script> | ||
<script type="module" src="analytics.js"></script> | ||
|
||
<p>In this demo, analytics events involving <code><rh-cta></code> elements are parsed by a | ||
<p>In this demo, analytics events involving <code><rh-cta></code> elements are parsed by a | ||
document-level analytics event listener. Unlike <code><pfe-cta></code>, which implemented | ||
support for analytics internally, <code><rh-cta></code> users must implement their own | ||
analytics code, taking this demo as an example.</p> | ||
|
@@ -64,3 +56,61 @@ <h2>Complex Case: Slotted Link, Deep CTA Analytics</h2> | |
|
||
<h2>Last CTA Analytics Event</h2> | ||
<json-viewer>{}</json-viewer> | ||
|
||
<link rel="stylesheet" href="https://static.redhat.com/libs/redhat/redhat-font/4/webfonts/red-hat-font.min.css"> | ||
<link rel="stylesheet" href="https://static.redhat.com/libs/redhat/redhat-theme/6/advanced-theme.css"> | ||
<link rel="stylesheet" href="/assets/prism.css"> | ||
|
||
<style> | ||
json-viewer { | ||
--json-viewer-background: white; | ||
--json-viewer-boolean-color: #f76707; | ||
--json-viewer-color: black; | ||
--json-viewer-key-color: #f76707; | ||
--json-viewer-null-color: Light #e03131; | ||
--json-viewer-number-color: #0ca678; | ||
--json-viewer-string-color: #0c8599; | ||
} | ||
</style> | ||
|
||
<script type="module"> | ||
import '@rhds/elements/rh-cta/rh-cta.js'; | ||
import 'https://ga.jspm.io/npm:[email protected]/prism.js'; | ||
import 'https://ga.jspm.io/npm:[email protected]/plugins/autoloader/prism-autoloader.js'; | ||
import 'https://ga.jspm.io/npm:@power-elements/[email protected]/json-viewer.js'; | ||
|
||
customElements.define('slotted-link', class SlottedLinkElement extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }).innerHTML = /* html */` | ||
<rh-cta><slot name="default"></slot></rh-cta> | ||
<rh-cta variant="primary"><slot name="primary"></slot></rh-cta> | ||
<rh-cta variant="secondary"><slot name="secondary"></slot></rh-cta> | ||
<rh-cta variant="brick"><slot name="brick"></slot></rh-cta> | ||
`; | ||
} | ||
}); | ||
|
||
function deepClosest(event, selector) { | ||
for (const node of event.composedPath().reverse()) { | ||
if (node.matches?.(selector)) { | ||
return node; | ||
} | ||
} | ||
return event.target.closest(selector); | ||
} | ||
|
||
document.addEventListener('click', function(event) { | ||
const cta = deepClosest(event, 'rh-cta'); | ||
if (cta) { | ||
const { href, text, title } = cta.cta; | ||
const color = cta.colorPalette; | ||
const type = cta.variant ?? 'default'; | ||
const data = { href, text, title, color, type }; | ||
// for the purposes of the demo, let's enable console logging here | ||
// eslint-disable-next-line no-console | ||
console.log('CTA ANALYTICS EVENT', data); | ||
document.querySelector('json-viewer').object = data; | ||
} | ||
}); | ||
</script> |
38 changes: 0 additions & 38 deletions
38
assets/packages/@rhds/elements/elements/rh-cta/demo/analytics.js
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
assets/packages/@rhds/elements/elements/rh-cta/demo/brick.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div id="grid"> | ||
<rh-cta variant="brick"><a href="#">Link #1</a></rh-cta> | ||
<rh-cta variant="brick"><a href="#">Link #2</a></rh-cta> | ||
<rh-cta variant="brick"><a href="#">Link #3</a></rh-cta> | ||
<rh-cta variant="brick"> | ||
<a href="#default">Supercalifragilisticexpialidocious</a> | ||
</rh-cta> | ||
</div> | ||
|
||
<script type="module"> | ||
import '@rhds/elements/rh-cta/rh-cta.js'; | ||
</script> | ||
|
||
<style> | ||
#grid { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
gap: 1rem; | ||
} | ||
</style> |
46 changes: 46 additions & 0 deletions
46
assets/packages/@rhds/elements/elements/rh-cta/demo/button.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<section> | ||
<h2>Links</h2> | ||
<rh-cta> | ||
<a href="#">Link</a> | ||
</rh-cta> | ||
|
||
<rh-cta variant="primary"> | ||
<a href="#">Link</a> | ||
</rh-cta> | ||
|
||
<rh-cta variant="secondary"> | ||
<a href="#">Link</a> | ||
</rh-cta> | ||
</section> | ||
|
||
<section> | ||
<h2>Buttons</h2> | ||
<rh-cta> | ||
<button>Button</button> | ||
</rh-cta> | ||
|
||
<rh-cta variant="primary"> | ||
<button>Button</button> | ||
</rh-cta> | ||
|
||
<rh-cta variant="secondary"> | ||
<button>Button</button> | ||
</rh-cta> | ||
</section> | ||
|
||
<script type="module"> | ||
import '@rhds/elements/rh-cta/rh-cta.js'; | ||
</script> | ||
|
||
<style> | ||
section { | ||
display: grid; | ||
gap: var(--rh-space-md, 8px) var(--rh-space-xl, 24px); | ||
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); | ||
padding: var(--rh-space-lg, 16px); | ||
} | ||
|
||
h2 { | ||
grid-column: -1/1; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
assets/packages/@rhds/elements/elements/rh-cta/demo/demo.css
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.