A Pen by Dan Klammer on CodePen.
Created
February 13, 2020 18:22
-
-
Save danklammer/e44ad9e59a0c304619f77dfe82b37e45 to your computer and use it in GitHub Desktop.
NPS Score Selector - Modal
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
<div class="screen"> | |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 92" class="droop"> | |
<path fill="#0070B9" d="M0 0v82.6a1745.7 1745.7 0 00360 0V0H0z"/> | |
<path fill="#FFFFFF" d="M317 7v10h-10V7h10zm13 0a5 5 0 110 10 5 5 0 010-10zm23 0l-6 10-6-10h12z"/> | |
<text fill="#FFFFFF" font-size="20" font-weight="400" letter-spacing=".25"> | |
<tspan x="72" y="54">Good thing happened</tspan> | |
</text> | |
<path fill="#FFFFFF" d="M28.7 38.5c.4.4.4 1 0 1.4l-5 5.1H35a1 1 0 01.1 2H23.5l5.1 5c.4.4.4 1 0 1.4a1 1 0 01-1.3.1h-.1l-6.8-6.8a1 1 0 010-1.3v-.1l6.8-6.8a1 1 0 011.4 0z"/> | |
</svg> | |
<div class="modal-container"> | |
<!-- modal: step 1 --> | |
<div class="modal"> | |
<h1>How likely are you to recommend this app to a friend or colleague?</h1> | |
<div class="slider"> | |
<div class="emoji-container"> | |
<span class="emoji hide" data-range-show="0">😱</span> | |
<span class="emoji hide" data-range-show="1">😨</span> | |
<span class="emoji hide" data-range-show="2">😟</span> | |
<span class="emoji hide" data-range-show="3">😔</span> | |
<span class="emoji hide" data-range-show="4">😞</span> | |
<span class="emoji dim" data-range-show="5">🙁</span> | |
<span class="emoji hide" data-range-show="6">😕</span> | |
<span class="emoji hide" data-range-show="7">😐</span> | |
<span class="emoji hide" data-range-show="8">🙂</span> | |
<span class="emoji hide" data-range-show="9">😃</span> | |
<span class="emoji hide" data-range-show="10">😍</span> | |
</div> | |
<div class="slider-container"> | |
<div class="ticks"> | |
<span class="tick">0</span> | |
<span class="tick">1</span> | |
<span class="tick">2</span> | |
<span class="tick">3</span> | |
<span class="tick">4</span> | |
<span class="tick">5</span> | |
<span class="tick">6</span> | |
<span class="tick">7</span> | |
<span class="tick">8</span> | |
<span class="tick">9</span> | |
<span class="tick">10</span> | |
</div> | |
<input class="slider" id="rangeInput" type="range" min="0" max="10" step="1" onInput="updateHighlight(this.value)" /> | |
<div class="slider-highlight" name="amount" id="amount" for="rangeInput"></div> | |
<div class="captions"> | |
<span>Not likely</span> | |
<span>Very likely</span> | |
</div> | |
</div> | |
</div> | |
<a href="#" class="btn disabled" onClick="document.body.classList.add('show-step-2');"> | |
Next | |
</a> | |
</div> | |
<!-- modal: step 2 --> | |
<div class="modal"> | |
<h1>Please list any additional feedback or areas of improvement on our mobile app.</h1> | |
<textarea class="feedback" placeholder="Enter feedback (optional)"></textarea> | |
<a href="#" class="btn" onClick="document.body.classList.add('show-step-3');"> | |
Submit | |
</a> | |
</div> | |
<!-- modal: step 3 --> | |
<div class="modal"> | |
<h1>Thank you for your feedback!</h1> | |
<p>We appreciate hearing from you and we're doing everything we can to improve your experience.</p> | |
</div> | |
</div> | |
</div> | |
<input class="reload" type="button" value="Replay" onClick="document.location.reload(true)"> |
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
/* global consts */ | |
const SELECTOR = { | |
range: '.slider', | |
emoji: '.emoji', | |
} | |
const ELEMENT = { | |
range: document.querySelector(SELECTOR.range), | |
emojis: document.querySelectorAll(SELECTOR.emoji), | |
} | |
const DATA_ATTR = 'data-range-show'; | |
const BTN = document.querySelector('.btn'); | |
const HIGHLIGHT = document.querySelector('.slider-highlight'); | |
/* end global consts */ | |
/* helper functions */ | |
const hideElements = (...elementKeys) => { | |
elementKeys.forEach(key => { | |
ELEMENT[key].forEach(element => { | |
element.classList.add('hide'); | |
element.classList.remove('dim'); | |
}) | |
}) | |
} | |
const showElements = (data_attr, selectorKeys) => { | |
selectorKeys | |
.map(key => `${SELECTOR[key]}[${DATA_ATTR}="${data_attr}"]`) | |
.map(selector => document.querySelector(selector)) | |
.forEach(element => element.classList.remove('hide')) | |
} | |
/* end helper functions */ | |
/* event listeners */ | |
const handleRangeUpdate = ({ target: { value: elementToShow } }) => { | |
hideElements('emojis'); | |
showElements(elementToShow, ['emoji']); | |
BTN.classList.remove('disabled'); | |
} | |
ELEMENT.range.addEventListener('input', handleRangeUpdate) | |
/* end event listeners */ | |
function updateHighlight(val) { | |
HIGHLIGHT.setAttribute('data-width', val); | |
} |
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
* { box-sizing: border-box } | |
img { width: 100vw; height: auto; } | |
body { | |
font-family: "Roboto", sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji; | |
margin: 0; | |
background: #f9f9f9; | |
} | |
.reload { | |
display: none; | |
position: absolute; | |
bottom: 16px; | |
right: 16px; | |
font-size: 16px; | |
} | |
.screen { | |
margin: 0 auto; | |
text-align: center; | |
background: #f9f9f9; | |
position: relative; | |
width: 100vw; | |
height: 100vh; | |
overflow: hidden; | |
} | |
.screen:after { | |
content: " "; | |
display: block; | |
width: 100%; | |
height: 100%; | |
position: absolute; | |
top: 0; | |
left: 0; | |
background: rgba(0,0,0,0.6); | |
} | |
@media (min-width: 480px) { | |
body { | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
height: 97vh; | |
background: #ddd; | |
} | |
.screen { | |
width: 360px; | |
height: 640px; | |
overflow: hidden; | |
} | |
.reload { | |
display: inline-block; | |
} | |
} | |
.droop { | |
position: absolute; | |
width: 100%; | |
top: 0; | |
left: 0; | |
} | |
.modal-container { | |
display: flex; | |
width: inherit; | |
height: inherit; | |
align-items: center; | |
justify-content: left; | |
transition: all 0.3s ease; | |
position: relative; | |
} | |
.show-step-2 .modal-container { margin-left: -100%; } | |
.show-step-3 .modal-container { margin-left: -200%; } | |
.modal { | |
padding: 42px 16px; | |
background: #fff; | |
position: relative; | |
z-index: 2; | |
border-radius: 8px; | |
margin: 8px; | |
min-width: calc(100% - 16px); | |
min-height: 400px; | |
display: flex; | |
justify-content: center; | |
flex-direction: column; | |
} | |
h1 { | |
font-weight: 500; | |
font-size: 20px; | |
color: rgba(0,0,0,0.87); | |
letter-spacing: 0.25px; | |
margin: 8px 0 0; | |
text-align: center; | |
} | |
p { | |
font-size: 16px; | |
color: rgba(0,0,0,0.87); | |
letter-spacing: 0.5px; | |
text-align: center; | |
line-height: 28px; | |
} | |
.hide { | |
display: none; | |
} | |
.slider { user-select: none } | |
.emoji-container { | |
font-size: 48px; | |
height: 95px; | |
overflow: hidden; | |
padding: 16px; | |
} | |
.ticks { | |
display: flex; | |
justify-content: space-between; | |
font-size: 14px; | |
letter-spacing: -0.5px; | |
text-align: center; | |
padding: 0 3px 0 0; | |
} | |
.tick { | |
width: 20px; | |
display: block; | |
} | |
.tick:after { | |
content: " "; | |
display: block; | |
margin: 8px auto -7px; | |
width: 1px; | |
height: 6px; | |
background: #ddd; | |
border-radius: 2px; | |
} | |
.slider-highlight { | |
height: 3px; | |
width: 0; | |
background: #0070B9; | |
border-radius: 5px; | |
margin-top: -15px; | |
z-index: 1; | |
position: relative; | |
pointer-events: none; | |
} | |
.slider-highlight[data-width="1"] { width: 10%; } | |
.slider-highlight[data-width="2"] { width: 20%; } | |
.slider-highlight[data-width="3"] { width: 30%; } | |
.slider-highlight[data-width="4"] { width: 40% } | |
.slider-highlight[data-width="5"] { width: 50% } | |
.slider-highlight[data-width="6"] { width: 60% } | |
.slider-highlight[data-width="7"] { width: 70% } | |
.slider-highlight[data-width="8"] { width: 80% } | |
.slider-highlight[data-width="9"] { width: 90% } | |
.slider-highlight[data-width="10"] { width: 100% } | |
.captions { | |
margin: 20px 0 8px; | |
font-size: 14px; | |
color: rgba(0,0,0,0.87); | |
display: flex; | |
justify-content: space-between; | |
} | |
.feedback { | |
width: 100%; | |
margin: 24px 0 0; | |
border: 1px solid #000; | |
border-radius: 4px; | |
padding: 16px; | |
font-size: 16px; | |
min-height: 120px; | |
resize: none; | |
} | |
.feedback:focus { | |
outline: 0; | |
border: 1px solid #0070B9; | |
} | |
.btn { | |
display: block; | |
margin: 24px auto 0; | |
font-size: 14px; | |
letter-spacing: 0.5px; | |
line-height: 16px; | |
line-height: 0; | |
max-width: 268px; | |
text-decoration: none; | |
color: white; | |
display: inline-block; | |
width: 90%; | |
background: #0070B9; | |
padding: 25px; | |
border-radius: 25px; | |
transition: all 0.3s ease; | |
} | |
.btn.disabled { | |
background: rgba(0,0,0,0.15); | |
color: rgba(0,0,0,0.30); | |
pointer-events: none; | |
cursor: default; | |
} | |
.dim { opacity: 0.3; } | |
/* | |
https://github.com/darlanrod/input-range-scss/blob/master/example/inputrange.css | |
Only use Webkit for this demo | |
*/ | |
[type=range] { | |
-webkit-appearance: none; | |
background: transparent; | |
margin: 12px 0; | |
width: 100%; | |
} | |
[type=range]:focus { | |
outline: 0; | |
} | |
[type=range]:focus::-webkit-slider-runnable-track { | |
background: #d3d3d3; | |
} | |
[type=range]::-webkit-slider-runnable-track { | |
cursor: default; | |
height: 3px; | |
transition: all 0.2s ease; | |
width: 100%; | |
background: #d3d3d3; | |
border-radius: 5px; | |
} | |
[type=range]::-webkit-slider-thumb { | |
background: #0070B9; | |
border: 4px solid #fff; | |
box-shadow: 0 0 0 1px #D3D3D3; | |
border-radius: 24px; | |
box-sizing: border-box; | |
cursor: default; | |
height: 24px; | |
width: 24px; | |
-webkit-appearance: none; | |
margin-top: -10px; | |
transition: .2s ease; | |
z-index: 2; | |
position: relative; | |
} | |
input[type=range]::-webkit-slider-thumb:active { | |
transform: scale(1.75); | |
} | |
[type=range]:disabled::-webkit-slider-thumb, [type=range]:disabled::-webkit-slider-runnable-track { | |
cursor: not-allowed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment