@surreal-ui/web 0.8.0 → 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 -142
  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,272 +0,0 @@
1
- class RangeCalendarComponent extends HTMLElement {
2
- private _startDate: Date | null = null;
3
- private _endDate: Date | null = null;
4
- private _hoveredDate: Date | null = null;
5
- private _currentMonth: Date = new Date();
6
- private _numberOfMonths: number = 1;
7
- private _locale: string = 'en-US';
8
-
9
- static get observedAttributes() {
10
- return ['start-date', 'end-date', 'number-of-months', 'locale'];
11
- }
12
-
13
- connectedCallback() {
14
- this.render();
15
- }
16
-
17
- attributeChangedCallback(name: string, oldValue: string, newValue: string) {
18
- if (oldValue === newValue) return;
19
- if (name === 'start-date' && newValue) this._startDate = new Date(newValue);
20
- if (name === 'end-date' && newValue) this._endDate = new Date(newValue);
21
- if (name === 'number-of-months') this._numberOfMonths = parseInt(newValue, 10) || 1;
22
- if (name === 'locale' && newValue) this._locale = newValue;
23
- this.render();
24
- }
25
-
26
- private isSameDay(d1: Date | null, d2: Date | null): boolean {
27
- if (!d1 || !d2) return false;
28
- return (
29
- d1.getFullYear() === d2.getFullYear() &&
30
- d1.getMonth() === d2.getMonth() &&
31
- d1.getDate() === d2.getDate()
32
- );
33
- }
34
-
35
- private isBeforeDay(d1: Date, d2: Date): boolean {
36
- const t1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()).getTime();
37
- const t2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()).getTime();
38
- return t1 < t2;
39
- }
40
-
41
- private isAfterDay(d1: Date, d2: Date): boolean {
42
- const t1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()).getTime();
43
- const t2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()).getTime();
44
- return t1 > t2;
45
- }
46
-
47
- private isBetween(d: Date, start: Date | null, end: Date | null): boolean {
48
- if (!start || !end) return false;
49
- return this.isAfterDay(d, start) && this.isBeforeDay(d, end);
50
- }
51
-
52
- private selectDate(date: Date) {
53
- if (!this._startDate || (this._startDate && this._endDate)) {
54
- this._startDate = date;
55
- this._endDate = null;
56
- } else {
57
- if (this.isBeforeDay(date, this._startDate)) {
58
- this._endDate = this._startDate;
59
- this._startDate = date;
60
- } else {
61
- this._endDate = date;
62
- }
63
- }
64
- this.dispatchEvent(
65
- new CustomEvent('range-change', {
66
- detail: { start: this._startDate, end: this._endDate },
67
- bubbles: true
68
- })
69
- );
70
- this.render();
71
- }
72
-
73
- private getMonthMatrix(year: number, month: number) {
74
- const firstDay = new Date(year, month, 1).getDay();
75
- const daysInMonth = new Date(year, month + 1, 0).getDate();
76
- const daysInPrevMonth = new Date(year, month, 0).getDate();
77
-
78
- const matrix: { date: Date; outside: boolean }[][] = [];
79
- let week: { date: Date; outside: boolean }[] = [];
80
-
81
- for (let i = firstDay - 1; i >= 0; i--) {
82
- week.push({ date: new Date(year, month - 1, daysInPrevMonth - i), outside: true });
83
- }
84
- for (let d = 1; d <= daysInMonth; d++) {
85
- if (week.length === 7) {
86
- matrix.push(week);
87
- week = [];
88
- }
89
- week.push({ date: new Date(year, month, d), outside: false });
90
- }
91
- let nextD = 1;
92
- while (week.length > 0 && week.length < 7) {
93
- week.push({ date: new Date(year, month + 1, nextD++), outside: true });
94
- }
95
- if (week.length > 0) matrix.push(week);
96
- return matrix;
97
- }
98
-
99
- render() {
100
- const weekdays = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
101
- let monthsHtml = '';
102
-
103
- for (let m = 0; m < this._numberOfMonths; m++) {
104
- const target = new Date(
105
- this._currentMonth.getFullYear(),
106
- this._currentMonth.getMonth() + m,
107
- 1
108
- );
109
- const matrix = this.getMonthMatrix(target.getFullYear(), target.getMonth());
110
- const monthTitle = new Intl.DateTimeFormat(this._locale, {
111
- month: 'long',
112
- year: 'numeric'
113
- }).format(target);
114
-
115
- const rowsHtml = matrix
116
- .map(
117
- (week) => `
118
- <tr class="flex w-full">
119
- ${week
120
- .map((cell) => {
121
- const isStart = this.isSameDay(cell.date, this._startDate);
122
- const isEnd = this.isSameDay(cell.date, this._endDate);
123
- const effectiveEnd =
124
- this._endDate ||
125
- (this._startDate &&
126
- this._hoveredDate &&
127
- this.isAfterDay(this._hoveredDate, this._startDate)
128
- ? this._hoveredDate
129
- : null);
130
- const isMiddle = this.isBetween(cell.date, this._startDate, effectiveEnd);
131
- const isToday = this.isSameDay(cell.date, new Date());
132
-
133
- let cellWrapClass = 'relative size-9 p-0 text-center text-sm focus-within:z-20';
134
- if (isStart && !isEnd && this._endDate) cellWrapClass += ' rounded-s-md bg-accent';
135
- if (isEnd && !isStart) cellWrapClass += ' rounded-e-md bg-accent';
136
- if (isMiddle) cellWrapClass += ' bg-accent rounded-none';
137
- if (isStart && isEnd) cellWrapClass += ' rounded-md';
138
-
139
- let btnClass =
140
- 'inline-flex size-9 items-center justify-center rounded-md text-sm font-normal transition-colors select-none';
141
- if (cell.outside) btnClass += ' text-muted-foreground opacity-50';
142
- if (isToday && !isStart && !isEnd)
143
- btnClass += ' bg-accent text-accent-foreground font-semibold';
144
- if (isStart || isEnd) {
145
- btnClass +=
146
- ' bg-primary text-primary-foreground font-semibold hover:bg-primary hover:text-primary-foreground';
147
- } else if (isMiddle) {
148
- btnClass += ' text-foreground rounded-none hover:bg-accent';
149
- } else {
150
- btnClass += ' hover:bg-accent hover:text-accent-foreground';
151
- }
152
-
153
- return `
154
- <td class="${cellWrapClass}">
155
- <button
156
- type="button"
157
- data-date="${cell.date.toISOString()}"
158
- class="${btnClass}"
159
- >
160
- ${cell.date.getDate()}
161
- </button>
162
- </td>
163
- `;
164
- })
165
- .join('')}
166
- </tr>
167
- `
168
- )
169
- .join('');
170
-
171
- monthsHtml += `
172
- <div class="flex flex-col gap-3">
173
- <div class="flex h-7 items-center justify-center">
174
- <span class="text-sm font-medium text-foreground">${monthTitle}</span>
175
- </div>
176
- <table class="w-full border-collapse space-y-1">
177
- <thead>
178
- <tr class="flex">
179
- ${weekdays
180
- .map(
181
- (w) =>
182
- `<th class="w-9 rounded-md text-[0.8rem] font-normal text-muted-foreground text-center">${w}</th>`
183
- )
184
- .join('')}
185
- </tr>
186
- </thead>
187
- <tbody class="flex flex-col gap-1 mt-2">
188
- ${rowsHtml}
189
- </tbody>
190
- </table>
191
- </div>
192
- `;
193
- }
194
-
195
- this.className = 'inline-block select-none';
196
- this.innerHTML = `
197
- <div data-slot="range-calendar" class="p-3 bg-background border border-border rounded-lg shadow-sm w-fit">
198
- <div class="relative flex flex-col gap-4 md:flex-row">
199
- <nav class="absolute inset-x-0 top-0 flex w-full items-center justify-between pointer-events-none z-10">
200
- <button
201
- type="button"
202
- id="prev-btn"
203
- aria-label="Previous Month"
204
- class="pointer-events-auto inline-flex size-7 items-center justify-center rounded-md border border-input bg-transparent text-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
205
- >
206
- <svg class="size-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" /></svg>
207
- </button>
208
- <button
209
- type="button"
210
- id="next-btn"
211
- aria-label="Next Month"
212
- class="pointer-events-auto inline-flex size-7 items-center justify-center rounded-md border border-input bg-transparent text-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
213
- >
214
- <svg class="size-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" /></svg>
215
- </button>
216
- </nav>
217
- ${monthsHtml}
218
- </div>
219
- </div>
220
- `;
221
-
222
- this.querySelector('#prev-btn')?.addEventListener('click', () => {
223
- this._currentMonth = new Date(
224
- this._currentMonth.getFullYear(),
225
- this._currentMonth.getMonth() - 1,
226
- 1
227
- );
228
- this.render();
229
- });
230
-
231
- this.querySelector('#next-btn')?.addEventListener('click', () => {
232
- this._currentMonth = new Date(
233
- this._currentMonth.getFullYear(),
234
- this._currentMonth.getMonth() + 1,
235
- 1
236
- );
237
- this.render();
238
- });
239
-
240
- this.querySelectorAll('button[data-date]').forEach((btn) => {
241
- const dateStr = btn.getAttribute('data-date');
242
- if (!dateStr) return;
243
- const d = new Date(dateStr);
244
- btn.addEventListener('click', () => this.selectDate(d));
245
- btn.addEventListener('mouseenter', () => {
246
- if (this._startDate && !this._endDate) {
247
- this._hoveredDate = d;
248
- this.render();
249
- }
250
- });
251
- });
252
- }
253
- }
254
-
255
- if (!customElements.get('range-calendar')) {
256
- if (
257
- typeof customElements !== 'undefined' &&
258
- !customElements.get('surreal-shadcn-range-calendar')
259
- ) {
260
- customElements.define('surreal-shadcn-range-calendar', RangeCalendarComponent);
261
- }
262
- }
263
- export { RangeCalendarComponent as MinimalistRangeCalendar, RangeCalendarComponent };
264
-
265
- if (
266
- typeof customElements !== 'undefined' &&
267
- !customElements.get('surreal-minimalist-range-calendar')
268
- ) {
269
- customElements.define('surreal-minimalist-range-calendar', RangeCalendarComponent);
270
- }
271
-
272
- export default RangeCalendarComponent;
@@ -1,44 +0,0 @@
1
- class SurrealMinimalistResizable extends HTMLElement {
2
- private _width: number = 400;
3
- private _minWidth: number = 200;
4
- private _maxWidth: number = 800;
5
- private _isResizing: boolean = false;
6
- constructor() {
7
- super();
8
- this.attachShadow({ mode: 'open' });
9
- }
10
- connectedCallback() {
11
- this.render();
12
- this.setupListeners();
13
- }
14
- private render() {
15
- this.shadowRoot!.innerHTML = `<style>.resizable { display: flex; border: 1px solid #e5e7eb; width: ${this._width}px; position: relative; }.content { flex: 1; padding: 1rem; }.handle { width: 4px; background: #d1d5db; cursor: ew-resize; }.handle:hover { background: #9ca3af; }</style><div class="resizable"><div class="content"><slot></slot></div><div class="handle" role="separator" aria-label="Resize handle" tabindex="0"></div></div>`;
16
- }
17
- private setupListeners() {
18
- const handle = this.shadowRoot!.querySelector('.handle')!;
19
- const onMouseMove = (e: MouseEvent) => {
20
- if (!this._isResizing) return;
21
- if (e.clientX >= this._minWidth && e.clientX <= this._maxWidth) {
22
- this._width = e.clientX;
23
- this.shadowRoot!.querySelector<HTMLElement>('.resizable')!.style.width = `${this._width}px`;
24
- }
25
- };
26
- const onMouseUp = () => {
27
- this._isResizing = false;
28
- window.removeEventListener('mousemove', onMouseMove);
29
- window.removeEventListener('mouseup', onMouseUp);
30
- };
31
- handle.addEventListener('mousedown', () => {
32
- this._isResizing = true;
33
- window.addEventListener('mousemove', onMouseMove);
34
- window.addEventListener('mouseup', onMouseUp);
35
- });
36
- }
37
- }
38
-
39
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-resizable')) {
40
- customElements.define('surreal-minimalist-resizable', SurrealMinimalistResizable);
41
- }
42
- export { SurrealMinimalistResizable as MinimalistResizable, SurrealMinimalistResizable };
43
-
44
- export default SurrealMinimalistResizable;
@@ -1,42 +0,0 @@
1
- class SurrealModernScrollArea extends HTMLElement {
2
- constructor() {
3
- super();
4
- this.attachShadow({ mode: 'open' });
5
- this._code = '';
6
- this._copied = false;
7
- }
8
- static get observedAttributes() {
9
- return ['code', 'copied', 'active-platform'];
10
- }
11
- attributeChangedCallback(name, oldValue, newValue) {
12
- if (name === 'code') this._code = newValue;
13
- if (name === 'copied') this._copied = newValue !== null;
14
- this.render();
15
- }
16
- connectedCallback() {
17
- this.render();
18
- this.shadowRoot.addEventListener('click', (e) => {
19
- const btn = e.composedPath().find((el) => el && el.tagName === 'BUTTON');
20
- if (btn) {
21
- this.dispatchEvent(new CustomEvent('copy', { bubbles: true, composed: true }));
22
- }
23
- });
24
- }
25
- render() {
26
- const formatted = (this._code || '').trim();
27
- this.shadowRoot.innerHTML = `<style>@import "https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css";</style><div class="relative"><button class="absolute right-4 top-4 px-3 py-1.5 bg-slate-800/80 hover:bg-slate-700 text-slate-200 text-xs font-semibold rounded-lg border border-slate-700 flex items-center gap-1.5 transition-colors z-10">${this._copied ? '<span class="text-emerald-400">Copied!</span>' : '<span>Copy Code</span>'}</button><pre class="p-6 rounded-2xl bg-slate-950 border border-slate-800 text-xs font-mono text-indigo-200 overflow-x-auto leading-relaxed"><code>${formatted}</code></pre></div>`;
28
- }
29
- }
30
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-modern-scroll-area')) {
31
- customElements.define('surreal-modern-scroll-area', SurrealModernScrollArea);
32
- }
33
- export { SurrealModernScrollArea as MinimalistScrollArea, SurrealModernScrollArea };
34
-
35
- if (
36
- typeof customElements !== 'undefined' &&
37
- !customElements.get('surreal-minimalist-scroll-area')
38
- ) {
39
- customElements.define('surreal-minimalist-scroll-area', SurrealModernScrollArea);
40
- }
41
-
42
- export default SurrealModernScrollArea;
@@ -1,103 +0,0 @@
1
- class SurrealShadcnSelect extends HTMLElement {
2
- private _open: boolean = false;
3
- private _value: string = '';
4
-
5
- static get observedAttributes() {
6
- return ['open', 'value', 'size'];
7
- }
8
-
9
- constructor() {
10
- super();
11
- this.attachShadow({ mode: 'open' });
12
- }
13
-
14
- connectedCallback() {
15
- this.render();
16
- this.setupListeners();
17
- }
18
-
19
- attributeChangedCallback(name: string, oldValue: string, newValue: string) {
20
- if (oldValue !== newValue) {
21
- if (name === 'open') this._open = this.hasAttribute('open');
22
- if (name === 'value') this._value = newValue || '';
23
- this.render();
24
- }
25
- }
26
-
27
- get value(): string {
28
- return this._value;
29
- }
30
-
31
- set value(val: string) {
32
- this._value = val;
33
- this.setAttribute('value', val);
34
- }
35
-
36
- get open(): boolean {
37
- return this._open;
38
- }
39
-
40
- set open(val: boolean) {
41
- this._open = val;
42
- if (val) this.setAttribute('open', '');
43
- else this.removeAttribute('open');
44
- }
45
-
46
- private setupListeners() {
47
- this.shadowRoot?.addEventListener('click', (e) => {
48
- const target = e.target as HTMLElement;
49
- const trigger = target.closest('[data-slot="select-trigger"]');
50
- if (trigger) {
51
- this.open = !this.open;
52
- return;
53
- }
54
- const item = target.closest('[data-slot="select-item"]') as HTMLElement;
55
- if (item && !item.hasAttribute('data-disabled')) {
56
- const val = item.getAttribute('data-value') || '';
57
- this.value = val;
58
- this.open = false;
59
- this.dispatchEvent(new CustomEvent('change', { detail: { value: val }, bubbles: true }));
60
- }
61
- });
62
- }
63
-
64
- private render() {
65
- if (!this.shadowRoot) return;
66
- const size = this.getAttribute('size') || 'default';
67
- const isOpen = this.hasAttribute('open');
68
-
69
- this.shadowRoot.innerHTML = `
70
- <div class="relative inline-block text-left">
71
- <button
72
- type="button"
73
- data-slot="select-trigger"
74
- data-size="${size}"
75
- class="gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm transition-colors select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 data-[size=default]:h-8 data-[size=sm]:h-7 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50"
76
- >
77
- <slot name="trigger-value"><span>${this._value || 'Select an option'}</span></slot>
78
- <svg class="size-4 text-muted-foreground pointer-events-none" 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="m6 9 6 6 6-6"/></svg>
79
- </button>
80
- <div
81
- data-slot="select-content"
82
- style="display: ${isOpen ? 'block' : 'none'};"
83
- class="min-w-36 rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 absolute z-50 overflow-x-hidden overflow-y-auto mt-1 p-1"
84
- >
85
- <slot></slot>
86
- </div>
87
- </div>
88
- `;
89
- }
90
- }
91
-
92
- if (!customElements.get('surreal-select')) {
93
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-select')) {
94
- customElements.define('surreal-shadcn-select', SurrealShadcnSelect);
95
- }
96
- }
97
- export { SurrealShadcnSelect as MinimalistSelect, SurrealShadcnSelect };
98
-
99
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-select')) {
100
- customElements.define('surreal-minimalist-select', SurrealShadcnSelect);
101
- }
102
-
103
- export default SurrealShadcnSelect;
@@ -1,52 +0,0 @@
1
- import { cn } from '@surreal-ui/core';
2
-
3
- export class SurrealShadcnSeparator extends HTMLElement {
4
- static get observedAttributes() {
5
- return ['orientation', 'decorative', 'class'];
6
- }
7
-
8
- connectedCallback() {
9
- this.render();
10
- }
11
-
12
- attributeChangedCallback() {
13
- this.render();
14
- }
15
-
16
- render() {
17
- const orientation = this.getAttribute('orientation') || 'horizontal';
18
- const decorative = this.getAttribute('decorative') !== 'false';
19
- const customClass = this.getAttribute('class') || '';
20
-
21
- this.setAttribute('data-slot', 'separator');
22
- this.setAttribute('data-orientation', orientation);
23
-
24
- if (decorative) {
25
- this.setAttribute('role', 'none');
26
- this.removeAttribute('aria-orientation');
27
- } else {
28
- this.setAttribute('role', 'separator');
29
- if (orientation === 'vertical') {
30
- this.setAttribute('aria-orientation', 'vertical');
31
- } else {
32
- this.removeAttribute('aria-orientation');
33
- }
34
- }
35
-
36
- this.className = cn(
37
- 'shrink-0 bg-border block data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px data-[orientation=vertical]:h-full',
38
- customClass
39
- );
40
- }
41
- }
42
-
43
- if (!customElements.get('surreal-separator')) {
44
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-separator')) {
45
- customElements.define('surreal-shadcn-separator', SurrealShadcnSeparator);
46
- }
47
- }
48
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-separator')) {
49
- customElements.define('surreal-minimalist-separator', SurrealShadcnSeparator);
50
- }
51
-
52
- export default SurrealShadcnSeparator;
@@ -1,165 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-sheet')) {
156
- customElements.define('surreal-shadcn-sheet', SurrealShadcnSheet);
157
- }
158
- }
159
- export { SurrealShadcnSheet as MinimalistSheet, SurrealShadcnSheet };
160
-
161
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-sheet')) {
162
- customElements.define('surreal-minimalist-sheet', SurrealShadcnSheet);
163
- }
164
-
165
- export default SurrealShadcnSheet;