UNPKG

@adobe/coral-spectrum

Version:

Coral Spectrum is a JavaScript library of Web Components following Spectrum design patterns.

145 lines (128 loc) 5.9 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Coral.Checkbox</title> <script>document.addEventListener('click', function(event) {if (event.target.nodeName === 'A' || event.matchedTarget && event.matchedTarget.nodeName === 'A') {event.preventDefault();}});</script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css"> <style>.hljs{background:#fff;font-size:12px;border-radius:4px;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;}</style> <script> document.addEventListener('DOMContentLoaded', function() { const markup = document.body.querySelectorAll('.markup'); for (var i = 0; i < markup.length; i++) { const code = markup[i].innerHTML; const id = 'markup-code-' + i; markup[i].insertAdjacentHTML('afterend', '<div style="margin:10px 0">' + '<a onclick="this.nextElementSibling.hidden = !this.nextElementSibling.hidden" class="coral-Link" href="#">Toggle markup</a>' + '<pre hidden>' + '<code id="'+ id +'" class="html">' + '</code>' + '</pre>' + '</div>'); document.getElementById(id).textContent = code; } window.hljs.initHighlightingOnLoad(); }); </script> <link rel="stylesheet" href="../css/coral.css"> <script> document.addEventListener('DOMContentLoaded', function() { const script = document.createElement('script'); script.src = '../js/coral.js'; script.dataset.coralIcons = '../resources/'; document.head.appendChild(script); }); </script> </head> <body class="coral--lightest"> <main class="u-coral-margin"> <div style="position:absolute;top:16px;right:16px;"> <strong style="padding-right:8px"><span class="u-coral-hiddenS">Theme:</span></strong> <a href="#" class="coral-Link theme" onclick="document.body.className='coral--light'">Light</a> | <a href="#" class="coral-Link theme" onclick="document.body.className='coral--lightest'">Lightest</a> | <a href="#" class="coral-Link theme" onclick="document.body.className='coral--dark'">Dark</a> | <a href="#" class="coral-Link theme" onclick="document.body.className='coral--darkest'">Darkest</a> <strong style="padding:0 8px 0 16px"><span class="u-coral-hiddenS">Scale:</span></strong> <a href="#" class="coral-Link scale" onclick="document.body.classList.remove('coral--large')">Medium</a> | <a href="#" class="coral-Link scale" onclick="document.body.classList.add('coral--large')">Large</a> </div> <h1 class="coral-Heading--XXL">Checkbox</h1> <h2 class="coral-Heading--M">Usage notes</h2> <hr class="coral-Divider--L"> <p class="coral-Body--M u-coral-padding-vertical"> Checkboxes allow users to select multiple items from a list of individual items, or to mark one individual item as selected. </p> <h2 class="coral--Heading--S">Default</h2> <div class="markup"> <coral-checkbox></coral-checkbox> </div> <h2 class="coral--Heading--S">Checked</h2> <div class="markup"> <coral-checkbox checked>Checked</coral-checkbox> </div> <h2 class="coral--Heading--S">Indeterminate</h2> <div class="markup"> <coral-checkbox indeterminate>Indeterminate</coral-checkbox> </div> <h2 class="coral--Heading--S">Disabled</h2> <div class="markup"> <coral-checkbox disabled>Disabled</coral-checkbox> </div> <h2 class="coral--Heading--S">Checked and disabled</h2> <div class="markup"> <coral-checkbox checked disabled>Checked and disabled</coral-checkbox> </div> <h2 class="coral--Heading--S">Labelled</h2> <div class="markup"> <coral-checkbox>Check</coral-checkbox> <coral-checkbox labelled="Check"></coral-checkbox> </div> <h2 class="coral--Heading--S">From JavaScript</h2> <div class="markup"> <div id="from-javascript"></div> <script> window.addEventListener('load', function() { var checkboxFromJS = document.createElement('coral-checkbox'); checkboxFromJS.style.width = '149px'; checkboxFromJS.textContent = 'Add Adobe Stock. Get one month free.*'; document.getElementById('from-javascript').appendChild(checkboxFromJS); }); </script> </div> <h2 class="coral--Heading--S">Tri-State Cycling</h2> <div class="markup"> <div id="tri-state"></div> <script type="text/javascript"> window.addEventListener('load', function() { var checkbox = document.createElement('coral-checkbox'); checkbox.innerHTML = 'Cycle States by Clicking Me'; var exampleDiv = document.getElementById('tri-state'); exampleDiv.appendChild(checkbox); var state = 0; checkbox.addEventListener('change', function() { state++; switch(state) { case 1: checkbox.checked = true; checkbox.indeterminate = false; break; case 2: checkbox.checked = true; checkbox.indeterminate = true; break; case 3: checkbox.checked = false; checkbox.indeterminate = false; state = 0; break; } }); }); </script> </div> </main> </body> </html>