Files
dees-catalog/ts_web/elements/dees-input-quantityselector.demo.ts
Juergen Kunz 3e81f54e99 update
2025-06-27 16:29:19 +00:00

353 lines
12 KiB
TypeScript

import { html, css, cssManager } from '@design.estate/dees-element';
export const demoFunc = () => html`
<dees-demowrapper>
<style>
${css`
.demo-container {
display: flex;
flex-direction: column;
gap: 24px;
padding: 24px;
max-width: 1200px;
margin: 0 auto;
}
.shopping-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 20px;
}
.product-card {
background: ${cssManager.bdTheme('hsl(0 0% 100%)', 'hsl(215 20.2% 11.8%)')};
border: 1px solid ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')};
border-radius: 8px;
overflow: hidden;
transition: all 0.2s ease;
display: flex;
flex-direction: column;
}
.product-card:hover {
border-color: ${cssManager.bdTheme('hsl(0 0% 79.8%)', 'hsl(0 0% 20.9%)')};
box-shadow: 0 4px 6px -1px hsl(0 0% 0% / 0.1), 0 2px 4px -2px hsl(0 0% 0% / 0.1);
}
.product-image {
width: 100%;
height: 180px;
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 16.8%)')};
display: flex;
align-items: center;
justify-content: center;
font-size: 48px;
color: ${cssManager.bdTheme('hsl(215 20.2% 65.1%)', 'hsl(215 20.2% 35.1%)')};
}
.product-content {
padding: 16px;
display: flex;
flex-direction: column;
gap: 12px;
flex: 1;
}
.product-header {
display: flex;
flex-direction: column;
gap: 4px;
}
.product-category {
font-size: 12px;
font-weight: 500;
color: ${cssManager.bdTheme('hsl(215.4 16.3% 56.9%)', 'hsl(215 20.2% 55.1%)')};
text-transform: uppercase;
letter-spacing: 0.05em;
}
.product-name {
font-size: 16px;
font-weight: 600;
color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')};
line-height: 1.4;
}
.product-description {
font-size: 13px;
color: ${cssManager.bdTheme('hsl(215.4 16.3% 46.9%)', 'hsl(215 20.2% 65.1%)')};
line-height: 1.5;
flex: 1;
}
.product-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding-top: 12px;
border-top: 1px solid ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')};
}
.product-price {
display: flex;
flex-direction: column;
gap: 2px;
}
.price-current {
font-size: 20px;
font-weight: 600;
color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')};
}
.price-original {
font-size: 14px;
color: ${cssManager.bdTheme('hsl(215.4 16.3% 56.9%)', 'hsl(215 20.2% 55.1%)')};
text-decoration: line-through;
}
.in-stock {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 12px;
color: ${cssManager.bdTheme('hsl(142.1 70.6% 45.3%)', 'hsl(142.1 76.2% 36.3%)')};
margin-top: 8px;
}
.in-stock dees-icon {
font-size: 14px;
}
.cart-summary {
margin-top: 24px;
padding: 20px;
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 16.8%)')};
border: 1px solid ${cssManager.bdTheme('hsl(214.3 31.8% 91.4%)', 'hsl(215 20.2% 21.8%)')};
border-radius: 8px;
}
.cart-summary-title {
font-size: 18px;
font-weight: 600;
margin-bottom: 16px;
color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')};
}
.cart-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 0;
font-size: 14px;
color: ${cssManager.bdTheme('hsl(215.3 25% 26.7%)', 'hsl(217.9 10.6% 74.9%)')};
}
.cart-total {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 16px;
margin-top: 16px;
border-top: 2px solid ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')};
font-size: 18px;
font-weight: 600;
color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')};
}
`}
</style>
<div class="demo-container">
<dees-panel .title=${'Basic Quantity Selector'} .subtitle=${'Simple quantity input with increment/decrement buttons'}>
<dees-input-quantityselector
.label=${'Quantity'}
.description=${'Select the desired quantity'}
.value=${1}
></dees-input-quantityselector>
<dees-input-quantityselector
.label=${'Items in Cart'}
.description=${'Adjust the quantity of items'}
.value=${3}
></dees-input-quantityselector>
</dees-panel>
<dees-panel .title=${'Shopping Cart'} .subtitle=${'Modern e-commerce product cards with interactive quantity selectors'} .runAfterRender=${async (elementArg: HTMLElement) => {
const updateCartSummary = () => {
const qty1 = (elementArg.querySelector('#headphones-qty') as any)?.getValue() || 0;
const qty2 = (elementArg.querySelector('#mouse-qty') as any)?.getValue() || 0;
const qty3 = (elementArg.querySelector('#keyboard-qty') as any)?.getValue() || 0;
const price1 = 349.99 * qty1;
const price2 = 99.99 * qty2;
const price3 = 79.99 * qty3;
const total = price1 + price2 + price3;
const summary = elementArg.querySelector('#cart-summary-content');
if (summary) {
summary.innerHTML = `
${qty1 > 0 ? `<div class="cart-item">
<span>Sony WH-1000XM5 (${qty1})</span>
<span>$${price1.toFixed(2)}</span>
</div>` : ''}
${qty2 > 0 ? `<div class="cart-item">
<span>Logitech MX Master 3S (${qty2})</span>
<span>$${price2.toFixed(2)}</span>
</div>` : ''}
${qty3 > 0 ? `<div class="cart-item">
<span>Keychron K2 (${qty3})</span>
<span>$${price3.toFixed(2)}</span>
</div>` : ''}
${total === 0 ? '<div class="cart-item" style="text-align: center; color: #999;">Your cart is empty</div>' : ''}
<div class="cart-total">
<span>Total</span>
<span>$${total.toFixed(2)}</span>
</div>
`;
}
};
// Initial update
setTimeout(updateCartSummary, 100);
// Set up listeners
elementArg.querySelectorAll('dees-input-quantityselector').forEach(selector => {
selector.addEventListener('changeSubject', updateCartSummary);
});
}}>
<div class="shopping-grid">
<div class="product-card">
<div class="product-image">
<dees-icon .iconName=${'lucide:headphones'}></dees-icon>
</div>
<div class="product-content">
<div class="product-header">
<div class="product-category">Audio</div>
<div class="product-name">Sony WH-1000XM5 Wireless Headphones</div>
</div>
<div class="product-description">
Industry-leading noise canceling with Auto NC Optimizer
</div>
<div class="in-stock">
<dees-icon .iconName=${'lucide:check-circle'}></dees-icon>
In Stock
</div>
<div class="product-footer">
<div class="product-price">
<span class="price-current">$349.99</span>
<span class="price-original">$399.99</span>
</div>
<dees-input-quantityselector
id="headphones-qty"
.value=${1}
></dees-input-quantityselector>
</div>
</div>
</div>
<div class="product-card">
<div class="product-image">
<dees-icon .iconName=${'lucide:mouse-pointer'}></dees-icon>
</div>
<div class="product-content">
<div class="product-header">
<div class="product-category">Accessories</div>
<div class="product-name">Logitech MX Master 3S</div>
</div>
<div class="product-description">
Performance wireless mouse with ultra-fast scrolling
</div>
<div class="in-stock">
<dees-icon .iconName=${'lucide:check-circle'}></dees-icon>
In Stock
</div>
<div class="product-footer">
<div class="product-price">
<span class="price-current">$99.99</span>
</div>
<dees-input-quantityselector
id="mouse-qty"
.value=${2}
></dees-input-quantityselector>
</div>
</div>
</div>
<div class="product-card">
<div class="product-image">
<dees-icon .iconName=${'lucide:keyboard'}></dees-icon>
</div>
<div class="product-content">
<div class="product-header">
<div class="product-category">Keyboards</div>
<div class="product-name">Keychron K2 Wireless Mechanical Keyboard</div>
</div>
<div class="product-description">
Compact 75% layout with hot-swappable switches
</div>
<div class="in-stock">
<dees-icon .iconName=${'lucide:check-circle'}></dees-icon>
In Stock
</div>
<div class="product-footer">
<div class="product-price">
<span class="price-current">$79.99</span>
<span class="price-original">$94.99</span>
</div>
<dees-input-quantityselector
id="keyboard-qty"
.value=${1}
></dees-input-quantityselector>
</div>
</div>
</div>
</div>
<div class="cart-summary">
<h3 class="cart-summary-title">Order Summary</h3>
<div id="cart-summary-content">
<!-- Content will be dynamically updated -->
</div>
</div>
</dees-panel>
<dees-panel .title=${'Required & Disabled States'} .subtitle=${'Different states for validation and restrictions'}>
<dees-input-quantityselector
.label=${'Number of Licenses'}
.description=${'Select how many licenses you need'}
.required=${true}
.value=${1}
></dees-input-quantityselector>
<dees-input-quantityselector
.label=${'Fixed Quantity'}
.description=${'This quantity cannot be changed'}
.disabled=${true}
.value=${5}
></dees-input-quantityselector>
</dees-panel>
<dees-panel .title=${'Order Form'} .subtitle=${'Complete order form with quantity selection'}>
<dees-form>
<dees-input-text .label=${'Customer Name'} .required=${true}></dees-input-text>
<dees-input-dropdown
.label=${'Product'}
.options=${['Basic Plan', 'Pro Plan', 'Enterprise Plan']}
.required=${true}
></dees-input-dropdown>
<dees-input-quantityselector
.label=${'Quantity'}
.description=${'Number of licenses'}
.value=${1}
></dees-input-quantityselector>
<dees-input-text
.label=${'Special Instructions'}
.inputType=${'textarea'}
></dees-input-text>
</dees-form>
</dees-panel>
</div>
</dees-demowrapper>
`;