@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.
Files changed (124) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/index.js +12075 -0
  3. package/package.json +27 -0
  4. package/src/components/GlassmorphismAlert.ts +116 -0
  5. package/src/components/GlassmorphismButton.ts +19 -0
  6. package/src/components/GlassmorphismCard.ts +33 -0
  7. package/src/components/GlassmorphismEmptyState.ts +29 -0
  8. package/src/components/GlassmorphismInputGroup.ts +202 -0
  9. package/src/components/GlassmorphismMenubar.ts +36 -0
  10. package/src/components/GlassmorphismScrollArea.ts +83 -0
  11. package/src/components/GlassmorphismTable.ts +52 -0
  12. package/src/components/GlassmorphismTypography.ts +67 -0
  13. package/src/components/MinimalistAccordion.ts +248 -0
  14. package/src/components/MinimalistAlert.ts +99 -0
  15. package/src/components/MinimalistAlertDialog.ts +100 -0
  16. package/src/components/MinimalistAspectRatio.ts +34 -0
  17. package/src/components/MinimalistAvatar.ts +98 -0
  18. package/src/components/MinimalistBadge.ts +71 -0
  19. package/src/components/MinimalistBreadcrumb.ts +92 -0
  20. package/src/components/MinimalistButton.ts +111 -0
  21. package/src/components/MinimalistButtonGroup.ts +110 -0
  22. package/src/components/MinimalistCalendar.ts +282 -0
  23. package/src/components/MinimalistCard.ts +131 -0
  24. package/src/components/MinimalistCarousel.ts +122 -0
  25. package/src/components/MinimalistChart.ts +151 -0
  26. package/src/components/MinimalistCheckbox.ts +179 -0
  27. package/src/components/MinimalistCodeBlock.ts +113 -0
  28. package/src/components/MinimalistCollapsible.ts +155 -0
  29. package/src/components/MinimalistCommand.ts +112 -0
  30. package/src/components/MinimalistContextMenu.ts +99 -0
  31. package/src/components/MinimalistDialog.ts +104 -0
  32. package/src/components/MinimalistDrawer.ts +223 -0
  33. package/src/components/MinimalistDropdownMenu.ts +120 -0
  34. package/src/components/MinimalistEmpty.ts +98 -0
  35. package/src/components/MinimalistEmptyState.ts +38 -0
  36. package/src/components/MinimalistField.ts +171 -0
  37. package/src/components/MinimalistForm.ts +101 -0
  38. package/src/components/MinimalistHoverCard.ts +150 -0
  39. package/src/components/MinimalistInput.ts +105 -0
  40. package/src/components/MinimalistInputGroup.ts +93 -0
  41. package/src/components/MinimalistInputOtp.ts +155 -0
  42. package/src/components/MinimalistItem.ts +160 -0
  43. package/src/components/MinimalistKbd.ts +38 -0
  44. package/src/components/MinimalistLabel.ts +54 -0
  45. package/src/components/MinimalistMenubar.ts +82 -0
  46. package/src/components/MinimalistNativeSelect.ts +144 -0
  47. package/src/components/MinimalistNavigationMenu.ts +98 -0
  48. package/src/components/MinimalistPagination.ts +141 -0
  49. package/src/components/MinimalistPopover.ts +113 -0
  50. package/src/components/MinimalistProgress.ts +71 -0
  51. package/src/components/MinimalistRadioGroup.ts +226 -0
  52. package/src/components/MinimalistRangeCalendar.ts +267 -0
  53. package/src/components/MinimalistResizable.ts +44 -0
  54. package/src/components/MinimalistScrollArea.ts +11 -0
  55. package/src/components/MinimalistSelect.ts +104 -0
  56. package/src/components/MinimalistSeparator.ts +53 -0
  57. package/src/components/MinimalistSheet.ts +166 -0
  58. package/src/components/MinimalistSidebar.ts +75 -0
  59. package/src/components/MinimalistSkeleton.ts +33 -0
  60. package/src/components/MinimalistSlider.ts +237 -0
  61. package/src/components/MinimalistSonner.ts +94 -0
  62. package/src/components/MinimalistSpinner.ts +53 -0
  63. package/src/components/MinimalistSwitch.ts +166 -0
  64. package/src/components/MinimalistTable.ts +35 -0
  65. package/src/components/MinimalistTabs.ts +98 -0
  66. package/src/components/MinimalistTextarea.ts +100 -0
  67. package/src/components/MinimalistToggle.ts +105 -0
  68. package/src/components/MinimalistToggleGroup.ts +175 -0
  69. package/src/components/MinimalistTooltip.ts +83 -0
  70. package/src/components/MinimalistTypography.ts +107 -0
  71. package/src/components/NeubrutalismCard.ts +35 -0
  72. package/src/components/NeubrutalismItem.ts +67 -0
  73. package/src/components/ShadcnAccordion.ts +244 -0
  74. package/src/components/ShadcnAlertDialog.ts +96 -0
  75. package/src/components/ShadcnAspectRatio.ts +30 -0
  76. package/src/components/ShadcnAvatar.ts +94 -0
  77. package/src/components/ShadcnBadge.ts +67 -0
  78. package/src/components/ShadcnBreadcrumb.ts +88 -0
  79. package/src/components/ShadcnButton.ts +107 -0
  80. package/src/components/ShadcnButtonGroup.ts +106 -0
  81. package/src/components/ShadcnCalendar.ts +278 -0
  82. package/src/components/ShadcnCarousel.ts +118 -0
  83. package/src/components/ShadcnChart.ts +147 -0
  84. package/src/components/ShadcnCheckbox.ts +175 -0
  85. package/src/components/ShadcnCodeBlock.ts +109 -0
  86. package/src/components/ShadcnCollapsible.ts +151 -0
  87. package/src/components/ShadcnCommand.ts +108 -0
  88. package/src/components/ShadcnContextMenu.ts +95 -0
  89. package/src/components/ShadcnDialog.ts +100 -0
  90. package/src/components/ShadcnDrawer.ts +219 -0
  91. package/src/components/ShadcnDropdownMenu.ts +116 -0
  92. package/src/components/ShadcnEmpty.ts +94 -0
  93. package/src/components/ShadcnField.ts +167 -0
  94. package/src/components/ShadcnForm.ts +97 -0
  95. package/src/components/ShadcnHoverCard.ts +146 -0
  96. package/src/components/ShadcnInput.ts +101 -0
  97. package/src/components/ShadcnInputGroup.ts +89 -0
  98. package/src/components/ShadcnInputOtp.ts +151 -0
  99. package/src/components/ShadcnItem.ts +156 -0
  100. package/src/components/ShadcnKbd.ts +34 -0
  101. package/src/components/ShadcnLabel.ts +50 -0
  102. package/src/components/ShadcnMenubar.ts +78 -0
  103. package/src/components/ShadcnNativeSelect.ts +140 -0
  104. package/src/components/ShadcnNavigationMenu.ts +94 -0
  105. package/src/components/ShadcnPagination.ts +137 -0
  106. package/src/components/ShadcnPopover.ts +109 -0
  107. package/src/components/ShadcnProgress.ts +67 -0
  108. package/src/components/ShadcnRadioGroup.ts +222 -0
  109. package/src/components/ShadcnRangeCalendar.ts +263 -0
  110. package/src/components/ShadcnSelect.ts +100 -0
  111. package/src/components/ShadcnSeparator.ts +49 -0
  112. package/src/components/ShadcnSheet.ts +162 -0
  113. package/src/components/ShadcnSidebar.ts +71 -0
  114. package/src/components/ShadcnSkeleton.ts +29 -0
  115. package/src/components/ShadcnSlider.ts +233 -0
  116. package/src/components/ShadcnSonner.ts +90 -0
  117. package/src/components/ShadcnSpinner.ts +49 -0
  118. package/src/components/ShadcnSwitch.ts +162 -0
  119. package/src/components/ShadcnTabs.ts +94 -0
  120. package/src/components/ShadcnTextarea.ts +96 -0
  121. package/src/components/ShadcnToggle.ts +101 -0
  122. package/src/components/ShadcnToggleGroup.ts +171 -0
  123. package/src/components/ShadcnTooltip.ts +79 -0
  124. package/src/index.ts +124 -0
