Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send GA event when toggling AND send events on interaction #256

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions contents/components/radio-buttons.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,30 @@ <h3>Selected / Unselected</h3>
<div class="cf nr2 nl2 mb3">
<div class="fl-ns w-50-ns ph2">
<img src="../images/components/radio-buttons/radiobutton-states.svg" alt="Example of a selected and an unselected radio button." id="showImage" style="height:202px;">
<iframe class="db w-100" height="202.5" src="https://designakt.github.io/PDS/components/radio-buttons/behavior.html" allowfullscreen="allowfullscreen" frameborder="0" id="showExample" style="display: none; margin-bottom: 15px;"></iframe>
<small class="db grey-50 mb3 mb0-ns">
<a href="#" onclick="document.getElementById('showImage').style.display='block';
document.getElementById('showExample').style.display='none';
return false;">Image</a> /
<a href="#" onclick="document.getElementById('showImage').style.display='none';
document.getElementById('showExample').style.display='block';
return false;">Interactive example</a> (Currently only renders correctly in Firefox.)
</small>
<div class='interactive'>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it should probably be <div class="interactive"> instead of <div class='interactive'>, so double quotes instead of single quotes

<div id="select-unselect-example" class="interactive-example" style="display: none;">
<div class="container-demo">
<div class="radiobutton-wrapper">
<div class="group-radio-buttons">
<input name="group1" class="track-clicks" id="radio-01" checked="" type="radio">
<label for="radio-01">Show browsing history</label>
</div>
<div class="group-radio-buttons">
<input name="group1" class="track-clicks" id="radio-02" type="radio">
<label for="radio-02">Show bookmarks</label>
</div>
</div>
</div>
</div>
<small class="db grey-50 mb3 mb0-ns">
<a href="#" class="image-toggle" onclick="document.getElementById('showImage').style.display='block';
document.getElementById('select-unselect-example').style.display='none';
return false;">Image</a> /
<a href="#" class="interactive-toggle" onclick="document.getElementById('showImage').style.display='none';
document.getElementById('select-unselect-example').style.display='block';
return false;">Interactive example</a> (Currently only renders correctly in Firefox.)
</small>
</div>
</div>
<div class="fl-ns w-50-ns ph2">
<h4 class="mb2">Selected:</h4>
Expand Down
3 changes: 3 additions & 0 deletions images/components/checkboxes/radio-16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion src/components/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require('../../node_modules/highlight.js/styles/color-brewer.css');
const React = require('react');
const { connect } = require('react-redux');
const ReactDOM = require('react-dom');
const { getPage } = require('./utilities.js');
const { getPage, sendEvent } = require('./utilities.js');

const Editor = React.createClass({
displayName: 'Editor',
Expand Down Expand Up @@ -39,6 +39,7 @@ const Editor = React.createClass({
componentDidUpdate: function(prevProps) {
if (prevProps.text !== this.props.text) {
this.addIds();
this.addInteractionEvents();
const page = this.props.page;
let title = `${page.title} | Photon Design System`;
if(page.category !== page.title) {
Expand All @@ -61,6 +62,22 @@ const Editor = React.createClass({
}
},

addInteractionEvents: function() {
let node = ReactDOM.findDOMNode(this);
let interactiveElements = Array.from(node.querySelectorAll('.interactive'));
interactiveElements.forEach(element => {
element.addEventListener('click', e => {
if (e.target.classList.contains('interactive-toggle')) {
sendEvent('click', 'interactive-toggle', window.location.pathname);
} else if (e.target.classList.contains('image-toggle')) {
sendEvent('click', 'image-toggle', window.location.pathname);
} else if (e.target.classList.contains ('track-clicks')) {
sendEvent('click', 'interaction-with-demo', e.target.closest('div[id]').id);
}
});
});
},

addIds: function () {
let node = ReactDOM.findDOMNode(this);
let headings = Array.from(node.querySelectorAll('h1,h2,h3,h4'));
Expand Down
2 changes: 1 addition & 1 deletion src/components/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getSiblingPages(page, pages) {
var current_index = shown_pages.indexOf(page);
var previous_page = shown_pages[current_index - 1] || shown_pages[shown_pages.length - 1];
var next_page = shown_pages[current_index + 1] || shown_pages[0];
return { previous_page, next_page }
return { previous_page, next_page };
}

function sendPageview(url, hash) {
Expand Down
80 changes: 80 additions & 0 deletions src/styles/page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,83 @@ div[data-tabs] input[type="radio"]:checked + label {
div[data-tabs] input[type="radio"]:checked + label + div[data-tab] {
display: block;
}

/* Interactive checkbox */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if these styles should live in a separate scss partial. I will leave it as it is and we can change it later if you agree 😃

.interactive-example {
background-color: var(--grey-10);
height: 202.5px; // same height as images
margin-bottom: 15px;
outline: 1px solid rgba(12, 12, 13, .1);
outline-offset: -1px;
width: 100%;
}

.container-demo {
align-items: center;
display: flex;
height: 100%;
width: 100%;
}

.radiobutton-wrapper {
margin: 0 auto;
padding: 20px;
width: -moz-fit-content;
}

.group-radio-buttons {
align-items: center;
display: flex;
margin-bottom: 6px;
}

input[type="radio"]:checked {
background-color: var(--blue-60);
background-image: url("../../images/components/checkboxes/radio-16.svg");
background-size: 16px;
border: none;
}

input[type="radio"] {
-moz-appearance: none;
background-color: var(--grey-90-a10);
background-position: center center;
background-repeat: no-repeat;
background-size: 4px;
border: 1px solid var(--grey-90-a30);
border-radius: 100%;
font-size: 14px;
height: 16px;
margin-right: 4px;
width: 16px;
}

input[type="radio"] + label {
flex: 1 1 auto;
font-size: 14px;
}

input[type="radio"]:hover {
background-color: var(--grey-90-a20);
}

input[type="radio"]:hover:active {
background-color: var(--grey-90-a30);
}

input[type="radio"]:focus {
animation: none;
border: 0;
box-shadow:
0 0 0 1px var(--blue-50) inset,
0 0 0 1px var(--blue-50),
0 0 0 4px var(--blue-50-a30);
}

input[type="radio"]:checked:hover {
background-color: var(--blue-70);
}

input[type="radio"]:checked:hover:active {
background-color: var(--blue-80);
}