@surreal-ui/web 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/dist/index.js +12075 -0
- package/package.json +27 -0
- package/src/components/GlassmorphismAlert.ts +116 -0
- package/src/components/GlassmorphismButton.ts +19 -0
- package/src/components/GlassmorphismCard.ts +33 -0
- package/src/components/GlassmorphismEmptyState.ts +29 -0
- package/src/components/GlassmorphismInputGroup.ts +202 -0
- package/src/components/GlassmorphismMenubar.ts +36 -0
- package/src/components/GlassmorphismScrollArea.ts +83 -0
- package/src/components/GlassmorphismTable.ts +52 -0
- package/src/components/GlassmorphismTypography.ts +67 -0
- package/src/components/MinimalistAccordion.ts +248 -0
- package/src/components/MinimalistAlert.ts +99 -0
- package/src/components/MinimalistAlertDialog.ts +100 -0
- package/src/components/MinimalistAspectRatio.ts +34 -0
- package/src/components/MinimalistAvatar.ts +98 -0
- package/src/components/MinimalistBadge.ts +71 -0
- package/src/components/MinimalistBreadcrumb.ts +92 -0
- package/src/components/MinimalistButton.ts +111 -0
- package/src/components/MinimalistButtonGroup.ts +110 -0
- package/src/components/MinimalistCalendar.ts +282 -0
- package/src/components/MinimalistCard.ts +131 -0
- package/src/components/MinimalistCarousel.ts +122 -0
- package/src/components/MinimalistChart.ts +151 -0
- package/src/components/MinimalistCheckbox.ts +179 -0
- package/src/components/MinimalistCodeBlock.ts +113 -0
- package/src/components/MinimalistCollapsible.ts +155 -0
- package/src/components/MinimalistCommand.ts +112 -0
- package/src/components/MinimalistContextMenu.ts +99 -0
- package/src/components/MinimalistDialog.ts +104 -0
- package/src/components/MinimalistDrawer.ts +223 -0
- package/src/components/MinimalistDropdownMenu.ts +120 -0
- package/src/components/MinimalistEmpty.ts +98 -0
- package/src/components/MinimalistEmptyState.ts +38 -0
- package/src/components/MinimalistField.ts +171 -0
- package/src/components/MinimalistForm.ts +101 -0
- package/src/components/MinimalistHoverCard.ts +150 -0
- package/src/components/MinimalistInput.ts +105 -0
- package/src/components/MinimalistInputGroup.ts +93 -0
- package/src/components/MinimalistInputOtp.ts +155 -0
- package/src/components/MinimalistItem.ts +160 -0
- package/src/components/MinimalistKbd.ts +38 -0
- package/src/components/MinimalistLabel.ts +54 -0
- package/src/components/MinimalistMenubar.ts +82 -0
- package/src/components/MinimalistNativeSelect.ts +144 -0
- package/src/components/MinimalistNavigationMenu.ts +98 -0
- package/src/components/MinimalistPagination.ts +141 -0
- package/src/components/MinimalistPopover.ts +113 -0
- package/src/components/MinimalistProgress.ts +71 -0
- package/src/components/MinimalistRadioGroup.ts +226 -0
- package/src/components/MinimalistRangeCalendar.ts +267 -0
- package/src/components/MinimalistResizable.ts +44 -0
- package/src/components/MinimalistScrollArea.ts +11 -0
- package/src/components/MinimalistSelect.ts +104 -0
- package/src/components/MinimalistSeparator.ts +53 -0
- package/src/components/MinimalistSheet.ts +166 -0
- package/src/components/MinimalistSidebar.ts +75 -0
- package/src/components/MinimalistSkeleton.ts +33 -0
- package/src/components/MinimalistSlider.ts +237 -0
- package/src/components/MinimalistSonner.ts +94 -0
- package/src/components/MinimalistSpinner.ts +53 -0
- package/src/components/MinimalistSwitch.ts +166 -0
- package/src/components/MinimalistTable.ts +35 -0
- package/src/components/MinimalistTabs.ts +98 -0
- package/src/components/MinimalistTextarea.ts +100 -0
- package/src/components/MinimalistToggle.ts +105 -0
- package/src/components/MinimalistToggleGroup.ts +175 -0
- package/src/components/MinimalistTooltip.ts +83 -0
- package/src/components/MinimalistTypography.ts +107 -0
- package/src/components/NeubrutalismCard.ts +35 -0
- package/src/components/NeubrutalismItem.ts +67 -0
- package/src/components/ShadcnAccordion.ts +244 -0
- package/src/components/ShadcnAlertDialog.ts +96 -0
- package/src/components/ShadcnAspectRatio.ts +30 -0
- package/src/components/ShadcnAvatar.ts +94 -0
- package/src/components/ShadcnBadge.ts +67 -0
- package/src/components/ShadcnBreadcrumb.ts +88 -0
- package/src/components/ShadcnButton.ts +107 -0
- package/src/components/ShadcnButtonGroup.ts +106 -0
- package/src/components/ShadcnCalendar.ts +278 -0
- package/src/components/ShadcnCarousel.ts +118 -0
- package/src/components/ShadcnChart.ts +147 -0
- package/src/components/ShadcnCheckbox.ts +175 -0
- package/src/components/ShadcnCodeBlock.ts +109 -0
- package/src/components/ShadcnCollapsible.ts +151 -0
- package/src/components/ShadcnCommand.ts +108 -0
- package/src/components/ShadcnContextMenu.ts +95 -0
- package/src/components/ShadcnDialog.ts +100 -0
- package/src/components/ShadcnDrawer.ts +219 -0
- package/src/components/ShadcnDropdownMenu.ts +116 -0
- package/src/components/ShadcnEmpty.ts +94 -0
- package/src/components/ShadcnField.ts +167 -0
- package/src/components/ShadcnForm.ts +97 -0
- package/src/components/ShadcnHoverCard.ts +146 -0
- package/src/components/ShadcnInput.ts +101 -0
- package/src/components/ShadcnInputGroup.ts +89 -0
- package/src/components/ShadcnInputOtp.ts +151 -0
- package/src/components/ShadcnItem.ts +156 -0
- package/src/components/ShadcnKbd.ts +34 -0
- package/src/components/ShadcnLabel.ts +50 -0
- package/src/components/ShadcnMenubar.ts +78 -0
- package/src/components/ShadcnNativeSelect.ts +140 -0
- package/src/components/ShadcnNavigationMenu.ts +94 -0
- package/src/components/ShadcnPagination.ts +137 -0
- package/src/components/ShadcnPopover.ts +109 -0
- package/src/components/ShadcnProgress.ts +67 -0
- package/src/components/ShadcnRadioGroup.ts +222 -0
- package/src/components/ShadcnRangeCalendar.ts +263 -0
- package/src/components/ShadcnSelect.ts +100 -0
- package/src/components/ShadcnSeparator.ts +49 -0
- package/src/components/ShadcnSheet.ts +162 -0
- package/src/components/ShadcnSidebar.ts +71 -0
- package/src/components/ShadcnSkeleton.ts +29 -0
- package/src/components/ShadcnSlider.ts +233 -0
- package/src/components/ShadcnSonner.ts +90 -0
- package/src/components/ShadcnSpinner.ts +49 -0
- package/src/components/ShadcnSwitch.ts +162 -0
- package/src/components/ShadcnTabs.ts +94 -0
- package/src/components/ShadcnTextarea.ts +96 -0
- package/src/components/ShadcnToggle.ts +101 -0
- package/src/components/ShadcnToggleGroup.ts +171 -0
- package/src/components/ShadcnTooltip.ts +79 -0
- package/src/index.ts +124 -0
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
|
|
257
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-range-calendar')) {
|
|
258
|
+
customElements.define('surreal-shadcn-range-calendar', RangeCalendarComponent);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
export { RangeCalendarComponent as MinimalistRangeCalendar, RangeCalendarComponent };
|
|
262
|
+
|
|
263
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-range-calendar')) {
|
|
264
|
+
customElements.define('surreal-minimalist-range-calendar', RangeCalendarComponent);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export default RangeCalendarComponent;
|
|
@@ -0,0 +1,44 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class SurrealModernScrollArea extends HTMLElement {constructor() {super();this.attachShadow({ mode: 'open' });this._code = '';this._copied = false;}static get observedAttributes() {return ['code', 'copied', 'active-platform'];}attributeChangedCallback(name, oldValue, newValue) {if (name === 'code') this._code = newValue;if (name === 'copied') this._copied = newValue !== null;this.render();}connectedCallback() {this.render();this.shadowRoot.addEventListener('click', (e) => {const btn = e.composedPath().find(el => el && el.tagName === 'BUTTON');if (btn) {this.dispatchEvent(new CustomEvent('copy', { bubbles: true, composed: true }));}});} render() {const formatted = (this._code || '').trim();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>`;}}
|
|
2
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-modern-scroll-area')) {
|
|
3
|
+
customElements.define('surreal-modern-scroll-area', SurrealModernScrollArea);
|
|
4
|
+
};
|
|
5
|
+
export { SurrealModernScrollArea as MinimalistScrollArea, SurrealModernScrollArea };
|
|
6
|
+
|
|
7
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-scroll-area')) {
|
|
8
|
+
customElements.define('surreal-minimalist-scroll-area', SurrealModernScrollArea);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default SurrealModernScrollArea;
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
|
|
94
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-select')) {
|
|
95
|
+
customElements.define('surreal-shadcn-select', SurrealShadcnSelect);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export { SurrealShadcnSelect as MinimalistSelect, SurrealShadcnSelect };
|
|
99
|
+
|
|
100
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-select')) {
|
|
101
|
+
customElements.define('surreal-minimalist-select', SurrealShadcnSelect);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default SurrealShadcnSelect;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
45
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-separator')) {
|
|
46
|
+
customElements.define('surreal-shadcn-separator', SurrealShadcnSeparator);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-separator')) {
|
|
50
|
+
customElements.define('surreal-minimalist-separator', SurrealShadcnSeparator);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default SurrealShadcnSeparator;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
class SurrealShadcnSheet extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ['open', 'side'];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.attachShadow({ mode: 'open' });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get open() {
|
|
12
|
+
return this.hasAttribute('open');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
set open(value) {
|
|
16
|
+
if (value) {
|
|
17
|
+
this.setAttribute('open', '');
|
|
18
|
+
} else {
|
|
19
|
+
this.removeAttribute('open');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get side() {
|
|
24
|
+
return this.getAttribute('side') || 'right';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set side(val) {
|
|
28
|
+
this.setAttribute('side', val);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
this.render();
|
|
33
|
+
this.setupListeners();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
37
|
+
if (oldValue !== newValue) {
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setupListeners() {
|
|
43
|
+
this.shadowRoot?.addEventListener('click', (e) => {
|
|
44
|
+
const target = e.target;
|
|
45
|
+
if (
|
|
46
|
+
target &&
|
|
47
|
+
(target.matches('[data-slot="sheet-overlay"]') ||
|
|
48
|
+
target.closest('[data-slot="sheet-close"]'))
|
|
49
|
+
) {
|
|
50
|
+
this.open = false;
|
|
51
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
render() {
|
|
57
|
+
const isOpen = this.open;
|
|
58
|
+
const side = this.side;
|
|
59
|
+
|
|
60
|
+
const sideClasses =
|
|
61
|
+
{
|
|
62
|
+
right: 'top-0 right-0 h-full w-3/4 max-w-sm border-l translate-x-0',
|
|
63
|
+
left: 'top-0 left-0 h-full w-3/4 max-w-sm border-r translate-x-0',
|
|
64
|
+
top: 'top-0 inset-x-0 h-auto border-b translate-y-0',
|
|
65
|
+
bottom: 'bottom-0 inset-x-0 h-auto border-t translate-y-0',
|
|
66
|
+
}[side] || 'top-0 right-0 h-full w-3/4 max-w-sm border-l';
|
|
67
|
+
|
|
68
|
+
this.shadowRoot.innerHTML = `
|
|
69
|
+
<style>
|
|
70
|
+
:host {
|
|
71
|
+
display: contents;
|
|
72
|
+
}
|
|
73
|
+
.portal {
|
|
74
|
+
position: fixed;
|
|
75
|
+
inset: 0;
|
|
76
|
+
z-index: 50;
|
|
77
|
+
display: ${isOpen ? 'flex' : 'none'};
|
|
78
|
+
}
|
|
79
|
+
.overlay {
|
|
80
|
+
position: fixed;
|
|
81
|
+
inset: 0;
|
|
82
|
+
background-color: rgba(0, 0, 0, 0.8);
|
|
83
|
+
animation: fadeIn 0.2s ease-out;
|
|
84
|
+
}
|
|
85
|
+
.content {
|
|
86
|
+
position: fixed;
|
|
87
|
+
z-index: 50;
|
|
88
|
+
display: flex;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
gap: 1rem;
|
|
91
|
+
padding: 1.5rem;
|
|
92
|
+
font-size: 0.875rem;
|
|
93
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
|
94
|
+
background-color: var(--background, #ffffff);
|
|
95
|
+
color: var(--foreground, #09090b);
|
|
96
|
+
border-color: var(--border, #e4e4e7);
|
|
97
|
+
box-sizing: border-box;
|
|
98
|
+
transition: transform 0.3s ease-in-out;
|
|
99
|
+
}
|
|
100
|
+
.close-btn {
|
|
101
|
+
position: absolute;
|
|
102
|
+
top: 1rem;
|
|
103
|
+
right: 1rem;
|
|
104
|
+
display: flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
border: none;
|
|
108
|
+
background: transparent;
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
opacity: 0.7;
|
|
111
|
+
padding: 0.25rem;
|
|
112
|
+
border-radius: 0.25rem;
|
|
113
|
+
}
|
|
114
|
+
.close-btn:hover {
|
|
115
|
+
opacity: 1;
|
|
116
|
+
}
|
|
117
|
+
.close-btn svg {
|
|
118
|
+
width: 1rem;
|
|
119
|
+
height: 1rem;
|
|
120
|
+
stroke: currentColor;
|
|
121
|
+
}
|
|
122
|
+
::slotted([slot="header"]) {
|
|
123
|
+
display: flex;
|
|
124
|
+
flex-direction: column;
|
|
125
|
+
gap: 0.375rem;
|
|
126
|
+
}
|
|
127
|
+
::slotted([slot="footer"]) {
|
|
128
|
+
margin-top: auto;
|
|
129
|
+
display: flex;
|
|
130
|
+
flex-direction: column;
|
|
131
|
+
gap: 0.5rem;
|
|
132
|
+
}
|
|
133
|
+
@keyframes fadeIn {
|
|
134
|
+
from { opacity: 0; }
|
|
135
|
+
to { opacity: 1; }
|
|
136
|
+
}
|
|
137
|
+
</style>
|
|
138
|
+
<slot name="trigger"></slot>
|
|
139
|
+
<div class="portal">
|
|
140
|
+
<div class="overlay" data-slot="sheet-overlay"></div>
|
|
141
|
+
<div class="content ${sideClasses}" data-slot="sheet-content" data-side="${side}">
|
|
142
|
+
<slot name="header"></slot>
|
|
143
|
+
<slot></slot>
|
|
144
|
+
<slot name="footer"></slot>
|
|
145
|
+
<button class="close-btn" data-slot="sheet-close" aria-label="Close">
|
|
146
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
|
|
147
|
+
</button>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!customElements.get('surreal-sheet')) {
|
|
155
|
+
|
|
156
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-sheet')) {
|
|
157
|
+
customElements.define('surreal-shadcn-sheet', SurrealShadcnSheet);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
export { SurrealShadcnSheet as MinimalistSheet, SurrealShadcnSheet };
|
|
161
|
+
|
|
162
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-sheet')) {
|
|
163
|
+
customElements.define('surreal-minimalist-sheet', SurrealShadcnSheet);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export default SurrealShadcnSheet;
|