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,191 @@
|
|
|
1
|
+
import { element, property, watch, query, dispatch, on, ready } from 'snice';
|
|
2
|
+
import css from './snice-breadcrumbs.css?inline';
|
|
3
|
+
import type { BreadcrumbItem, BreadcrumbSeparator, BreadcrumbSize, SniceBreadcrumbsElement } from './snice-breadcrumbs.types';
|
|
4
|
+
import type { SniceCrumbElement } from './snice-breadcrumbs.types';
|
|
5
|
+
|
|
6
|
+
@element('snice-breadcrumbs')
|
|
7
|
+
export class SniceBreadcrumbs extends HTMLElement implements SniceBreadcrumbsElement {
|
|
8
|
+
@property({ type: Array })
|
|
9
|
+
items: BreadcrumbItem[] = [];
|
|
10
|
+
|
|
11
|
+
@property({ reflect: true })
|
|
12
|
+
separator: BreadcrumbSeparator = '/';
|
|
13
|
+
|
|
14
|
+
@property({ reflect: true })
|
|
15
|
+
size: BreadcrumbSize = 'medium';
|
|
16
|
+
|
|
17
|
+
@property({ type: Number, reflect: true })
|
|
18
|
+
maxItems = 0;
|
|
19
|
+
|
|
20
|
+
@query('.breadcrumb')
|
|
21
|
+
breadcrumbElement?: HTMLElement;
|
|
22
|
+
|
|
23
|
+
private collapsed = true;
|
|
24
|
+
private slotItems: BreadcrumbItem[] = [];
|
|
25
|
+
|
|
26
|
+
html() {
|
|
27
|
+
const allItems = this.getAllItems();
|
|
28
|
+
const visibleItems = this.getVisibleItems(allItems);
|
|
29
|
+
const hasCollapsed = this.maxItems > 0 && allItems.length > this.maxItems && this.collapsed;
|
|
30
|
+
|
|
31
|
+
return /*html*/`
|
|
32
|
+
<slot style="display: none"></slot>
|
|
33
|
+
<nav aria-label="Breadcrumb">
|
|
34
|
+
<ol class="breadcrumb ${hasCollapsed ? 'breadcrumb--collapsed' : ''}">
|
|
35
|
+
${visibleItems.map((item, index) => {
|
|
36
|
+
const isLast = index === visibleItems.length - 1;
|
|
37
|
+
const isActive = item.active || isLast;
|
|
38
|
+
const isHidden = hasCollapsed && index > 0 && index < visibleItems.length - 2;
|
|
39
|
+
|
|
40
|
+
return /*html*/`
|
|
41
|
+
<li class="breadcrumb-item ${isActive ? 'breadcrumb-item--active' : ''} ${isHidden ? 'breadcrumb-item--hidden' : ''}">
|
|
42
|
+
${item.href && !isActive ? /*html*/`
|
|
43
|
+
<a href="${item.href}"
|
|
44
|
+
class="breadcrumb-link"
|
|
45
|
+
aria-current="${isActive ? 'page' : ''}"
|
|
46
|
+
tabindex="0">
|
|
47
|
+
${this.renderIcon(item)}
|
|
48
|
+
${item.label}
|
|
49
|
+
</a>
|
|
50
|
+
` : /*html*/`
|
|
51
|
+
<span class="breadcrumb-text"
|
|
52
|
+
aria-current="${isActive ? 'page' : ''}">
|
|
53
|
+
${this.renderIcon(item)}
|
|
54
|
+
${item.label}
|
|
55
|
+
</span>
|
|
56
|
+
`}
|
|
57
|
+
${!isLast ? /*html*/`
|
|
58
|
+
<span class="breadcrumb-separator" aria-hidden="true">
|
|
59
|
+
${this.separator}
|
|
60
|
+
</span>
|
|
61
|
+
` : ''}
|
|
62
|
+
</li>
|
|
63
|
+
${hasCollapsed && index === 0 && allItems.length > this.maxItems ? /*html*/`
|
|
64
|
+
<li class="breadcrumb-item">
|
|
65
|
+
<button class="breadcrumb-ellipsis"
|
|
66
|
+
aria-label="Show all breadcrumbs"
|
|
67
|
+
tabindex="0">
|
|
68
|
+
•••
|
|
69
|
+
</button>
|
|
70
|
+
<span class="breadcrumb-separator" aria-hidden="true">
|
|
71
|
+
${this.separator}
|
|
72
|
+
</span>
|
|
73
|
+
</li>
|
|
74
|
+
` : ''}
|
|
75
|
+
`;
|
|
76
|
+
}).join('')}
|
|
77
|
+
</ol>
|
|
78
|
+
</nav>
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
css() {
|
|
83
|
+
return css;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private getAllItems(): BreadcrumbItem[] {
|
|
87
|
+
// Prefer slot items if available, otherwise use items property
|
|
88
|
+
return this.slotItems.length > 0 ? this.slotItems : this.items;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private getVisibleItems(allItems: BreadcrumbItem[]): BreadcrumbItem[] {
|
|
92
|
+
if (this.maxItems <= 0 || allItems.length <= this.maxItems || !this.collapsed) {
|
|
93
|
+
return allItems;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Show first item and last (maxItems - 1) items
|
|
97
|
+
const firstItem = allItems[0];
|
|
98
|
+
const lastItems = allItems.slice(-(this.maxItems - 1));
|
|
99
|
+
return [firstItem, ...lastItems];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@on('click', '.breadcrumb-ellipsis')
|
|
103
|
+
handleEllipsisClick() {
|
|
104
|
+
this.collapsed = false;
|
|
105
|
+
this.render();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@on('click', '.breadcrumb-link')
|
|
109
|
+
@dispatch('breadcrumb-click')
|
|
110
|
+
handleLinkClick(event: MouseEvent) {
|
|
111
|
+
const target = event.target as HTMLAnchorElement;
|
|
112
|
+
const label = target.textContent?.trim() || '';
|
|
113
|
+
const href = target.getAttribute('href') || '';
|
|
114
|
+
|
|
115
|
+
// Find the item index
|
|
116
|
+
const allItems = this.getAllItems();
|
|
117
|
+
const index = allItems.findIndex(item => item.label === label);
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
item: allItems[index],
|
|
121
|
+
index,
|
|
122
|
+
href,
|
|
123
|
+
label
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private handleSlotChange() {
|
|
128
|
+
const slot = this.shadowRoot?.querySelector('slot');
|
|
129
|
+
if (!slot) return;
|
|
130
|
+
|
|
131
|
+
const crumbs = slot.assignedElements().filter(
|
|
132
|
+
el => el.tagName.toLowerCase() === 'snice-crumb'
|
|
133
|
+
) as SniceCrumbElement[];
|
|
134
|
+
|
|
135
|
+
this.slotItems = crumbs.map(crumb => ({
|
|
136
|
+
label: crumb.label || crumb.textContent?.trim() || '',
|
|
137
|
+
href: crumb.href || undefined,
|
|
138
|
+
icon: crumb.icon || undefined,
|
|
139
|
+
iconImage: crumb.iconImage || undefined,
|
|
140
|
+
active: crumb.active || false
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
this.render();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@ready()
|
|
147
|
+
init() {
|
|
148
|
+
// Setup slot change handling
|
|
149
|
+
const slot = this.shadowRoot?.querySelector('slot');
|
|
150
|
+
if (slot) {
|
|
151
|
+
slot.addEventListener('slotchange', () => this.handleSlotChange());
|
|
152
|
+
// Initial check for slotted content
|
|
153
|
+
this.handleSlotChange();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@watch('items', 'separator', 'maxItems')
|
|
158
|
+
updateBreadcrumb() {
|
|
159
|
+
this.collapsed = true;
|
|
160
|
+
// Only render if not using slot items, otherwise slot change will handle it
|
|
161
|
+
if (!this.slotItems || this.slotItems.length === 0) {
|
|
162
|
+
this.render();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
setItems(items: BreadcrumbItem[]) {
|
|
167
|
+
this.items = items;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private renderIcon(item: BreadcrumbItem): string {
|
|
171
|
+
return /*html*/`
|
|
172
|
+
<img class="breadcrumb-icon-image" src="${item.iconImage || ''}" alt="" ${item.iconImage ? '' : 'hidden'}>
|
|
173
|
+
<span class="breadcrumb-icon" ${item.icon ? '' : 'hidden'}>${item.icon || ''}</span>
|
|
174
|
+
`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private render() {
|
|
178
|
+
const shadow = this.shadowRoot;
|
|
179
|
+
if (shadow) {
|
|
180
|
+
shadow.innerHTML = '';
|
|
181
|
+
if (this.css) {
|
|
182
|
+
const style = document.createElement('style');
|
|
183
|
+
style.textContent = this.css();
|
|
184
|
+
shadow.appendChild(style);
|
|
185
|
+
}
|
|
186
|
+
const template = document.createElement('template');
|
|
187
|
+
template.innerHTML = this.html();
|
|
188
|
+
shadow.appendChild(template.content.cloneNode(true));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type BreadcrumbSeparator = '/' | '>' | '»' | '•' | '|';
|
|
2
|
+
export type BreadcrumbSize = 'small' | 'medium' | 'large';
|
|
3
|
+
|
|
4
|
+
export interface BreadcrumbItem {
|
|
5
|
+
label: string;
|
|
6
|
+
href?: string;
|
|
7
|
+
icon?: string;
|
|
8
|
+
iconImage?: string;
|
|
9
|
+
active?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SniceBreadcrumbsElement extends HTMLElement {
|
|
13
|
+
items: BreadcrumbItem[];
|
|
14
|
+
separator: BreadcrumbSeparator;
|
|
15
|
+
size: BreadcrumbSize;
|
|
16
|
+
maxItems: number;
|
|
17
|
+
setItems(items: BreadcrumbItem[]): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SniceCrumbElement extends HTMLElement {
|
|
21
|
+
label: string;
|
|
22
|
+
href: string;
|
|
23
|
+
icon: string;
|
|
24
|
+
iconImage: string;
|
|
25
|
+
active: boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { element, property } from 'snice';
|
|
2
|
+
import type { SniceCrumbElement } from './snice-breadcrumbs.types';
|
|
3
|
+
|
|
4
|
+
@element('snice-crumb')
|
|
5
|
+
export class SniceCrumb extends HTMLElement implements SniceCrumbElement {
|
|
6
|
+
@property({ reflect: true })
|
|
7
|
+
label = '';
|
|
8
|
+
|
|
9
|
+
@property({ reflect: true })
|
|
10
|
+
href = '';
|
|
11
|
+
|
|
12
|
+
@property({ reflect: true })
|
|
13
|
+
icon = '';
|
|
14
|
+
|
|
15
|
+
@property({ attribute: 'icon-image', reflect: true })
|
|
16
|
+
iconImage = '';
|
|
17
|
+
|
|
18
|
+
@property({ type: Boolean, reflect: true })
|
|
19
|
+
active = false;
|
|
20
|
+
|
|
21
|
+
// No shadow DOM - this is a data element
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
// Hide the element as it's only for data
|
|
24
|
+
this.style.display = 'none';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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>Button 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
|
+
}
|
|
15
|
+
|
|
16
|
+
.row {
|
|
17
|
+
margin-bottom: 20px;
|
|
18
|
+
display: flex;
|
|
19
|
+
gap: 10px;
|
|
20
|
+
align-items: center;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
h2 {
|
|
24
|
+
color: var(--snice-color-text);
|
|
25
|
+
margin-bottom: 20px;
|
|
26
|
+
}
|
|
27
|
+
</style>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<h2>Button Variants</h2>
|
|
31
|
+
<div class="row">
|
|
32
|
+
<snice-button variant="default">Default</snice-button>
|
|
33
|
+
<snice-button variant="primary">Primary</snice-button>
|
|
34
|
+
<snice-button variant="success">Success</snice-button>
|
|
35
|
+
<snice-button variant="warning">Warning</snice-button>
|
|
36
|
+
<snice-button variant="danger">Danger</snice-button>
|
|
37
|
+
<snice-button variant="text">Text</snice-button>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<script type="module" src="./snice-button.ts"></script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
position: relative;
|
|
4
|
+
width: auto;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
:host([disabled]) {
|
|
9
|
+
cursor: not-allowed;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.button {
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
width: 100%;
|
|
17
|
+
border: 1px solid;
|
|
18
|
+
font-family: var(--snice-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif);
|
|
19
|
+
font-weight: var(--snice-font-weight-medium, 500);
|
|
20
|
+
text-decoration: none;
|
|
21
|
+
user-select: none;
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
vertical-align: middle;
|
|
24
|
+
padding: 0;
|
|
25
|
+
transition:
|
|
26
|
+
color var(--snice-transition-fast, 150ms) ease,
|
|
27
|
+
background-color var(--snice-transition-fast, 150ms) ease,
|
|
28
|
+
border-color var(--snice-transition-fast, 150ms) ease,
|
|
29
|
+
box-shadow var(--snice-transition-fast, 150ms) ease;
|
|
30
|
+
cursor: inherit;
|
|
31
|
+
position: relative;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.button:focus-visible {
|
|
35
|
+
outline: none;
|
|
36
|
+
box-shadow: 0 0 0 var(--snice-focus-ring-width, 2px) var(--snice-focus-ring-color, rgb(59 130 246 / 0.5));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.button--disabled {
|
|
40
|
+
opacity: 0.5;
|
|
41
|
+
cursor: not-allowed;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* Sizes */
|
|
45
|
+
.button--small {
|
|
46
|
+
font-size: var(--snice-font-size-sm, 0.875rem);
|
|
47
|
+
height: 1.875rem; /* 30px */
|
|
48
|
+
padding: 0 var(--snice-spacing-sm, 0.75rem);
|
|
49
|
+
border-radius: var(--snice-border-radius-md, 0.25rem);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.button--medium {
|
|
53
|
+
font-size: var(--snice-font-size-md, 1rem);
|
|
54
|
+
height: 2.5rem; /* 40px */
|
|
55
|
+
padding: 0 var(--snice-spacing-md, 1rem);
|
|
56
|
+
border-radius: var(--snice-border-radius-md, 0.25rem);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.button--large {
|
|
60
|
+
font-size: var(--snice-font-size-lg, 1.125rem);
|
|
61
|
+
height: 3.125rem; /* 50px */
|
|
62
|
+
padding: 0 var(--snice-spacing-lg, 1.5rem);
|
|
63
|
+
border-radius: var(--snice-border-radius-md, 0.25rem);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Variants - Default */
|
|
67
|
+
.button--default {
|
|
68
|
+
background-color: var(--snice-color-background, rgb(255 255 255));
|
|
69
|
+
color: var(--snice-color-text, rgb(23 23 23));
|
|
70
|
+
border-color: var(--snice-color-border, rgb(226 226 226));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.button--default:hover:not(.button--disabled) {
|
|
74
|
+
background-color: var(--snice-color-background-secondary, rgb(250 250 250));
|
|
75
|
+
border-color: var(--snice-color-border-hover, rgb(204 204 204));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.button--default:active:not(.button--disabled) {
|
|
79
|
+
background-color: var(--snice-color-background-tertiary, rgb(241 241 241));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* Variants - Primary */
|
|
83
|
+
.button--primary {
|
|
84
|
+
background-color: var(--snice-color-primary, rgb(37 99 235));
|
|
85
|
+
color: var(--snice-color-text-inverse, rgb(250 250 250));
|
|
86
|
+
border-color: var(--snice-color-primary, rgb(37 99 235));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.button--primary:hover:not(.button--disabled) {
|
|
90
|
+
background-color: var(--snice-color-primary-hover, rgb(29 78 216));
|
|
91
|
+
border-color: var(--snice-color-primary-hover, rgb(29 78 216));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.button--primary:active:not(.button--disabled) {
|
|
95
|
+
background-color: var(--snice-color-primary-hover, rgb(29 78 216));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Variants - Success */
|
|
99
|
+
.button--success {
|
|
100
|
+
background-color: var(--snice-color-success, rgb(22 163 74));
|
|
101
|
+
color: var(--snice-color-text-inverse, rgb(250 250 250));
|
|
102
|
+
border-color: var(--snice-color-success, rgb(22 163 74));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.button--success:hover:not(.button--disabled) {
|
|
106
|
+
background-color: var(--snice-color-success-hover, rgb(21 128 61));
|
|
107
|
+
border-color: var(--snice-color-success-hover, rgb(21 128 61));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Variants - Warning */
|
|
111
|
+
.button--warning {
|
|
112
|
+
background-color: var(--snice-color-warning, rgb(202 138 4));
|
|
113
|
+
color: var(--snice-color-text-inverse, rgb(250 250 250));
|
|
114
|
+
border-color: var(--snice-color-warning, rgb(202 138 4));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.button--warning:hover:not(.button--disabled) {
|
|
118
|
+
background-color: var(--snice-color-warning-hover, rgb(161 98 7));
|
|
119
|
+
border-color: var(--snice-color-warning-hover, rgb(161 98 7));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* Variants - Danger */
|
|
123
|
+
.button--danger {
|
|
124
|
+
background-color: var(--snice-color-danger, rgb(220 38 38));
|
|
125
|
+
color: var(--snice-color-text-inverse, rgb(250 250 250));
|
|
126
|
+
border-color: var(--snice-color-danger, rgb(220 38 38));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.button--danger:hover:not(.button--disabled) {
|
|
130
|
+
background-color: var(--snice-color-danger-hover, rgb(185 28 28));
|
|
131
|
+
border-color: var(--snice-color-danger-hover, rgb(185 28 28));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* Variants - Text */
|
|
135
|
+
.button--text {
|
|
136
|
+
background-color: transparent;
|
|
137
|
+
color: var(--snice-color-primary, rgb(37 99 235));
|
|
138
|
+
border-color: transparent;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.button--text:hover:not(.button--disabled) {
|
|
142
|
+
background-color: rgb(59 130 246 / 0.1);
|
|
143
|
+
color: var(--snice-color-primary-hover, rgb(29 78 216));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* Outline modifier */
|
|
147
|
+
.button--outline.button--default {
|
|
148
|
+
background-color: transparent;
|
|
149
|
+
color: var(--snice-color-text, rgb(23 23 23));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.button--outline.button--primary {
|
|
153
|
+
background-color: transparent;
|
|
154
|
+
color: var(--snice-color-primary, rgb(37 99 235));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.button--outline.button--success {
|
|
158
|
+
background-color: transparent;
|
|
159
|
+
color: var(--snice-color-success, rgb(22 163 74));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.button--outline.button--warning {
|
|
163
|
+
background-color: transparent;
|
|
164
|
+
color: var(--snice-color-warning, rgb(202 138 4));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.button--outline.button--danger {
|
|
168
|
+
background-color: transparent;
|
|
169
|
+
color: var(--snice-color-danger, rgb(220 38 38));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.button--outline:hover:not(.button--disabled) {
|
|
173
|
+
background-color: rgb(115 115 115 / 0.1);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* Shape modifiers */
|
|
177
|
+
.button--pill {
|
|
178
|
+
border-radius: var(--snice-border-radius-pill, 9999px);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.button--circle {
|
|
182
|
+
border-radius: var(--snice-border-radius-circle, 50%);
|
|
183
|
+
width: var(--size);
|
|
184
|
+
padding: 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.button--small.button--circle { --size: 1.875rem; /* 30px */ }
|
|
188
|
+
.button--medium.button--circle { --size: 2.5rem; /* 40px */ }
|
|
189
|
+
.button--large.button--circle { --size: 3.125rem; /* 50px */ }
|
|
190
|
+
|
|
191
|
+
/* Loading state */
|
|
192
|
+
.button--loading {
|
|
193
|
+
position: relative;
|
|
194
|
+
cursor: wait;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.button--loading .label {
|
|
198
|
+
visibility: hidden;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.spinner {
|
|
202
|
+
display: none;
|
|
203
|
+
position: absolute;
|
|
204
|
+
top: 50%;
|
|
205
|
+
left: 50%;
|
|
206
|
+
transform: translate(-50%, -50%);
|
|
207
|
+
width: 1em;
|
|
208
|
+
height: 1em;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.button--loading .spinner {
|
|
212
|
+
display: block;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.spinner::after {
|
|
216
|
+
content: '';
|
|
217
|
+
display: block;
|
|
218
|
+
width: 100%;
|
|
219
|
+
height: 100%;
|
|
220
|
+
border: 2px solid currentColor;
|
|
221
|
+
border-right-color: transparent;
|
|
222
|
+
border-radius: 50%;
|
|
223
|
+
animation: spin 0.6s linear infinite;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@keyframes spin {
|
|
227
|
+
to {
|
|
228
|
+
transform: rotate(360deg);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { element, property, query, on, dispatch, watch } from 'snice';
|
|
2
|
+
import css from './snice-button.css?inline';
|
|
3
|
+
import type { ButtonVariant, ButtonSize, IconPlacement, SniceButtonElement } from './snice-button.types';
|
|
4
|
+
|
|
5
|
+
@element('snice-button')
|
|
6
|
+
export class SniceButton extends HTMLElement implements SniceButtonElement {
|
|
7
|
+
@property({ reflect: true })
|
|
8
|
+
variant: ButtonVariant = 'default';
|
|
9
|
+
|
|
10
|
+
@property({ reflect: true })
|
|
11
|
+
size: ButtonSize = 'medium';
|
|
12
|
+
|
|
13
|
+
@property({ type: Boolean, reflect: true })
|
|
14
|
+
disabled = false;
|
|
15
|
+
|
|
16
|
+
@property({ type: Boolean, reflect: true })
|
|
17
|
+
loading = false;
|
|
18
|
+
|
|
19
|
+
@property({ type: Boolean, reflect: true })
|
|
20
|
+
outline = false;
|
|
21
|
+
|
|
22
|
+
@property({ type: Boolean, reflect: true })
|
|
23
|
+
pill = false;
|
|
24
|
+
|
|
25
|
+
@property({ type: Boolean, reflect: true })
|
|
26
|
+
circle = false;
|
|
27
|
+
|
|
28
|
+
@property({ type: String, reflect: true })
|
|
29
|
+
href = '';
|
|
30
|
+
|
|
31
|
+
@property({ type: String, reflect: true })
|
|
32
|
+
target = '';
|
|
33
|
+
|
|
34
|
+
@property({ type: String, reflect: true })
|
|
35
|
+
download = '';
|
|
36
|
+
|
|
37
|
+
@property({ type: String, reflect: true })
|
|
38
|
+
icon = '';
|
|
39
|
+
|
|
40
|
+
@property({ attribute: 'icon-placement', reflect: true })
|
|
41
|
+
iconPlacement: IconPlacement = 'start';
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@query('.button')
|
|
45
|
+
button?: HTMLButtonElement;
|
|
46
|
+
|
|
47
|
+
@query('.spinner')
|
|
48
|
+
spinner?: HTMLElement;
|
|
49
|
+
|
|
50
|
+
@query('.label')
|
|
51
|
+
label?: HTMLElement;
|
|
52
|
+
|
|
53
|
+
@query('.icon')
|
|
54
|
+
iconElement?: HTMLImageElement;
|
|
55
|
+
|
|
56
|
+
html() {
|
|
57
|
+
const classes = [
|
|
58
|
+
'button',
|
|
59
|
+
`button--${this.variant || 'default'}`,
|
|
60
|
+
`button--${this.size || 'medium'}`,
|
|
61
|
+
this.outline ? 'button--outline' : '',
|
|
62
|
+
this.pill ? 'button--pill' : '',
|
|
63
|
+
this.circle ? 'button--circle' : '',
|
|
64
|
+
this.loading ? 'button--loading' : '',
|
|
65
|
+
this.disabled ? 'button--disabled' : '',
|
|
66
|
+
this.icon ? `button--has-icon` : '',
|
|
67
|
+
this.icon ? `button--icon-${this.iconPlacement}` : ''
|
|
68
|
+
].filter(Boolean).join(' ');
|
|
69
|
+
|
|
70
|
+
const iconElement = this.icon ? /*html*/`
|
|
71
|
+
<img class="icon" src="${this.icon}" alt="" part="icon" />
|
|
72
|
+
` : '';
|
|
73
|
+
|
|
74
|
+
return /*html*/`
|
|
75
|
+
<button class="${classes}" type="button" ${this.disabled ? 'disabled' : ''} part="base">
|
|
76
|
+
<span class="spinner" part="spinner"></span>
|
|
77
|
+
${this.iconPlacement === 'start' ? iconElement : ''}
|
|
78
|
+
<span class="label" part="label">
|
|
79
|
+
<slot></slot>
|
|
80
|
+
</span>
|
|
81
|
+
${this.iconPlacement === 'end' ? iconElement : ''}
|
|
82
|
+
</button>
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
css() {
|
|
87
|
+
return css;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@watch('*')
|
|
91
|
+
updateButtonClasses() {
|
|
92
|
+
if (!this.button) return;
|
|
93
|
+
|
|
94
|
+
// Rebuild all classes based on current state
|
|
95
|
+
const classes = [
|
|
96
|
+
'button',
|
|
97
|
+
`button--${this.variant}`,
|
|
98
|
+
`button--${this.size}`,
|
|
99
|
+
this.outline ? 'button--outline' : '',
|
|
100
|
+
this.pill ? 'button--pill' : '',
|
|
101
|
+
this.circle ? 'button--circle' : '',
|
|
102
|
+
this.loading ? 'button--loading' : '',
|
|
103
|
+
this.disabled ? 'button--disabled' : '',
|
|
104
|
+
this.icon ? `button--has-icon` : '',
|
|
105
|
+
this.icon ? `button--icon-${this.iconPlacement}` : ''
|
|
106
|
+
].filter(Boolean);
|
|
107
|
+
|
|
108
|
+
// Set the className directly to avoid class manipulation issues
|
|
109
|
+
this.button.className = classes.join(' ');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@watch('disabled')
|
|
113
|
+
updateDisabledState() {
|
|
114
|
+
if (this.button) {
|
|
115
|
+
this.button.disabled = this.disabled;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Keep these methods for backwards compatibility if needed
|
|
120
|
+
setLoading(loading: boolean) {
|
|
121
|
+
this.loading = loading;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
setDisabled(disabled: boolean) {
|
|
125
|
+
this.disabled = disabled;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
setVariant(variant: typeof this.variant) {
|
|
129
|
+
this.variant = variant;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@on('click')
|
|
133
|
+
@dispatch('@snice/click')
|
|
134
|
+
handleClick(event: MouseEvent) {
|
|
135
|
+
if (this.disabled || this.loading) {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
event.stopPropagation();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Handle navigation if href is set
|
|
142
|
+
if (this.href) {
|
|
143
|
+
if (this.download) {
|
|
144
|
+
const a = document.createElement('a');
|
|
145
|
+
a.href = this.href;
|
|
146
|
+
a.download = this.download;
|
|
147
|
+
a.click();
|
|
148
|
+
} else if (this.target) {
|
|
149
|
+
window.open(this.href, this.target);
|
|
150
|
+
} else {
|
|
151
|
+
window.location.href = this.href;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { originalEvent: event };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
focus(options?: FocusOptions) {
|
|
159
|
+
this.button?.focus(options);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
blur() {
|
|
163
|
+
this.button?.blur();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
click() {
|
|
167
|
+
this.button?.click();
|
|
168
|
+
}
|
|
169
|
+
}
|