snice 1.14.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/templates/base/tsconfig.json +5 -4
- package/components/accordion/demo.html +403 -0
- package/components/accordion/snice-accordion-item.css +85 -0
- package/components/accordion/snice-accordion-item.ts +226 -0
- package/components/accordion/snice-accordion.css +31 -0
- package/components/accordion/snice-accordion.ts +182 -0
- package/components/accordion/snice-accordion.types.ts +32 -0
- package/components/alert/demo.html +445 -0
- package/components/alert/snice-alert.css +195 -0
- package/components/alert/snice-alert.ts +141 -0
- package/components/alert/snice-alert.types.ts +12 -0
- package/components/avatar/demo.html +598 -0
- package/components/avatar/snice-avatar.css +131 -0
- package/components/avatar/snice-avatar.ts +136 -0
- package/components/avatar/snice-avatar.types.ts +13 -0
- package/components/badge/demo.html +523 -0
- package/components/badge/snice-badge.css +161 -0
- package/components/badge/snice-badge.ts +117 -0
- package/components/badge/snice-badge.types.ts +16 -0
- package/components/breadcrumbs/demo.html +404 -0
- package/components/breadcrumbs/snice-breadcrumbs.css +133 -0
- package/components/breadcrumbs/snice-breadcrumbs.ts +191 -0
- package/components/breadcrumbs/snice-breadcrumbs.types.ts +26 -0
- package/components/breadcrumbs/snice-crumb.ts +26 -0
- package/components/button/demo.html +42 -0
- package/components/button/snice-button.css +230 -0
- package/components/button/snice-button.ts +169 -0
- package/components/button/snice-button.types.ts +25 -0
- package/components/card/demo.html +525 -0
- package/components/card/snice-card.css +140 -0
- package/components/card/snice-card.ts +102 -0
- package/components/card/snice-card.types.ts +10 -0
- package/components/checkbox/demo.html +253 -0
- package/components/checkbox/snice-checkbox.css +164 -0
- package/components/checkbox/snice-checkbox.ts +223 -0
- package/components/checkbox/snice-checkbox.types.ts +22 -0
- package/components/chip/demo.html +383 -0
- package/components/chip/snice-chip.css +195 -0
- package/components/chip/snice-chip.ts +139 -0
- package/components/chip/snice-chip.types.ts +15 -0
- package/components/date-picker/README.md +233 -0
- package/components/date-picker/demo.html +191 -0
- package/components/date-picker/snice-date-picker.css +330 -0
- package/components/date-picker/snice-date-picker.ts +777 -0
- package/components/date-picker/snice-date-picker.types.ts +83 -0
- package/components/divider/demo.html +233 -0
- package/components/divider/snice-divider.css +155 -0
- package/components/divider/snice-divider.ts +69 -0
- package/components/divider/snice-divider.types.ts +15 -0
- package/components/drawer/demo.html +328 -0
- package/components/drawer/snice-drawer.css +476 -0
- package/components/drawer/snice-drawer.ts +287 -0
- package/components/drawer/snice-drawer.types.ts +17 -0
- package/components/global.d.ts +14 -0
- package/components/input/demo.html +303 -0
- package/components/input/snice-input.css +257 -0
- package/components/input/snice-input.ts +442 -0
- package/components/input/snice-input.types.ts +59 -0
- package/components/input/test.html +77 -0
- package/components/layout/README.md +260 -0
- package/components/layout/demo.html +538 -0
- package/components/layout/snice-layout-blog.css +129 -0
- package/components/layout/snice-layout-blog.ts +48 -0
- package/components/layout/snice-layout-card.css +104 -0
- package/components/layout/snice-layout-card.ts +35 -0
- package/components/layout/snice-layout-centered.css +51 -0
- package/components/layout/snice-layout-centered.ts +22 -0
- package/components/layout/snice-layout-dashboard.css +98 -0
- package/components/layout/snice-layout-dashboard.ts +45 -0
- package/components/layout/snice-layout-fullscreen.css +72 -0
- package/components/layout/snice-layout-fullscreen.ts +34 -0
- package/components/layout/snice-layout-landing.css +92 -0
- package/components/layout/snice-layout-landing.ts +47 -0
- package/components/layout/snice-layout-minimal.css +16 -0
- package/components/layout/snice-layout-minimal.ts +19 -0
- package/components/layout/snice-layout-sidebar.css +117 -0
- package/components/layout/snice-layout-sidebar.ts +48 -0
- package/components/layout/snice-layout-split.css +103 -0
- package/components/layout/snice-layout-split.ts +29 -0
- package/components/layout/snice-layout.css +72 -0
- package/components/layout/snice-layout.ts +35 -0
- package/components/layout/snice-layout.types.ts +5 -0
- package/components/login/demo-auth-controller.ts +185 -0
- package/components/login/demo.html +470 -0
- package/components/login/snice-login.css +204 -0
- package/components/login/snice-login.ts +337 -0
- package/components/login/snice-login.types.ts +34 -0
- package/components/modal/demo.html +291 -0
- package/components/modal/snice-modal.css +203 -0
- package/components/modal/snice-modal.ts +233 -0
- package/components/modal/snice-modal.types.ts +21 -0
- package/components/pagination/demo.html +395 -0
- package/components/pagination/snice-pagination.ts +333 -0
- package/components/pagination/snice-pagination.types.ts +21 -0
- package/components/progress/demo.html +510 -0
- package/components/progress/snice-progress.css +267 -0
- package/components/progress/snice-progress.ts +247 -0
- package/components/progress/snice-progress.types.ts +19 -0
- package/components/radio/demo.html +287 -0
- package/components/radio/snice-radio.css +171 -0
- package/components/radio/snice-radio.ts +218 -0
- package/components/radio/snice-radio.types.ts +21 -0
- package/components/select/demo.html +511 -0
- package/components/select/snice-option.ts +52 -0
- package/components/select/snice-option.types.ts +14 -0
- package/components/select/snice-select.css +392 -0
- package/components/select/snice-select.ts +796 -0
- package/components/select/snice-select.types.ts +55 -0
- package/components/skeleton/demo.html +514 -0
- package/components/skeleton/snice-skeleton.css +109 -0
- package/components/skeleton/snice-skeleton.ts +126 -0
- package/components/skeleton/snice-skeleton.types.ts +11 -0
- package/components/switch/demo.html +284 -0
- package/components/switch/snice-switch.css +221 -0
- package/components/switch/snice-switch.ts +229 -0
- package/components/switch/snice-switch.types.ts +23 -0
- package/components/symbols.ts +23 -0
- package/components/table/demo-table-controller.ts +100 -0
- package/components/table/demo.html +480 -0
- package/components/table/snice-cell-boolean.ts +112 -0
- package/components/table/snice-cell-date.ts +210 -0
- package/components/table/snice-cell-duration.ts +91 -0
- package/components/table/snice-cell-filesize.ts +90 -0
- package/components/table/snice-cell-number.ts +165 -0
- package/components/table/snice-cell-progress.ts +83 -0
- package/components/table/snice-cell-rating.ts +82 -0
- package/components/table/snice-cell-sparkline.ts +253 -0
- package/components/table/snice-cell-text.ts +125 -0
- package/components/table/snice-cell.css +296 -0
- package/components/table/snice-cell.ts +473 -0
- package/components/table/snice-column.ts +353 -0
- package/components/table/snice-header.css +243 -0
- package/components/table/snice-header.ts +261 -0
- package/components/table/snice-progress.ts +66 -0
- package/components/table/snice-rating.ts +45 -0
- package/components/table/snice-row.css +255 -0
- package/components/table/snice-row.ts +331 -0
- package/components/table/snice-table.css +241 -0
- package/components/table/snice-table.ts +737 -0
- package/components/table/snice-table.types.ts +158 -0
- package/components/tabs/demo.html +487 -0
- package/components/tabs/snice-tab-panel.css +264 -0
- package/components/tabs/snice-tab-panel.ts +47 -0
- package/components/tabs/snice-tab.css +96 -0
- package/components/tabs/snice-tab.ts +65 -0
- package/components/tabs/snice-tabs.css +189 -0
- package/components/tabs/snice-tabs.ts +332 -0
- package/components/tabs/snice-tabs.types.ts +28 -0
- package/components/theme/theme.css +234 -0
- package/components/toast/demo.html +329 -0
- package/components/toast/snice-toast-container.ts +256 -0
- package/components/toast/snice-toast.css +213 -0
- package/components/toast/snice-toast.ts +276 -0
- package/components/toast/snice-toast.types.ts +35 -0
- package/components/tooltip/demo.html +350 -0
- package/components/tooltip/snice-tooltip-portal.css +79 -0
- package/components/tooltip/snice-tooltip.css +117 -0
- package/components/tooltip/snice-tooltip.ts +612 -0
- package/components/tooltip/snice-tooltip.types.ts +32 -0
- package/components/transitions.ts +94 -0
- package/components/tsconfig.json +18 -0
- package/dist/index.cjs +441 -329
- package/dist/index.cjs.map +1 -1
- package/dist/index.cjs.min.map +1 -1
- package/dist/index.esm.js +441 -329
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +3 -3
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +441 -329
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +3 -3
- package/dist/index.iife.min.js.map +1 -1
- package/dist/symbols.esm.js +1 -1
- package/dist/transitions.esm.js +1 -1
- package/dist/types/controller.d.ts +1 -1
- package/dist/types/element.d.ts +10 -10
- package/dist/types/events.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/observe.d.ts +1 -1
- package/dist/types/request-response.d.ts +2 -3
- package/dist/types/router.d.ts +1 -1
- package/package.json +9 -3
- package/dist/index.cjs.min +0 -15
- package/dist/symbols.cjs +0 -103
- package/dist/transitions.cjs +0 -219
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { element, property, on, dispatch, ready } from 'snice';
|
|
2
|
+
import css from './snice-card.css?inline';
|
|
3
|
+
import type { CardVariant, CardSize, SniceCardElement } from './snice-card.types';
|
|
4
|
+
|
|
5
|
+
@element('snice-card')
|
|
6
|
+
export class SniceCard extends HTMLElement implements SniceCardElement {
|
|
7
|
+
@property({ reflect: true })
|
|
8
|
+
variant: CardVariant = 'elevated';
|
|
9
|
+
|
|
10
|
+
@property({ reflect: true })
|
|
11
|
+
size: CardSize = 'medium';
|
|
12
|
+
|
|
13
|
+
@property({ type: Boolean, reflect: true })
|
|
14
|
+
clickable = false;
|
|
15
|
+
|
|
16
|
+
@property({ type: Boolean, reflect: true })
|
|
17
|
+
selected = false;
|
|
18
|
+
|
|
19
|
+
@property({ type: Boolean, reflect: true })
|
|
20
|
+
disabled = false;
|
|
21
|
+
|
|
22
|
+
private hasHeader = false;
|
|
23
|
+
private hasFooter = false;
|
|
24
|
+
|
|
25
|
+
html() {
|
|
26
|
+
return /*html*/`
|
|
27
|
+
<div class="card"
|
|
28
|
+
role="${this.clickable ? 'button' : 'article'}"
|
|
29
|
+
tabindex="${this.clickable && !this.disabled ? '0' : '-1'}"
|
|
30
|
+
aria-selected="${this.selected}"
|
|
31
|
+
aria-disabled="${this.disabled}">
|
|
32
|
+
<slot name="image" class="card-image-slot"></slot>
|
|
33
|
+
<div class="card-header" ${this.hasHeader ? '' : 'hidden'}>
|
|
34
|
+
<slot name="header"></slot>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="card-body">
|
|
37
|
+
<slot></slot>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="card-footer" ${this.hasFooter ? '' : 'hidden'}>
|
|
40
|
+
<slot name="footer"></slot>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
css() {
|
|
47
|
+
return css;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@ready()
|
|
51
|
+
init() {
|
|
52
|
+
// Check for slotted content
|
|
53
|
+
this.setupSlotListeners();
|
|
54
|
+
this.checkSlots();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private setupSlotListeners() {
|
|
58
|
+
const slots = this.shadowRoot?.querySelectorAll('slot');
|
|
59
|
+
slots?.forEach(slot => {
|
|
60
|
+
slot.addEventListener('slotchange', () => this.checkSlots());
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private checkSlots() {
|
|
65
|
+
const headerSlot = this.shadowRoot?.querySelector('slot[name="header"]') as HTMLSlotElement;
|
|
66
|
+
const footerSlot = this.shadowRoot?.querySelector('slot[name="footer"]') as HTMLSlotElement;
|
|
67
|
+
|
|
68
|
+
this.hasHeader = (headerSlot?.assignedNodes().length || 0) > 0;
|
|
69
|
+
this.hasFooter = (footerSlot?.assignedNodes().length || 0) > 0;
|
|
70
|
+
|
|
71
|
+
// Update visibility
|
|
72
|
+
const header = this.shadowRoot?.querySelector('.card-header') as HTMLElement;
|
|
73
|
+
const footer = this.shadowRoot?.querySelector('.card-footer') as HTMLElement;
|
|
74
|
+
|
|
75
|
+
if (header) header.toggleAttribute('hidden', !this.hasHeader);
|
|
76
|
+
if (footer) footer.toggleAttribute('hidden', !this.hasFooter);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@on('click', '.card')
|
|
80
|
+
@dispatch('card-click')
|
|
81
|
+
handleClick(event: MouseEvent) {
|
|
82
|
+
if (!this.clickable || this.disabled) return;
|
|
83
|
+
|
|
84
|
+
if (this.clickable && !this.disabled) {
|
|
85
|
+
this.selected = !this.selected;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
selected: this.selected
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@on('keydown', '.card')
|
|
94
|
+
handleKeydown(event: KeyboardEvent) {
|
|
95
|
+
if (!this.clickable || this.disabled) return;
|
|
96
|
+
|
|
97
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
this.handleClick(new MouseEvent('click'));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type CardVariant = 'elevated' | 'bordered' | 'flat';
|
|
2
|
+
export type CardSize = 'small' | 'medium' | 'large';
|
|
3
|
+
|
|
4
|
+
export interface SniceCardElement extends HTMLElement {
|
|
5
|
+
variant: CardVariant;
|
|
6
|
+
size: CardSize;
|
|
7
|
+
clickable: boolean;
|
|
8
|
+
selected: boolean;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Checkbox Demo</title>
|
|
7
|
+
<link rel="stylesheet" href="../theme/theme.css">
|
|
8
|
+
<style>
|
|
9
|
+
body {
|
|
10
|
+
padding: 40px;
|
|
11
|
+
font-family: var(--snice-font-family);
|
|
12
|
+
background: var(--snice-color-background);
|
|
13
|
+
color: var(--snice-color-text);
|
|
14
|
+
max-width: 800px;
|
|
15
|
+
margin: 0 auto;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.section {
|
|
19
|
+
margin-bottom: 40px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
h2 {
|
|
23
|
+
color: var(--snice-color-text);
|
|
24
|
+
margin-bottom: 20px;
|
|
25
|
+
font-size: var(--snice-font-size-2xl);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
h3 {
|
|
29
|
+
color: var(--snice-color-text-secondary);
|
|
30
|
+
margin-bottom: 16px;
|
|
31
|
+
font-size: var(--snice-font-size-lg);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.checkbox-group {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
gap: 12px;
|
|
38
|
+
margin-bottom: 20px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.row {
|
|
42
|
+
display: flex;
|
|
43
|
+
gap: 20px;
|
|
44
|
+
align-items: center;
|
|
45
|
+
flex-wrap: wrap;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.output {
|
|
49
|
+
padding: 10px;
|
|
50
|
+
background: var(--snice-color-background-secondary);
|
|
51
|
+
border-radius: var(--snice-border-radius-md);
|
|
52
|
+
font-family: monospace;
|
|
53
|
+
font-size: var(--snice-font-size-sm);
|
|
54
|
+
margin-top: 10px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
button {
|
|
58
|
+
padding: 8px 16px;
|
|
59
|
+
background: var(--snice-color-primary);
|
|
60
|
+
color: white;
|
|
61
|
+
border: none;
|
|
62
|
+
border-radius: var(--snice-border-radius-md);
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
font-size: var(--snice-font-size-md);
|
|
65
|
+
margin-right: 8px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
button:hover {
|
|
69
|
+
background: var(--snice-color-primary-hover);
|
|
70
|
+
}
|
|
71
|
+
</style>
|
|
72
|
+
</head>
|
|
73
|
+
<body>
|
|
74
|
+
<h2>Checkbox Component Demo</h2>
|
|
75
|
+
|
|
76
|
+
<div class="section">
|
|
77
|
+
<h3>Basic Checkboxes</h3>
|
|
78
|
+
<div class="checkbox-group">
|
|
79
|
+
<snice-checkbox label="Default checkbox"></snice-checkbox>
|
|
80
|
+
<snice-checkbox label="Pre-checked" checked></snice-checkbox>
|
|
81
|
+
<snice-checkbox label="Disabled" disabled></snice-checkbox>
|
|
82
|
+
<snice-checkbox label="Disabled checked" disabled checked></snice-checkbox>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div class="section">
|
|
87
|
+
<h3>Sizes</h3>
|
|
88
|
+
<div class="checkbox-group">
|
|
89
|
+
<snice-checkbox size="small" label="Small checkbox"></snice-checkbox>
|
|
90
|
+
<snice-checkbox size="medium" label="Medium checkbox (default)"></snice-checkbox>
|
|
91
|
+
<snice-checkbox size="large" label="Large checkbox"></snice-checkbox>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<div class="section">
|
|
96
|
+
<h3>States</h3>
|
|
97
|
+
<div class="checkbox-group">
|
|
98
|
+
<snice-checkbox label="Required field" required></snice-checkbox>
|
|
99
|
+
<snice-checkbox label="Invalid state" invalid></snice-checkbox>
|
|
100
|
+
<snice-checkbox label="Invalid and checked" invalid checked></snice-checkbox>
|
|
101
|
+
<snice-checkbox id="indeterminate-checkbox" label="Indeterminate state" indeterminate></snice-checkbox>
|
|
102
|
+
</div>
|
|
103
|
+
<button onclick="document.getElementById('indeterminate-checkbox').setIndeterminate()">
|
|
104
|
+
Set Indeterminate
|
|
105
|
+
</button>
|
|
106
|
+
<button onclick="document.getElementById('indeterminate-checkbox').checked = true">
|
|
107
|
+
Check
|
|
108
|
+
</button>
|
|
109
|
+
<button onclick="document.getElementById('indeterminate-checkbox').checked = false">
|
|
110
|
+
Uncheck
|
|
111
|
+
</button>
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div class="section">
|
|
115
|
+
<h3>Checkbox Group Example</h3>
|
|
116
|
+
<div class="checkbox-group">
|
|
117
|
+
<strong>Select your interests:</strong>
|
|
118
|
+
<snice-checkbox name="interests" value="coding" label="Coding" checked></snice-checkbox>
|
|
119
|
+
<snice-checkbox name="interests" value="design" label="Design"></snice-checkbox>
|
|
120
|
+
<snice-checkbox name="interests" value="music" label="Music"></snice-checkbox>
|
|
121
|
+
<snice-checkbox name="interests" value="sports" label="Sports"></snice-checkbox>
|
|
122
|
+
<snice-checkbox name="interests" value="reading" label="Reading"></snice-checkbox>
|
|
123
|
+
</div>
|
|
124
|
+
<button onclick="getSelectedInterests()">Get Selected</button>
|
|
125
|
+
<div id="interests-output" class="output">Click button to see selected interests</div>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<div class="section">
|
|
129
|
+
<h3>Terms and Conditions Example</h3>
|
|
130
|
+
<div class="checkbox-group">
|
|
131
|
+
<snice-checkbox
|
|
132
|
+
id="terms-all"
|
|
133
|
+
label="Accept all terms"
|
|
134
|
+
indeterminate>
|
|
135
|
+
</snice-checkbox>
|
|
136
|
+
<div style="margin-left: 24px;">
|
|
137
|
+
<snice-checkbox
|
|
138
|
+
class="terms-item"
|
|
139
|
+
label="I accept the Terms of Service"
|
|
140
|
+
required>
|
|
141
|
+
</snice-checkbox>
|
|
142
|
+
<snice-checkbox
|
|
143
|
+
class="terms-item"
|
|
144
|
+
label="I accept the Privacy Policy"
|
|
145
|
+
required>
|
|
146
|
+
</snice-checkbox>
|
|
147
|
+
<snice-checkbox
|
|
148
|
+
class="terms-item"
|
|
149
|
+
label="I want to receive newsletters">
|
|
150
|
+
</snice-checkbox>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
|
|
155
|
+
<div class="section">
|
|
156
|
+
<h3>Interactive Example</h3>
|
|
157
|
+
<div class="checkbox-group">
|
|
158
|
+
<snice-checkbox
|
|
159
|
+
id="interactive-checkbox"
|
|
160
|
+
label="Click me or press Space when focused">
|
|
161
|
+
</snice-checkbox>
|
|
162
|
+
</div>
|
|
163
|
+
<div class="row">
|
|
164
|
+
<button onclick="document.getElementById('interactive-checkbox').toggle()">Toggle</button>
|
|
165
|
+
<button onclick="document.getElementById('interactive-checkbox').focus()">Focus</button>
|
|
166
|
+
<button onclick="document.getElementById('interactive-checkbox').click()">Click</button>
|
|
167
|
+
</div>
|
|
168
|
+
<div id="event-output" class="output">Events will appear here...</div>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<div class="section">
|
|
172
|
+
<h3>Form Example</h3>
|
|
173
|
+
<form id="demo-form">
|
|
174
|
+
<div class="checkbox-group">
|
|
175
|
+
<snice-checkbox name="subscribe" label="Subscribe to newsletter"></snice-checkbox>
|
|
176
|
+
<snice-checkbox name="terms" label="I accept the terms" required></snice-checkbox>
|
|
177
|
+
<snice-checkbox name="privacy" label="I accept the privacy policy" required></snice-checkbox>
|
|
178
|
+
</div>
|
|
179
|
+
<button type="submit">Submit</button>
|
|
180
|
+
</form>
|
|
181
|
+
<div id="form-output" class="output">Form data will appear here...</div>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<script type="module">
|
|
185
|
+
import './snice-checkbox.ts';
|
|
186
|
+
|
|
187
|
+
// Interactive checkbox events
|
|
188
|
+
const interactiveCheckbox = document.getElementById('interactive-checkbox');
|
|
189
|
+
const eventOutput = document.getElementById('event-output');
|
|
190
|
+
|
|
191
|
+
interactiveCheckbox.addEventListener('@snice/checkbox-change', (e) => {
|
|
192
|
+
eventOutput.textContent = `Changed: checked=${e.detail.checked}, indeterminate=${e.detail.indeterminate}`;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Get selected interests
|
|
196
|
+
window.getSelectedInterests = function() {
|
|
197
|
+
const checkboxes = document.querySelectorAll('snice-checkbox[name="interests"]');
|
|
198
|
+
const selected = Array.from(checkboxes)
|
|
199
|
+
.filter(cb => cb.checked)
|
|
200
|
+
.map(cb => cb.value);
|
|
201
|
+
document.getElementById('interests-output').textContent =
|
|
202
|
+
`Selected: ${selected.length > 0 ? selected.join(', ') : 'None'}`;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// Terms "select all" functionality
|
|
206
|
+
const termsAll = document.getElementById('terms-all');
|
|
207
|
+
const termsItems = document.querySelectorAll('.terms-item');
|
|
208
|
+
|
|
209
|
+
termsAll.addEventListener('@snice/checkbox-change', (e) => {
|
|
210
|
+
if (!e.detail.indeterminate) {
|
|
211
|
+
termsItems.forEach(item => {
|
|
212
|
+
item.checked = e.detail.checked;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
termsItems.forEach(item => {
|
|
218
|
+
item.addEventListener('@snice/checkbox-change', updateTermsAll);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
function updateTermsAll() {
|
|
222
|
+
const checkedCount = Array.from(termsItems).filter(item => item.checked).length;
|
|
223
|
+
if (checkedCount === 0) {
|
|
224
|
+
termsAll.checked = false;
|
|
225
|
+
termsAll.indeterminate = false;
|
|
226
|
+
} else if (checkedCount === termsItems.length) {
|
|
227
|
+
termsAll.checked = true;
|
|
228
|
+
termsAll.indeterminate = false;
|
|
229
|
+
} else {
|
|
230
|
+
termsAll.indeterminate = true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Form submission
|
|
235
|
+
document.getElementById('demo-form').addEventListener('submit', (e) => {
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
const formData = new FormData(e.target);
|
|
238
|
+
const data = {};
|
|
239
|
+
const checkboxes = e.target.querySelectorAll('snice-checkbox');
|
|
240
|
+
checkboxes.forEach(cb => {
|
|
241
|
+
if (cb.name) {
|
|
242
|
+
data[cb.name] = cb.checked;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
document.getElementById('form-output').textContent =
|
|
246
|
+
`Form data: ${JSON.stringify(data, null, 2)}`;
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Initialize terms state
|
|
250
|
+
updateTermsAll();
|
|
251
|
+
</script>
|
|
252
|
+
</body>
|
|
253
|
+
</html>
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
font-family: var(--snice-font-family);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.checkbox-wrapper {
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
position: relative;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
user-select: none;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.checkbox-wrapper--disabled {
|
|
15
|
+
cursor: not-allowed;
|
|
16
|
+
opacity: 0.6;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* Hide native checkbox */
|
|
20
|
+
.checkbox-input {
|
|
21
|
+
position: absolute;
|
|
22
|
+
opacity: 0;
|
|
23
|
+
width: 0;
|
|
24
|
+
height: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Custom checkbox */
|
|
28
|
+
.checkbox {
|
|
29
|
+
position: relative;
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
background: var(--snice-color-background);
|
|
34
|
+
border: 2px solid var(--snice-color-border);
|
|
35
|
+
border-radius: var(--snice-border-radius-sm);
|
|
36
|
+
transition: all var(--snice-transition-fast) ease;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* Size variants */
|
|
40
|
+
.checkbox--small {
|
|
41
|
+
width: 1rem; /* 16px */
|
|
42
|
+
height: 1rem; /* 16px */
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.checkbox--medium {
|
|
46
|
+
width: 1.25rem; /* 20px */
|
|
47
|
+
height: 1.25rem; /* 20px */
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.checkbox--large {
|
|
51
|
+
width: 1.5rem; /* 24px */
|
|
52
|
+
height: 1.5rem; /* 24px */
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* States */
|
|
56
|
+
.checkbox-input:checked ~ .checkbox {
|
|
57
|
+
background: var(--snice-color-primary);
|
|
58
|
+
border-color: var(--snice-color-primary);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.checkbox-input:focus-visible ~ .checkbox {
|
|
62
|
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.checkbox-input:disabled ~ .checkbox {
|
|
66
|
+
background: var(--snice-color-background-secondary);
|
|
67
|
+
border-color: var(--snice-color-border);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.checkbox-input:disabled:checked ~ .checkbox {
|
|
71
|
+
background: var(--snice-color-text-secondary);
|
|
72
|
+
border-color: var(--snice-color-text-secondary);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Invalid state */
|
|
76
|
+
.checkbox--invalid {
|
|
77
|
+
border-color: var(--snice-color-danger);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.checkbox-input:checked ~ .checkbox--invalid {
|
|
81
|
+
background: var(--snice-color-danger);
|
|
82
|
+
border-color: var(--snice-color-danger);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Checkmark */
|
|
86
|
+
.checkbox-icon {
|
|
87
|
+
position: absolute;
|
|
88
|
+
display: none;
|
|
89
|
+
color: white;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.checkbox-input:checked ~ .checkbox .checkbox-icon--check {
|
|
93
|
+
display: block;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.checkbox--indeterminate .checkbox-icon--check {
|
|
97
|
+
display: none !important;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.checkbox--indeterminate .checkbox-icon--indeterminate {
|
|
101
|
+
display: block !important;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Icon sizes */
|
|
105
|
+
.checkbox--small .checkbox-icon {
|
|
106
|
+
width: 0.75rem; /* 12px */
|
|
107
|
+
height: 0.75rem; /* 12px */
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.checkbox--medium .checkbox-icon {
|
|
111
|
+
width: 0.875rem; /* 14px */
|
|
112
|
+
height: 0.875rem; /* 14px */
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.checkbox--large .checkbox-icon {
|
|
116
|
+
width: 1.125rem; /* 18px */
|
|
117
|
+
height: 1.125rem; /* 18px */
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Label */
|
|
121
|
+
.checkbox-label {
|
|
122
|
+
margin-left: 0.5rem; /* 8px */
|
|
123
|
+
color: var(--snice-color-text);
|
|
124
|
+
cursor: pointer;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.checkbox-label--small {
|
|
128
|
+
font-size: var(--snice-font-size-sm);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.checkbox-label--medium {
|
|
132
|
+
font-size: var(--snice-font-size-md);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.checkbox-label--large {
|
|
136
|
+
font-size: var(--snice-font-size-lg);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.checkbox-wrapper--disabled .checkbox-label {
|
|
140
|
+
color: var(--snice-color-text-secondary);
|
|
141
|
+
cursor: not-allowed;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* Required indicator */
|
|
145
|
+
.checkbox-label--required::after {
|
|
146
|
+
content: ' *';
|
|
147
|
+
color: var(--snice-color-danger);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* Focus ring for keyboard navigation */
|
|
151
|
+
.checkbox-input:focus-visible ~ .checkbox {
|
|
152
|
+
outline: 2px solid var(--snice-color-primary);
|
|
153
|
+
outline-offset: 2px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* Hover effect */
|
|
157
|
+
.checkbox-wrapper:not(.checkbox-wrapper--disabled):hover .checkbox {
|
|
158
|
+
border-color: var(--snice-color-primary);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.checkbox-wrapper:not(.checkbox-wrapper--disabled):hover .checkbox-input:checked ~ .checkbox {
|
|
162
|
+
background: var(--snice-color-primary-hover);
|
|
163
|
+
border-color: var(--snice-color-primary-hover);
|
|
164
|
+
}
|