@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,162 @@
|
|
|
1
|
+
class SurrealShadcnSheet extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ['open', 'side'];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.attachShadow({ mode: 'open' });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get open() {
|
|
12
|
+
return this.hasAttribute('open');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
set open(value) {
|
|
16
|
+
if (value) {
|
|
17
|
+
this.setAttribute('open', '');
|
|
18
|
+
} else {
|
|
19
|
+
this.removeAttribute('open');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get side() {
|
|
24
|
+
return this.getAttribute('side') || 'right';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set side(val) {
|
|
28
|
+
this.setAttribute('side', val);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
this.render();
|
|
33
|
+
this.setupListeners();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
37
|
+
if (oldValue !== newValue) {
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setupListeners() {
|
|
43
|
+
this.shadowRoot?.addEventListener('click', (e) => {
|
|
44
|
+
const target = e.target;
|
|
45
|
+
if (
|
|
46
|
+
target &&
|
|
47
|
+
(target.matches('[data-slot="sheet-overlay"]') ||
|
|
48
|
+
target.closest('[data-slot="sheet-close"]'))
|
|
49
|
+
) {
|
|
50
|
+
this.open = false;
|
|
51
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
render() {
|
|
57
|
+
const isOpen = this.open;
|
|
58
|
+
const side = this.side;
|
|
59
|
+
|
|
60
|
+
const sideClasses =
|
|
61
|
+
{
|
|
62
|
+
right: 'top-0 right-0 h-full w-3/4 max-w-sm border-l translate-x-0',
|
|
63
|
+
left: 'top-0 left-0 h-full w-3/4 max-w-sm border-r translate-x-0',
|
|
64
|
+
top: 'top-0 inset-x-0 h-auto border-b translate-y-0',
|
|
65
|
+
bottom: 'bottom-0 inset-x-0 h-auto border-t translate-y-0',
|
|
66
|
+
}[side] || 'top-0 right-0 h-full w-3/4 max-w-sm border-l';
|
|
67
|
+
|
|
68
|
+
this.shadowRoot.innerHTML = `
|
|
69
|
+
<style>
|
|
70
|
+
:host {
|
|
71
|
+
display: contents;
|
|
72
|
+
}
|
|
73
|
+
.portal {
|
|
74
|
+
position: fixed;
|
|
75
|
+
inset: 0;
|
|
76
|
+
z-index: 50;
|
|
77
|
+
display: ${isOpen ? 'flex' : 'none'};
|
|
78
|
+
}
|
|
79
|
+
.overlay {
|
|
80
|
+
position: fixed;
|
|
81
|
+
inset: 0;
|
|
82
|
+
background-color: rgba(0, 0, 0, 0.8);
|
|
83
|
+
animation: fadeIn 0.2s ease-out;
|
|
84
|
+
}
|
|
85
|
+
.content {
|
|
86
|
+
position: fixed;
|
|
87
|
+
z-index: 50;
|
|
88
|
+
display: flex;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
gap: 1rem;
|
|
91
|
+
padding: 1.5rem;
|
|
92
|
+
font-size: 0.875rem;
|
|
93
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
|
94
|
+
background-color: var(--background, #ffffff);
|
|
95
|
+
color: var(--foreground, #09090b);
|
|
96
|
+
border-color: var(--border, #e4e4e7);
|
|
97
|
+
box-sizing: border-box;
|
|
98
|
+
transition: transform 0.3s ease-in-out;
|
|
99
|
+
}
|
|
100
|
+
.close-btn {
|
|
101
|
+
position: absolute;
|
|
102
|
+
top: 1rem;
|
|
103
|
+
right: 1rem;
|
|
104
|
+
display: flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
border: none;
|
|
108
|
+
background: transparent;
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
opacity: 0.7;
|
|
111
|
+
padding: 0.25rem;
|
|
112
|
+
border-radius: 0.25rem;
|
|
113
|
+
}
|
|
114
|
+
.close-btn:hover {
|
|
115
|
+
opacity: 1;
|
|
116
|
+
}
|
|
117
|
+
.close-btn svg {
|
|
118
|
+
width: 1rem;
|
|
119
|
+
height: 1rem;
|
|
120
|
+
stroke: currentColor;
|
|
121
|
+
}
|
|
122
|
+
::slotted([slot="header"]) {
|
|
123
|
+
display: flex;
|
|
124
|
+
flex-direction: column;
|
|
125
|
+
gap: 0.375rem;
|
|
126
|
+
}
|
|
127
|
+
::slotted([slot="footer"]) {
|
|
128
|
+
margin-top: auto;
|
|
129
|
+
display: flex;
|
|
130
|
+
flex-direction: column;
|
|
131
|
+
gap: 0.5rem;
|
|
132
|
+
}
|
|
133
|
+
@keyframes fadeIn {
|
|
134
|
+
from { opacity: 0; }
|
|
135
|
+
to { opacity: 1; }
|
|
136
|
+
}
|
|
137
|
+
</style>
|
|
138
|
+
<slot name="trigger"></slot>
|
|
139
|
+
<div class="portal">
|
|
140
|
+
<div class="overlay" data-slot="sheet-overlay"></div>
|
|
141
|
+
<div class="content ${sideClasses}" data-slot="sheet-content" data-side="${side}">
|
|
142
|
+
<slot name="header"></slot>
|
|
143
|
+
<slot></slot>
|
|
144
|
+
<slot name="footer"></slot>
|
|
145
|
+
<button class="close-btn" data-slot="sheet-close" aria-label="Close">
|
|
146
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
|
|
147
|
+
</button>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!customElements.get('surreal-sheet')) {
|
|
155
|
+
|
|
156
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-sheet')) {
|
|
157
|
+
customElements.define('surreal-shadcn-sheet', SurrealShadcnSheet);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
export { SurrealShadcnSheet as ShadcnSheet, SurrealShadcnSheet };
|
|
161
|
+
|
|
162
|
+
export default SurrealShadcnSheet;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const SIDEBAR_TEMPLATE = document.createElement('template');
|
|
2
|
+
SIDEBAR_TEMPLATE.innerHTML = `
|
|
3
|
+
<div data-slot="sidebar-wrapper" class="group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar">
|
|
4
|
+
<div data-slot="sidebar-inner-wrapper" class="group peer hidden text-sidebar-foreground md:block" data-state="expanded" data-collapsible="" data-variant="sidebar" data-side="left">
|
|
5
|
+
<div data-slot="sidebar-gap" class="transition-[width] duration-200 ease-linear relative w-64 bg-transparent group-data-[collapsible=icon]:w-12"></div>
|
|
6
|
+
<div data-slot="sidebar-container" class="fixed inset-y-0 start-0 z-10 hidden h-svh w-64 transition-[left,right,width] duration-200 ease-linear md:flex border-e border-sidebar-border group-data-[collapsible=icon]:w-12">
|
|
7
|
+
<div data-sidebar="sidebar" data-slot="sidebar-inner" class="bg-sidebar flex size-full flex-col">
|
|
8
|
+
<slot></slot>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export class SurrealShadcnSidebar extends HTMLElement {
|
|
16
|
+
private _open = true;
|
|
17
|
+
private _collapsible = 'icon';
|
|
18
|
+
private _variant = 'sidebar';
|
|
19
|
+
private _side = 'left';
|
|
20
|
+
|
|
21
|
+
static get observedAttributes() {
|
|
22
|
+
return ['open', 'collapsible', 'variant', 'side'];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
connectedCallback() {
|
|
26
|
+
if (!this.shadowRoot) {
|
|
27
|
+
this.attachShadow({ mode: 'open' });
|
|
28
|
+
this.shadowRoot!.appendChild(SIDEBAR_TEMPLATE.content.cloneNode(true));
|
|
29
|
+
this._syncAttributes();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
34
|
+
if (oldValue === newValue) return;
|
|
35
|
+
if (name === 'open') {
|
|
36
|
+
this._open = newValue !== 'false';
|
|
37
|
+
} else if (name === 'collapsible') {
|
|
38
|
+
this._collapsible = newValue || 'icon';
|
|
39
|
+
} else if (name === 'variant') {
|
|
40
|
+
this._variant = newValue || 'sidebar';
|
|
41
|
+
} else if (name === 'side') {
|
|
42
|
+
this._side = newValue || 'left';
|
|
43
|
+
}
|
|
44
|
+
this._syncAttributes();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toggle() {
|
|
48
|
+
this._open = !this._open;
|
|
49
|
+
this.setAttribute('open', String(this._open));
|
|
50
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: this._open } }));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private _syncAttributes() {
|
|
54
|
+
if (!this.shadowRoot) return;
|
|
55
|
+
const wrapper = this.shadowRoot.querySelector('[data-slot="sidebar-inner-wrapper"]');
|
|
56
|
+
if (wrapper) {
|
|
57
|
+
wrapper.setAttribute('data-state', this._open ? 'expanded' : 'collapsed');
|
|
58
|
+
wrapper.setAttribute('data-collapsible', this._open ? '' : this._collapsible);
|
|
59
|
+
wrapper.setAttribute('data-variant', this._variant);
|
|
60
|
+
wrapper.setAttribute('data-side', this._side);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!customElements.get('surreal-sidebar')) {
|
|
66
|
+
|
|
67
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-sidebar')) {
|
|
68
|
+
customElements.define('surreal-shadcn-sidebar', SurrealShadcnSidebar);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export default SurrealShadcnSidebar;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { cn } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
export class SurrealShadcnSkeleton extends HTMLElement {
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['class'];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
connectedCallback() {
|
|
9
|
+
this.render();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
attributeChangedCallback() {
|
|
13
|
+
this.render();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
render() {
|
|
17
|
+
this.setAttribute('data-slot', 'skeleton');
|
|
18
|
+
const userClass = this.getAttribute('class') || '';
|
|
19
|
+
this.className = cn('block rounded-md bg-muted animate-pulse', userClass);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!customElements.get('surreal-skeleton')) {
|
|
24
|
+
|
|
25
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-skeleton')) {
|
|
26
|
+
customElements.define('surreal-shadcn-skeleton', SurrealShadcnSkeleton);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export default SurrealShadcnSkeleton;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
export class SurrealShadcnSliderElement extends HTMLElement {
|
|
2
|
+
private _values: number[] = [0];
|
|
3
|
+
private _min: number = 0;
|
|
4
|
+
private _max: number = 100;
|
|
5
|
+
private _step: number = 1;
|
|
6
|
+
private _orientation: 'horizontal' | 'vertical' = 'horizontal';
|
|
7
|
+
private _disabled: boolean = false;
|
|
8
|
+
private _activeIndex: number | null = null;
|
|
9
|
+
private _trackEl: HTMLElement | null = null;
|
|
10
|
+
private _rangeEl: HTMLElement | null = null;
|
|
11
|
+
private _thumbEls: HTMLElement[] = [];
|
|
12
|
+
|
|
13
|
+
static get observedAttributes() {
|
|
14
|
+
return ['value', 'min', 'max', 'step', 'orientation', 'disabled'];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
connectedCallback() {
|
|
18
|
+
this.render();
|
|
19
|
+
this.setupListeners();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
23
|
+
if (oldValue === newValue) return;
|
|
24
|
+
if (name === 'value' && newValue !== null) {
|
|
25
|
+
this._values = newValue.split(',').map((n) => parseFloat(n.trim()) || 0);
|
|
26
|
+
} else if (name === 'min' && newValue !== null) {
|
|
27
|
+
this._min = parseFloat(newValue) || 0;
|
|
28
|
+
} else if (name === 'max' && newValue !== null) {
|
|
29
|
+
this._max = parseFloat(newValue) || 100;
|
|
30
|
+
} else if (name === 'step' && newValue !== null) {
|
|
31
|
+
this._step = parseFloat(newValue) || 1;
|
|
32
|
+
} else if (name === 'orientation' && newValue !== null) {
|
|
33
|
+
this._orientation = newValue === 'vertical' ? 'vertical' : 'horizontal';
|
|
34
|
+
} else if (name === 'disabled') {
|
|
35
|
+
this._disabled = newValue !== null;
|
|
36
|
+
}
|
|
37
|
+
this.render();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get value(): number[] {
|
|
41
|
+
return this._values;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
set value(val: number[]) {
|
|
45
|
+
this._values = Array.isArray(val) ? val : [val];
|
|
46
|
+
this.setAttribute('value', this._values.join(','));
|
|
47
|
+
this.render();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private getPercentage(val: number): number {
|
|
51
|
+
return Math.max(0, Math.min(100, ((val - this._min) / (this._max - this._min)) * 100));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private getValueFromPointer(e: PointerEvent): number {
|
|
55
|
+
if (!this._trackEl) return this._min;
|
|
56
|
+
const rect = this._trackEl.getBoundingClientRect();
|
|
57
|
+
let percent = 0;
|
|
58
|
+
if (this._orientation === 'horizontal') {
|
|
59
|
+
percent = (e.clientX - rect.left) / rect.width;
|
|
60
|
+
} else {
|
|
61
|
+
percent = (rect.bottom - e.clientY) / rect.height;
|
|
62
|
+
}
|
|
63
|
+
percent = Math.max(0, Math.min(1, percent));
|
|
64
|
+
const rawVal = this._min + percent * (this._max - this._min);
|
|
65
|
+
const steppedVal = Math.round(rawVal / this._step) * this._step;
|
|
66
|
+
return Math.max(this._min, Math.min(this._max, steppedVal));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private updateValue(index: number, newVal: number) {
|
|
70
|
+
const next = [...this._values];
|
|
71
|
+
next[index] = newVal;
|
|
72
|
+
if (next.length === 2) {
|
|
73
|
+
if (index === 0 && next[0] > next[1]) next[0] = next[1];
|
|
74
|
+
if (index === 1 && next[1] < next[0]) next[1] = next[0];
|
|
75
|
+
}
|
|
76
|
+
this._values = next;
|
|
77
|
+
this.renderThumbsAndRange();
|
|
78
|
+
this.dispatchEvent(
|
|
79
|
+
new CustomEvent('input', { detail: { value: this._values }, bubbles: true }),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private renderThumbsAndRange() {
|
|
84
|
+
if (!this._rangeEl) return;
|
|
85
|
+
if (this._values.length === 1) {
|
|
86
|
+
const pct = this.getPercentage(this._values[0]);
|
|
87
|
+
if (this._orientation === 'horizontal') {
|
|
88
|
+
this._rangeEl.style.left = '0%';
|
|
89
|
+
this._rangeEl.style.width = `${pct}%`;
|
|
90
|
+
this._rangeEl.style.height = '100%';
|
|
91
|
+
this._rangeEl.style.bottom = '';
|
|
92
|
+
} else {
|
|
93
|
+
this._rangeEl.style.bottom = '0%';
|
|
94
|
+
this._rangeEl.style.height = `${pct}%`;
|
|
95
|
+
this._rangeEl.style.width = '100%';
|
|
96
|
+
this._rangeEl.style.left = '';
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
const p1 = this.getPercentage(this._values[0]);
|
|
100
|
+
const p2 = this.getPercentage(this._values[1]);
|
|
101
|
+
const left = Math.min(p1, p2);
|
|
102
|
+
const size = Math.abs(p2 - p1);
|
|
103
|
+
if (this._orientation === 'horizontal') {
|
|
104
|
+
this._rangeEl.style.left = `${left}%`;
|
|
105
|
+
this._rangeEl.style.width = `${size}%`;
|
|
106
|
+
this._rangeEl.style.height = '100%';
|
|
107
|
+
this._rangeEl.style.bottom = '';
|
|
108
|
+
} else {
|
|
109
|
+
this._rangeEl.style.bottom = `${left}%`;
|
|
110
|
+
this._rangeEl.style.height = `${size}%`;
|
|
111
|
+
this._rangeEl.style.width = '100%';
|
|
112
|
+
this._rangeEl.style.left = '';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this._thumbEls.forEach((thumb, idx) => {
|
|
117
|
+
const val = this._values[idx] ?? this._min;
|
|
118
|
+
const pct = this.getPercentage(val);
|
|
119
|
+
thumb.setAttribute('aria-valuenow', val.toString());
|
|
120
|
+
if (this._orientation === 'horizontal') {
|
|
121
|
+
thumb.style.left = `calc(${pct}% - 8px)`;
|
|
122
|
+
thumb.style.top = '50%';
|
|
123
|
+
thumb.style.transform = 'translateY(-50%)';
|
|
124
|
+
} else {
|
|
125
|
+
thumb.style.bottom = `calc(${pct}% - 8px)`;
|
|
126
|
+
thumb.style.left = '50%';
|
|
127
|
+
thumb.style.transform = 'translateX(-50%)';
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private setupListeners() {
|
|
133
|
+
this.addEventListener('pointerdown', (e: PointerEvent) => {
|
|
134
|
+
if (this._disabled) return;
|
|
135
|
+
this.setPointerCapture(e.pointerId);
|
|
136
|
+
const pointerVal = this.getValueFromPointer(e);
|
|
137
|
+
let closestIdx = 0;
|
|
138
|
+
let minDiff = Infinity;
|
|
139
|
+
this._values.forEach((val, idx) => {
|
|
140
|
+
const diff = Math.abs(val - pointerVal);
|
|
141
|
+
if (diff < minDiff) {
|
|
142
|
+
minDiff = diff;
|
|
143
|
+
closestIdx = idx;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
this._activeIndex = closestIdx;
|
|
147
|
+
this.updateValue(closestIdx, pointerVal);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
this.addEventListener('pointermove', (e: PointerEvent) => {
|
|
151
|
+
if (this._disabled || this._activeIndex === null) return;
|
|
152
|
+
const pointerVal = this.getValueFromPointer(e);
|
|
153
|
+
this.updateValue(this._activeIndex, pointerVal);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
this.addEventListener('pointerup', (e: PointerEvent) => {
|
|
157
|
+
if (this._disabled || this._activeIndex === null) return;
|
|
158
|
+
this.releasePointerCapture(e.pointerId);
|
|
159
|
+
this._activeIndex = null;
|
|
160
|
+
this.dispatchEvent(
|
|
161
|
+
new CustomEvent('change', { detail: { value: this._values }, bubbles: true }),
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
render() {
|
|
167
|
+
this.className = `relative flex touch-none select-none items-center ${
|
|
168
|
+
this._orientation === 'vertical'
|
|
169
|
+
? 'h-full min-h-40 w-auto flex-col'
|
|
170
|
+
: 'h-auto w-full flex-row'
|
|
171
|
+
} ${this._disabled ? 'opacity-50 pointer-events-none' : ''}`;
|
|
172
|
+
this.setAttribute('data-slot', 'slider');
|
|
173
|
+
this.setAttribute('data-orientation', this._orientation);
|
|
174
|
+
|
|
175
|
+
this.innerHTML = `
|
|
176
|
+
<span data-slot="slider-track" data-orientation="${this._orientation}" class="relative grow overflow-hidden rounded-full bg-muted ${this._orientation === 'horizontal' ? 'h-1.5 w-full' : 'h-full w-1.5'}">
|
|
177
|
+
<span data-slot="slider-range" data-orientation="${this._orientation}" class="absolute bg-primary"></span>
|
|
178
|
+
</span>
|
|
179
|
+
${this._values
|
|
180
|
+
.map(
|
|
181
|
+
(val, idx) => `
|
|
182
|
+
<span
|
|
183
|
+
role="slider"
|
|
184
|
+
tabindex="${this._disabled ? -1 : 0}"
|
|
185
|
+
aria-valuemin="${this._min}"
|
|
186
|
+
aria-valuemax="${this._max}"
|
|
187
|
+
aria-valuenow="${val}"
|
|
188
|
+
aria-orientation="${this._orientation}"
|
|
189
|
+
data-slot="slider-thumb"
|
|
190
|
+
data-index="${idx}"
|
|
191
|
+
class="absolute block size-4 shrink-0 rounded-full border border-primary bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
|
|
192
|
+
></span>
|
|
193
|
+
`,
|
|
194
|
+
)
|
|
195
|
+
.join('')}
|
|
196
|
+
`;
|
|
197
|
+
|
|
198
|
+
this._trackEl = this.querySelector('[data-slot="slider-track"]');
|
|
199
|
+
this._rangeEl = this.querySelector('[data-slot="slider-range"]');
|
|
200
|
+
this._thumbEls = Array.from(this.querySelectorAll('[data-slot="slider-thumb"]'));
|
|
201
|
+
|
|
202
|
+
this._thumbEls.forEach((thumb, idx) => {
|
|
203
|
+
thumb.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
204
|
+
if (this._disabled) return;
|
|
205
|
+
let delta = 0;
|
|
206
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowUp') delta = this._step;
|
|
207
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') delta = -this._step;
|
|
208
|
+
else if (e.key === 'PageUp') delta = this._step * 10;
|
|
209
|
+
else if (e.key === 'PageDown') delta = -this._step * 10;
|
|
210
|
+
else if (e.key === 'Home') delta = this._min - this._values[idx];
|
|
211
|
+
else if (e.key === 'End') delta = this._max - this._values[idx];
|
|
212
|
+
else return;
|
|
213
|
+
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
const newVal = Math.max(this._min, Math.min(this._max, this._values[idx] + delta));
|
|
216
|
+
this.updateValue(idx, newVal);
|
|
217
|
+
this.dispatchEvent(
|
|
218
|
+
new CustomEvent('change', { detail: { value: this._values }, bubbles: true }),
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
this.renderThumbsAndRange();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!customElements.get('surreal-slider')) {
|
|
228
|
+
|
|
229
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-slider')) {
|
|
230
|
+
customElements.define('surreal-shadcn-slider', SurrealShadcnSliderElement);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export default SurrealShadcnSliderElement;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
class SonnerToasterElement extends HTMLElement {
|
|
2
|
+
private container: HTMLDivElement | null = null;
|
|
3
|
+
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['position', 'theme'];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
connectedCallback() {
|
|
9
|
+
if (!this.shadowRoot) {
|
|
10
|
+
this.attachShadow({ mode: 'open' });
|
|
11
|
+
}
|
|
12
|
+
this.render();
|
|
13
|
+
window.addEventListener('ui-toast', this.handleToastEvent as EventListener);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
disconnectedCallback() {
|
|
17
|
+
window.removeEventListener('ui-toast', this.handleToastEvent as EventListener);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private handleToastEvent = (
|
|
21
|
+
event: CustomEvent<{
|
|
22
|
+
message: string;
|
|
23
|
+
type?: 'success' | 'error' | 'info' | 'warning';
|
|
24
|
+
description?: string;
|
|
25
|
+
}>,
|
|
26
|
+
) => {
|
|
27
|
+
this.addToast(event.detail.message, event.detail.type || 'info', event.detail.description);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
public toast(
|
|
31
|
+
message: string,
|
|
32
|
+
options?: { type?: 'success' | 'error' | 'info' | 'warning'; description?: string },
|
|
33
|
+
) {
|
|
34
|
+
this.addToast(message, options?.type || 'info', options?.description);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private getIcon(type: string): string {
|
|
38
|
+
switch (type) {
|
|
39
|
+
case 'success':
|
|
40
|
+
return `<svg class="size-4 text-emerald-500 shrink-0" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>`;
|
|
41
|
+
case 'error':
|
|
42
|
+
return `<svg class="size-4 text-destructive shrink-0" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="7.86 2 16.14 2 22 7.86 22 16.14 16.14 22 7.86 22 2 16.14 2 7.86 7.86 2"/><line x1="15" x2="9" y1="9" y2="15"/><line x1="9" x2="15" y1="9" y2="15"/></svg>`;
|
|
43
|
+
case 'warning':
|
|
44
|
+
return `<svg class="size-4 text-amber-500 shrink-0" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" x2="12" y1="9" y2="13"/><line x1="12" x2="12.01" y1="17" y2="17"/></svg>`;
|
|
45
|
+
default:
|
|
46
|
+
return `<svg class="size-4 text-blue-500 shrink-0" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="16" y2="12"/><line x1="12" x2="12.01" y1="8" y2="8"/></svg>`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private addToast(message: string, type: string = 'info', description?: string) {
|
|
51
|
+
if (!this.container) return;
|
|
52
|
+
const toastEl = document.createElement('div');
|
|
53
|
+
toastEl.className =
|
|
54
|
+
'pointer-events-auto flex items-start gap-3 w-80 rounded-lg border border-border bg-popover p-4 text-popover-foreground shadow-lg transition-all duration-300 animate-in fade-in-0 slide-in-from-bottom-5';
|
|
55
|
+
toastEl.innerHTML = `
|
|
56
|
+
${this.getIcon(type)}
|
|
57
|
+
<div class="grid gap-1 flex-1">
|
|
58
|
+
<div class="text-sm font-semibold">${message}</div>
|
|
59
|
+
${description ? `<div class="text-xs text-muted-foreground">${description}</div>` : ''}
|
|
60
|
+
</div>
|
|
61
|
+
`;
|
|
62
|
+
this.container.appendChild(toastEl);
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
toastEl.classList.add('opacity-0', 'translate-y-2');
|
|
65
|
+
setTimeout(() => toastEl.remove(), 300);
|
|
66
|
+
}, 4000);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private render() {
|
|
70
|
+
if (!this.shadowRoot) return;
|
|
71
|
+
this.shadowRoot.innerHTML = `
|
|
72
|
+
<style>
|
|
73
|
+
:host { position: fixed; bottom: 1rem; right: 1rem; z-index: 9999; pointer-events: none; font-family: inherit; }
|
|
74
|
+
.toaster-container { display: flex; flex-direction: column; gap: 0.5rem; }
|
|
75
|
+
</style>
|
|
76
|
+
<div class="toaster-container" id="toast-box"></div>
|
|
77
|
+
`;
|
|
78
|
+
this.container = this.shadowRoot.getElementById('toast-box') as HTMLDivElement;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!customElements.get('sonner-toaster')) {
|
|
83
|
+
|
|
84
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-sonner')) {
|
|
85
|
+
customElements.define('surreal-shadcn-sonner', SonnerToasterElement);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { SonnerToasterElement };
|
|
90
|
+
export default SonnerToasterElement;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { cn } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
export class SurrealShadcnSpinner extends HTMLElement {
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['class', 'role', 'aria-label', 'size', 'color'];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
connectedCallback() {
|
|
9
|
+
this.render();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
attributeChangedCallback() {
|
|
13
|
+
this.render();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
render() {
|
|
17
|
+
const role = this.getAttribute('role') || 'status';
|
|
18
|
+
const ariaLabel = this.getAttribute('aria-label') || 'Loading';
|
|
19
|
+
const customClass = this.getAttribute('class') || '';
|
|
20
|
+
const color = this.getAttribute('color') || 'currentColor';
|
|
21
|
+
|
|
22
|
+
this.innerHTML = `
|
|
23
|
+
<svg
|
|
24
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
25
|
+
width="24"
|
|
26
|
+
height="24"
|
|
27
|
+
viewBox="0 0 24 24"
|
|
28
|
+
fill="none"
|
|
29
|
+
stroke="${color}"
|
|
30
|
+
stroke-width="2"
|
|
31
|
+
stroke-linecap="round"
|
|
32
|
+
stroke-linejoin="round"
|
|
33
|
+
role="${role}"
|
|
34
|
+
aria-label="${ariaLabel}"
|
|
35
|
+
class="${cn('size-4 animate-spin', customClass)}"
|
|
36
|
+
>
|
|
37
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
38
|
+
</svg>
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!customElements.get('surreal-spinner')) {
|
|
44
|
+
|
|
45
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-spinner')) {
|
|
46
|
+
customElements.define('surreal-shadcn-spinner', SurrealShadcnSpinner);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default SurrealShadcnSpinner;
|