@surreal-ui/svelte 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 +66 -0
- package/package.json +33 -0
- package/src/components/GlassmorphismAlert.svelte +37 -0
- package/src/components/GlassmorphismButton.svelte +16 -0
- package/src/components/GlassmorphismCard.svelte +37 -0
- package/src/components/GlassmorphismEmptyState.svelte +19 -0
- package/src/components/GlassmorphismInputGroup.svelte +124 -0
- package/src/components/GlassmorphismMenubar.svelte +98 -0
- package/src/components/GlassmorphismScrollArea.svelte +61 -0
- package/src/components/GlassmorphismTable.svelte +54 -0
- package/src/components/GlassmorphismTypography.svelte +31 -0
- package/src/components/MinimalistAccordion.svelte +189 -0
- package/src/components/MinimalistAlert.svelte +35 -0
- package/src/components/MinimalistAlertDialog.svelte +247 -0
- package/src/components/MinimalistAspectRatio.svelte +31 -0
- package/src/components/MinimalistAvatar.svelte +127 -0
- package/src/components/MinimalistBadge.svelte +60 -0
- package/src/components/MinimalistBreadcrumb.svelte +141 -0
- package/src/components/MinimalistButton.svelte +94 -0
- package/src/components/MinimalistButtonGroup.svelte +93 -0
- package/src/components/MinimalistCalendar.svelte +307 -0
- package/src/components/MinimalistCard.svelte +87 -0
- package/src/components/MinimalistCarousel.svelte +258 -0
- package/src/components/MinimalistChart.svelte +225 -0
- package/src/components/MinimalistCheckbox.svelte +95 -0
- package/src/components/MinimalistCodeBlock.svelte +189 -0
- package/src/components/MinimalistCollapsible.svelte +88 -0
- package/src/components/MinimalistCommand.svelte +299 -0
- package/src/components/MinimalistContextMenu.svelte +236 -0
- package/src/components/MinimalistDialog.svelte +218 -0
- package/src/components/MinimalistDrawer.svelte +209 -0
- package/src/components/MinimalistDropdownMenu.svelte +349 -0
- package/src/components/MinimalistEmpty.svelte +136 -0
- package/src/components/MinimalistEmptyState.svelte +27 -0
- package/src/components/MinimalistField.svelte +239 -0
- package/src/components/MinimalistForm.svelte +157 -0
- package/src/components/MinimalistHoverCard.svelte +71 -0
- package/src/components/MinimalistInput.svelte +53 -0
- package/src/components/MinimalistInputGroup.svelte +165 -0
- package/src/components/MinimalistInputOtp.svelte +171 -0
- package/src/components/MinimalistItem.svelte +225 -0
- package/src/components/MinimalistKbd.svelte +39 -0
- package/src/components/MinimalistLabel.svelte +26 -0
- package/src/components/MinimalistMenubar.svelte +373 -0
- package/src/components/MinimalistNativeSelect.svelte +81 -0
- package/src/components/MinimalistNavigationMenu.svelte +188 -0
- package/src/components/MinimalistPagination.svelte +189 -0
- package/src/components/MinimalistPopover.svelte +160 -0
- package/src/components/MinimalistProgress.svelte +42 -0
- package/src/components/MinimalistRadioGroup.svelte +90 -0
- package/src/components/MinimalistRangeCalendar.svelte +273 -0
- package/src/components/MinimalistResizable.svelte +45 -0
- package/src/components/MinimalistScrollArea.svelte +24 -0
- package/src/components/MinimalistSelect.svelte +237 -0
- package/src/components/MinimalistSeparator.svelte +35 -0
- package/src/components/MinimalistSheet.svelte +189 -0
- package/src/components/MinimalistSidebar.svelte +601 -0
- package/src/components/MinimalistSkeleton.svelte +19 -0
- package/src/components/MinimalistSlider.svelte +192 -0
- package/src/components/MinimalistSonner.svelte +30 -0
- package/src/components/MinimalistSpinner.svelte +35 -0
- package/src/components/MinimalistSwitch.svelte +67 -0
- package/src/components/MinimalistTable.svelte +53 -0
- package/src/components/MinimalistTabs.svelte +169 -0
- package/src/components/MinimalistTextarea.svelte +31 -0
- package/src/components/MinimalistToggle.svelte +74 -0
- package/src/components/MinimalistToggleGroup.svelte +184 -0
- package/src/components/MinimalistTooltip.svelte +121 -0
- package/src/components/MinimalistTypography.svelte +25 -0
- package/src/components/NeubrutalismCard.svelte +85 -0
- package/src/components/NeubrutalismItem.svelte +53 -0
- package/src/components/ShadcnAccordion.svelte +189 -0
- package/src/components/ShadcnAlertDialog.svelte +247 -0
- package/src/components/ShadcnAspectRatio.svelte +31 -0
- package/src/components/ShadcnAvatar.svelte +127 -0
- package/src/components/ShadcnBadge.svelte +60 -0
- package/src/components/ShadcnBreadcrumb.svelte +141 -0
- package/src/components/ShadcnButton.svelte +94 -0
- package/src/components/ShadcnButtonGroup.svelte +93 -0
- package/src/components/ShadcnCalendar.svelte +307 -0
- package/src/components/ShadcnCarousel.svelte +258 -0
- package/src/components/ShadcnChart.svelte +225 -0
- package/src/components/ShadcnCheckbox.svelte +95 -0
- package/src/components/ShadcnCodeBlock.svelte +189 -0
- package/src/components/ShadcnCollapsible.svelte +88 -0
- package/src/components/ShadcnCommand.svelte +299 -0
- package/src/components/ShadcnContextMenu.svelte +236 -0
- package/src/components/ShadcnDialog.svelte +218 -0
- package/src/components/ShadcnDrawer.svelte +209 -0
- package/src/components/ShadcnDropdownMenu.svelte +349 -0
- package/src/components/ShadcnEmpty.svelte +136 -0
- package/src/components/ShadcnField.svelte +239 -0
- package/src/components/ShadcnForm.svelte +157 -0
- package/src/components/ShadcnHoverCard.svelte +71 -0
- package/src/components/ShadcnInput.svelte +53 -0
- package/src/components/ShadcnInputGroup.svelte +165 -0
- package/src/components/ShadcnInputOtp.svelte +171 -0
- package/src/components/ShadcnItem.svelte +225 -0
- package/src/components/ShadcnKbd.svelte +39 -0
- package/src/components/ShadcnLabel.svelte +26 -0
- package/src/components/ShadcnMenubar.svelte +373 -0
- package/src/components/ShadcnNativeSelect.svelte +81 -0
- package/src/components/ShadcnNavigationMenu.svelte +188 -0
- package/src/components/ShadcnPagination.svelte +189 -0
- package/src/components/ShadcnPopover.svelte +160 -0
- package/src/components/ShadcnProgress.svelte +42 -0
- package/src/components/ShadcnRadioGroup.svelte +90 -0
- package/src/components/ShadcnRangeCalendar.svelte +273 -0
- package/src/components/ShadcnSelect.svelte +237 -0
- package/src/components/ShadcnSeparator.svelte +35 -0
- package/src/components/ShadcnSheet.svelte +189 -0
- package/src/components/ShadcnSidebar.svelte +601 -0
- package/src/components/ShadcnSkeleton.svelte +19 -0
- package/src/components/ShadcnSlider.svelte +192 -0
- package/src/components/ShadcnSonner.svelte +30 -0
- package/src/components/ShadcnSpinner.svelte +35 -0
- package/src/components/ShadcnSwitch.svelte +67 -0
- package/src/components/ShadcnTabs.svelte +169 -0
- package/src/components/ShadcnTextarea.svelte +31 -0
- package/src/components/ShadcnToggle.svelte +74 -0
- package/src/components/ShadcnToggleGroup.svelte +184 -0
- package/src/components/ShadcnTooltip.svelte +121 -0
- package/src/index.d.ts +123 -0
- package/src/index.js +123 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
export interface DateRange {
|
|
4
|
+
start?: Date | null;
|
|
5
|
+
end?: Date | null;
|
|
6
|
+
}
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import ChevronLeft from '@lucide/svelte/icons/chevron-left';
|
|
11
|
+
import ChevronRight from '@lucide/svelte/icons/chevron-right';
|
|
12
|
+
import ChevronDown from '@lucide/svelte/icons/chevron-down';
|
|
13
|
+
import type { Snippet } from 'svelte';
|
|
14
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
15
|
+
|
|
16
|
+
interface ShadcnRangeCalendarProps extends HTMLAttributes<HTMLDivElement> {
|
|
17
|
+
value?: DateRange;
|
|
18
|
+
placeholder?: Date;
|
|
19
|
+
numberOfMonths?: number;
|
|
20
|
+
locale?: string;
|
|
21
|
+
weekdayFormat?: 'short' | 'narrow' | 'long';
|
|
22
|
+
captionLayout?: 'dropdown' | 'dropdown-months' | 'dropdown-years' | 'label';
|
|
23
|
+
disableDaysOutsideMonth?: boolean;
|
|
24
|
+
onValueChange?: (range: DateRange) => void;
|
|
25
|
+
children?: Snippet;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
value = $bindable({ start: null, end: null }),
|
|
30
|
+
placeholder = $bindable(new Date()),
|
|
31
|
+
numberOfMonths = 1,
|
|
32
|
+
locale = 'en-US',
|
|
33
|
+
weekdayFormat = 'short',
|
|
34
|
+
captionLayout = 'label',
|
|
35
|
+
disableDaysOutsideMonth = false,
|
|
36
|
+
onValueChange,
|
|
37
|
+
class: className = '',
|
|
38
|
+
children,
|
|
39
|
+
...restProps
|
|
40
|
+
}: ShadcnRangeCalendarProps = $props();
|
|
41
|
+
|
|
42
|
+
let hoveredDate = $state<Date | null>(null);
|
|
43
|
+
|
|
44
|
+
function isSameDay(d1?: Date | null, d2?: Date | null): boolean {
|
|
45
|
+
if (!d1 || !d2) return false;
|
|
46
|
+
return (
|
|
47
|
+
d1.getFullYear() === d2.getFullYear() &&
|
|
48
|
+
d1.getMonth() === d2.getMonth() &&
|
|
49
|
+
d1.getDate() === d2.getDate()
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isBeforeDay(d1: Date, d2: Date): boolean {
|
|
54
|
+
const t1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()).getTime();
|
|
55
|
+
const t2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()).getTime();
|
|
56
|
+
return t1 < t2;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isAfterDay(d1: Date, d2: Date): boolean {
|
|
60
|
+
const t1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()).getTime();
|
|
61
|
+
const t2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()).getTime();
|
|
62
|
+
return t1 > t2;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isBetweenDays(date: Date, start?: Date | null, end?: Date | null): boolean {
|
|
66
|
+
if (!start || !end) return false;
|
|
67
|
+
return isAfterDay(date, start) && isBeforeDay(date, end);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function handleSelectDate(date: Date) {
|
|
71
|
+
if (!value.start || (value.start && value.end)) {
|
|
72
|
+
value = { start: date, end: null };
|
|
73
|
+
} else if (value.start && !value.end) {
|
|
74
|
+
if (isBeforeDay(date, value.start)) {
|
|
75
|
+
value = { start: date, end: value.start };
|
|
76
|
+
} else {
|
|
77
|
+
value = { start: value.start, end: date };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
onValueChange?.(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function prevMonth() {
|
|
84
|
+
const next = new Date(placeholder);
|
|
85
|
+
next.setMonth(next.getMonth() - 1);
|
|
86
|
+
placeholder = next;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function nextMonth() {
|
|
90
|
+
const next = new Date(placeholder);
|
|
91
|
+
next.setMonth(next.getMonth() + 1);
|
|
92
|
+
placeholder = next;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getMonthData(offset: number) {
|
|
96
|
+
const target = new Date(placeholder.getFullYear(), placeholder.getMonth() + offset, 1);
|
|
97
|
+
const year = target.getFullYear();
|
|
98
|
+
const month = target.getMonth();
|
|
99
|
+
const firstDayOfWeek = new Date(year, month, 1).getDay();
|
|
100
|
+
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
|
101
|
+
const daysInPrevMonth = new Date(year, month, 0).getDate();
|
|
102
|
+
|
|
103
|
+
const matrix: { date: Date; outside: boolean }[][] = [];
|
|
104
|
+
let currentWeek: { date: Date; outside: boolean }[] = [];
|
|
105
|
+
|
|
106
|
+
for (let i = firstDayOfWeek - 1; i >= 0; i--) {
|
|
107
|
+
currentWeek.push({
|
|
108
|
+
date: new Date(year, month - 1, daysInPrevMonth - i),
|
|
109
|
+
outside: true,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
114
|
+
if (currentWeek.length === 7) {
|
|
115
|
+
matrix.push(currentWeek);
|
|
116
|
+
currentWeek = [];
|
|
117
|
+
}
|
|
118
|
+
currentWeek.push({
|
|
119
|
+
date: new Date(year, month, day),
|
|
120
|
+
outside: false,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let nextMonthDay = 1;
|
|
125
|
+
while (currentWeek.length > 0 && currentWeek.length < 7) {
|
|
126
|
+
currentWeek.push({
|
|
127
|
+
date: new Date(year, month + 1, nextMonthDay++),
|
|
128
|
+
outside: true,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (currentWeek.length > 0) {
|
|
132
|
+
matrix.push(currentWeek);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { year, month, target, matrix };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const weekdays = $derived.by(() => {
|
|
139
|
+
const now = new Date();
|
|
140
|
+
const start = new Date(now.setDate(now.getDate() - now.getDay()));
|
|
141
|
+
return Array.from({ length: 7 }).map((_, i) => {
|
|
142
|
+
const d = new Date(start);
|
|
143
|
+
d.setDate(start.getDate() + i);
|
|
144
|
+
return new Intl.DateTimeFormat(locale, { weekday: weekdayFormat }).format(d);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
</script>
|
|
148
|
+
|
|
149
|
+
<div
|
|
150
|
+
data-slot="range-calendar"
|
|
151
|
+
class={cn(
|
|
152
|
+
'p-3 bg-background border border-border rounded-lg shadow-sm w-fit select-none',
|
|
153
|
+
className,
|
|
154
|
+
)}
|
|
155
|
+
{...restProps}
|
|
156
|
+
>
|
|
157
|
+
{#if children}
|
|
158
|
+
{@render children?.()}
|
|
159
|
+
{:else}
|
|
160
|
+
<div class="relative flex flex-col gap-4 md:flex-row">
|
|
161
|
+
<nav
|
|
162
|
+
class="absolute inset-x-0 top-0 flex w-full items-center justify-between pointer-events-none z-10"
|
|
163
|
+
>
|
|
164
|
+
<button
|
|
165
|
+
type="button"
|
|
166
|
+
onclick={prevMonth}
|
|
167
|
+
aria-label="Previous Month"
|
|
168
|
+
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"
|
|
169
|
+
>
|
|
170
|
+
<ChevronLeft class="size-4" />
|
|
171
|
+
</button>
|
|
172
|
+
<button
|
|
173
|
+
type="button"
|
|
174
|
+
onclick={nextMonth}
|
|
175
|
+
aria-label="Next Month"
|
|
176
|
+
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"
|
|
177
|
+
>
|
|
178
|
+
<ChevronRight class="size-4" />
|
|
179
|
+
</button>
|
|
180
|
+
</nav>
|
|
181
|
+
|
|
182
|
+
{#each Array.from({ length: numberOfMonths }) as _, idx (idx)}
|
|
183
|
+
{@const monthData = getMonthData(idx)}
|
|
184
|
+
<div class="flex flex-col gap-3">
|
|
185
|
+
<div class="flex h-7 items-center justify-center">
|
|
186
|
+
{#if captionLayout.startsWith('dropdown')}
|
|
187
|
+
<div class="flex items-center gap-1.5">
|
|
188
|
+
<span class="text-sm font-medium text-foreground">
|
|
189
|
+
{new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' }).format(
|
|
190
|
+
monthData.target,
|
|
191
|
+
)}
|
|
192
|
+
</span>
|
|
193
|
+
</div>
|
|
194
|
+
{:else}
|
|
195
|
+
<span class="text-sm font-medium text-foreground">
|
|
196
|
+
{new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' }).format(
|
|
197
|
+
monthData.target,
|
|
198
|
+
)}
|
|
199
|
+
</span>
|
|
200
|
+
{/if}
|
|
201
|
+
</div>
|
|
202
|
+
|
|
203
|
+
<table class="w-full border-collapse space-y-1">
|
|
204
|
+
<thead>
|
|
205
|
+
<tr class="flex">
|
|
206
|
+
{#each weekdays as day (day)}
|
|
207
|
+
<th
|
|
208
|
+
class="w-9 rounded-md text-[0.8rem] font-normal text-muted-foreground text-center"
|
|
209
|
+
>
|
|
210
|
+
{day.slice(0, 2)}
|
|
211
|
+
</th>
|
|
212
|
+
{/each}
|
|
213
|
+
</tr>
|
|
214
|
+
</thead>
|
|
215
|
+
<tbody class="flex flex-col gap-1 mt-2">
|
|
216
|
+
{#each monthData.matrix as week, weekIdx (weekIdx)}
|
|
217
|
+
<tr class="flex w-full">
|
|
218
|
+
{#each week as cell, cellIdx (cellIdx)}
|
|
219
|
+
{@const isStart = isSameDay(cell.date, value.start)}
|
|
220
|
+
{@const isEnd = isSameDay(cell.date, value.end)}
|
|
221
|
+
{@const effectiveEnd =
|
|
222
|
+
value.end ||
|
|
223
|
+
(value.start && hoveredDate && isAfterDay(hoveredDate, value.start)
|
|
224
|
+
? hoveredDate
|
|
225
|
+
: null)}
|
|
226
|
+
{@const isMiddle = isBetweenDays(cell.date, value.start, effectiveEnd)}
|
|
227
|
+
{@const isToday = isSameDay(cell.date, new Date())}
|
|
228
|
+
<td
|
|
229
|
+
class={cn(
|
|
230
|
+
'relative size-9 p-0 text-center text-sm focus-within:z-20',
|
|
231
|
+
isStart && !isEnd && value.end && 'rounded-s-md bg-accent',
|
|
232
|
+
isEnd && !isStart && 'rounded-e-md bg-accent',
|
|
233
|
+
isMiddle && 'bg-accent rounded-none',
|
|
234
|
+
isStart && isEnd && 'rounded-md',
|
|
235
|
+
)}
|
|
236
|
+
>
|
|
237
|
+
{#if disableDaysOutsideMonth && cell.outside}
|
|
238
|
+
<div class="size-9" />
|
|
239
|
+
{:else}
|
|
240
|
+
<button
|
|
241
|
+
type="button"
|
|
242
|
+
onclick={() => handleSelectDate(cell.date)}
|
|
243
|
+
onmouseenter={() => (hoveredDate = cell.date)}
|
|
244
|
+
class={cn(
|
|
245
|
+
'inline-flex size-9 items-center justify-center rounded-md text-sm font-normal transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring select-none',
|
|
246
|
+
cell.outside && 'text-muted-foreground opacity-50',
|
|
247
|
+
isToday &&
|
|
248
|
+
!isStart &&
|
|
249
|
+
!isEnd &&
|
|
250
|
+
'bg-accent text-accent-foreground font-semibold',
|
|
251
|
+
(isStart || isEnd) &&
|
|
252
|
+
'bg-primary text-primary-foreground font-semibold hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground',
|
|
253
|
+
isMiddle && 'text-foreground rounded-none hover:bg-accent',
|
|
254
|
+
!isStart &&
|
|
255
|
+
!isEnd &&
|
|
256
|
+
!isMiddle &&
|
|
257
|
+
'hover:bg-accent hover:text-accent-foreground',
|
|
258
|
+
)}
|
|
259
|
+
>
|
|
260
|
+
{cell.date.getDate()}
|
|
261
|
+
</button>
|
|
262
|
+
{/if}
|
|
263
|
+
</td>
|
|
264
|
+
{/each}
|
|
265
|
+
</tr>
|
|
266
|
+
{/each}
|
|
267
|
+
</tbody>
|
|
268
|
+
</table>
|
|
269
|
+
</div>
|
|
270
|
+
{/each}
|
|
271
|
+
</div>
|
|
272
|
+
{/if}
|
|
273
|
+
</div>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
let {
|
|
3
|
+
initialWidth = 400,
|
|
4
|
+
minWidth = 200,
|
|
5
|
+
maxWidth = 800,
|
|
6
|
+
children,
|
|
7
|
+
}: {
|
|
8
|
+
initialWidth?: number;
|
|
9
|
+
minWidth?: number;
|
|
10
|
+
maxWidth?: number;
|
|
11
|
+
children?: import('svelte').Snippet;
|
|
12
|
+
} = $props();
|
|
13
|
+
let width = $state(initialWidth);
|
|
14
|
+
let isResizing = $state(false);
|
|
15
|
+
function startResize(e: MouseEvent) {
|
|
16
|
+
isResizing = true;
|
|
17
|
+
window.addEventListener('mousemove', resize);
|
|
18
|
+
window.addEventListener('mouseup', stopResize);
|
|
19
|
+
}
|
|
20
|
+
function resize(e: MouseEvent) {
|
|
21
|
+
if (!isResizing) return;
|
|
22
|
+
const newWidth = e.clientX;
|
|
23
|
+
if (newWidth >= minWidth && newWidth <= maxWidth) {
|
|
24
|
+
width = newWidth;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function stopResize() {
|
|
28
|
+
isResizing = false;
|
|
29
|
+
window.removeEventListener('mousemove', resize);
|
|
30
|
+
window.removeEventListener('mouseup', stopResize);
|
|
31
|
+
}
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<div class="resizable-container border border-gray-200 relative flex" style="width: {width}px;">
|
|
35
|
+
<div class="content flex-1 p-4">
|
|
36
|
+
{#if children}{@render children()}{/if}
|
|
37
|
+
</div>
|
|
38
|
+
<div
|
|
39
|
+
role="separator"
|
|
40
|
+
aria-label="Resize handle"
|
|
41
|
+
tabindex="0"
|
|
42
|
+
class="resize-handle w-1 bg-gray-300 hover:bg-gray-400 cursor-ew-resize"
|
|
43
|
+
onmousedown={startResize}
|
|
44
|
+
></div>
|
|
45
|
+
</div>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Copy, Check } from '@lucide/svelte';
|
|
3
|
+
interface Props {
|
|
4
|
+
activePlatform?: string;
|
|
5
|
+
code?: string;
|
|
6
|
+
copied?: boolean;
|
|
7
|
+
onCopy?: () => void;
|
|
8
|
+
}
|
|
9
|
+
let { activePlatform = 'svelte', code = '', copied = false, onCopy = () => {} }: Props = $props();
|
|
10
|
+
let formattedCode = $derived((code || '').trim());
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<div class="relative">
|
|
14
|
+
<button
|
|
15
|
+
onclick={onCopy}
|
|
16
|
+
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"
|
|
17
|
+
>
|
|
18
|
+
{#if copied}<Check class="w-3.5 h-3.5 text-emerald-400" />
|
|
19
|
+
<span class="text-emerald-400">Copied!</span>{:else}<Copy class="w-3.5 h-3.5" />
|
|
20
|
+
<span>Copy Code</span>{/if}
|
|
21
|
+
</button>
|
|
22
|
+
<pre
|
|
23
|
+
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>{formattedCode}</code></pre>
|
|
24
|
+
</div>
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import type { HTMLAttributes, HTMLButtonAttributes } from 'svelte/elements';
|
|
5
|
+
|
|
6
|
+
export interface ShadcnSelectRootProps {
|
|
7
|
+
open?: boolean;
|
|
8
|
+
value?: string;
|
|
9
|
+
onValueChange?: (val: string) => void;
|
|
10
|
+
children?: Snippet;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ShadcnSelectTriggerProps extends HTMLButtonAttributes {
|
|
14
|
+
class?: string;
|
|
15
|
+
size?: 'default' | 'sm';
|
|
16
|
+
children?: Snippet;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ShadcnSelectContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
20
|
+
class?: string;
|
|
21
|
+
sideOffset?: number;
|
|
22
|
+
preventScroll?: boolean;
|
|
23
|
+
children?: Snippet;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ShadcnSelectGroupProps extends HTMLAttributes<HTMLDivElement> {
|
|
27
|
+
class?: string;
|
|
28
|
+
children?: Snippet;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SelectGroupHeadingProps extends HTMLAttributes<HTMLDivElement> {
|
|
32
|
+
class?: string;
|
|
33
|
+
children?: Snippet;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ShadcnSelectLabelProps extends HTMLAttributes<HTMLDivElement> {
|
|
37
|
+
class?: string;
|
|
38
|
+
children?: Snippet;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ShadcnSelectItemProps extends HTMLAttributes<HTMLDivElement> {
|
|
42
|
+
class?: string;
|
|
43
|
+
value: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
children?: Snippet<[{ selected: boolean; highlighted: boolean }]>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ShadcnSelectSeparatorProps extends HTMLAttributes<HTMLDivElement> {
|
|
50
|
+
class?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SelectScrollButtonProps extends HTMLAttributes<HTMLDivElement> {
|
|
54
|
+
class?: string;
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<script lang="ts">
|
|
59
|
+
import { Check, ChevronDown, ChevronUp } from '@lucide/svelte';
|
|
60
|
+
|
|
61
|
+
let {
|
|
62
|
+
open = $bindable(false),
|
|
63
|
+
value = $bindable(''),
|
|
64
|
+
onValueChange,
|
|
65
|
+
children,
|
|
66
|
+
}: ShadcnSelectRootProps = $props();
|
|
67
|
+
|
|
68
|
+
let selectedValue = $state(value);
|
|
69
|
+
let isOpen = $state(open);
|
|
70
|
+
|
|
71
|
+
$effect(() => {
|
|
72
|
+
selectedValue = value;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
$effect(() => {
|
|
76
|
+
isOpen = open;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
function handleSelect(val: string) {
|
|
80
|
+
selectedValue = val;
|
|
81
|
+
value = val;
|
|
82
|
+
open = false;
|
|
83
|
+
isOpen = false;
|
|
84
|
+
onValueChange?.(val);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function toggleOpen() {
|
|
88
|
+
isOpen = !isOpen;
|
|
89
|
+
open = isOpen;
|
|
90
|
+
}
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
{#snippet SelectTrigger({
|
|
94
|
+
class: className = '',
|
|
95
|
+
size = 'default',
|
|
96
|
+
children,
|
|
97
|
+
...props
|
|
98
|
+
}: ShadcnSelectTriggerProps = {})}
|
|
99
|
+
<button
|
|
100
|
+
type="button"
|
|
101
|
+
data-slot="select-trigger"
|
|
102
|
+
data-size={size}
|
|
103
|
+
onclick={toggleOpen}
|
|
104
|
+
class={cn(
|
|
105
|
+
"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 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:flex *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
106
|
+
className,
|
|
107
|
+
)}
|
|
108
|
+
{...props}
|
|
109
|
+
>
|
|
110
|
+
{@render children?.()}
|
|
111
|
+
<ChevronDown class="size-4 text-muted-foreground pointer-events-none" />
|
|
112
|
+
</button>
|
|
113
|
+
{/snippet}
|
|
114
|
+
|
|
115
|
+
{#snippet SelectContent({ class: className = '', children, ...props }: ShadcnSelectContentProps = {})}
|
|
116
|
+
{#if isOpen}
|
|
117
|
+
<div
|
|
118
|
+
data-slot="select-content"
|
|
119
|
+
class={cn(
|
|
120
|
+
'min-w-36 rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 relative isolate z-50 overflow-x-hidden overflow-y-auto mt-1 p-1',
|
|
121
|
+
className,
|
|
122
|
+
)}
|
|
123
|
+
{...props}
|
|
124
|
+
>
|
|
125
|
+
<div class="h-full w-full scroll-my-1">
|
|
126
|
+
{@render children?.()}
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
{/if}
|
|
130
|
+
{/snippet}
|
|
131
|
+
|
|
132
|
+
{#snippet SelectGroup({ class: className = '', children, ...props }: ShadcnSelectGroupProps = {})}
|
|
133
|
+
<div data-slot="select-group" class={cn('scroll-my-1 p-1', className)} {...props}>
|
|
134
|
+
{@render children?.()}
|
|
135
|
+
</div>
|
|
136
|
+
{/snippet}
|
|
137
|
+
|
|
138
|
+
{#snippet SelectGroupHeading({
|
|
139
|
+
class: className = '',
|
|
140
|
+
children,
|
|
141
|
+
...props
|
|
142
|
+
}: SelectGroupHeadingProps = {})}
|
|
143
|
+
<div
|
|
144
|
+
data-slot="select-group-heading"
|
|
145
|
+
class={cn('px-2 py-1.5 text-xs text-muted-foreground', className)}
|
|
146
|
+
{...props}
|
|
147
|
+
>
|
|
148
|
+
{@render children?.()}
|
|
149
|
+
</div>
|
|
150
|
+
{/snippet}
|
|
151
|
+
|
|
152
|
+
{#snippet SelectLabel({ class: className = '', children, ...props }: ShadcnSelectLabelProps = {})}
|
|
153
|
+
<div
|
|
154
|
+
data-slot="select-label"
|
|
155
|
+
class={cn('px-1.5 py-1 text-xs text-muted-foreground', className)}
|
|
156
|
+
{...props}
|
|
157
|
+
>
|
|
158
|
+
{@render children?.()}
|
|
159
|
+
</div>
|
|
160
|
+
{/snippet}
|
|
161
|
+
|
|
162
|
+
{#snippet SelectItem({
|
|
163
|
+
class: className = '',
|
|
164
|
+
value: itemValue,
|
|
165
|
+
label,
|
|
166
|
+
disabled = false,
|
|
167
|
+
children,
|
|
168
|
+
...props
|
|
169
|
+
}: SelectItemProps)}
|
|
170
|
+
<div
|
|
171
|
+
role="option"
|
|
172
|
+
aria-selected={selectedValue === itemValue}
|
|
173
|
+
data-slot="select-item"
|
|
174
|
+
data-highlighted={selectedValue === itemValue ? '' : undefined}
|
|
175
|
+
data-disabled={disabled ? '' : undefined}
|
|
176
|
+
onclick={() => !disabled && handleSelect(itemValue)}
|
|
177
|
+
class={cn(
|
|
178
|
+
"gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2 relative flex w-full cursor-default items-center outline-hidden select-none hover:bg-accent hover:text-accent-foreground data-highlighted:bg-accent data-highlighted:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
179
|
+
className,
|
|
180
|
+
)}
|
|
181
|
+
{...props}
|
|
182
|
+
>
|
|
183
|
+
<span class="absolute end-2 flex size-3.5 items-center justify-center">
|
|
184
|
+
{#if selectedValue === itemValue}
|
|
185
|
+
<Check class="size-4" />
|
|
186
|
+
{/if}
|
|
187
|
+
</span>
|
|
188
|
+
<span class="flex flex-1 gap-2 shrink-0 whitespace-nowrap">
|
|
189
|
+
{#if children}
|
|
190
|
+
{@render children({
|
|
191
|
+
selected: selectedValue === itemValue,
|
|
192
|
+
highlighted: selectedValue === itemValue,
|
|
193
|
+
})}
|
|
194
|
+
{:else}
|
|
195
|
+
{label || itemValue}
|
|
196
|
+
{/if}
|
|
197
|
+
</span>
|
|
198
|
+
</div>
|
|
199
|
+
{/snippet}
|
|
200
|
+
|
|
201
|
+
{#snippet SelectSeparator({ class: className = '', ...props }: ShadcnSelectSeparatorProps = {})}
|
|
202
|
+
<div
|
|
203
|
+
data-slot="select-separator"
|
|
204
|
+
class={cn('-mx-1 my-1 h-px bg-border pointer-events-none', className)}
|
|
205
|
+
{...props}
|
|
206
|
+
/>
|
|
207
|
+
{/snippet}
|
|
208
|
+
|
|
209
|
+
{#snippet SelectScrollUpButton({ class: className = '', ...props }: SelectScrollButtonProps = {})}
|
|
210
|
+
<div
|
|
211
|
+
data-slot="select-scroll-up-button"
|
|
212
|
+
class={cn(
|
|
213
|
+
"z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4 top-0 w-full",
|
|
214
|
+
className,
|
|
215
|
+
)}
|
|
216
|
+
{...props}
|
|
217
|
+
>
|
|
218
|
+
<ChevronUp class="size-4" />
|
|
219
|
+
</div>
|
|
220
|
+
{/snippet}
|
|
221
|
+
|
|
222
|
+
{#snippet SelectScrollDownButton({ class: className = '', ...props }: SelectScrollButtonProps = {})}
|
|
223
|
+
<div
|
|
224
|
+
data-slot="select-scroll-down-button"
|
|
225
|
+
class={cn(
|
|
226
|
+
"z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4 bottom-0 w-full",
|
|
227
|
+
className,
|
|
228
|
+
)}
|
|
229
|
+
{...props}
|
|
230
|
+
>
|
|
231
|
+
<ChevronDown class="size-4" />
|
|
232
|
+
</div>
|
|
233
|
+
{/snippet}
|
|
234
|
+
|
|
235
|
+
<div class="relative inline-block text-left">
|
|
236
|
+
{@render children?.()}
|
|
237
|
+
</div>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
|
+
|
|
6
|
+
interface ShadcnSeparatorProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
ref?: HTMLElement | null;
|
|
8
|
+
orientation?: 'horizontal' | 'vertical';
|
|
9
|
+
decorative?: boolean;
|
|
10
|
+
'data-slot'?: string;
|
|
11
|
+
class?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
ref = $bindable(null),
|
|
16
|
+
orientation = 'horizontal',
|
|
17
|
+
decorative = true,
|
|
18
|
+
class: className,
|
|
19
|
+
'data-slot': dataSlot = 'separator',
|
|
20
|
+
...restProps
|
|
21
|
+
}: ShadcnSeparatorProps = $props();
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<div
|
|
25
|
+
bind:this={ref}
|
|
26
|
+
role={decorative ? 'none' : 'separator'}
|
|
27
|
+
aria-orientation={decorative ? undefined : orientation === 'vertical' ? 'vertical' : undefined}
|
|
28
|
+
data-orientation={orientation}
|
|
29
|
+
data-slot={dataSlot}
|
|
30
|
+
class={cn(
|
|
31
|
+
'shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px data-[orientation=vertical]:h-full',
|
|
32
|
+
className,
|
|
33
|
+
)}
|
|
34
|
+
{...restProps}
|
|
35
|
+
></div>
|