@surreal-ui/web 0.8.1 → 0.9.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 (127) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +832 -6249
  3. package/dist/utils.d.ts +9 -0
  4. package/dist/utils.js +14 -0
  5. package/package.json +14 -3
  6. package/CHANGELOG.md +0 -149
  7. package/src/components/GlassmorphismAlert.ts +0 -115
  8. package/src/components/GlassmorphismButton.ts +0 -18
  9. package/src/components/GlassmorphismCard.ts +0 -36
  10. package/src/components/GlassmorphismEmptyState.ts +0 -35
  11. package/src/components/GlassmorphismInputGroup.ts +0 -205
  12. package/src/components/GlassmorphismMenubar.ts +0 -36
  13. package/src/components/GlassmorphismScrollArea.ts +0 -86
  14. package/src/components/GlassmorphismTable.ts +0 -52
  15. package/src/components/GlassmorphismTypography.ts +0 -70
  16. package/src/components/MinimalistAccordion.ts +0 -252
  17. package/src/components/MinimalistAlert.ts +0 -98
  18. package/src/components/MinimalistAlertDialog.ts +0 -102
  19. package/src/components/MinimalistAspectRatio.ts +0 -36
  20. package/src/components/MinimalistAvatar.ts +0 -97
  21. package/src/components/MinimalistBadge.ts +0 -70
  22. package/src/components/MinimalistBreadcrumb.ts +0 -92
  23. package/src/components/MinimalistButton.ts +0 -110
  24. package/src/components/MinimalistButtonGroup.ts +0 -112
  25. package/src/components/MinimalistCalendar.ts +0 -281
  26. package/src/components/MinimalistCard.ts +0 -130
  27. package/src/components/MinimalistCarousel.ts +0 -121
  28. package/src/components/MinimalistChart.ts +0 -150
  29. package/src/components/MinimalistCheckbox.ts +0 -178
  30. package/src/components/MinimalistCodeBlock.ts +0 -112
  31. package/src/components/MinimalistCollapsible.ts +0 -160
  32. package/src/components/MinimalistCommand.ts +0 -111
  33. package/src/components/MinimalistContextMenu.ts +0 -101
  34. package/src/components/MinimalistDialog.ts +0 -103
  35. package/src/components/MinimalistDrawer.ts +0 -222
  36. package/src/components/MinimalistDropdownMenu.ts +0 -125
  37. package/src/components/MinimalistEmpty.ts +0 -97
  38. package/src/components/MinimalistEmptyState.ts +0 -41
  39. package/src/components/MinimalistField.ts +0 -176
  40. package/src/components/MinimalistForm.ts +0 -102
  41. package/src/components/MinimalistHoverCard.ts +0 -149
  42. package/src/components/MinimalistInput.ts +0 -104
  43. package/src/components/MinimalistInputGroup.ts +0 -95
  44. package/src/components/MinimalistInputOtp.ts +0 -154
  45. package/src/components/MinimalistItem.ts +0 -159
  46. package/src/components/MinimalistKbd.ts +0 -37
  47. package/src/components/MinimalistLabel.ts +0 -53
  48. package/src/components/MinimalistMenubar.ts +0 -81
  49. package/src/components/MinimalistNativeSelect.ts +0 -149
  50. package/src/components/MinimalistNavigationMenu.ts +0 -103
  51. package/src/components/MinimalistPagination.ts +0 -140
  52. package/src/components/MinimalistPopover.ts +0 -112
  53. package/src/components/MinimalistProgress.ts +0 -70
  54. package/src/components/MinimalistRadioGroup.ts +0 -228
  55. package/src/components/MinimalistRangeCalendar.ts +0 -272
  56. package/src/components/MinimalistResizable.ts +0 -44
  57. package/src/components/MinimalistScrollArea.ts +0 -42
  58. package/src/components/MinimalistSelect.ts +0 -103
  59. package/src/components/MinimalistSeparator.ts +0 -52
  60. package/src/components/MinimalistSheet.ts +0 -165
  61. package/src/components/MinimalistSidebar.ts +0 -74
  62. package/src/components/MinimalistSkeleton.ts +0 -32
  63. package/src/components/MinimalistSlider.ts +0 -236
  64. package/src/components/MinimalistSonner.ts +0 -93
  65. package/src/components/MinimalistSpinner.ts +0 -52
  66. package/src/components/MinimalistSwitch.ts +0 -165
  67. package/src/components/MinimalistTable.ts +0 -35
  68. package/src/components/MinimalistTabs.ts +0 -97
  69. package/src/components/MinimalistTextarea.ts +0 -99
  70. package/src/components/MinimalistToggle.ts +0 -104
  71. package/src/components/MinimalistToggleGroup.ts +0 -177
  72. package/src/components/MinimalistTooltip.ts +0 -82
  73. package/src/components/MinimalistTypography.ts +0 -106
  74. package/src/components/NeubrutalismCard.ts +0 -35
  75. package/src/components/NeubrutalismItem.ts +0 -67
  76. package/src/components/ShadcnAccordion.ts +0 -248
  77. package/src/components/ShadcnAlertDialog.ts +0 -95
  78. package/src/components/ShadcnAspectRatio.ts +0 -29
  79. package/src/components/ShadcnAvatar.ts +0 -93
  80. package/src/components/ShadcnBadge.ts +0 -66
  81. package/src/components/ShadcnBreadcrumb.ts +0 -88
  82. package/src/components/ShadcnButton.ts +0 -106
  83. package/src/components/ShadcnButtonGroup.ts +0 -105
  84. package/src/components/ShadcnCalendar.ts +0 -277
  85. package/src/components/ShadcnCarousel.ts +0 -117
  86. package/src/components/ShadcnChart.ts +0 -146
  87. package/src/components/ShadcnCheckbox.ts +0 -174
  88. package/src/components/ShadcnCodeBlock.ts +0 -108
  89. package/src/components/ShadcnCollapsible.ts +0 -153
  90. package/src/components/ShadcnCommand.ts +0 -107
  91. package/src/components/ShadcnContextMenu.ts +0 -94
  92. package/src/components/ShadcnDialog.ts +0 -99
  93. package/src/components/ShadcnDrawer.ts +0 -218
  94. package/src/components/ShadcnDropdownMenu.ts +0 -118
  95. package/src/components/ShadcnEmpty.ts +0 -93
  96. package/src/components/ShadcnField.ts +0 -172
  97. package/src/components/ShadcnForm.ts +0 -98
  98. package/src/components/ShadcnHoverCard.ts +0 -145
  99. package/src/components/ShadcnInput.ts +0 -100
  100. package/src/components/ShadcnInputGroup.ts +0 -88
  101. package/src/components/ShadcnInputOtp.ts +0 -150
  102. package/src/components/ShadcnItem.ts +0 -155
  103. package/src/components/ShadcnKbd.ts +0 -33
  104. package/src/components/ShadcnLabel.ts +0 -49
  105. package/src/components/ShadcnMenubar.ts +0 -77
  106. package/src/components/ShadcnNativeSelect.ts +0 -142
  107. package/src/components/ShadcnNavigationMenu.ts +0 -96
  108. package/src/components/ShadcnPagination.ts +0 -136
  109. package/src/components/ShadcnPopover.ts +0 -108
  110. package/src/components/ShadcnProgress.ts +0 -66
  111. package/src/components/ShadcnRadioGroup.ts +0 -221
  112. package/src/components/ShadcnRangeCalendar.ts +0 -265
  113. package/src/components/ShadcnSelect.ts +0 -99
  114. package/src/components/ShadcnSeparator.ts +0 -48
  115. package/src/components/ShadcnSheet.ts +0 -161
  116. package/src/components/ShadcnSidebar.ts +0 -70
  117. package/src/components/ShadcnSkeleton.ts +0 -28
  118. package/src/components/ShadcnSlider.ts +0 -232
  119. package/src/components/ShadcnSonner.ts +0 -89
  120. package/src/components/ShadcnSpinner.ts +0 -48
  121. package/src/components/ShadcnSwitch.ts +0 -161
  122. package/src/components/ShadcnTabs.ts +0 -93
  123. package/src/components/ShadcnTextarea.ts +0 -95
  124. package/src/components/ShadcnToggle.ts +0 -100
  125. package/src/components/ShadcnToggleGroup.ts +0 -170
  126. package/src/components/ShadcnTooltip.ts +0 -78
  127. package/src/index.ts +0 -124