@@ -0,0 +1,75 @@
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
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-sidebar')) {
72
+ customElements.define('surreal-minimalist-sidebar', SurrealShadcnSidebar);
73
+ }
74
+
75
+ export default SurrealShadcnSidebar;
@@ -0,0 +1,33 @@
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
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-skeleton')) {
30
+ customElements.define('surreal-minimalist-skeleton', SurrealShadcnSkeleton);
31
+ }
32
+
33
+ export default SurrealShadcnSkeleton;
@@ -0,0 +1,237 @@
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
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-slider')) {
234
+ customElements.define('surreal-minimalist-slider', SurrealShadcnSliderElement);
235
+ }
236
+
237
+ export default SurrealShadcnSliderElement;
@@ -0,0 +1,94 @@
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
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-sonner')) {
91
+ customElements.define('surreal-minimalist-sonner', SonnerToasterElement);
92
+ }
93
+
94
+ export default SonnerToasterElement;
@@ -0,0 +1,53 @@
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
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-spinner')) {
50
+ customElements.define('surreal-minimalist-spinner', SurrealShadcnSpinner);
51
+ }
52
+
53
+ export default SurrealShadcnSpinner;
@@ -0,0 +1,166 @@
1
+ class SurrealShadcnSwitch extends HTMLElement {
2
+ static get observedAttributes() {
3
+ return ['checked', 'disabled', 'size', 'class'];
4
+ }
5
+
6
+ private _button: HTMLButtonElement;
7
+ private _thumb: HTMLSpanElement;
8
+
9
+ constructor() {
10
+ super();
11
+ this.attachShadow({ mode: 'open' });
12
+ this.shadowRoot!.innerHTML = `
13
+ <style>
14
+ :host {
15
+ display: inline-flex;
16
+ vertical-align: middle;
17
+ }
18
+ button {
19
+ box-sizing: border-box;
20
+ position: relative;
21
+ display: inline-flex;
22
+ align-items: center;
23
+ flex-shrink: 0;
24
+ border-radius: 9999px;
25
+ border: 1px solid transparent;
26
+ background-color: var(--input, #e4e4e7);
27
+ cursor: pointer;
28
+ user-select: none;
29
+ padding: 0;
30
+ outline: none;
31
+ transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1);
32
+ }
33
+ button:focus-visible {
34
+ box-shadow: 0 0 0 3px var(--ring, rgba(24, 24, 27, 0.5));
35
+ }
36
+ button[data-state="checked"] {
37
+ background-color: var(--primary, #18181b);
38
+ }
39
+ button:disabled {
40
+ cursor: not-allowed;
41
+ opacity: 0.5;
42
+ }
43
+ button[data-size="default"] {
44
+ height: 18.4px;
45
+ width: 32px;
46
+ }
47
+ button[data-size="sm"] {
48
+ height: 14px;
49
+ width: 24px;
50
+ }
51
+ .thumb {
52
+ pointer-events: none;
53
+ display: block;
54
+ border-radius: 9999px;
55
+ background-color: var(--background, #ffffff);
56
+ transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
57
+ }
58
+ button[data-size="default"] .thumb {
59
+ width: 16px;
60
+ height: 16px;
61
+ transform: translateX(0px);
62
+ }
63
+ button[data-size="default"][data-state="checked"] .thumb {
64
+ transform: translateX(14px);
65
+ }
66
+ button[data-size="sm"] .thumb {
67
+ width: 12px;
68
+ height: 12px;
69
+ transform: translateX(0px);
70
+ }
71
+ button[data-size="sm"][data-state="checked"] .thumb {
72
+ transform: translateX(10px);
73
+ }
74
+ </style>
75
+ <button type="button" role="switch" part="control">
76
+ <span class="thumb" part="thumb"></span>
77
+ </button>
78
+ `;
79
+ this._button = this.shadowRoot!.querySelector('button')!;
80
+ this._thumb = this.shadowRoot!.querySelector('.thumb')!;
81
+
82
+ this._button.addEventListener('click', () => this._toggle());
83
+ this._button.addEventListener('keydown', (e) => {
84
+ if (e.key === ' ' || e.key === 'Enter') {
85
+ e.preventDefault();
86
+ this._toggle();
87
+ }
88
+ });
89
+ }
90
+
91
+ get checked(): boolean {
92
+ return this.hasAttribute('checked');
93
+ }
94
+
95
+ set checked(val: boolean) {
96
+ if (val) {
97
+ this.setAttribute('checked', '');
98
+ } else {
99
+ this.removeAttribute('checked');
100
+ }
101
+ }
102
+
103
+ get disabled(): boolean {
104
+ return this.hasAttribute('disabled');
105
+ }
106
+
107
+ set disabled(val: boolean) {
108
+ if (val) {
109
+ this.setAttribute('disabled', '');
110
+ } else {
111
+ this.removeAttribute('disabled');
112
+ }
113
+ }
114
+
115
+ get size(): string {
116
+ return this.getAttribute('size') || 'default';
117
+ }
118
+
119
+ set size(val: string) {
120
+ this.setAttribute('size', val);
121
+ }
122
+
123
+ private _toggle() {
124
+ if (this.disabled) return;
125
+ this.checked = !this.checked;
126
+ this.dispatchEvent(
127
+ new CustomEvent('change', {
128
+ detail: { checked: this.checked },
129
+ bubbles: true,
130
+ composed: true,
131
+ }),
132
+ );
133
+ }
134
+
135
+ connectedCallback() {
136
+ this._update();
137
+ }
138
+
139
+ attributeChangedCallback() {
140
+ this._update();
141
+ }
142
+
143
+ private _update() {
144
+ const isChecked = this.checked;
145
+ const isDisabled = this.disabled;
146
+ const size = this.size;
147
+
148
+ this._button.setAttribute('data-state', isChecked ? 'checked' : 'unchecked');
149
+ this._button.setAttribute('aria-checked', String(isChecked));
150
+ this._button.setAttribute('data-size', size);
151
+ this._button.disabled = isDisabled;
152
+ }
153
+ }
154
+
155
+ if (!customElements.get('surreal-switch')) {
156
+
157
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-switch')) {
158
+ customElements.define('surreal-shadcn-switch', SurrealShadcnSwitch);
159
+ }
160
+ }
161
+ export { SurrealShadcnSwitch };
162
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-switch')) {
163
+ customElements.define('surreal-minimalist-switch', SurrealShadcnSwitch);
164
+ }
165
+
166
+ export default SurrealShadcnSwitch;