@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,93 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cn, cva, type VariantProps } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
|
|
7
|
+
export const shadcnButtonGroupVariants = cva(
|
|
8
|
+
"has-[>[data-slot=button-group]]:gap-2 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-lg flex w-fit items-stretch [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
orientation: {
|
|
12
|
+
horizontal:
|
|
13
|
+
'[&>[data-slot]:not(:has(~[data-slot]))]:rounded-r-lg! [&>[data-slot]]:rounded-r-none [&>[data-slot]~[data-slot]]:rounded-l-none [&>[data-slot]~[data-slot]]:border-l-0',
|
|
14
|
+
vertical:
|
|
15
|
+
'[&>[data-slot]:not(:has(~[data-slot]))]:rounded-b-lg! flex-col [&>[data-slot]]:rounded-b-none [&>[data-slot]~[data-slot]]:rounded-t-none [&>[data-slot]~[data-slot]]:border-t-0',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: {
|
|
19
|
+
orientation: 'horizontal',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export type ShadcnButtonGroupOrientation = VariantProps<typeof shadcnButtonGroupVariants>['orientation'];
|
|
25
|
+
|
|
26
|
+
export interface ShadcnButtonGroupProps extends HTMLAttributes<HTMLDivElement> {
|
|
27
|
+
ref?: HTMLDivElement | null;
|
|
28
|
+
orientation?: ButtonGroupOrientation;
|
|
29
|
+
children?: Snippet;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ShadcnButtonGroupSeparatorProps extends HTMLAttributes<HTMLDivElement> {
|
|
33
|
+
ref?: HTMLDivElement | null;
|
|
34
|
+
orientation?: 'horizontal' | 'vertical';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ShadcnButtonGroupTextProps extends HTMLAttributes<HTMLDivElement> {
|
|
38
|
+
ref?: HTMLDivElement | null;
|
|
39
|
+
children?: Snippet;
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<script lang="ts">
|
|
44
|
+
let {
|
|
45
|
+
ref = $bindable(null),
|
|
46
|
+
class: className,
|
|
47
|
+
orientation = 'horizontal',
|
|
48
|
+
children,
|
|
49
|
+
...restProps
|
|
50
|
+
}: ShadcnButtonGroupProps = $props();
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
{#snippet ButtonGroupSeparator({
|
|
54
|
+
class: className = '',
|
|
55
|
+
orientation = 'vertical',
|
|
56
|
+
...props
|
|
57
|
+
}: ShadcnButtonGroupSeparatorProps = {})}
|
|
58
|
+
<div
|
|
59
|
+
role="separator"
|
|
60
|
+
aria-orientation={orientation}
|
|
61
|
+
data-slot="button-group-separator"
|
|
62
|
+
data-orientation={orientation}
|
|
63
|
+
class={cn(
|
|
64
|
+
'bg-input relative self-stretch data-[orientation=horizontal]:mx-px data-[orientation=horizontal]:w-auto data-[orientation=vertical]:my-px data-[orientation=vertical]:h-auto',
|
|
65
|
+
className,
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
{/snippet}
|
|
70
|
+
|
|
71
|
+
{#snippet ButtonGroupText({ class: className = '', children, ...props }: ShadcnButtonGroupTextProps = {})}
|
|
72
|
+
<div
|
|
73
|
+
data-slot="button-group-text"
|
|
74
|
+
class={cn(
|
|
75
|
+
"gap-2 rounded-lg border bg-muted px-2.5 text-sm font-medium [&_svg:not([class*='size-'])]:size-4 flex items-center [&_svg]:pointer-events-none",
|
|
76
|
+
className,
|
|
77
|
+
)}
|
|
78
|
+
{...props}
|
|
79
|
+
>
|
|
80
|
+
{@render children?.()}
|
|
81
|
+
</div>
|
|
82
|
+
{/snippet}
|
|
83
|
+
|
|
84
|
+
<div
|
|
85
|
+
bind:this={ref}
|
|
86
|
+
role="group"
|
|
87
|
+
data-slot="button-group"
|
|
88
|
+
data-orientation={orientation}
|
|
89
|
+
class={cn(shadcnButtonGroupVariants({ orientation }), className)}
|
|
90
|
+
{...restProps}
|
|
91
|
+
>
|
|
92
|
+
{@render children?.()}
|
|
93
|
+
</div>
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
export interface ShadcnCalendarProps {
|
|
4
|
+
value?: Date | string | null;
|
|
5
|
+
placeholder?: Date;
|
|
6
|
+
class?: string;
|
|
7
|
+
locale?: string;
|
|
8
|
+
weekdayFormat?: 'short' | 'narrow' | 'long';
|
|
9
|
+
captionLayout?: 'label' | 'dropdown' | 'dropdown-months' | 'dropdown-years';
|
|
10
|
+
buttonVariant?: 'ghost' | 'outline' | 'default';
|
|
11
|
+
minDate?: Date;
|
|
12
|
+
maxDate?: Date;
|
|
13
|
+
disableDaysOutsideMonth?: boolean;
|
|
14
|
+
onchange?: (date: Date) => void;
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { ChevronLeft, ChevronRight, ChevronDown } from '@lucide/svelte';
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
value = $bindable(null),
|
|
23
|
+
placeholder = $bindable(new Date()),
|
|
24
|
+
class: className = '',
|
|
25
|
+
locale = 'en-US',
|
|
26
|
+
weekdayFormat = 'short',
|
|
27
|
+
captionLayout = 'label',
|
|
28
|
+
buttonVariant = 'ghost',
|
|
29
|
+
minDate,
|
|
30
|
+
maxDate,
|
|
31
|
+
disableDaysOutsideMonth = false,
|
|
32
|
+
onchange,
|
|
33
|
+
...restProps
|
|
34
|
+
}: ShadcnCalendarProps = $props();
|
|
35
|
+
|
|
36
|
+
let currentMonth = $state(
|
|
37
|
+
placeholder
|
|
38
|
+
? new Date(placeholder.getFullYear(), placeholder.getMonth(), 1)
|
|
39
|
+
: new Date(new Date().getFullYear(), new Date().getMonth(), 1),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const selectedDate = $derived.by(() => {
|
|
43
|
+
if (!value) return null;
|
|
44
|
+
const d = new Date(value);
|
|
45
|
+
return isNaN(d.getTime()) ? null : d;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const weekdays = $derived.by(() => {
|
|
49
|
+
const days = [];
|
|
50
|
+
const temp = new Date(2023, 0, 1); // Sunday
|
|
51
|
+
for (let i = 0; i < 7; i++) {
|
|
52
|
+
days.push(new Intl.DateTimeFormat(locale, { weekday: weekdayFormat }).format(temp));
|
|
53
|
+
temp.setDate(temp.getDate() + 1);
|
|
54
|
+
}
|
|
55
|
+
return days;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const monthYearLabel = $derived.by(() => {
|
|
59
|
+
const monthStr = new Intl.DateTimeFormat(locale, { month: 'long' }).format(currentMonth);
|
|
60
|
+
const yearStr = new Intl.DateTimeFormat(locale, { year: 'numeric' }).format(currentMonth);
|
|
61
|
+
return { month: monthStr, year: yearStr, full: `${monthStr} ${yearStr}` };
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const calendarGrid = $derived.by(() => {
|
|
65
|
+
const year = currentMonth.getFullYear();
|
|
66
|
+
const month = currentMonth.getMonth();
|
|
67
|
+
const firstDayOfMonth = new Date(year, month, 1);
|
|
68
|
+
const lastDayOfMonth = new Date(year, month + 1, 0);
|
|
69
|
+
|
|
70
|
+
const startOffset = firstDayOfMonth.getDay();
|
|
71
|
+
const daysInMonth = lastDayOfMonth.getDate();
|
|
72
|
+
|
|
73
|
+
const weeks: Array<
|
|
74
|
+
Array<{
|
|
75
|
+
date: Date;
|
|
76
|
+
isCurrentMonth: boolean;
|
|
77
|
+
isToday: boolean;
|
|
78
|
+
isSelected: boolean;
|
|
79
|
+
isDisabled: boolean;
|
|
80
|
+
}>
|
|
81
|
+
> = [];
|
|
82
|
+
let currentWeek: Array<{
|
|
83
|
+
date: Date;
|
|
84
|
+
isCurrentMonth: boolean;
|
|
85
|
+
isToday: boolean;
|
|
86
|
+
isSelected: boolean;
|
|
87
|
+
isDisabled: boolean;
|
|
88
|
+
}> = [];
|
|
89
|
+
|
|
90
|
+
const today = new Date();
|
|
91
|
+
today.setHours(0, 0, 0, 0);
|
|
92
|
+
|
|
93
|
+
// Prev month trailing days
|
|
94
|
+
const prevMonthLastDay = new Date(year, month, 0).getDate();
|
|
95
|
+
for (let i = startOffset - 1; i >= 0; i--) {
|
|
96
|
+
const d = new Date(year, month - 1, prevMonthLastDay - i);
|
|
97
|
+
d.setHours(0, 0, 0, 0);
|
|
98
|
+
currentWeek.push({
|
|
99
|
+
date: d,
|
|
100
|
+
isCurrentMonth: false,
|
|
101
|
+
isToday: d.getTime() === today.getTime(),
|
|
102
|
+
isSelected: !!selectedDate && d.getTime() === selectedDate.setHours(0, 0, 0, 0),
|
|
103
|
+
isDisabled:
|
|
104
|
+
disableDaysOutsideMonth || (!!minDate && d < minDate) || (!!maxDate && d > maxDate),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Current month days
|
|
109
|
+
for (let dayNum = 1; dayNum <= daysInMonth; dayNum++) {
|
|
110
|
+
const d = new Date(year, month, dayNum);
|
|
111
|
+
d.setHours(0, 0, 0, 0);
|
|
112
|
+
const isSelected =
|
|
113
|
+
!!selectedDate &&
|
|
114
|
+
d.getFullYear() === selectedDate.getFullYear() &&
|
|
115
|
+
d.getMonth() === selectedDate.getMonth() &&
|
|
116
|
+
d.getDate() === selectedDate.getDate();
|
|
117
|
+
|
|
118
|
+
currentWeek.push({
|
|
119
|
+
date: d,
|
|
120
|
+
isCurrentMonth: true,
|
|
121
|
+
isToday: d.getTime() === today.getTime(),
|
|
122
|
+
isSelected,
|
|
123
|
+
isDisabled: (!!minDate && d < minDate) || (!!maxDate && d > maxDate),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (currentWeek.length === 7) {
|
|
127
|
+
weeks.push(currentWeek);
|
|
128
|
+
currentWeek = [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Next month leading days
|
|
133
|
+
if (currentWeek.length > 0) {
|
|
134
|
+
let nextMonthDay = 1;
|
|
135
|
+
while (currentWeek.length < 7) {
|
|
136
|
+
const d = new Date(year, month + 1, nextMonthDay);
|
|
137
|
+
d.setHours(0, 0, 0, 0);
|
|
138
|
+
currentWeek.push({
|
|
139
|
+
date: d,
|
|
140
|
+
isCurrentMonth: false,
|
|
141
|
+
isToday: d.getTime() === today.getTime(),
|
|
142
|
+
isSelected: !!selectedDate && d.getTime() === selectedDate.setHours(0, 0, 0, 0),
|
|
143
|
+
isDisabled:
|
|
144
|
+
disableDaysOutsideMonth || (!!minDate && d < minDate) || (!!maxDate && d > maxDate),
|
|
145
|
+
});
|
|
146
|
+
nextMonthDay++;
|
|
147
|
+
}
|
|
148
|
+
weeks.push(currentWeek);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return weeks;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
function prevMonth() {
|
|
155
|
+
currentMonth = new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function nextMonth() {
|
|
159
|
+
currentMonth = new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function handleSelect(date: Date, disabled: boolean) {
|
|
163
|
+
if (disabled) return;
|
|
164
|
+
value = date;
|
|
165
|
+
onchange?.(date);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const monthNames = [
|
|
169
|
+
'January',
|
|
170
|
+
'February',
|
|
171
|
+
'March',
|
|
172
|
+
'April',
|
|
173
|
+
'May',
|
|
174
|
+
'June',
|
|
175
|
+
'July',
|
|
176
|
+
'August',
|
|
177
|
+
'September',
|
|
178
|
+
'October',
|
|
179
|
+
'November',
|
|
180
|
+
'December',
|
|
181
|
+
];
|
|
182
|
+
const currentYearNum = $derived(currentMonth.getFullYear());
|
|
183
|
+
const yearList = $derived.by(() => {
|
|
184
|
+
const startYear = currentYearNum - 10;
|
|
185
|
+
return Array.from({ length: 21 }, (_, i) => startYear + i);
|
|
186
|
+
});
|
|
187
|
+
</script>
|
|
188
|
+
|
|
189
|
+
<div
|
|
190
|
+
data-slot="calendar"
|
|
191
|
+
class={cn(
|
|
192
|
+
'p-3 rounded-lg border border-border bg-background text-foreground shadow-sm inline-block select-none',
|
|
193
|
+
className,
|
|
194
|
+
)}
|
|
195
|
+
{...restProps}
|
|
196
|
+
>
|
|
197
|
+
<div class="flex flex-col gap-4">
|
|
198
|
+
<!-- Header -->
|
|
199
|
+
<div class="relative flex items-center justify-between pt-1">
|
|
200
|
+
<div class="flex items-center gap-1.5 text-sm font-semibold pl-1">
|
|
201
|
+
{#if captionLayout === 'dropdown' || captionLayout === 'dropdown-months'}
|
|
202
|
+
<div class="relative flex items-center">
|
|
203
|
+
<select
|
|
204
|
+
class="appearance-none bg-transparent hover:bg-accent hover:text-accent-foreground text-sm font-medium py-1 ps-2 pe-6 rounded-md border border-input cursor-pointer focus:outline-none focus:ring-1 focus:ring-ring"
|
|
205
|
+
value={currentMonth.getMonth()}
|
|
206
|
+
onchange={(e) => {
|
|
207
|
+
const m = parseInt(e.currentTarget.value, 10);
|
|
208
|
+
currentMonth = new Date(currentMonth.getFullYear(), m, 1);
|
|
209
|
+
}}
|
|
210
|
+
>
|
|
211
|
+
{#each monthNames as mName, idx}
|
|
212
|
+
<option value={idx}>{mName}</option>
|
|
213
|
+
{/each}
|
|
214
|
+
</select>
|
|
215
|
+
<ChevronDown
|
|
216
|
+
class="pointer-events-none absolute right-1.5 size-3.5 text-muted-foreground"
|
|
217
|
+
/>
|
|
218
|
+
</div>
|
|
219
|
+
{:else}
|
|
220
|
+
<span>{monthYearLabel.month}</span>
|
|
221
|
+
{/if}
|
|
222
|
+
|
|
223
|
+
{#if captionLayout === 'dropdown' || captionLayout === 'dropdown-years'}
|
|
224
|
+
<div class="relative flex items-center">
|
|
225
|
+
<select
|
|
226
|
+
class="appearance-none bg-transparent hover:bg-accent hover:text-accent-foreground text-sm font-medium py-1 ps-2 pe-6 rounded-md border border-input cursor-pointer focus:outline-none focus:ring-1 focus:ring-ring"
|
|
227
|
+
value={currentMonth.getFullYear()}
|
|
228
|
+
onchange={(e) => {
|
|
229
|
+
const y = parseInt(e.currentTarget.value, 10);
|
|
230
|
+
currentMonth = new Date(y, currentMonth.getMonth(), 1);
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
{#each yearList as y}
|
|
234
|
+
<option value={y}>{y}</option>
|
|
235
|
+
{/each}
|
|
236
|
+
</select>
|
|
237
|
+
<ChevronDown
|
|
238
|
+
class="pointer-events-none absolute right-1.5 size-3.5 text-muted-foreground"
|
|
239
|
+
/>
|
|
240
|
+
</div>
|
|
241
|
+
{:else}
|
|
242
|
+
<span>{monthYearLabel.year}</span>
|
|
243
|
+
{/if}
|
|
244
|
+
</div>
|
|
245
|
+
|
|
246
|
+
<!-- Navigation Buttons -->
|
|
247
|
+
<div class="flex items-center gap-1">
|
|
248
|
+
<button
|
|
249
|
+
type="button"
|
|
250
|
+
onclick={prevMonth}
|
|
251
|
+
aria-label="Previous Month"
|
|
252
|
+
class="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
253
|
+
>
|
|
254
|
+
<ChevronLeft class="size-4" />
|
|
255
|
+
</button>
|
|
256
|
+
<button
|
|
257
|
+
type="button"
|
|
258
|
+
onclick={nextMonth}
|
|
259
|
+
aria-label="Next Month"
|
|
260
|
+
class="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
261
|
+
>
|
|
262
|
+
<ChevronRight class="size-4" />
|
|
263
|
+
</button>
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
|
|
267
|
+
<!-- Table Grid -->
|
|
268
|
+
<div class="w-full">
|
|
269
|
+
<div class="grid grid-cols-7 mb-1">
|
|
270
|
+
{#each weekdays as day}
|
|
271
|
+
<div
|
|
272
|
+
class="size-8 flex items-center justify-center text-[0.8rem] font-medium text-muted-foreground"
|
|
273
|
+
>
|
|
274
|
+
{day.slice(0, 2)}
|
|
275
|
+
</div>
|
|
276
|
+
{/each}
|
|
277
|
+
</div>
|
|
278
|
+
|
|
279
|
+
<div class="grid grid-cols-7 gap-y-1">
|
|
280
|
+
{#each calendarGrid as week}
|
|
281
|
+
{#each week as cell}
|
|
282
|
+
<button
|
|
283
|
+
type="button"
|
|
284
|
+
disabled={cell.isDisabled}
|
|
285
|
+
onclick={() => handleSelect(cell.date, cell.isDisabled)}
|
|
286
|
+
class={cn(
|
|
287
|
+
'size-8 flex items-center justify-center rounded-md text-sm font-normal transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
|
288
|
+
!cell.isCurrentMonth && 'text-muted-foreground opacity-40',
|
|
289
|
+
cell.isToday &&
|
|
290
|
+
!cell.isSelected &&
|
|
291
|
+
'bg-accent text-accent-foreground font-semibold',
|
|
292
|
+
cell.isSelected &&
|
|
293
|
+
'bg-primary text-primary-foreground font-medium hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground',
|
|
294
|
+
!cell.isSelected &&
|
|
295
|
+
!cell.isDisabled &&
|
|
296
|
+
'hover:bg-accent hover:text-accent-foreground',
|
|
297
|
+
cell.isDisabled && 'pointer-events-none opacity-20',
|
|
298
|
+
)}
|
|
299
|
+
>
|
|
300
|
+
{cell.date.getDate()}
|
|
301
|
+
</button>
|
|
302
|
+
{/each}
|
|
303
|
+
{/each}
|
|
304
|
+
</div>
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
</div>
|
|
@@ -0,0 +1,258 @@
|
|
|
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 type ShadcnCarouselOrientation = 'horizontal' | 'vertical';
|
|
7
|
+
|
|
8
|
+
export interface ShadcnCarouselProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
opts?: Record<string, unknown>;
|
|
10
|
+
orientation?: CarouselOrientation;
|
|
11
|
+
children?: Snippet;
|
|
12
|
+
class?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ShadcnCarouselContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
16
|
+
children?: Snippet;
|
|
17
|
+
class?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ShadcnCarouselItemProps extends HTMLAttributes<HTMLDivElement> {
|
|
21
|
+
children?: Snippet;
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ShadcnCarouselButtonProps extends HTMLButtonAttributes {
|
|
26
|
+
class?: string;
|
|
27
|
+
variant?: 'default' | 'outline' | 'secondary' | 'ghost';
|
|
28
|
+
size?: 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm';
|
|
29
|
+
children?: Snippet;
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script lang="ts">
|
|
34
|
+
import { setContext, getContext } from 'svelte';
|
|
35
|
+
|
|
36
|
+
import { ChevronLeft, ChevronRight } from '@lucide/svelte';
|
|
37
|
+
|
|
38
|
+
let {
|
|
39
|
+
opts = {},
|
|
40
|
+
orientation = 'horizontal',
|
|
41
|
+
class: className = '',
|
|
42
|
+
children,
|
|
43
|
+
...restProps
|
|
44
|
+
}: ShadcnCarouselProps = $props();
|
|
45
|
+
|
|
46
|
+
let containerRef = $state<HTMLDivElement | null>(null);
|
|
47
|
+
let selectedIndex = $state(0);
|
|
48
|
+
let totalItems = $state(0);
|
|
49
|
+
let canScrollPrev = $state(false);
|
|
50
|
+
let canScrollNext = $state(false);
|
|
51
|
+
|
|
52
|
+
function updateScrollState() {
|
|
53
|
+
if (!containerRef) return;
|
|
54
|
+
const items = containerRef.querySelectorAll('[data-slot="carousel-item"]');
|
|
55
|
+
totalItems = items.length;
|
|
56
|
+
if (orientation === 'horizontal') {
|
|
57
|
+
const sl = containerRef.scrollLeft;
|
|
58
|
+
const maxScroll = containerRef.scrollWidth - containerRef.clientWidth;
|
|
59
|
+
canScrollPrev = sl > 2;
|
|
60
|
+
canScrollNext = sl < maxScroll - 2;
|
|
61
|
+
if (containerRef.clientWidth > 0) {
|
|
62
|
+
selectedIndex = Math.round(sl / containerRef.clientWidth);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
const st = containerRef.scrollTop;
|
|
66
|
+
const maxScroll = containerRef.scrollHeight - containerRef.clientHeight;
|
|
67
|
+
canScrollPrev = st > 2;
|
|
68
|
+
canScrollNext = st < maxScroll - 2;
|
|
69
|
+
if (containerRef.clientHeight > 0) {
|
|
70
|
+
selectedIndex = Math.round(st / containerRef.clientHeight);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function scrollPrev() {
|
|
76
|
+
if (!containerRef) return;
|
|
77
|
+
if (orientation === 'horizontal') {
|
|
78
|
+
containerRef.scrollBy({ left: -containerRef.clientWidth, behavior: 'smooth' });
|
|
79
|
+
} else {
|
|
80
|
+
containerRef.scrollBy({ top: -containerRef.clientHeight, behavior: 'smooth' });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function scrollNext() {
|
|
85
|
+
if (!containerRef) return;
|
|
86
|
+
if (orientation === 'horizontal') {
|
|
87
|
+
containerRef.scrollBy({ left: containerRef.clientWidth, behavior: 'smooth' });
|
|
88
|
+
} else {
|
|
89
|
+
containerRef.scrollBy({ top: containerRef.clientHeight, behavior: 'smooth' });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function scrollTo(index: number) {
|
|
94
|
+
if (!containerRef) return;
|
|
95
|
+
if (orientation === 'horizontal') {
|
|
96
|
+
containerRef.scrollTo({ left: index * containerRef.clientWidth, behavior: 'smooth' });
|
|
97
|
+
} else {
|
|
98
|
+
containerRef.scrollTo({ top: index * containerRef.clientHeight, behavior: 'smooth' });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
103
|
+
if (e.key === 'ArrowLeft' || (orientation === 'vertical' && e.key === 'ArrowUp')) {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
scrollPrev();
|
|
106
|
+
} else if (e.key === 'ArrowRight' || (orientation === 'vertical' && e.key === 'ArrowDown')) {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
scrollNext();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const carouselCtx = {
|
|
113
|
+
get orientation() {
|
|
114
|
+
return orientation;
|
|
115
|
+
},
|
|
116
|
+
get canScrollPrev() {
|
|
117
|
+
return canScrollPrev;
|
|
118
|
+
},
|
|
119
|
+
get canScrollNext() {
|
|
120
|
+
return canScrollNext;
|
|
121
|
+
},
|
|
122
|
+
get selectedIndex() {
|
|
123
|
+
return selectedIndex;
|
|
124
|
+
},
|
|
125
|
+
scrollPrev,
|
|
126
|
+
scrollNext,
|
|
127
|
+
scrollTo,
|
|
128
|
+
handleKeyDown,
|
|
129
|
+
setContainer: (el: HTMLDivElement | null) => {
|
|
130
|
+
containerRef = el;
|
|
131
|
+
if (el) {
|
|
132
|
+
setTimeout(updateScrollState, 50);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
updateScrollState,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
setContext('CAROUSEL_CONTEXT', carouselCtx);
|
|
139
|
+
</script>
|
|
140
|
+
|
|
141
|
+
{#snippet CarouselContent({
|
|
142
|
+
class: contentClass = '',
|
|
143
|
+
children: contentChildren,
|
|
144
|
+
...props
|
|
145
|
+
}: ShadcnCarouselContentProps = {})}
|
|
146
|
+
<div data-slot="carousel-content" class="overflow-hidden">
|
|
147
|
+
<div
|
|
148
|
+
data-embla-container=""
|
|
149
|
+
class={cn(
|
|
150
|
+
'flex transition-transform scroll-smooth select-none no-scrollbar',
|
|
151
|
+
orientation === 'horizontal'
|
|
152
|
+
? '-ms-4 overflow-x-auto snap-x snap-mandatory'
|
|
153
|
+
: '-mt-4 flex-col overflow-y-auto snap-y snap-mandatory',
|
|
154
|
+
contentClass,
|
|
155
|
+
)}
|
|
156
|
+
onscroll={updateScrollState}
|
|
157
|
+
{...props}
|
|
158
|
+
>
|
|
159
|
+
{@render contentChildren?.()}
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
{/snippet}
|
|
163
|
+
|
|
164
|
+
{#snippet CarouselItem({
|
|
165
|
+
class: itemClass = '',
|
|
166
|
+
children: itemChildren,
|
|
167
|
+
...props
|
|
168
|
+
}: ShadcnCarouselItemProps = {})}
|
|
169
|
+
<div
|
|
170
|
+
data-slot="carousel-item"
|
|
171
|
+
role="group"
|
|
172
|
+
aria-roledescription="slide"
|
|
173
|
+
class={cn(
|
|
174
|
+
'min-w-0 shrink-0 grow-0 basis-full snap-start',
|
|
175
|
+
orientation === 'horizontal' ? 'ps-4' : 'pt-4',
|
|
176
|
+
itemClass,
|
|
177
|
+
)}
|
|
178
|
+
data-embla-slide=""
|
|
179
|
+
{...props}
|
|
180
|
+
>
|
|
181
|
+
{@render itemChildren?.()}
|
|
182
|
+
</div>
|
|
183
|
+
{/snippet}
|
|
184
|
+
|
|
185
|
+
{#snippet CarouselPrevious({
|
|
186
|
+
class: btnClass = '',
|
|
187
|
+
variant = 'outline',
|
|
188
|
+
size = 'icon-sm',
|
|
189
|
+
children: btnChildren,
|
|
190
|
+
...props
|
|
191
|
+
}: ShadcnCarouselButtonProps = {})}
|
|
192
|
+
<button
|
|
193
|
+
type="button"
|
|
194
|
+
data-slot="carousel-previous"
|
|
195
|
+
aria-disabled={!canScrollPrev}
|
|
196
|
+
disabled={!canScrollPrev}
|
|
197
|
+
class={cn(
|
|
198
|
+
'inline-flex items-center justify-center rounded-full text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-xs hover:bg-accent hover:text-accent-foreground h-8 w-8 absolute touch-manipulation z-10',
|
|
199
|
+
orientation === 'horizontal'
|
|
200
|
+
? 'inset-y-0 -start-12 my-auto'
|
|
201
|
+
: 'start-1/2 -top-12 -translate-x-1/2 rotate-90',
|
|
202
|
+
btnClass,
|
|
203
|
+
)}
|
|
204
|
+
onclick={scrollPrev}
|
|
205
|
+
onkeydown={handleKeyDown}
|
|
206
|
+
{...props}
|
|
207
|
+
>
|
|
208
|
+
{#if btnChildren}
|
|
209
|
+
{@render btnChildren()}
|
|
210
|
+
{:else}
|
|
211
|
+
<ChevronLeft class="h-4 w-4" />
|
|
212
|
+
<span class="sr-only">Previous slide</span>
|
|
213
|
+
{/if}
|
|
214
|
+
</button>
|
|
215
|
+
{/snippet}
|
|
216
|
+
|
|
217
|
+
{#snippet CarouselNext({
|
|
218
|
+
class: btnClass = '',
|
|
219
|
+
variant = 'outline',
|
|
220
|
+
size = 'icon-sm',
|
|
221
|
+
children: btnChildren,
|
|
222
|
+
...props
|
|
223
|
+
}: ShadcnCarouselButtonProps = {})}
|
|
224
|
+
<button
|
|
225
|
+
type="button"
|
|
226
|
+
data-slot="carousel-next"
|
|
227
|
+
aria-disabled={!canScrollNext}
|
|
228
|
+
disabled={!canScrollNext}
|
|
229
|
+
class={cn(
|
|
230
|
+
'inline-flex items-center justify-center rounded-full text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-xs hover:bg-accent hover:text-accent-foreground h-8 w-8 absolute touch-manipulation z-10',
|
|
231
|
+
orientation === 'horizontal'
|
|
232
|
+
? 'inset-y-0 -end-12 my-auto'
|
|
233
|
+
: 'start-1/2 -bottom-12 -translate-x-1/2 rotate-90',
|
|
234
|
+
btnClass,
|
|
235
|
+
)}
|
|
236
|
+
onclick={scrollNext}
|
|
237
|
+
onkeydown={handleKeyDown}
|
|
238
|
+
{...props}
|
|
239
|
+
>
|
|
240
|
+
{#if btnChildren}
|
|
241
|
+
{@render btnChildren()}
|
|
242
|
+
{:else}
|
|
243
|
+
<ChevronRight class="h-4 w-4" />
|
|
244
|
+
<span class="sr-only">Next slide</span>
|
|
245
|
+
{/if}
|
|
246
|
+
</button>
|
|
247
|
+
{/snippet}
|
|
248
|
+
|
|
249
|
+
<div
|
|
250
|
+
data-slot="carousel"
|
|
251
|
+
class={cn('relative', className)}
|
|
252
|
+
role="region"
|
|
253
|
+
aria-roledescription="carousel"
|
|
254
|
+
onkeydown={handleKeyDown}
|
|
255
|
+
{...restProps}
|
|
256
|
+
>
|
|
257
|
+
{@render children?.()}
|
|
258
|
+
</div>
|