@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,141 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
import { ChevronRight, MoreHorizontal } from '@lucide/svelte';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
|
+
import type {
|
|
7
|
+
HTMLAttributes,
|
|
8
|
+
HTMLAnchorAttributes,
|
|
9
|
+
HTMLLiAttributes,
|
|
10
|
+
HTMLOlAttributes,
|
|
11
|
+
} from 'svelte/elements';
|
|
12
|
+
|
|
13
|
+
interface ShadcnBreadcrumbProps extends HTMLAttributes<HTMLElement> {
|
|
14
|
+
ref?: HTMLElement | null;
|
|
15
|
+
class?: string;
|
|
16
|
+
children?: Snippet;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ShadcnBreadcrumbListProps extends HTMLOlAttributes {
|
|
20
|
+
class?: string;
|
|
21
|
+
children?: Snippet;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ShadcnBreadcrumbItemProps extends HTMLLiAttributes {
|
|
25
|
+
class?: string;
|
|
26
|
+
children?: Snippet;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ShadcnBreadcrumbLinkProps extends HTMLAnchorAttributes {
|
|
30
|
+
class?: string;
|
|
31
|
+
href?: string;
|
|
32
|
+
children?: Snippet;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface BreadcrumbPageProps extends HTMLAttributes<HTMLSpanElement> {
|
|
36
|
+
class?: string;
|
|
37
|
+
children?: Snippet;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface ShadcnBreadcrumbSeparatorProps extends HTMLLiAttributes {
|
|
41
|
+
class?: string;
|
|
42
|
+
children?: Snippet;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface BreadcrumbEllipsisProps extends HTMLAttributes<HTMLSpanElement> {
|
|
46
|
+
class?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let {
|
|
50
|
+
ref = $bindable(null),
|
|
51
|
+
class: className = '',
|
|
52
|
+
children,
|
|
53
|
+
...restProps
|
|
54
|
+
}: ShadcnBreadcrumbProps = $props();
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
{#snippet List({ class: className = '', children, ...props }: ShadcnBreadcrumbListProps = {})}
|
|
58
|
+
<ol
|
|
59
|
+
data-slot="breadcrumb-list"
|
|
60
|
+
class={cn(
|
|
61
|
+
'gap-1.5 text-sm text-muted-foreground flex flex-wrap items-center wrap-break-word',
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
{...props}
|
|
65
|
+
>
|
|
66
|
+
{@render children?.()}
|
|
67
|
+
</ol>
|
|
68
|
+
{/snippet}
|
|
69
|
+
|
|
70
|
+
{#snippet Item({ class: className = '', children, ...props }: ShadcnBreadcrumbItemProps = {})}
|
|
71
|
+
<li
|
|
72
|
+
data-slot="breadcrumb-item"
|
|
73
|
+
class={cn('gap-1 inline-flex items-center', className)}
|
|
74
|
+
{...props}
|
|
75
|
+
>
|
|
76
|
+
{@render children?.()}
|
|
77
|
+
</li>
|
|
78
|
+
{/snippet}
|
|
79
|
+
|
|
80
|
+
{#snippet Link({ class: className = '', href, children, ...props }: ShadcnBreadcrumbLinkProps = {})}
|
|
81
|
+
<a
|
|
82
|
+
data-slot="breadcrumb-link"
|
|
83
|
+
{href}
|
|
84
|
+
class={cn('transition-colors hover:text-foreground', className)}
|
|
85
|
+
{...props}
|
|
86
|
+
>
|
|
87
|
+
{@render children?.()}
|
|
88
|
+
</a>
|
|
89
|
+
{/snippet}
|
|
90
|
+
|
|
91
|
+
{#snippet Page({ class: className = '', children, ...props }: BreadcrumbPageProps = {})}
|
|
92
|
+
<span
|
|
93
|
+
data-slot="breadcrumb-page"
|
|
94
|
+
role="link"
|
|
95
|
+
aria-disabled="true"
|
|
96
|
+
aria-current="page"
|
|
97
|
+
class={cn('font-normal text-foreground', className)}
|
|
98
|
+
{...props}
|
|
99
|
+
>
|
|
100
|
+
{@render children?.()}
|
|
101
|
+
</span>
|
|
102
|
+
{/snippet}
|
|
103
|
+
|
|
104
|
+
{#snippet Separator({ class: className = '', children, ...props }: ShadcnBreadcrumbSeparatorProps = {})}
|
|
105
|
+
<li
|
|
106
|
+
data-slot="breadcrumb-separator"
|
|
107
|
+
role="presentation"
|
|
108
|
+
aria-hidden="true"
|
|
109
|
+
class={cn('[&>svg]:size-3.5', className)}
|
|
110
|
+
{...props}
|
|
111
|
+
>
|
|
112
|
+
{#if children}
|
|
113
|
+
{@render children?.()}
|
|
114
|
+
{:else}
|
|
115
|
+
<ChevronRight />
|
|
116
|
+
{/if}
|
|
117
|
+
</li>
|
|
118
|
+
{/snippet}
|
|
119
|
+
|
|
120
|
+
{#snippet Ellipsis({ class: className = '', ...props }: BreadcrumbEllipsisProps = {})}
|
|
121
|
+
<span
|
|
122
|
+
data-slot="breadcrumb-ellipsis"
|
|
123
|
+
role="presentation"
|
|
124
|
+
aria-hidden="true"
|
|
125
|
+
class={cn('size-5 [&>svg]:size-4 flex items-center justify-center', className)}
|
|
126
|
+
{...props}
|
|
127
|
+
>
|
|
128
|
+
<MoreHorizontal />
|
|
129
|
+
<span class="sr-only">More</span>
|
|
130
|
+
</span>
|
|
131
|
+
{/snippet}
|
|
132
|
+
|
|
133
|
+
<nav
|
|
134
|
+
bind:this={ref}
|
|
135
|
+
data-slot="breadcrumb"
|
|
136
|
+
aria-label="breadcrumb"
|
|
137
|
+
class={cn('cn-breadcrumb', className)}
|
|
138
|
+
{...restProps}
|
|
139
|
+
>
|
|
140
|
+
{@render children?.()}
|
|
141
|
+
</nav>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cn, cva, type VariantProps } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
|
+
|
|
7
|
+
export const shadcnButtonVariants = cva(
|
|
8
|
+
"rounded-lg border border-transparent bg-clip-padding text-sm font-medium focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 group/button inline-flex shrink-0 items-center justify-center whitespace-nowrap transition-all outline-none select-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: 'bg-primary text-primary-foreground [a]:hover:bg-primary/80',
|
|
13
|
+
outline:
|
|
14
|
+
'border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50',
|
|
15
|
+
secondary:
|
|
16
|
+
'bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground',
|
|
17
|
+
ghost:
|
|
18
|
+
'hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50',
|
|
19
|
+
destructive:
|
|
20
|
+
'bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40',
|
|
21
|
+
link: 'text-primary underline-offset-4 hover:underline',
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default:
|
|
25
|
+
'h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
|
26
|
+
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
27
|
+
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
28
|
+
lg: 'h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
|
29
|
+
icon: 'size-8',
|
|
30
|
+
'icon-xs':
|
|
31
|
+
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
|
32
|
+
'icon-sm':
|
|
33
|
+
'size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg',
|
|
34
|
+
'icon-lg': 'size-9',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
defaultVariants: {
|
|
38
|
+
variant: 'default',
|
|
39
|
+
size: 'default',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export type ShadcnButtonVariant = VariantProps<typeof shadcnButtonVariants>['variant'];
|
|
45
|
+
export type ShadcnButtonSize = VariantProps<typeof shadcnButtonVariants>['size'];
|
|
46
|
+
|
|
47
|
+
export interface ShadcnButtonProps extends HTMLButtonAttributes, HTMLAnchorAttributes {
|
|
48
|
+
variant?: ShadcnButtonVariant;
|
|
49
|
+
size?: ButtonSize;
|
|
50
|
+
ref?: HTMLElement | null;
|
|
51
|
+
href?: string;
|
|
52
|
+
children?: Snippet;
|
|
53
|
+
}
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<script lang="ts">
|
|
57
|
+
let {
|
|
58
|
+
class: className,
|
|
59
|
+
variant = 'default',
|
|
60
|
+
size = 'default',
|
|
61
|
+
ref = $bindable(null),
|
|
62
|
+
href = undefined,
|
|
63
|
+
type = 'button',
|
|
64
|
+
disabled = false,
|
|
65
|
+
children,
|
|
66
|
+
...restProps
|
|
67
|
+
}: ShadcnButtonProps = $props();
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
{#if href}
|
|
71
|
+
<a
|
|
72
|
+
bind:this={ref}
|
|
73
|
+
data-slot="button"
|
|
74
|
+
class={cn(shadcnButtonVariants({ variant, size }), className)}
|
|
75
|
+
href={disabled ? undefined : href}
|
|
76
|
+
aria-disabled={disabled}
|
|
77
|
+
role={disabled ? 'link' : undefined}
|
|
78
|
+
tabindex={disabled ? -1 : undefined}
|
|
79
|
+
{...restProps}
|
|
80
|
+
>
|
|
81
|
+
{@render children?.()}
|
|
82
|
+
</a>
|
|
83
|
+
{:else}
|
|
84
|
+
<button
|
|
85
|
+
bind:this={ref}
|
|
86
|
+
data-slot="button"
|
|
87
|
+
class={cn(shadcnButtonVariants({ variant, size }), className)}
|
|
88
|
+
{type}
|
|
89
|
+
{disabled}
|
|
90
|
+
{...restProps}
|
|
91
|
+
>
|
|
92
|
+
{@render children?.()}
|
|
93
|
+
</button>
|
|
94
|
+
{/if}
|
|
@@ -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>
|