@surreal-ui/web 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/dist/index.js +12075 -0
- package/package.json +27 -0
- package/src/components/GlassmorphismAlert.ts +116 -0
- package/src/components/GlassmorphismButton.ts +19 -0
- package/src/components/GlassmorphismCard.ts +33 -0
- package/src/components/GlassmorphismEmptyState.ts +29 -0
- package/src/components/GlassmorphismInputGroup.ts +202 -0
- package/src/components/GlassmorphismMenubar.ts +36 -0
- package/src/components/GlassmorphismScrollArea.ts +83 -0
- package/src/components/GlassmorphismTable.ts +52 -0
- package/src/components/GlassmorphismTypography.ts +67 -0
- package/src/components/MinimalistAccordion.ts +248 -0
- package/src/components/MinimalistAlert.ts +99 -0
- package/src/components/MinimalistAlertDialog.ts +100 -0
- package/src/components/MinimalistAspectRatio.ts +34 -0
- package/src/components/MinimalistAvatar.ts +98 -0
- package/src/components/MinimalistBadge.ts +71 -0
- package/src/components/MinimalistBreadcrumb.ts +92 -0
- package/src/components/MinimalistButton.ts +111 -0
- package/src/components/MinimalistButtonGroup.ts +110 -0
- package/src/components/MinimalistCalendar.ts +282 -0
- package/src/components/MinimalistCard.ts +131 -0
- package/src/components/MinimalistCarousel.ts +122 -0
- package/src/components/MinimalistChart.ts +151 -0
- package/src/components/MinimalistCheckbox.ts +179 -0
- package/src/components/MinimalistCodeBlock.ts +113 -0
- package/src/components/MinimalistCollapsible.ts +155 -0
- package/src/components/MinimalistCommand.ts +112 -0
- package/src/components/MinimalistContextMenu.ts +99 -0
- package/src/components/MinimalistDialog.ts +104 -0
- package/src/components/MinimalistDrawer.ts +223 -0
- package/src/components/MinimalistDropdownMenu.ts +120 -0
- package/src/components/MinimalistEmpty.ts +98 -0
- package/src/components/MinimalistEmptyState.ts +38 -0
- package/src/components/MinimalistField.ts +171 -0
- package/src/components/MinimalistForm.ts +101 -0
- package/src/components/MinimalistHoverCard.ts +150 -0
- package/src/components/MinimalistInput.ts +105 -0
- package/src/components/MinimalistInputGroup.ts +93 -0
- package/src/components/MinimalistInputOtp.ts +155 -0
- package/src/components/MinimalistItem.ts +160 -0
- package/src/components/MinimalistKbd.ts +38 -0
- package/src/components/MinimalistLabel.ts +54 -0
- package/src/components/MinimalistMenubar.ts +82 -0
- package/src/components/MinimalistNativeSelect.ts +144 -0
- package/src/components/MinimalistNavigationMenu.ts +98 -0
- package/src/components/MinimalistPagination.ts +141 -0
- package/src/components/MinimalistPopover.ts +113 -0
- package/src/components/MinimalistProgress.ts +71 -0
- package/src/components/MinimalistRadioGroup.ts +226 -0
- package/src/components/MinimalistRangeCalendar.ts +267 -0
- package/src/components/MinimalistResizable.ts +44 -0
- package/src/components/MinimalistScrollArea.ts +11 -0
- package/src/components/MinimalistSelect.ts +104 -0
- package/src/components/MinimalistSeparator.ts +53 -0
- package/src/components/MinimalistSheet.ts +166 -0
- package/src/components/MinimalistSidebar.ts +75 -0
- package/src/components/MinimalistSkeleton.ts +33 -0
- package/src/components/MinimalistSlider.ts +237 -0
- package/src/components/MinimalistSonner.ts +94 -0
- package/src/components/MinimalistSpinner.ts +53 -0
- package/src/components/MinimalistSwitch.ts +166 -0
- package/src/components/MinimalistTable.ts +35 -0
- package/src/components/MinimalistTabs.ts +98 -0
- package/src/components/MinimalistTextarea.ts +100 -0
- package/src/components/MinimalistToggle.ts +105 -0
- package/src/components/MinimalistToggleGroup.ts +175 -0
- package/src/components/MinimalistTooltip.ts +83 -0
- package/src/components/MinimalistTypography.ts +107 -0
- package/src/components/NeubrutalismCard.ts +35 -0
- package/src/components/NeubrutalismItem.ts +67 -0
- package/src/components/ShadcnAccordion.ts +244 -0
- package/src/components/ShadcnAlertDialog.ts +96 -0
- package/src/components/ShadcnAspectRatio.ts +30 -0
- package/src/components/ShadcnAvatar.ts +94 -0
- package/src/components/ShadcnBadge.ts +67 -0
- package/src/components/ShadcnBreadcrumb.ts +88 -0
- package/src/components/ShadcnButton.ts +107 -0
- package/src/components/ShadcnButtonGroup.ts +106 -0
- package/src/components/ShadcnCalendar.ts +278 -0
- package/src/components/ShadcnCarousel.ts +118 -0
- package/src/components/ShadcnChart.ts +147 -0
- package/src/components/ShadcnCheckbox.ts +175 -0
- package/src/components/ShadcnCodeBlock.ts +109 -0
- package/src/components/ShadcnCollapsible.ts +151 -0
- package/src/components/ShadcnCommand.ts +108 -0
- package/src/components/ShadcnContextMenu.ts +95 -0
- package/src/components/ShadcnDialog.ts +100 -0
- package/src/components/ShadcnDrawer.ts +219 -0
- package/src/components/ShadcnDropdownMenu.ts +116 -0
- package/src/components/ShadcnEmpty.ts +94 -0
- package/src/components/ShadcnField.ts +167 -0
- package/src/components/ShadcnForm.ts +97 -0
- package/src/components/ShadcnHoverCard.ts +146 -0
- package/src/components/ShadcnInput.ts +101 -0
- package/src/components/ShadcnInputGroup.ts +89 -0
- package/src/components/ShadcnInputOtp.ts +151 -0
- package/src/components/ShadcnItem.ts +156 -0
- package/src/components/ShadcnKbd.ts +34 -0
- package/src/components/ShadcnLabel.ts +50 -0
- package/src/components/ShadcnMenubar.ts +78 -0
- package/src/components/ShadcnNativeSelect.ts +140 -0
- package/src/components/ShadcnNavigationMenu.ts +94 -0
- package/src/components/ShadcnPagination.ts +137 -0
- package/src/components/ShadcnPopover.ts +109 -0
- package/src/components/ShadcnProgress.ts +67 -0
- package/src/components/ShadcnRadioGroup.ts +222 -0
- package/src/components/ShadcnRangeCalendar.ts +263 -0
- package/src/components/ShadcnSelect.ts +100 -0
- package/src/components/ShadcnSeparator.ts +49 -0
- package/src/components/ShadcnSheet.ts +162 -0
- package/src/components/ShadcnSidebar.ts +71 -0
- package/src/components/ShadcnSkeleton.ts +29 -0
- package/src/components/ShadcnSlider.ts +233 -0
- package/src/components/ShadcnSonner.ts +90 -0
- package/src/components/ShadcnSpinner.ts +49 -0
- package/src/components/ShadcnSwitch.ts +162 -0
- package/src/components/ShadcnTabs.ts +94 -0
- package/src/components/ShadcnTextarea.ts +96 -0
- package/src/components/ShadcnToggle.ts +101 -0
- package/src/components/ShadcnToggleGroup.ts +171 -0
- package/src/components/ShadcnTooltip.ts +79 -0
- package/src/index.ts +124 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { cn } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
export class BreadcrumbRoot extends HTMLElement {
|
|
4
|
+
connectedCallback() {
|
|
5
|
+
this.setAttribute('data-slot', 'breadcrumb');
|
|
6
|
+
this.setAttribute('aria-label', 'breadcrumb');
|
|
7
|
+
this.className = cn('cn-breadcrumb block', this.className);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class BreadcrumbList extends HTMLElement {
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.setAttribute('data-slot', 'breadcrumb-list');
|
|
14
|
+
this.className = cn(
|
|
15
|
+
'gap-1.5 text-sm text-muted-foreground flex flex-wrap items-center wrap-break-word list-none p-0 m-0',
|
|
16
|
+
this.className,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class BreadcrumbItem extends HTMLElement {
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
this.setAttribute('data-slot', 'breadcrumb-item');
|
|
24
|
+
this.className = cn('gap-1 inline-flex items-center', this.className);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class BreadcrumbLink extends HTMLElement {
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
this.setAttribute('data-slot', 'breadcrumb-link');
|
|
31
|
+
const href = this.getAttribute('href') || '#';
|
|
32
|
+
const content = this.innerHTML;
|
|
33
|
+
this.innerHTML = `<a href="${href}" class="${cn('transition-colors hover:text-foreground text-inherit no-underline', this.getAttribute('link-class') || '')}">${content}</a>`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class BreadcrumbPage extends HTMLElement {
|
|
38
|
+
connectedCallback() {
|
|
39
|
+
this.setAttribute('data-slot', 'breadcrumb-page');
|
|
40
|
+
this.setAttribute('role', 'link');
|
|
41
|
+
this.setAttribute('aria-disabled', 'true');
|
|
42
|
+
this.setAttribute('aria-current', 'page');
|
|
43
|
+
this.className = cn('font-normal text-foreground', this.className);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class BreadcrumbSeparator extends HTMLElement {
|
|
48
|
+
connectedCallback() {
|
|
49
|
+
this.setAttribute('data-slot', 'breadcrumb-separator');
|
|
50
|
+
this.setAttribute('role', 'presentation');
|
|
51
|
+
this.setAttribute('aria-hidden', 'true');
|
|
52
|
+
this.className = cn(
|
|
53
|
+
'[&>svg]:size-3.5 inline-flex items-center text-muted-foreground',
|
|
54
|
+
this.className,
|
|
55
|
+
);
|
|
56
|
+
if (!this.innerHTML.trim()) {
|
|
57
|
+
this.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="size-3.5"><path d="m9 18 6-6-6-6"/></svg>`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class BreadcrumbEllipsis extends HTMLElement {
|
|
63
|
+
connectedCallback() {
|
|
64
|
+
this.setAttribute('data-slot', 'breadcrumb-ellipsis');
|
|
65
|
+
this.setAttribute('role', 'presentation');
|
|
66
|
+
this.setAttribute('aria-hidden', 'true');
|
|
67
|
+
this.className = cn('size-5 [&>svg]:size-4 flex items-center justify-center', this.className);
|
|
68
|
+
this.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="size-4"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></svg><span class="sr-only">More</span>`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!customElements.get('ui-breadcrumb'))
|
|
73
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-breadcrumb')) {
|
|
74
|
+
customElements.define('surreal-shadcn-breadcrumb', BreadcrumbRoot);
|
|
75
|
+
}
|
|
76
|
+
if (!customElements.get('ui-breadcrumb-list'))
|
|
77
|
+
customElements.define('surreal-shadcn-breadcrumb', BreadcrumbList);
|
|
78
|
+
if (!customElements.get('ui-breadcrumb-item'))
|
|
79
|
+
customElements.define('surreal-shadcn-breadcrumb', BreadcrumbItem);
|
|
80
|
+
if (!customElements.get('ui-breadcrumb-link'))
|
|
81
|
+
customElements.define('surreal-shadcn-breadcrumb', BreadcrumbLink);
|
|
82
|
+
if (!customElements.get('ui-breadcrumb-page'))
|
|
83
|
+
customElements.define('surreal-shadcn-breadcrumb', BreadcrumbPage);
|
|
84
|
+
if (!customElements.get('ui-breadcrumb-separator'))
|
|
85
|
+
customElements.define('surreal-shadcn-breadcrumb', BreadcrumbSeparator);
|
|
86
|
+
if (!customElements.get('ui-breadcrumb-ellipsis'))
|
|
87
|
+
customElements.define('surreal-shadcn-breadcrumb', BreadcrumbEllipsis);
|
|
88
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-breadcrumb')) {
|
|
89
|
+
customElements.define('surreal-minimalist-breadcrumb', BreadcrumbRoot);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default BreadcrumbRoot;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { cn, cva } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
const buttonVariants = cva(
|
|
4
|
+
"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",
|
|
5
|
+
{
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
default: 'bg-primary text-primary-foreground [a]:hover:bg-primary/80',
|
|
9
|
+
outline:
|
|
10
|
+
'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',
|
|
11
|
+
secondary:
|
|
12
|
+
'bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground',
|
|
13
|
+
ghost:
|
|
14
|
+
'hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50',
|
|
15
|
+
destructive:
|
|
16
|
+
'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',
|
|
17
|
+
link: 'text-primary underline-offset-4 hover:underline',
|
|
18
|
+
},
|
|
19
|
+
size: {
|
|
20
|
+
default:
|
|
21
|
+
'h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
|
22
|
+
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",
|
|
23
|
+
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",
|
|
24
|
+
lg: 'h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
|
25
|
+
icon: 'size-8',
|
|
26
|
+
'icon-xs':
|
|
27
|
+
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
|
28
|
+
'icon-sm':
|
|
29
|
+
'size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg',
|
|
30
|
+
'icon-lg': 'size-9',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultVariants: {
|
|
34
|
+
variant: 'default',
|
|
35
|
+
size: 'default',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export class SurrealShadcnButton extends HTMLElement {
|
|
41
|
+
static get observedAttributes() {
|
|
42
|
+
return ['variant', 'size', 'href', 'disabled', 'type', 'class'];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private element: HTMLButtonElement | HTMLAnchorElement | null = null;
|
|
46
|
+
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
this.render();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
attributeChangedCallback() {
|
|
52
|
+
this.render();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private render() {
|
|
56
|
+
const variant = (this.getAttribute('variant') || 'default') as any;
|
|
57
|
+
const size = (this.getAttribute('size') || 'default') as any;
|
|
58
|
+
const href = this.getAttribute('href');
|
|
59
|
+
const disabled = this.hasAttribute('disabled');
|
|
60
|
+
const type = this.getAttribute('type') || 'button';
|
|
61
|
+
const customClass = this.getAttribute('class') || '';
|
|
62
|
+
const classes = cn(buttonVariants({ variant, size }), customClass);
|
|
63
|
+
|
|
64
|
+
const isAnchor = Boolean(href);
|
|
65
|
+
const tagName = isAnchor ? 'a' : 'button';
|
|
66
|
+
|
|
67
|
+
if (!this.element || this.element.tagName.toLowerCase() !== tagName) {
|
|
68
|
+
this.innerHTML = '';
|
|
69
|
+
this.element = document.createElement(tagName);
|
|
70
|
+
this.element.setAttribute('data-slot', 'button');
|
|
71
|
+
|
|
72
|
+
while (this.childNodes.length > 0) {
|
|
73
|
+
this.element.appendChild(this.childNodes[0]);
|
|
74
|
+
}
|
|
75
|
+
this.appendChild(this.element);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.element.className = classes;
|
|
79
|
+
|
|
80
|
+
if (isAnchor) {
|
|
81
|
+
const anchor = this.element as HTMLAnchorElement;
|
|
82
|
+
if (disabled) {
|
|
83
|
+
anchor.removeAttribute('href');
|
|
84
|
+
anchor.setAttribute('aria-disabled', 'true');
|
|
85
|
+
anchor.setAttribute('role', 'link');
|
|
86
|
+
anchor.setAttribute('tabindex', '-1');
|
|
87
|
+
} else {
|
|
88
|
+
anchor.setAttribute('href', href!);
|
|
89
|
+
anchor.removeAttribute('aria-disabled');
|
|
90
|
+
anchor.removeAttribute('role');
|
|
91
|
+
anchor.removeAttribute('tabindex');
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
const btn = this.element as HTMLButtonElement;
|
|
95
|
+
btn.type = type;
|
|
96
|
+
btn.disabled = disabled;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!customElements.get('surreal-button')) {
|
|
102
|
+
|
|
103
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-button')) {
|
|
104
|
+
customElements.define('surreal-shadcn-button', SurrealShadcnButton);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-button')) {
|
|
108
|
+
customElements.define('surreal-minimalist-button', SurrealShadcnButton);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default SurrealShadcnButton;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { cn, cva } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
const buttonGroupVariants = cva(
|
|
4
|
+
"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",
|
|
5
|
+
{
|
|
6
|
+
variants: {
|
|
7
|
+
orientation: {
|
|
8
|
+
horizontal:
|
|
9
|
+
'[&>[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',
|
|
10
|
+
vertical:
|
|
11
|
+
'[&>[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',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
defaultVariants: {
|
|
15
|
+
orientation: 'horizontal',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export class ButtonGroupElement extends HTMLElement {
|
|
21
|
+
static get observedAttributes() {
|
|
22
|
+
return ['orientation', 'class'];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
connectedCallback() {
|
|
26
|
+
this.setAttribute('role', 'group');
|
|
27
|
+
this.setAttribute('data-slot', 'button-group');
|
|
28
|
+
this.render();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
attributeChangedCallback() {
|
|
32
|
+
this.render();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
render() {
|
|
36
|
+
const orientation =
|
|
37
|
+
(this.getAttribute('orientation') as 'horizontal' | 'vertical') || 'horizontal';
|
|
38
|
+
this.setAttribute('data-orientation', orientation);
|
|
39
|
+
const customClass = this.getAttribute('class') || '';
|
|
40
|
+
this.className = cn(buttonGroupVariants({ orientation }), customClass);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class ButtonGroupSeparatorElement extends HTMLElement {
|
|
45
|
+
static get observedAttributes() {
|
|
46
|
+
return ['orientation', 'class'];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
connectedCallback() {
|
|
50
|
+
this.setAttribute('role', 'separator');
|
|
51
|
+
this.setAttribute('data-slot', 'button-group-separator');
|
|
52
|
+
this.render();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
attributeChangedCallback() {
|
|
56
|
+
this.render();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
render() {
|
|
60
|
+
const orientation = this.getAttribute('orientation') || 'vertical';
|
|
61
|
+
this.setAttribute('data-orientation', orientation);
|
|
62
|
+
this.setAttribute('aria-orientation', orientation);
|
|
63
|
+
const customClass = this.getAttribute('class') || '';
|
|
64
|
+
this.className = cn(
|
|
65
|
+
'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',
|
|
66
|
+
customClass,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class ButtonGroupTextElement extends HTMLElement {
|
|
72
|
+
static get observedAttributes() {
|
|
73
|
+
return ['class'];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
connectedCallback() {
|
|
77
|
+
this.setAttribute('data-slot', 'button-group-text');
|
|
78
|
+
this.render();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
attributeChangedCallback() {
|
|
82
|
+
this.render();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
render() {
|
|
86
|
+
const customClass = this.getAttribute('class') || '';
|
|
87
|
+
this.className = cn(
|
|
88
|
+
"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",
|
|
89
|
+
customClass,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!customElements.get('surreal-button-group')) {
|
|
95
|
+
|
|
96
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-button-group')) {
|
|
97
|
+
customElements.define('surreal-shadcn-button-group', ButtonGroupElement);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!customElements.get('surreal-button-group-separator')) {
|
|
101
|
+
customElements.define('surreal-shadcn-button-group', ButtonGroupSeparatorElement);
|
|
102
|
+
}
|
|
103
|
+
if (!customElements.get('surreal-button-group-text')) {
|
|
104
|
+
customElements.define('surreal-shadcn-button-group', ButtonGroupTextElement);
|
|
105
|
+
}
|
|
106
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-button-group')) {
|
|
107
|
+
customElements.define('surreal-minimalist-button-group', ButtonGroupElement);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default ButtonGroupElement;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
export class SurrealShadcnCalendar extends HTMLElement {
|
|
2
|
+
private _value: Date | null = null;
|
|
3
|
+
private _currentMonth: Date = new Date();
|
|
4
|
+
private _captionLayout: string = 'label';
|
|
5
|
+
private _locale: string = 'en-US';
|
|
6
|
+
|
|
7
|
+
static get observedAttributes() {
|
|
8
|
+
return ['value', 'caption-layout', 'locale'];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
connectedCallback() {
|
|
16
|
+
if (this.hasAttribute('value')) {
|
|
17
|
+
this._value = new Date(this.getAttribute('value') || '');
|
|
18
|
+
}
|
|
19
|
+
if (this.hasAttribute('caption-layout')) {
|
|
20
|
+
this._captionLayout = this.getAttribute('caption-layout') || 'label';
|
|
21
|
+
}
|
|
22
|
+
if (this.hasAttribute('locale')) {
|
|
23
|
+
this._locale = this.getAttribute('locale') || 'en-US';
|
|
24
|
+
}
|
|
25
|
+
if (this._value && !isNaN(this._value.getTime())) {
|
|
26
|
+
this._currentMonth = new Date(this._value.getFullYear(), this._value.getMonth(), 1);
|
|
27
|
+
} else {
|
|
28
|
+
this._currentMonth = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
|
|
29
|
+
}
|
|
30
|
+
this.render();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
34
|
+
if (oldValue === newValue) return;
|
|
35
|
+
if (name === 'value') {
|
|
36
|
+
this._value = newValue ? new Date(newValue) : null;
|
|
37
|
+
} else if (name === 'caption-layout') {
|
|
38
|
+
this._captionLayout = newValue || 'label';
|
|
39
|
+
} else if (name === 'locale') {
|
|
40
|
+
this._locale = newValue || 'en-US';
|
|
41
|
+
}
|
|
42
|
+
this.render();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get value(): Date | null {
|
|
46
|
+
return this._value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
set value(val: Date | string | null) {
|
|
50
|
+
this._value = val ? new Date(val) : null;
|
|
51
|
+
this.render();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private _prevMonth = () => {
|
|
55
|
+
this._currentMonth = new Date(
|
|
56
|
+
this._currentMonth.getFullYear(),
|
|
57
|
+
this._currentMonth.getMonth() - 1,
|
|
58
|
+
1,
|
|
59
|
+
);
|
|
60
|
+
this.render();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
private _nextMonth = () => {
|
|
64
|
+
this._currentMonth = new Date(
|
|
65
|
+
this._currentMonth.getFullYear(),
|
|
66
|
+
this._currentMonth.getMonth() + 1,
|
|
67
|
+
1,
|
|
68
|
+
);
|
|
69
|
+
this.render();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
private _selectDate(date: Date) {
|
|
73
|
+
this._value = date;
|
|
74
|
+
this.setAttribute('value', date.toISOString());
|
|
75
|
+
this.dispatchEvent(
|
|
76
|
+
new CustomEvent('change', { detail: { value: date }, bubbles: true, composed: true }),
|
|
77
|
+
);
|
|
78
|
+
this.render();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
render() {
|
|
82
|
+
const year = this._currentMonth.getFullYear();
|
|
83
|
+
const month = this._currentMonth.getMonth();
|
|
84
|
+
const monthNames = [
|
|
85
|
+
'January',
|
|
86
|
+
'February',
|
|
87
|
+
'March',
|
|
88
|
+
'April',
|
|
89
|
+
'May',
|
|
90
|
+
'June',
|
|
91
|
+
'July',
|
|
92
|
+
'August',
|
|
93
|
+
'September',
|
|
94
|
+
'October',
|
|
95
|
+
'November',
|
|
96
|
+
'December',
|
|
97
|
+
];
|
|
98
|
+
const monthStr = new Intl.DateTimeFormat(this._locale, { month: 'long' }).format(
|
|
99
|
+
this._currentMonth,
|
|
100
|
+
);
|
|
101
|
+
const yearStr = new Intl.DateTimeFormat(this._locale, { year: 'numeric' }).format(
|
|
102
|
+
this._currentMonth,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const weekdays = [];
|
|
106
|
+
const temp = new Date(2023, 0, 1);
|
|
107
|
+
for (let i = 0; i < 7; i++) {
|
|
108
|
+
weekdays.push(
|
|
109
|
+
new Intl.DateTimeFormat(this._locale, { weekday: 'short' }).format(temp).slice(0, 2),
|
|
110
|
+
);
|
|
111
|
+
temp.setDate(temp.getDate() + 1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const firstDay = new Date(year, month, 1);
|
|
115
|
+
const lastDay = new Date(year, month + 1, 0);
|
|
116
|
+
const startOffset = firstDay.getDay();
|
|
117
|
+
const daysInMonth = lastDay.getDate();
|
|
118
|
+
const prevMonthLastDay = new Date(year, month, 0).getDate();
|
|
119
|
+
|
|
120
|
+
const today = new Date();
|
|
121
|
+
today.setHours(0, 0, 0, 0);
|
|
122
|
+
|
|
123
|
+
const cells: Array<{
|
|
124
|
+
date: Date;
|
|
125
|
+
isCurrentMonth: boolean;
|
|
126
|
+
isToday: boolean;
|
|
127
|
+
isSelected: boolean;
|
|
128
|
+
}> = [];
|
|
129
|
+
|
|
130
|
+
for (let i = startOffset - 1; i >= 0; i--) {
|
|
131
|
+
const d = new Date(year, month - 1, prevMonthLastDay - i);
|
|
132
|
+
d.setHours(0, 0, 0, 0);
|
|
133
|
+
cells.push({
|
|
134
|
+
date: d,
|
|
135
|
+
isCurrentMonth: false,
|
|
136
|
+
isToday: d.getTime() === today.getTime(),
|
|
137
|
+
isSelected:
|
|
138
|
+
!!this._value &&
|
|
139
|
+
d.getFullYear() === this._value.getFullYear() &&
|
|
140
|
+
d.getMonth() === this._value.getMonth() &&
|
|
141
|
+
d.getDate() === this._value.getDate(),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
for (let dNum = 1; dNum <= daysInMonth; dNum++) {
|
|
146
|
+
const d = new Date(year, month, dNum);
|
|
147
|
+
d.setHours(0, 0, 0, 0);
|
|
148
|
+
cells.push({
|
|
149
|
+
date: d,
|
|
150
|
+
isCurrentMonth: true,
|
|
151
|
+
isToday: d.getTime() === today.getTime(),
|
|
152
|
+
isSelected:
|
|
153
|
+
!!this._value &&
|
|
154
|
+
d.getFullYear() === this._value.getFullYear() &&
|
|
155
|
+
d.getMonth() === this._value.getMonth() &&
|
|
156
|
+
d.getDate() === this._value.getDate(),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let nextD = 1;
|
|
161
|
+
while (cells.length % 7 !== 0) {
|
|
162
|
+
const d = new Date(year, month + 1, nextD);
|
|
163
|
+
d.setHours(0, 0, 0, 0);
|
|
164
|
+
cells.push({
|
|
165
|
+
date: d,
|
|
166
|
+
isCurrentMonth: false,
|
|
167
|
+
isToday: d.getTime() === today.getTime(),
|
|
168
|
+
isSelected:
|
|
169
|
+
!!this._value &&
|
|
170
|
+
d.getFullYear() === this._value.getFullYear() &&
|
|
171
|
+
d.getMonth() === this._value.getMonth() &&
|
|
172
|
+
d.getDate() === this._value.getDate(),
|
|
173
|
+
});
|
|
174
|
+
nextD++;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.innerHTML = `
|
|
178
|
+
<div data-slot="calendar" class="p-3 rounded-lg border border-border bg-background text-foreground shadow-sm inline-block select-none">
|
|
179
|
+
<div class="flex flex-col gap-4">
|
|
180
|
+
<div class="relative flex items-center justify-between pt-1">
|
|
181
|
+
<div class="flex items-center gap-1.5 text-sm font-semibold pl-1">
|
|
182
|
+
${
|
|
183
|
+
this._captionLayout === 'dropdown' || this._captionLayout === 'dropdown-months'
|
|
184
|
+
? `<div class="relative flex items-center">
|
|
185
|
+
<select data-role="month-select" 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">
|
|
186
|
+
${monthNames.map((m, idx) => `<option value="${idx}" ${idx === month ? 'selected' : ''}>${m}</option>`).join('')}
|
|
187
|
+
</select>
|
|
188
|
+
</div>`
|
|
189
|
+
: `<span>${monthStr}</span>`
|
|
190
|
+
}
|
|
191
|
+
${
|
|
192
|
+
this._captionLayout === 'dropdown' || this._captionLayout === 'dropdown-years'
|
|
193
|
+
? `<div class="relative flex items-center">
|
|
194
|
+
<select data-role="year-select" 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">
|
|
195
|
+
${Array.from({ length: 21 }, (_, i) => year - 10 + i)
|
|
196
|
+
.map(
|
|
197
|
+
(y) =>
|
|
198
|
+
`<option value="${y}" ${y === year ? 'selected' : ''}>${y}</option>`,
|
|
199
|
+
)
|
|
200
|
+
.join('')}
|
|
201
|
+
</select>
|
|
202
|
+
</div>`
|
|
203
|
+
: `<span>${yearStr}</span>`
|
|
204
|
+
}
|
|
205
|
+
</div>
|
|
206
|
+
<div class="flex items-center gap-1">
|
|
207
|
+
<button type="button" data-role="prev-btn" aria-label="Previous Month" 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">
|
|
208
|
+
<svg class="size-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" /></svg>
|
|
209
|
+
</button>
|
|
210
|
+
<button type="button" data-role="next-btn" aria-label="Next Month" 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">
|
|
211
|
+
<svg class="size-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" /></svg>
|
|
212
|
+
</button>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
<div class="w-full">
|
|
216
|
+
<div class="grid grid-cols-7 mb-1">
|
|
217
|
+
${weekdays.map((d) => `<div class="size-8 flex items-center justify-center text-[0.8rem] font-medium text-muted-foreground">${d}</div>`).join('')}
|
|
218
|
+
</div>
|
|
219
|
+
<div class="grid grid-cols-7 gap-y-1">
|
|
220
|
+
${cells
|
|
221
|
+
.map((cell, idx) => {
|
|
222
|
+
let classes =
|
|
223
|
+
'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';
|
|
224
|
+
if (!cell.isCurrentMonth) classes += ' text-muted-foreground opacity-40';
|
|
225
|
+
if (cell.isToday && !cell.isSelected)
|
|
226
|
+
classes += ' bg-accent text-accent-foreground font-semibold';
|
|
227
|
+
if (cell.isSelected)
|
|
228
|
+
classes +=
|
|
229
|
+
' bg-primary text-primary-foreground font-medium hover:bg-primary hover:text-primary-foreground';
|
|
230
|
+
if (!cell.isSelected) classes += ' hover:bg-accent hover:text-accent-foreground';
|
|
231
|
+
return `<button type="button" data-date-index="${idx}" class="${classes}">${cell.date.getDate()}</button>`;
|
|
232
|
+
})
|
|
233
|
+
.join('')}
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
`;
|
|
239
|
+
|
|
240
|
+
this.querySelector('[data-role="prev-btn"]')?.addEventListener('click', this._prevMonth);
|
|
241
|
+
this.querySelector('[data-role="next-btn"]')?.addEventListener('click', this._nextMonth);
|
|
242
|
+
|
|
243
|
+
const monthSelect = this.querySelector('[data-role="month-select"]') as HTMLSelectElement;
|
|
244
|
+
if (monthSelect) {
|
|
245
|
+
monthSelect.addEventListener('change', (e) => {
|
|
246
|
+
const m = parseInt((e.target as HTMLSelectElement).value, 10);
|
|
247
|
+
this._currentMonth = new Date(this._currentMonth.getFullYear(), m, 1);
|
|
248
|
+
this.render();
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const yearSelect = this.querySelector('[data-role="year-select"]') as HTMLSelectElement;
|
|
253
|
+
if (yearSelect) {
|
|
254
|
+
yearSelect.addEventListener('change', (e) => {
|
|
255
|
+
const y = parseInt((e.target as HTMLSelectElement).value, 10);
|
|
256
|
+
this._currentMonth = new Date(y, this._currentMonth.getMonth(), 1);
|
|
257
|
+
this.render();
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this.querySelectorAll('[data-date-index]').forEach((btn) => {
|
|
262
|
+
btn.addEventListener('click', () => {
|
|
263
|
+
const idx = parseInt(btn.getAttribute('data-date-index') || '0', 10);
|
|
264
|
+
if (cells[idx]) {
|
|
265
|
+
this._selectDate(cells[idx].date);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (!customElements.get('surreal-calendar')) {
|
|
273
|
+
|
|
274
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-calendar')) {
|
|
275
|
+
customElements.define('surreal-shadcn-calendar', SurrealShadcnCalendar);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-calendar')) {
|
|
279
|
+
customElements.define('surreal-minimalist-calendar', SurrealShadcnCalendar);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export default SurrealShadcnCalendar;
|