@surreal-ui/web 0.8.1 → 0.9.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.
Files changed (127) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +832 -6249
  3. package/dist/utils.d.ts +9 -0
  4. package/dist/utils.js +14 -0
  5. package/package.json +14 -3
  6. package/CHANGELOG.md +0 -149
  7. package/src/components/GlassmorphismAlert.ts +0 -115
  8. package/src/components/GlassmorphismButton.ts +0 -18
  9. package/src/components/GlassmorphismCard.ts +0 -36
  10. package/src/components/GlassmorphismEmptyState.ts +0 -35
  11. package/src/components/GlassmorphismInputGroup.ts +0 -205
  12. package/src/components/GlassmorphismMenubar.ts +0 -36
  13. package/src/components/GlassmorphismScrollArea.ts +0 -86
  14. package/src/components/GlassmorphismTable.ts +0 -52
  15. package/src/components/GlassmorphismTypography.ts +0 -70
  16. package/src/components/MinimalistAccordion.ts +0 -252
  17. package/src/components/MinimalistAlert.ts +0 -98
  18. package/src/components/MinimalistAlertDialog.ts +0 -102
  19. package/src/components/MinimalistAspectRatio.ts +0 -36
  20. package/src/components/MinimalistAvatar.ts +0 -97
  21. package/src/components/MinimalistBadge.ts +0 -70
  22. package/src/components/MinimalistBreadcrumb.ts +0 -92
  23. package/src/components/MinimalistButton.ts +0 -110
  24. package/src/components/MinimalistButtonGroup.ts +0 -112
  25. package/src/components/MinimalistCalendar.ts +0 -281
  26. package/src/components/MinimalistCard.ts +0 -130
  27. package/src/components/MinimalistCarousel.ts +0 -121
  28. package/src/components/MinimalistChart.ts +0 -150
  29. package/src/components/MinimalistCheckbox.ts +0 -178
  30. package/src/components/MinimalistCodeBlock.ts +0 -112
  31. package/src/components/MinimalistCollapsible.ts +0 -160
  32. package/src/components/MinimalistCommand.ts +0 -111
  33. package/src/components/MinimalistContextMenu.ts +0 -101
  34. package/src/components/MinimalistDialog.ts +0 -103
  35. package/src/components/MinimalistDrawer.ts +0 -222
  36. package/src/components/MinimalistDropdownMenu.ts +0 -125
  37. package/src/components/MinimalistEmpty.ts +0 -97
  38. package/src/components/MinimalistEmptyState.ts +0 -41
  39. package/src/components/MinimalistField.ts +0 -176
  40. package/src/components/MinimalistForm.ts +0 -102
  41. package/src/components/MinimalistHoverCard.ts +0 -149
  42. package/src/components/MinimalistInput.ts +0 -104
  43. package/src/components/MinimalistInputGroup.ts +0 -95
  44. package/src/components/MinimalistInputOtp.ts +0 -154
  45. package/src/components/MinimalistItem.ts +0 -159
  46. package/src/components/MinimalistKbd.ts +0 -37
  47. package/src/components/MinimalistLabel.ts +0 -53
  48. package/src/components/MinimalistMenubar.ts +0 -81
  49. package/src/components/MinimalistNativeSelect.ts +0 -149
  50. package/src/components/MinimalistNavigationMenu.ts +0 -103
  51. package/src/components/MinimalistPagination.ts +0 -140
  52. package/src/components/MinimalistPopover.ts +0 -112
  53. package/src/components/MinimalistProgress.ts +0 -70
  54. package/src/components/MinimalistRadioGroup.ts +0 -228
  55. package/src/components/MinimalistRangeCalendar.ts +0 -272
  56. package/src/components/MinimalistResizable.ts +0 -44
  57. package/src/components/MinimalistScrollArea.ts +0 -42
  58. package/src/components/MinimalistSelect.ts +0 -103
  59. package/src/components/MinimalistSeparator.ts +0 -52
  60. package/src/components/MinimalistSheet.ts +0 -165
  61. package/src/components/MinimalistSidebar.ts +0 -74
  62. package/src/components/MinimalistSkeleton.ts +0 -32
  63. package/src/components/MinimalistSlider.ts +0 -236
  64. package/src/components/MinimalistSonner.ts +0 -93
  65. package/src/components/MinimalistSpinner.ts +0 -52
  66. package/src/components/MinimalistSwitch.ts +0 -165
  67. package/src/components/MinimalistTable.ts +0 -35
  68. package/src/components/MinimalistTabs.ts +0 -97
  69. package/src/components/MinimalistTextarea.ts +0 -99
  70. package/src/components/MinimalistToggle.ts +0 -104
  71. package/src/components/MinimalistToggleGroup.ts +0 -177
  72. package/src/components/MinimalistTooltip.ts +0 -82
  73. package/src/components/MinimalistTypography.ts +0 -106
  74. package/src/components/NeubrutalismCard.ts +0 -35
  75. package/src/components/NeubrutalismItem.ts +0 -67
  76. package/src/components/ShadcnAccordion.ts +0 -248
  77. package/src/components/ShadcnAlertDialog.ts +0 -95
  78. package/src/components/ShadcnAspectRatio.ts +0 -29
  79. package/src/components/ShadcnAvatar.ts +0 -93
  80. package/src/components/ShadcnBadge.ts +0 -66
  81. package/src/components/ShadcnBreadcrumb.ts +0 -88
  82. package/src/components/ShadcnButton.ts +0 -106
  83. package/src/components/ShadcnButtonGroup.ts +0 -105
  84. package/src/components/ShadcnCalendar.ts +0 -277
  85. package/src/components/ShadcnCarousel.ts +0 -117
  86. package/src/components/ShadcnChart.ts +0 -146
  87. package/src/components/ShadcnCheckbox.ts +0 -174
  88. package/src/components/ShadcnCodeBlock.ts +0 -108
  89. package/src/components/ShadcnCollapsible.ts +0 -153
  90. package/src/components/ShadcnCommand.ts +0 -107
  91. package/src/components/ShadcnContextMenu.ts +0 -94
  92. package/src/components/ShadcnDialog.ts +0 -99
  93. package/src/components/ShadcnDrawer.ts +0 -218
  94. package/src/components/ShadcnDropdownMenu.ts +0 -118
  95. package/src/components/ShadcnEmpty.ts +0 -93
  96. package/src/components/ShadcnField.ts +0 -172
  97. package/src/components/ShadcnForm.ts +0 -98
  98. package/src/components/ShadcnHoverCard.ts +0 -145
  99. package/src/components/ShadcnInput.ts +0 -100
  100. package/src/components/ShadcnInputGroup.ts +0 -88
  101. package/src/components/ShadcnInputOtp.ts +0 -150
  102. package/src/components/ShadcnItem.ts +0 -155
  103. package/src/components/ShadcnKbd.ts +0 -33
  104. package/src/components/ShadcnLabel.ts +0 -49
  105. package/src/components/ShadcnMenubar.ts +0 -77
  106. package/src/components/ShadcnNativeSelect.ts +0 -142
  107. package/src/components/ShadcnNavigationMenu.ts +0 -96
  108. package/src/components/ShadcnPagination.ts +0 -136
  109. package/src/components/ShadcnPopover.ts +0 -108
  110. package/src/components/ShadcnProgress.ts +0 -66
  111. package/src/components/ShadcnRadioGroup.ts +0 -221
  112. package/src/components/ShadcnRangeCalendar.ts +0 -265
  113. package/src/components/ShadcnSelect.ts +0 -99
  114. package/src/components/ShadcnSeparator.ts +0 -48
  115. package/src/components/ShadcnSheet.ts +0 -161
  116. package/src/components/ShadcnSidebar.ts +0 -70
  117. package/src/components/ShadcnSkeleton.ts +0 -28
  118. package/src/components/ShadcnSlider.ts +0 -232
  119. package/src/components/ShadcnSonner.ts +0 -89
  120. package/src/components/ShadcnSpinner.ts +0 -48
  121. package/src/components/ShadcnSwitch.ts +0 -161
  122. package/src/components/ShadcnTabs.ts +0 -93
  123. package/src/components/ShadcnTextarea.ts +0 -95
  124. package/src/components/ShadcnToggle.ts +0 -100
  125. package/src/components/ShadcnToggleGroup.ts +0 -170
  126. package/src/components/ShadcnTooltip.ts +0 -78
  127. package/src/index.ts +0 -124
