@surreal-ui/web 0.5.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/CHANGELOG.md +69 -0
- package/dist/index.js +12075 -0
- package/package.json +27 -0
- package/src/components/GlassmorphismAlert.ts +116 -0
- package/src/components/GlassmorphismButton.ts +19 -0
- package/src/components/GlassmorphismCard.ts +33 -0
- package/src/components/GlassmorphismEmptyState.ts +29 -0
- package/src/components/GlassmorphismInputGroup.ts +202 -0
- package/src/components/GlassmorphismMenubar.ts +36 -0
- package/src/components/GlassmorphismScrollArea.ts +83 -0
- package/src/components/GlassmorphismTable.ts +52 -0
- package/src/components/GlassmorphismTypography.ts +67 -0
- package/src/components/MinimalistAccordion.ts +248 -0
- package/src/components/MinimalistAlert.ts +99 -0
- package/src/components/MinimalistAlertDialog.ts +100 -0
- package/src/components/MinimalistAspectRatio.ts +34 -0
- package/src/components/MinimalistAvatar.ts +98 -0
- package/src/components/MinimalistBadge.ts +71 -0
- package/src/components/MinimalistBreadcrumb.ts +92 -0
- package/src/components/MinimalistButton.ts +111 -0
- package/src/components/MinimalistButtonGroup.ts +110 -0
- package/src/components/MinimalistCalendar.ts +282 -0
- package/src/components/MinimalistCard.ts +131 -0
- package/src/components/MinimalistCarousel.ts +122 -0
- package/src/components/MinimalistChart.ts +151 -0
- package/src/components/MinimalistCheckbox.ts +179 -0
- package/src/components/MinimalistCodeBlock.ts +113 -0
- package/src/components/MinimalistCollapsible.ts +155 -0
- package/src/components/MinimalistCommand.ts +112 -0
- package/src/components/MinimalistContextMenu.ts +99 -0
- package/src/components/MinimalistDialog.ts +104 -0
- package/src/components/MinimalistDrawer.ts +223 -0
- package/src/components/MinimalistDropdownMenu.ts +120 -0
- package/src/components/MinimalistEmpty.ts +98 -0
- package/src/components/MinimalistEmptyState.ts +38 -0
- package/src/components/MinimalistField.ts +171 -0
- package/src/components/MinimalistForm.ts +101 -0
- package/src/components/MinimalistHoverCard.ts +150 -0
- package/src/components/MinimalistInput.ts +105 -0
- package/src/components/MinimalistInputGroup.ts +93 -0
- package/src/components/MinimalistInputOtp.ts +155 -0
- package/src/components/MinimalistItem.ts +160 -0
- package/src/components/MinimalistKbd.ts +38 -0
- package/src/components/MinimalistLabel.ts +54 -0
- package/src/components/MinimalistMenubar.ts +82 -0
- package/src/components/MinimalistNativeSelect.ts +144 -0
- package/src/components/MinimalistNavigationMenu.ts +98 -0
- package/src/components/MinimalistPagination.ts +141 -0
- package/src/components/MinimalistPopover.ts +113 -0
- package/src/components/MinimalistProgress.ts +71 -0
- package/src/components/MinimalistRadioGroup.ts +226 -0
- package/src/components/MinimalistRangeCalendar.ts +267 -0
- package/src/components/MinimalistResizable.ts +44 -0
- package/src/components/MinimalistScrollArea.ts +11 -0
- package/src/components/MinimalistSelect.ts +104 -0
- package/src/components/MinimalistSeparator.ts +53 -0
- package/src/components/MinimalistSheet.ts +166 -0
- package/src/components/MinimalistSidebar.ts +75 -0
- package/src/components/MinimalistSkeleton.ts +33 -0
- package/src/components/MinimalistSlider.ts +237 -0
- package/src/components/MinimalistSonner.ts +94 -0
- package/src/components/MinimalistSpinner.ts +53 -0
- package/src/components/MinimalistSwitch.ts +166 -0
- package/src/components/MinimalistTable.ts +35 -0
- package/src/components/MinimalistTabs.ts +98 -0
- package/src/components/MinimalistTextarea.ts +100 -0
- package/src/components/MinimalistToggle.ts +105 -0
- package/src/components/MinimalistToggleGroup.ts +175 -0
- package/src/components/MinimalistTooltip.ts +83 -0
- package/src/components/MinimalistTypography.ts +107 -0
- package/src/components/NeubrutalismCard.ts +35 -0
- package/src/components/NeubrutalismItem.ts +67 -0
- package/src/components/ShadcnAccordion.ts +244 -0
- package/src/components/ShadcnAlertDialog.ts +96 -0
- package/src/components/ShadcnAspectRatio.ts +30 -0
- package/src/components/ShadcnAvatar.ts +94 -0
- package/src/components/ShadcnBadge.ts +67 -0
- package/src/components/ShadcnBreadcrumb.ts +88 -0
- package/src/components/ShadcnButton.ts +107 -0
- package/src/components/ShadcnButtonGroup.ts +106 -0
- package/src/components/ShadcnCalendar.ts +278 -0
- package/src/components/ShadcnCarousel.ts +118 -0
- package/src/components/ShadcnChart.ts +147 -0
- package/src/components/ShadcnCheckbox.ts +175 -0
- package/src/components/ShadcnCodeBlock.ts +109 -0
- package/src/components/ShadcnCollapsible.ts +151 -0
- package/src/components/ShadcnCommand.ts +108 -0
- package/src/components/ShadcnContextMenu.ts +95 -0
- package/src/components/ShadcnDialog.ts +100 -0
- package/src/components/ShadcnDrawer.ts +219 -0
- package/src/components/ShadcnDropdownMenu.ts +116 -0
- package/src/components/ShadcnEmpty.ts +94 -0
- package/src/components/ShadcnField.ts +167 -0
- package/src/components/ShadcnForm.ts +97 -0
- package/src/components/ShadcnHoverCard.ts +146 -0
- package/src/components/ShadcnInput.ts +101 -0
- package/src/components/ShadcnInputGroup.ts +89 -0
- package/src/components/ShadcnInputOtp.ts +151 -0
- package/src/components/ShadcnItem.ts +156 -0
- package/src/components/ShadcnKbd.ts +34 -0
- package/src/components/ShadcnLabel.ts +50 -0
- package/src/components/ShadcnMenubar.ts +78 -0
- package/src/components/ShadcnNativeSelect.ts +140 -0
- package/src/components/ShadcnNavigationMenu.ts +94 -0
- package/src/components/ShadcnPagination.ts +137 -0
- package/src/components/ShadcnPopover.ts +109 -0
- package/src/components/ShadcnProgress.ts +67 -0
- package/src/components/ShadcnRadioGroup.ts +222 -0
- package/src/components/ShadcnRangeCalendar.ts +263 -0
- package/src/components/ShadcnSelect.ts +100 -0
- package/src/components/ShadcnSeparator.ts +49 -0
- package/src/components/ShadcnSheet.ts +162 -0
- package/src/components/ShadcnSidebar.ts +71 -0
- package/src/components/ShadcnSkeleton.ts +29 -0
- package/src/components/ShadcnSlider.ts +233 -0
- package/src/components/ShadcnSonner.ts +90 -0
- package/src/components/ShadcnSpinner.ts +49 -0
- package/src/components/ShadcnSwitch.ts +162 -0
- package/src/components/ShadcnTabs.ts +94 -0
- package/src/components/ShadcnTextarea.ts +96 -0
- package/src/components/ShadcnToggle.ts +101 -0
- package/src/components/ShadcnToggleGroup.ts +171 -0
- package/src/components/ShadcnTooltip.ts +79 -0
- package/src/index.ts +124 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class SurrealModernTableDocs extends HTMLElement {
|
|
2
|
+
private _data: any = {};
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.attachShadow({ mode: 'open' });
|
|
6
|
+
}
|
|
7
|
+
set data(val: any) {
|
|
8
|
+
this._data = val;
|
|
9
|
+
this.render();
|
|
10
|
+
}
|
|
11
|
+
get data() {
|
|
12
|
+
return this._data;
|
|
13
|
+
}
|
|
14
|
+
connectedCallback() {
|
|
15
|
+
this.render();
|
|
16
|
+
}
|
|
17
|
+
private render() {
|
|
18
|
+
const docs = this._data?.docs || {};
|
|
19
|
+
const usageCode = (docs.usage || "import Component from '@surreal-ui/wc';").trim();
|
|
20
|
+
const propsList = docs.props || [];
|
|
21
|
+
if (!this.shadowRoot) return;
|
|
22
|
+
this.shadowRoot.innerHTML = `<style>@import 'https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/tailwind.min.css';:host { display: block; }</style><div class="space-y-6 text-white"><div><h3 class="text-sm font-semibold text-slate-300 uppercase tracking-wider mb-2">Usage Example</h3><pre class="p-4 rounded-xl bg-slate-950 border border-slate-800 text-xs font-mono text-indigo-200 leading-relaxed overflow-x-auto"><code>${usageCode}</code></pre></div><div><h3 class="text-sm font-semibold text-slate-300 uppercase tracking-wider mb-3">Props & Component Interface</h3>${propsList.length > 0 ? `<div class="border border-slate-800 rounded-xl overflow-hidden text-xs"><table class="w-full text-left"><thead class="bg-slate-950 border-b border-slate-800 text-slate-400"><tr><th class="p-3 font-semibold">Name</th><th class="p-3 font-semibold">Type</th><th class="p-3 font-semibold">Default</th><th class="p-3 font-semibold">Description</th></tr></thead><tbody class="divide-y divide-slate-800 text-slate-300">${propsList.map((p: any) => `<tr><td class="p-3 font-mono font-bold text-indigo-300">${p.name}</td><td class="p-3 font-mono text-slate-400">${p.type}</td><td class="p-3 font-mono text-slate-500">${p.default || '-'}</td><td class="p-3">${p.description}</td></tr>`).join('')}</tbody></table></div>` : `<p class="text-xs text-slate-500">No prop documentation specified for this package.</p>`}</div></div>`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-modern-table')) {
|
|
27
|
+
customElements.define('surreal-modern-table', SurrealModernTableDocs);
|
|
28
|
+
};
|
|
29
|
+
export { SurrealModernTableDocs as MinimalistTable, SurrealModernTableDocs };
|
|
30
|
+
|
|
31
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-table')) {
|
|
32
|
+
customElements.define('surreal-minimalist-table', SurrealModernTableDocs);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default SurrealModernTableDocs;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
class SurrealShadcnTabs extends HTMLElement {
|
|
2
|
+
private _value: string = '';
|
|
3
|
+
private _orientation: string = 'horizontal';
|
|
4
|
+
|
|
5
|
+
static get observedAttributes() {
|
|
6
|
+
return ['value', 'orientation'];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
if (!this.getAttribute('data-slot')) {
|
|
11
|
+
this.setAttribute('data-slot', 'tabs');
|
|
12
|
+
}
|
|
13
|
+
this._value = this.getAttribute('value') || this.getAttribute('default-value') || '';
|
|
14
|
+
this._orientation = this.getAttribute('orientation') || 'horizontal';
|
|
15
|
+
this.updateClasses();
|
|
16
|
+
this.syncChildren();
|
|
17
|
+
|
|
18
|
+
this.addEventListener('click', this.handleClick.bind(this));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
22
|
+
if (oldValue === newValue) return;
|
|
23
|
+
if (name === 'value') {
|
|
24
|
+
this._value = newValue || '';
|
|
25
|
+
this.syncChildren();
|
|
26
|
+
} else if (name === 'orientation') {
|
|
27
|
+
this._orientation = newValue || 'horizontal';
|
|
28
|
+
this.updateClasses();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get value() {
|
|
33
|
+
return this._value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
set value(val: string) {
|
|
37
|
+
this._value = val;
|
|
38
|
+
this.setAttribute('value', val);
|
|
39
|
+
this.syncChildren();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private updateClasses() {
|
|
43
|
+
this.setAttribute('data-orientation', this._orientation);
|
|
44
|
+
const base = 'gap-2 group/tabs flex data-[orientation=horizontal]:flex-col';
|
|
45
|
+
const custom = this.getAttribute('class') || '';
|
|
46
|
+
if (!custom.includes('group/tabs')) {
|
|
47
|
+
this.className = `${base} ${custom}`.trim();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private handleClick(e: MouseEvent) {
|
|
52
|
+
const target = (e.target as HTMLElement).closest(
|
|
53
|
+
'[data-slot="tabs-trigger"]',
|
|
54
|
+
) as HTMLElement | null;
|
|
55
|
+
if (target && this.contains(target) && !target.hasAttribute('disabled')) {
|
|
56
|
+
const nextVal = target.getAttribute('value') || target.getAttribute('data-value') || '';
|
|
57
|
+
if (nextVal && nextVal !== this._value) {
|
|
58
|
+
this.value = nextVal;
|
|
59
|
+
this.dispatchEvent(
|
|
60
|
+
new CustomEvent('change', { detail: { value: nextVal }, bubbles: true }),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private syncChildren() {
|
|
67
|
+
const triggers = this.querySelectorAll('[data-slot="tabs-trigger"]');
|
|
68
|
+
triggers.forEach((trigger) => {
|
|
69
|
+
const tVal = trigger.getAttribute('value') || trigger.getAttribute('data-value');
|
|
70
|
+
const isActive = tVal === this._value;
|
|
71
|
+
trigger.setAttribute('data-state', isActive ? 'active' : 'inactive');
|
|
72
|
+
trigger.setAttribute('aria-selected', isActive ? 'true' : 'false');
|
|
73
|
+
trigger.setAttribute('tabindex', isActive ? '0' : '-1');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const contents = this.querySelectorAll('[data-slot="tabs-content"]');
|
|
77
|
+
contents.forEach((content) => {
|
|
78
|
+
const cVal = content.getAttribute('value') || content.getAttribute('data-value');
|
|
79
|
+
const isActive = cVal === this._value;
|
|
80
|
+
content.setAttribute('data-state', isActive ? 'active' : 'inactive');
|
|
81
|
+
(content as HTMLElement).style.display = isActive ? '' : 'none';
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (typeof window !== 'undefined' && !customElements.get('surreal-tabs')) {
|
|
87
|
+
|
|
88
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-tabs')) {
|
|
89
|
+
customElements.define('surreal-shadcn-tabs', SurrealShadcnTabs);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export { SurrealShadcnTabs as MinimalistTabs, SurrealShadcnTabs };
|
|
93
|
+
|
|
94
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-tabs')) {
|
|
95
|
+
customElements.define('surreal-minimalist-tabs', SurrealShadcnTabs);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default SurrealShadcnTabs;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { cn } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
export class SurrealShadcnTextarea extends HTMLElement {
|
|
4
|
+
private _textarea: HTMLTextAreaElement;
|
|
5
|
+
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return [
|
|
8
|
+
'placeholder',
|
|
9
|
+
'disabled',
|
|
10
|
+
'rows',
|
|
11
|
+
'value',
|
|
12
|
+
'name',
|
|
13
|
+
'required',
|
|
14
|
+
'aria-invalid',
|
|
15
|
+
'class',
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this._textarea = document.createElement('textarea');
|
|
22
|
+
this._textarea.setAttribute('data-slot', 'textarea');
|
|
23
|
+
this.updateClasses();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
connectedCallback() {
|
|
27
|
+
if (!this.contains(this._textarea)) {
|
|
28
|
+
this.appendChild(this._textarea);
|
|
29
|
+
}
|
|
30
|
+
this.syncAllAttributes();
|
|
31
|
+
this._textarea.addEventListener('input', (e) => {
|
|
32
|
+
this.dispatchEvent(
|
|
33
|
+
new CustomEvent('input', {
|
|
34
|
+
bubbles: true,
|
|
35
|
+
composed: true,
|
|
36
|
+
detail: (e.target as HTMLTextAreaElement).value,
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
this._textarea.addEventListener('change', (e) => {
|
|
41
|
+
this.dispatchEvent(
|
|
42
|
+
new CustomEvent('change', {
|
|
43
|
+
bubbles: true,
|
|
44
|
+
composed: true,
|
|
45
|
+
detail: (e.target as HTMLTextAreaElement).value,
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
|
|
52
|
+
if (name === 'class') {
|
|
53
|
+
this.updateClasses();
|
|
54
|
+
} else if (name === 'value') {
|
|
55
|
+
this._textarea.value = newValue ?? '';
|
|
56
|
+
} else if (name === 'disabled') {
|
|
57
|
+
this._textarea.disabled = this.hasAttribute('disabled');
|
|
58
|
+
} else if (newValue === null) {
|
|
59
|
+
this._textarea.removeAttribute(name);
|
|
60
|
+
} else {
|
|
61
|
+
this._textarea.setAttribute(name, newValue);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private updateClasses() {
|
|
66
|
+
this._textarea.className = cn(
|
|
67
|
+
'rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 flex field-sizing-content min-h-16 w-full outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
|
|
68
|
+
this.getAttribute('class'),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private syncAllAttributes() {
|
|
73
|
+
Array.from(this.attributes).forEach((attr) => {
|
|
74
|
+
if (attr.name !== 'class') {
|
|
75
|
+
this._textarea.setAttribute(attr.name, attr.value);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
this.updateClasses();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get value(): string {
|
|
82
|
+
return this._textarea.value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
set value(val: string) {
|
|
86
|
+
this._textarea.value = val;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!customElements.get('surreal-textarea')) {
|
|
91
|
+
|
|
92
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-textarea')) {
|
|
93
|
+
customElements.define('surreal-shadcn-textarea', SurrealShadcnTextarea);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-textarea')) {
|
|
97
|
+
customElements.define('surreal-minimalist-textarea', SurrealShadcnTextarea);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default SurrealShadcnTextarea;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { cn, cva } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
const toggleVariants = cva(
|
|
4
|
+
"gap-1 rounded-lg text-sm font-medium transition-all hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted data-[state=on]:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 group/toggle inline-flex items-center justify-center whitespace-nowrap outline-none hover:bg-muted focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 cursor-pointer",
|
|
5
|
+
{
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
default: 'bg-transparent',
|
|
9
|
+
outline: 'border border-input bg-transparent hover:bg-muted',
|
|
10
|
+
},
|
|
11
|
+
size: {
|
|
12
|
+
default:
|
|
13
|
+
'h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
|
14
|
+
sm: "h-7 min-w-7 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
15
|
+
lg: 'h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: {
|
|
19
|
+
variant: 'default',
|
|
20
|
+
size: 'default',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export class SurrealShadcnToggle extends HTMLElement {
|
|
26
|
+
static get observedAttributes() {
|
|
27
|
+
return ['pressed', 'variant', 'size', 'disabled'];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private button: HTMLButtonElement;
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
this.button = document.createElement('button');
|
|
35
|
+
this.button.type = 'button';
|
|
36
|
+
this.button.setAttribute('data-slot', 'toggle');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
connectedCallback() {
|
|
40
|
+
if (!this.button.parentNode) {
|
|
41
|
+
while (this.firstChild) {
|
|
42
|
+
this.button.appendChild(this.firstChild);
|
|
43
|
+
}
|
|
44
|
+
this.appendChild(this.button);
|
|
45
|
+
}
|
|
46
|
+
this.button.addEventListener('click', this.handleClick);
|
|
47
|
+
this.render();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
disconnectedCallback() {
|
|
51
|
+
this.button.removeEventListener('click', this.handleClick);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
attributeChangedCallback() {
|
|
55
|
+
this.render();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get pressed(): boolean {
|
|
59
|
+
return this.hasAttribute('pressed');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set pressed(value: boolean) {
|
|
63
|
+
if (value) {
|
|
64
|
+
this.setAttribute('pressed', '');
|
|
65
|
+
} else {
|
|
66
|
+
this.removeAttribute('pressed');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private handleClick = () => {
|
|
71
|
+
if (this.hasAttribute('disabled')) return;
|
|
72
|
+
this.pressed = !this.pressed;
|
|
73
|
+
this.dispatchEvent(
|
|
74
|
+
new CustomEvent('change', {
|
|
75
|
+
detail: { pressed: this.pressed },
|
|
76
|
+
bubbles: true,
|
|
77
|
+
composed: true,
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
private render() {
|
|
83
|
+
const variant = (this.getAttribute('variant') as 'default' | 'outline') || 'default';
|
|
84
|
+
const size = (this.getAttribute('size') as 'default' | 'sm' | 'lg') || 'default';
|
|
85
|
+
const isPressed = this.pressed;
|
|
86
|
+
const disabled = this.hasAttribute('disabled');
|
|
87
|
+
|
|
88
|
+
this.button.className = cn(toggleVariants({ variant, size }), this.getAttribute('class') || '');
|
|
89
|
+
this.button.setAttribute('aria-pressed', String(isPressed));
|
|
90
|
+
this.button.setAttribute('data-state', isPressed ? 'on' : 'off');
|
|
91
|
+
this.button.disabled = disabled;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!customElements.get('surreal-toggle')) {
|
|
96
|
+
|
|
97
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-toggle')) {
|
|
98
|
+
customElements.define('surreal-shadcn-toggle', SurrealShadcnToggle);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-toggle')) {
|
|
102
|
+
customElements.define('surreal-minimalist-toggle', SurrealShadcnToggle);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default SurrealShadcnToggle;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
export class ToggleGroupComponent extends HTMLElement {
|
|
2
|
+
private _value: string | string[] = '';
|
|
3
|
+
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['type', 'value', 'variant', 'size', 'spacing', 'orientation', 'disabled'];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.setAttribute('role', 'group');
|
|
14
|
+
this.setAttribute('data-slot', 'toggle-group');
|
|
15
|
+
this.updateClasses();
|
|
16
|
+
this.syncItems();
|
|
17
|
+
this.addEventListener('click', this.handleClick.bind(this));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
attributeChangedCallback() {
|
|
21
|
+
this.updateClasses();
|
|
22
|
+
this.syncItems();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get type(): 'single' | 'multiple' {
|
|
26
|
+
return (this.getAttribute('type') as 'single' | 'multiple') || 'single';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get variant(): string {
|
|
30
|
+
return this.getAttribute('variant') || 'default';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get size(): string {
|
|
34
|
+
return this.getAttribute('size') || 'default';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get spacing(): string {
|
|
38
|
+
return this.getAttribute('spacing') || '0';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get orientation(): string {
|
|
42
|
+
return this.getAttribute('orientation') || 'horizontal';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get value(): string | string[] {
|
|
46
|
+
const attr = this.getAttribute('value');
|
|
47
|
+
if (this.type === 'multiple') {
|
|
48
|
+
return attr ? attr.split(',').map((s) => s.trim()) : [];
|
|
49
|
+
}
|
|
50
|
+
return attr || '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
set value(val: string | string[]) {
|
|
54
|
+
if (Array.isArray(val)) {
|
|
55
|
+
this.setAttribute('value', val.join(','));
|
|
56
|
+
} else {
|
|
57
|
+
this.setAttribute('value', val);
|
|
58
|
+
}
|
|
59
|
+
this.syncItems();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private updateClasses() {
|
|
63
|
+
const orientation = this.orientation;
|
|
64
|
+
const spacing = this.spacing;
|
|
65
|
+
const size = this.size;
|
|
66
|
+
const variant = this.variant;
|
|
67
|
+
|
|
68
|
+
this.setAttribute('data-variant', variant);
|
|
69
|
+
this.setAttribute('data-size', size);
|
|
70
|
+
this.setAttribute('data-spacing', spacing);
|
|
71
|
+
this.setAttribute('data-orientation', orientation);
|
|
72
|
+
this.style.gap = `${spacing}px`;
|
|
73
|
+
|
|
74
|
+
const baseClasses =
|
|
75
|
+
'rounded-lg group/toggle-group flex w-fit flex-row items-center data-[orientation=vertical]:flex-col data-[orientation=vertical]:items-stretch';
|
|
76
|
+
this.className = baseClasses;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private handleClick(e: MouseEvent) {
|
|
80
|
+
const item = (e.target as HTMLElement).closest(
|
|
81
|
+
'toggle-group-item',
|
|
82
|
+
) as ToggleGroupItemComponent | null;
|
|
83
|
+
if (!item || item.hasAttribute('disabled') || this.hasAttribute('disabled')) return;
|
|
84
|
+
|
|
85
|
+
const itemValue = item.getAttribute('value') || '';
|
|
86
|
+
if (this.type === 'single') {
|
|
87
|
+
const next = this.value === itemValue ? '' : itemValue;
|
|
88
|
+
this.value = next;
|
|
89
|
+
this.dispatchEvent(new CustomEvent('change', { detail: { value: next } }));
|
|
90
|
+
} else {
|
|
91
|
+
const current = Array.isArray(this.value) ? [...this.value] : this.value ? [this.value] : [];
|
|
92
|
+
const idx = current.indexOf(itemValue);
|
|
93
|
+
if (idx > -1) {
|
|
94
|
+
current.splice(idx, 1);
|
|
95
|
+
} else {
|
|
96
|
+
current.push(itemValue);
|
|
97
|
+
}
|
|
98
|
+
this.value = current;
|
|
99
|
+
this.dispatchEvent(new CustomEvent('change', { detail: { value: current } }));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
syncItems() {
|
|
104
|
+
const items = this.querySelectorAll('toggle-group-item');
|
|
105
|
+
const currentVal = this.value;
|
|
106
|
+
items.forEach((item) => {
|
|
107
|
+
const val = item.getAttribute('value') || '';
|
|
108
|
+
const isSelected = Array.isArray(currentVal) ? currentVal.includes(val) : currentVal === val;
|
|
109
|
+
item.setAttribute('data-state', isSelected ? 'on' : 'off');
|
|
110
|
+
item.setAttribute('aria-checked', isSelected ? 'true' : 'false');
|
|
111
|
+
if (!item.getAttribute('variant')) {
|
|
112
|
+
item.setAttribute('data-variant', this.variant);
|
|
113
|
+
}
|
|
114
|
+
if (!item.getAttribute('size')) {
|
|
115
|
+
item.setAttribute('data-size', this.size);
|
|
116
|
+
}
|
|
117
|
+
item.setAttribute('data-spacing', this.spacing);
|
|
118
|
+
(item as ToggleGroupItemComponent).updateState?.();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export class ToggleGroupItemComponent extends HTMLElement {
|
|
124
|
+
static get observedAttributes() {
|
|
125
|
+
return ['value', 'variant', 'size', 'disabled', 'data-state'];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
connectedCallback() {
|
|
129
|
+
this.setAttribute('role', 'radio');
|
|
130
|
+
this.setAttribute('data-slot', 'toggle-group-item');
|
|
131
|
+
this.tabIndex = 0;
|
|
132
|
+
this.updateState();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
attributeChangedCallback() {
|
|
136
|
+
this.updateState();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
updateState() {
|
|
140
|
+
const variant = this.getAttribute('data-variant') || this.getAttribute('variant') || 'default';
|
|
141
|
+
const size = this.getAttribute('data-size') || this.getAttribute('size') || 'default';
|
|
142
|
+
const isOutline = variant === 'outline';
|
|
143
|
+
const isSm = size === 'sm';
|
|
144
|
+
const isLg = size === 'lg';
|
|
145
|
+
|
|
146
|
+
const base =
|
|
147
|
+
'inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors cursor-pointer select-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-data-[spacing=0]/toggle-group:rounded-none group-data-[spacing=0]/toggle-group:px-2 group-data-horizontal/toggle-group:data-[spacing=0]:first:rounded-l-lg group-data-vertical/toggle-group:data-[spacing=0]:first:rounded-t-lg group-data-horizontal/toggle-group:data-[spacing=0]:last:rounded-r-lg group-data-vertical/toggle-group:data-[spacing=0]:last:rounded-b-lg shrink-0 focus:z-10 focus-visible:z-10';
|
|
148
|
+
const variantClasses = isOutline
|
|
149
|
+
? 'border border-input bg-transparent hover:bg-accent hover:text-accent-foreground data-[state=on]:bg-accent data-[state=on]:text-accent-foreground group-data-horizontal/toggle-group:data-[spacing=0]:border-l-0 group-data-horizontal/toggle-group:data-[spacing=0]:first:border-l group-data-vertical/toggle-group:data-[spacing=0]:border-t-0 group-data-vertical/toggle-group:data-[spacing=0]:first:border-t'
|
|
150
|
+
: 'bg-transparent hover:bg-muted hover:text-muted-foreground data-[state=on]:bg-accent data-[state=on]:text-accent-foreground';
|
|
151
|
+
const sizeClasses = isSm
|
|
152
|
+
? 'h-8 px-2 min-w-8 text-xs'
|
|
153
|
+
: isLg
|
|
154
|
+
? 'h-10 px-3 min-w-10'
|
|
155
|
+
: 'h-9 px-3 min-w-9';
|
|
156
|
+
|
|
157
|
+
this.className = `${base} ${variantClasses} ${sizeClasses}`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!customElements.get('toggle-group')) {
|
|
162
|
+
|
|
163
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-toggle-group')) {
|
|
164
|
+
customElements.define('surreal-shadcn-toggle-group', ToggleGroupComponent);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!customElements.get('toggle-group-item')) {
|
|
169
|
+
customElements.define('surreal-shadcn-toggle-group', ToggleGroupItemComponent);
|
|
170
|
+
}
|
|
171
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-toggle-group')) {
|
|
172
|
+
customElements.define('surreal-minimalist-toggle-group', ToggleGroupComponent);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export default ToggleGroupComponent;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
class SurrealShadcnTooltip extends HTMLElement {
|
|
2
|
+
private timeoutId: number | null = null;
|
|
3
|
+
private triggerEl: HTMLElement | null = null;
|
|
4
|
+
private contentEl: HTMLElement | null = null;
|
|
5
|
+
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return ['open', 'side', 'delay'];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
connectedCallback() {
|
|
11
|
+
this.classList.add('relative', 'inline-flex', 'flex-col', 'items-center');
|
|
12
|
+
this.triggerEl = this.querySelector('[data-slot="tooltip-trigger"]');
|
|
13
|
+
this.contentEl = this.querySelector('[data-slot="tooltip-content"]');
|
|
14
|
+
|
|
15
|
+
if (this.triggerEl) {
|
|
16
|
+
this.triggerEl.addEventListener('mouseenter', this.handleShow.bind(this));
|
|
17
|
+
this.triggerEl.addEventListener('mouseleave', this.handleHide.bind(this));
|
|
18
|
+
this.triggerEl.addEventListener('focus', this.handleShow.bind(this));
|
|
19
|
+
this.triggerEl.addEventListener('blur', this.handleHide.bind(this));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this.render();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
disconnectedCallback() {
|
|
26
|
+
if (this.timeoutId) clearTimeout(this.timeoutId);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
attributeChangedCallback() {
|
|
30
|
+
this.render();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private handleShow() {
|
|
34
|
+
const delay = parseInt(this.getAttribute('delay') || '0', 10);
|
|
35
|
+
if (delay > 0) {
|
|
36
|
+
this.timeoutId = window.setTimeout(() => {
|
|
37
|
+
this.setAttribute('open', '');
|
|
38
|
+
}, delay);
|
|
39
|
+
} else {
|
|
40
|
+
this.setAttribute('open', '');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private handleHide() {
|
|
45
|
+
if (this.timeoutId) clearTimeout(this.timeoutId);
|
|
46
|
+
this.removeAttribute('open');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private render() {
|
|
50
|
+
const isOpen = this.hasAttribute('open');
|
|
51
|
+
const side = this.getAttribute('side') || 'top';
|
|
52
|
+
|
|
53
|
+
if (!this.contentEl) {
|
|
54
|
+
this.contentEl = this.querySelector('[data-slot="tooltip-content"]');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.contentEl) {
|
|
58
|
+
this.contentEl.setAttribute('data-side', side);
|
|
59
|
+
this.contentEl.setAttribute('data-state', isOpen ? 'open' : 'closed');
|
|
60
|
+
if (isOpen) {
|
|
61
|
+
this.contentEl.classList.remove('hidden');
|
|
62
|
+
this.contentEl.classList.add('inline-flex');
|
|
63
|
+
} else {
|
|
64
|
+
this.contentEl.classList.add('hidden');
|
|
65
|
+
this.contentEl.classList.remove('inline-flex');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!customElements.get('surreal-tooltip')) {
|
|
72
|
+
|
|
73
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-tooltip')) {
|
|
74
|
+
customElements.define('surreal-shadcn-tooltip', SurrealShadcnTooltip);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export { SurrealShadcnTooltip as MinimalistTooltip, SurrealShadcnTooltip };
|
|
78
|
+
|
|
79
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-tooltip')) {
|
|
80
|
+
customElements.define('surreal-minimalist-tooltip', SurrealShadcnTooltip);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default SurrealShadcnTooltip;
|