diff --git a/dev/card.html b/dev/card.html index a8d3a9bee0..68a187c210 100644 --- a/dev/card.html +++ b/dev/card.html @@ -15,14 +15,129 @@ import '@vaadin/card'; import { badge } from '@vaadin/vaadin-lumo-styles/badge.js'; + import '@vaadin/avatar'; + import '@vaadin/button'; + import '@vaadin/checkbox'; + import '@vaadin/checkbox-group'; import '@vaadin/icon'; import '@vaadin/icons'; import '@vaadin/vaadin-lumo-styles/icons.js'; + import '@vaadin/select'; + import '@vaadin/scroller'; import { utility } from '@vaadin/vaadin-lumo-styles/utility.js'; import { addGlobalThemeStyles } from '@vaadin/vaadin-themable-mixin/register-styles.js'; addGlobalThemeStyles('utility', utility); addGlobalThemeStyles('badge', badge); + + const playground = document.querySelector('.playground'); + const codeExample = document.querySelector('.code-example'); + const mediaSelect = document.querySelector('#media'); + const contentSelect = document.querySelector('#content'); + const slotCheckboxGroup = document.querySelector('.slot-options'); + const resizeOptions = document.querySelector('.playground-resize'); + const themeVariant = document.querySelector('.theme-variant'); + + mediaSelect.items = [ + { label: 'None', value: 'none' }, + { label: 'Image', value: '0' }, + { label: 'Icon', value: '1' }, + { label: 'Avatar', value: '2' }, + { label: 'Custom SVG', value: '3' }, + ]; + mediaSelect.value = 'none'; + const mediaElements = Array.from(document.querySelector('#media-options').content.querySelectorAll('*')); + mediaSelect.addEventListener('value-changed', (e) => { + const existing = playground.querySelector('[slot="media"]'); + if (existing) { + playground.removeChild(existing); + } + if (e.detail.value != 'none') { + playground.prepend(mediaElements[e.detail.value]); + } + updateCodeExample(); + }); + + const slotElements = document.querySelector('#slot-options').content.children; + const slotItems = { + 'header': slotElements[0], + 'header-prefix': slotElements[1], + 'header-suffix': slotElements[2], + 'title': slotElements[3], + 'subtitle': slotElements[4], + 'footer': slotElements[5], + }; + + slotCheckboxGroup.addEventListener('value-changed', (e) => { + Object.entries(slotItems).forEach(([key, val]) => { + if (e.detail.value.includes(key)) { + playground.append(val); + } else if (val.parentNode === playground) { + playground.removeChild(val); + } + }); + updateCodeExample(); + }); + + contentSelect.items = [ + { label: 'None', value: '-1' }, + { label: 'Text', value: '0' }, + { label: 'Scroller', value: '1' }, + { label: 'Image & Text', value: '2' }, + ]; + const contentElements = document.querySelector('#content-options').content.children; + contentSelect.addEventListener('value-changed', (e) => { + const existing = playground.querySelector(':scope > :not([slot])'); + if (existing) { + playground.removeChild(existing); + } + if (parseInt(e.detail.value) >= 0) { + playground.append(contentElements[e.detail.value].cloneNode(true)); + } + updateCodeExample(); + }); + contentSelect.value = '0'; + + resizeOptions.addEventListener('value-changed', (e) => { + playground.classList.toggle('resize-width', e.detail.value.includes('width')); + playground.classList.toggle('resize-height', e.detail.value.includes('height')); + }); + + themeVariant.addEventListener('value-changed', (e) => { + playground.setAttribute('theme', e.detail.value.filter(v => v != 'dark').join(' ')); + document.documentElement.setAttribute('theme', e.detail.value.includes('dark') ? 'dark' : ''); + updateCodeExample(); + }); + + function updateCodeExample() { + codeExample.textContent = format(playground.outerHTML + .replaceAll(/ tabindex="0"| role="button"| class="playground(.*?)"| style="(.+?)"| theme=""| has-content=""| has-title=""| has-subtitle=""| has-header=""| has-header-prefix=""| has-header-suffix=""| has-footer=""| has-media=""/g, '') + .replaceAll(/src=".+?"/g, 'src="..."') + .replace(/Lapland is the[\s\S]+?., 'Lapland is the...<') + .replace(/ fill="none"[\s\S]+?<\/svg>/, '>...') + .replace(/ overflow=".*?"/, '') + ).replace('\n ', ''); + } + + function format(html) { + var tab = ' '; + var result = ''; + var indent = ''; + + html.split(/>\s*).forEach(function (element) { + if (element.match(/^\/\w/)) { + indent = indent.substring(tab.length); + } + + result += indent + '<' + element + '>\r\n'; + + if (element.match(/^\w[^>]*[^/]$/) && !element.startsWith("input")) { + indent += tab; + } + }); + + return result.substring(1, result.length - 3); + } - - -
- -Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet, consectetur adipisicing elit incididunt ut.
- Label -Lorem ipsum dolor sit amet, consectetur adipisicing elit incididunt ut.
- Label -Lorem ipsum dolor sit amet
-Lorem ipsum dolor sit amet
-Lorem ipsum dolor sit amet
-12,450
- - 15.8% -$363.95
- - 34.0% -86.5%
- - 24.3% -Lorem ipsum dolor sit amet, consectetur adipisicing elit tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet
-Lorem ipsum dolor sit amet
-Lorem ipsum dolor sit amet
-12,450
- - 15.8% -$363.95
- - 34.0% -86.5%
- - 24.3% -Lorem ipsum dolor sit amet, consectetur adipisicing elit tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet, consectetur adipisicing elit tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet
-Lorem ipsum dolor sit amet
-Lorem ipsum dolor sit amet
-12,450
- - 15.8% -$363.95
- - 34.0% -86.5%
- - 24.3% -Lorem ipsum dolor sit amet, consectetur adipisicing elit tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet, consectetur adipisicing elit tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
- Label -Lorem ipsum dolor sit amet
-Lorem ipsum dolor sit amet
-Lorem ipsum dolor sit amet
-12,450
- - 15.8% -$363.95
- - 34.0% -86.5%
- - 24.3% -