@@ -1,74 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-sidebar')) {
67
- customElements.define('surreal-shadcn-sidebar', SurrealShadcnSidebar);
68
- }
69
- }
70
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-sidebar')) {
71
- customElements.define('surreal-minimalist-sidebar', SurrealShadcnSidebar);
72
- }
73
-
74
- export default SurrealShadcnSidebar;
@@ -1,32 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-skeleton')) {
25
- customElements.define('surreal-shadcn-skeleton', SurrealShadcnSkeleton);
26
- }
27
- }
28
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-skeleton')) {
29
- customElements.define('surreal-minimalist-skeleton', SurrealShadcnSkeleton);
30
- }
31
-
32
- export default SurrealShadcnSkeleton;
@@ -1,236 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-slider')) {
229
- customElements.define('surreal-shadcn-slider', SurrealShadcnSliderElement);
230
- }
231
- }
232
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-slider')) {
233
- customElements.define('surreal-minimalist-slider', SurrealShadcnSliderElement);
234
- }
235
-
236
- export default SurrealShadcnSliderElement;
@@ -1,93 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-sonner')) {
84
- customElements.define('surreal-shadcn-sonner', SonnerToasterElement);
85
- }
86
- }
87
-
88
- export { SonnerToasterElement };
89
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-sonner')) {
90
- customElements.define('surreal-minimalist-sonner', SonnerToasterElement);
91
- }
92
-
93
- export default SonnerToasterElement;
@@ -1,52 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-spinner')) {
45
- customElements.define('surreal-shadcn-spinner', SurrealShadcnSpinner);
46
- }
47
- }
48
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-spinner')) {
49
- customElements.define('surreal-minimalist-spinner', SurrealShadcnSpinner);
50
- }
51
-
52
- export default SurrealShadcnSpinner;
@@ -1,165 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-switch')) {
157
- customElements.define('surreal-shadcn-switch', SurrealShadcnSwitch);
158
- }
159
- }
160
- export { SurrealShadcnSwitch };
161
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-switch')) {
162
- customElements.define('surreal-minimalist-switch', SurrealShadcnSwitch);
163
- }
164
-
165
- export default SurrealShadcnSwitch;