Skip to content

Commit

Permalink
deploy: a6ca398
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Oct 10, 2023
1 parent e57fa17 commit df5d460
Show file tree
Hide file tree
Showing 26 changed files with 1,059 additions and 610 deletions.
9 changes: 9 additions & 0 deletions assets/dsd-polyfill.js
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);
68 changes: 59 additions & 9 deletions assets/packages/@rhds/elements/elements/rh-cta/demo/analytics.html
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>&lt;rh-cta></code> elements are parsed by a
<p>In this demo, analytics events involving <code>&lt;rh-cta></code> elements are parsed by a
document-level analytics event listener. Unlike <code>&lt;pfe-cta></code>, which implemented
support for analytics internally, <code>&lt;rh-cta></code> users must implement their own
analytics code, taking this demo as an example.</p>
Expand Down Expand Up @@ -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 assets/packages/@rhds/elements/elements/rh-cta/demo/analytics.js

This file was deleted.

20 changes: 20 additions & 0 deletions assets/packages/@rhds/elements/elements/rh-cta/demo/brick.html
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 assets/packages/@rhds/elements/elements/rh-cta/demo/button.html
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>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<rh-context-picker target="dark"></rh-context-picker>

<rh-context-provider id="dark" color-palette="darkest">
<h2>Dark Colour Context</h2>
<rh-cta><a href="#default">Default</a></rh-cta>
<rh-cta icon="circle-play"><a href="#default-video">Default Video</a></rh-cta>
<rh-cta variant="primary"><a href="#primary">Primary</a></rh-cta>
Expand All @@ -10,11 +10,22 @@ <h2>Dark Colour Context</h2>
<rh-cta variant="brick" icon="circle-play"><a href="#brick-video">Brick Video</a></rh-cta>
</rh-context-provider>

<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">
<script type="module" src="rh-cta.js"></script>
<script type="module">
import '@rhds/elements/lib/elements/rh-context-picker/rh-context-picker.js';
import '@rhds/elements/rh-cta/rh-cta.js';
import '@rhds/elements/lib/elements/rh-context-picker/rh-context-picker.js';
import '@rhds/elements/lib/elements/rh-context-provider/rh-context-provider.js';
</script>


<style>

rh-context-provider {
display: flex;
flex-flow: row wrap;
gap: 16px;
padding: 1em 2em;
margin-inline: -2em;
margin-block: 1em;
}

</style>
56 changes: 0 additions & 56 deletions assets/packages/@rhds/elements/elements/rh-cta/demo/demo.css

This file was deleted.

Loading

0 comments on commit df5d460

Please sign in to comment.