@@ -1,66 +0,0 @@
1
- import { cn, cva } from '@surreal-ui/core';
2
-
3
- const badgeVariants = cva(
4
- 'h-5 gap-1 rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! group/badge inline-flex w-fit shrink-0 items-center justify-center overflow-hidden whitespace-nowrap transition-colors focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none',
5
- {
6
- variants: {
7
- variant: {
8
- default: 'bg-primary text-primary-foreground [a]:hover:bg-primary/80',
9
- secondary: 'bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80',
10
- destructive:
11
- 'bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20',
12
- outline: 'border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground',
13
- ghost: 'hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50',
14
- link: 'text-primary underline-offset-4 hover:underline'
15
- }
16
- },
17
- defaultVariants: {
18
- variant: 'default'
19
- }
20
- }
21
- );
22
-
23
- export class UiBadge extends HTMLElement {
24
- static get observedAttributes() {
25
- return ['variant', 'href', 'class'];
26
- }
27
-
28
- private _element: HTMLElement | null = null;
29
-
30
- connectedCallback() {
31
- this.render();
32
- }
33
-
34
- attributeChangedCallback() {
35
- this.render();
36
- }
37
-
38
- private render() {
39
- const href = this.getAttribute('href');
40
- const variant = (this.getAttribute('variant') || 'default') as any;
41
- const customClass = this.getAttribute('class') || '';
42
-
43
- const tagName = href ? 'a' : 'span';
44
- if (!this._element || this._element.tagName.toLowerCase() !== tagName) {
45
- this.innerHTML = '';
46
- this._element = document.createElement(tagName);
47
- this._element.setAttribute('data-slot', 'badge');
48
- const slot = document.createElement('slot');
49
- this._element.appendChild(slot);
50
- this.appendChild(this._element);
51
- }
52
-
53
- if (href && this._element instanceof HTMLAnchorElement) {
54
- this._element.href = href;
55
- }
56
-
57
- this._element.className = cn(badgeVariants({ variant }), customClass);
58
- }
59
- }
60
-
61
- if (!customElements.get('ui-badge')) {
62
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-badge')) {
63
- customElements.define('surreal-shadcn-badge', UiBadge);
64
- }
65
- }
66
- export default UiBadge;
@@ -1,88 +0,0 @@
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
- export default BreadcrumbRoot;
@@ -1,106 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-button')) {
103
- customElements.define('surreal-shadcn-button', SurrealShadcnButton);
104
- }
105
- }
106
- export default SurrealShadcnButton;
@@ -1,105 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-button-group')) {
96
- customElements.define('surreal-shadcn-button-group', ButtonGroupElement);
97
- }
98
- }
99
- if (!customElements.get('surreal-button-group-separator')) {
100
- customElements.define('surreal-shadcn-button-group', ButtonGroupSeparatorElement);
101
- }
102
- if (!customElements.get('surreal-button-group-text')) {
103
- customElements.define('surreal-shadcn-button-group', ButtonGroupTextElement);
104
- }
105
- export default ButtonGroupElement;
@@ -1,277 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-calendar')) {
274
- customElements.define('surreal-shadcn-calendar', SurrealShadcnCalendar);
275
- }
276
- }
277
- export default SurrealShadcnCalendar;