@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.
Files changed (124) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/index.js +12075 -0
  3. package/package.json +27 -0
  4. package/src/components/GlassmorphismAlert.ts +116 -0
  5. package/src/components/GlassmorphismButton.ts +19 -0
  6. package/src/components/GlassmorphismCard.ts +33 -0
  7. package/src/components/GlassmorphismEmptyState.ts +29 -0
  8. package/src/components/GlassmorphismInputGroup.ts +202 -0
  9. package/src/components/GlassmorphismMenubar.ts +36 -0
  10. package/src/components/GlassmorphismScrollArea.ts +83 -0
  11. package/src/components/GlassmorphismTable.ts +52 -0
  12. package/src/components/GlassmorphismTypography.ts +67 -0
  13. package/src/components/MinimalistAccordion.ts +248 -0
  14. package/src/components/MinimalistAlert.ts +99 -0
  15. package/src/components/MinimalistAlertDialog.ts +100 -0
  16. package/src/components/MinimalistAspectRatio.ts +34 -0
  17. package/src/components/MinimalistAvatar.ts +98 -0
  18. package/src/components/MinimalistBadge.ts +71 -0
  19. package/src/components/MinimalistBreadcrumb.ts +92 -0
  20. package/src/components/MinimalistButton.ts +111 -0
  21. package/src/components/MinimalistButtonGroup.ts +110 -0
  22. package/src/components/MinimalistCalendar.ts +282 -0
  23. package/src/components/MinimalistCard.ts +131 -0
  24. package/src/components/MinimalistCarousel.ts +122 -0
  25. package/src/components/MinimalistChart.ts +151 -0
  26. package/src/components/MinimalistCheckbox.ts +179 -0
  27. package/src/components/MinimalistCodeBlock.ts +113 -0
  28. package/src/components/MinimalistCollapsible.ts +155 -0
  29. package/src/components/MinimalistCommand.ts +112 -0
  30. package/src/components/MinimalistContextMenu.ts +99 -0
  31. package/src/components/MinimalistDialog.ts +104 -0
  32. package/src/components/MinimalistDrawer.ts +223 -0
  33. package/src/components/MinimalistDropdownMenu.ts +120 -0
  34. package/src/components/MinimalistEmpty.ts +98 -0
  35. package/src/components/MinimalistEmptyState.ts +38 -0
  36. package/src/components/MinimalistField.ts +171 -0
  37. package/src/components/MinimalistForm.ts +101 -0
  38. package/src/components/MinimalistHoverCard.ts +150 -0
  39. package/src/components/MinimalistInput.ts +105 -0
  40. package/src/components/MinimalistInputGroup.ts +93 -0
  41. package/src/components/MinimalistInputOtp.ts +155 -0
  42. package/src/components/MinimalistItem.ts +160 -0
  43. package/src/components/MinimalistKbd.ts +38 -0
  44. package/src/components/MinimalistLabel.ts +54 -0
  45. package/src/components/MinimalistMenubar.ts +82 -0
  46. package/src/components/MinimalistNativeSelect.ts +144 -0
  47. package/src/components/MinimalistNavigationMenu.ts +98 -0
  48. package/src/components/MinimalistPagination.ts +141 -0
  49. package/src/components/MinimalistPopover.ts +113 -0
  50. package/src/components/MinimalistProgress.ts +71 -0
  51. package/src/components/MinimalistRadioGroup.ts +226 -0
  52. package/src/components/MinimalistRangeCalendar.ts +267 -0
  53. package/src/components/MinimalistResizable.ts +44 -0
  54. package/src/components/MinimalistScrollArea.ts +11 -0
  55. package/src/components/MinimalistSelect.ts +104 -0
  56. package/src/components/MinimalistSeparator.ts +53 -0
  57. package/src/components/MinimalistSheet.ts +166 -0
  58. package/src/components/MinimalistSidebar.ts +75 -0
  59. package/src/components/MinimalistSkeleton.ts +33 -0
  60. package/src/components/MinimalistSlider.ts +237 -0
  61. package/src/components/MinimalistSonner.ts +94 -0
  62. package/src/components/MinimalistSpinner.ts +53 -0
  63. package/src/components/MinimalistSwitch.ts +166 -0
  64. package/src/components/MinimalistTable.ts +35 -0
  65. package/src/components/MinimalistTabs.ts +98 -0
  66. package/src/components/MinimalistTextarea.ts +100 -0
  67. package/src/components/MinimalistToggle.ts +105 -0
  68. package/src/components/MinimalistToggleGroup.ts +175 -0
  69. package/src/components/MinimalistTooltip.ts +83 -0
  70. package/src/components/MinimalistTypography.ts +107 -0
  71. package/src/components/NeubrutalismCard.ts +35 -0
  72. package/src/components/NeubrutalismItem.ts +67 -0
  73. package/src/components/ShadcnAccordion.ts +244 -0
  74. package/src/components/ShadcnAlertDialog.ts +96 -0
  75. package/src/components/ShadcnAspectRatio.ts +30 -0
  76. package/src/components/ShadcnAvatar.ts +94 -0
  77. package/src/components/ShadcnBadge.ts +67 -0
  78. package/src/components/ShadcnBreadcrumb.ts +88 -0
  79. package/src/components/ShadcnButton.ts +107 -0
  80. package/src/components/ShadcnButtonGroup.ts +106 -0
  81. package/src/components/ShadcnCalendar.ts +278 -0
  82. package/src/components/ShadcnCarousel.ts +118 -0
  83. package/src/components/ShadcnChart.ts +147 -0
  84. package/src/components/ShadcnCheckbox.ts +175 -0
  85. package/src/components/ShadcnCodeBlock.ts +109 -0
  86. package/src/components/ShadcnCollapsible.ts +151 -0
  87. package/src/components/ShadcnCommand.ts +108 -0
  88. package/src/components/ShadcnContextMenu.ts +95 -0
  89. package/src/components/ShadcnDialog.ts +100 -0
  90. package/src/components/ShadcnDrawer.ts +219 -0
  91. package/src/components/ShadcnDropdownMenu.ts +116 -0
  92. package/src/components/ShadcnEmpty.ts +94 -0
  93. package/src/components/ShadcnField.ts +167 -0
  94. package/src/components/ShadcnForm.ts +97 -0
  95. package/src/components/ShadcnHoverCard.ts +146 -0
  96. package/src/components/ShadcnInput.ts +101 -0
  97. package/src/components/ShadcnInputGroup.ts +89 -0
  98. package/src/components/ShadcnInputOtp.ts +151 -0
  99. package/src/components/ShadcnItem.ts +156 -0
  100. package/src/components/ShadcnKbd.ts +34 -0
  101. package/src/components/ShadcnLabel.ts +50 -0
  102. package/src/components/ShadcnMenubar.ts +78 -0
  103. package/src/components/ShadcnNativeSelect.ts +140 -0
  104. package/src/components/ShadcnNavigationMenu.ts +94 -0
  105. package/src/components/ShadcnPagination.ts +137 -0
  106. package/src/components/ShadcnPopover.ts +109 -0
  107. package/src/components/ShadcnProgress.ts +67 -0
  108. package/src/components/ShadcnRadioGroup.ts +222 -0
  109. package/src/components/ShadcnRangeCalendar.ts +263 -0
  110. package/src/components/ShadcnSelect.ts +100 -0
  111. package/src/components/ShadcnSeparator.ts +49 -0
  112. package/src/components/ShadcnSheet.ts +162 -0
  113. package/src/components/ShadcnSidebar.ts +71 -0
  114. package/src/components/ShadcnSkeleton.ts +29 -0
  115. package/src/components/ShadcnSlider.ts +233 -0
  116. package/src/components/ShadcnSonner.ts +90 -0
  117. package/src/components/ShadcnSpinner.ts +49 -0
  118. package/src/components/ShadcnSwitch.ts +162 -0
  119. package/src/components/ShadcnTabs.ts +94 -0
  120. package/src/components/ShadcnTextarea.ts +96 -0
  121. package/src/components/ShadcnToggle.ts +101 -0
  122. package/src/components/ShadcnToggleGroup.ts +171 -0
  123. package/src/components/ShadcnTooltip.ts +79 -0
  124. package/src/index.ts +124 -0
@@ -0,0 +1,151 @@
1
+ export class SurrealShadcnCollapsible extends HTMLElement {
2
+ private _open = false;
3
+ private _disabled = false;
4
+
5
+ static get observedAttributes() {
6
+ return ['open', 'disabled'];
7
+ }
8
+
9
+ connectedCallback() {
10
+ this.setAttribute('data-slot', 'collapsible');
11
+ this._upgradeProperty('open');
12
+ this._upgradeProperty('disabled');
13
+ this._syncState();
14
+ }
15
+
16
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
17
+ if (oldValue === newValue) return;
18
+ if (name === 'open') {
19
+ this._open = newValue !== null;
20
+ } else if (name === 'disabled') {
21
+ this._disabled = newValue !== null;
22
+ }
23
+ this._syncState();
24
+ }
25
+
26
+ get open() {
27
+ return this._open;
28
+ }
29
+
30
+ set open(value: boolean) {
31
+ if (value) {
32
+ this.setAttribute('open', '');
33
+ } else {
34
+ this.removeAttribute('open');
35
+ }
36
+ }
37
+
38
+ get disabled() {
39
+ return this._disabled;
40
+ }
41
+
42
+ set disabled(value: boolean) {
43
+ if (value) {
44
+ this.setAttribute('disabled', '');
45
+ } else {
46
+ this.removeAttribute('disabled');
47
+ }
48
+ }
49
+
50
+ public toggle() {
51
+ if (this._disabled) return;
52
+ this.open = !this.open;
53
+ this.dispatchEvent(
54
+ new CustomEvent('openchange', { detail: { open: this.open }, bubbles: true }),
55
+ );
56
+ }
57
+
58
+ private _upgradeProperty(prop: string) {
59
+ if (Object.prototype.hasOwnProperty.call(this, prop)) {
60
+ const value = (this as any)[prop];
61
+ delete (this as any)[prop];
62
+ (this as any)[prop] = value;
63
+ }
64
+ }
65
+
66
+ private _syncState() {
67
+ const state = this._open ? 'open' : 'closed';
68
+ this.setAttribute('data-state', state);
69
+ if (this._disabled) {
70
+ this.setAttribute('data-disabled', '');
71
+ } else {
72
+ this.removeAttribute('data-disabled');
73
+ }
74
+
75
+ const triggers = this.querySelectorAll(
76
+ 'surreal-collapsible-trigger, [data-slot="collapsible-trigger"]',
77
+ );
78
+ triggers.forEach((trigger) => {
79
+ trigger.setAttribute('data-state', state);
80
+ trigger.setAttribute('aria-expanded', String(this._open));
81
+ if (this._disabled) trigger.setAttribute('disabled', '');
82
+ else trigger.removeAttribute('disabled');
83
+ });
84
+
85
+ const contents = this.querySelectorAll(
86
+ 'surreal-collapsible-content, [data-slot="collapsible-content"]',
87
+ );
88
+ contents.forEach((content) => {
89
+ content.setAttribute('data-state', state);
90
+ if (this._open) {
91
+ (content as HTMLElement).style.display = '';
92
+ } else {
93
+ (content as HTMLElement).style.display = 'none';
94
+ }
95
+ });
96
+ }
97
+ }
98
+
99
+ export class SurrealShadcnCollapsibleTrigger extends HTMLElement {
100
+ connectedCallback() {
101
+ this.setAttribute('data-slot', 'collapsible-trigger');
102
+ this.setAttribute('role', 'button');
103
+ this.setAttribute('tabindex', '0');
104
+ this.addEventListener('click', this._handleClick);
105
+ this.addEventListener('keydown', this._handleKeyDown);
106
+ }
107
+
108
+ disconnectedCallback() {
109
+ this.removeEventListener('click', this._handleClick);
110
+ this.removeEventListener('keydown', this._handleKeyDown);
111
+ }
112
+
113
+ private _handleClick = (e: MouseEvent) => {
114
+ if (this.hasAttribute('disabled')) return;
115
+ const parent = this.closest('surreal-collapsible') as SurrealShadcnCollapsible | null;
116
+ parent?.toggle();
117
+ };
118
+
119
+ private _handleKeyDown = (e: KeyboardEvent) => {
120
+ if (e.key === 'Enter' || e.key === ' ') {
121
+ e.preventDefault();
122
+ if (!this.hasAttribute('disabled')) {
123
+ const parent = this.closest('surreal-collapsible') as SurrealShadcnCollapsible | null;
124
+ parent?.toggle();
125
+ }
126
+ }
127
+ };
128
+ }
129
+
130
+ export class SurrealShadcnCollapsibleContent extends HTMLElement {
131
+ connectedCallback() {
132
+ this.setAttribute('data-slot', 'collapsible-content');
133
+ const parent = this.closest('surreal-collapsible') as SurrealShadcnCollapsible | null;
134
+ if (parent && !parent.open) {
135
+ this.style.display = 'none';
136
+ }
137
+ }
138
+ }
139
+
140
+ if (typeof customElements !== 'undefined') {
141
+ if (!customElements.get('surreal-collapsible'))
142
+
143
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-collapsible')) {
144
+ customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsible);
145
+ }
146
+ if (!customElements.get('surreal-collapsible-trigger'))
147
+ customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsibleTrigger);
148
+ if (!customElements.get('surreal-collapsible-content'))
149
+ customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsibleContent);
150
+ }
151
+ export default SurrealShadcnCollapsible;
@@ -0,0 +1,108 @@
1
+ export class SurrealShadcnCommand extends HTMLElement {
2
+ private _searchInput: HTMLInputElement | null = null;
3
+ private _items: HTMLElement[] = [];
4
+
5
+ static get observedAttributes() {
6
+ return ['value'];
7
+ }
8
+
9
+ connectedCallback() {
10
+ this.classList.add(
11
+ 'rounded-xl',
12
+ 'bg-popover',
13
+ 'p-1',
14
+ 'text-popover-foreground',
15
+ 'flex',
16
+ 'size-full',
17
+ 'flex-col',
18
+ 'overflow-hidden',
19
+ 'border',
20
+ 'border-border',
21
+ 'shadow-md',
22
+ );
23
+ this.setAttribute('data-slot', 'command');
24
+
25
+ this.addEventListener('input', this.handleInput.bind(this));
26
+ this.addEventListener('keydown', this.handleKeydown.bind(this));
27
+ }
28
+
29
+ private handleInput(e: Event) {
30
+ const target = e.target as HTMLInputElement;
31
+ if (target && target.getAttribute('data-slot') === 'command-input') {
32
+ const query = target.value.toLowerCase().trim();
33
+ this.filterItems(query);
34
+ }
35
+ }
36
+
37
+ private filterItems(query: string) {
38
+ const items = Array.from(this.querySelectorAll('[data-slot="command-item"]')) as HTMLElement[];
39
+ const groups = Array.from(
40
+ this.querySelectorAll('[data-slot="command-group"]'),
41
+ ) as HTMLElement[];
42
+ const empty = this.querySelector('[data-slot="command-empty"]') as HTMLElement | null;
43
+
44
+ let visibleCount = 0;
45
+
46
+ items.forEach((item) => {
47
+ const text = (item.textContent || '').toLowerCase();
48
+ const matches = !query || text.includes(query);
49
+ item.style.display = matches ? 'flex' : 'none';
50
+ if (matches) visibleCount++;
51
+ });
52
+
53
+ groups.forEach((group) => {
54
+ const groupItems = Array.from(
55
+ group.querySelectorAll('[data-slot="command-item"]'),
56
+ ) as HTMLElement[];
57
+ const hasVisible = groupItems.some((i) => i.style.display !== 'none');
58
+ group.style.display = hasVisible ? 'block' : 'none';
59
+ });
60
+
61
+ if (empty) {
62
+ empty.style.display = visibleCount === 0 ? 'block' : 'none';
63
+ }
64
+ }
65
+
66
+ private handleKeydown(e: KeyboardEvent) {
67
+ const items = Array.from(
68
+ this.querySelectorAll('[data-slot="command-item"]:not([data-disabled="true"])'),
69
+ ) as HTMLElement[];
70
+ const visibleItems = items.filter((i) => i.style.display !== 'none');
71
+
72
+ if (visibleItems.length === 0) return;
73
+
74
+ const currentIndex = visibleItems.findIndex((i) => i.getAttribute('data-selected') === 'true');
75
+
76
+ if (e.key === 'ArrowDown') {
77
+ e.preventDefault();
78
+ const nextIndex = (currentIndex + 1) % visibleItems.length;
79
+ this.setSelectedItem(visibleItems, nextIndex);
80
+ } else if (e.key === 'ArrowUp') {
81
+ e.preventDefault();
82
+ const prevIndex = (currentIndex - 1 + visibleItems.length) % visibleItems.length;
83
+ this.setSelectedItem(visibleItems, prevIndex);
84
+ } else if (e.key === 'Enter' && currentIndex >= 0) {
85
+ e.preventDefault();
86
+ visibleItems[currentIndex].click();
87
+ }
88
+ }
89
+
90
+ private setSelectedItem(items: HTMLElement[], index: number) {
91
+ items.forEach((item, idx) => {
92
+ if (idx === index) {
93
+ item.setAttribute('data-selected', 'true');
94
+ item.scrollIntoView({ block: 'nearest' });
95
+ } else {
96
+ item.removeAttribute('data-selected');
97
+ }
98
+ });
99
+ }
100
+ }
101
+
102
+ if (!customElements.get('surreal-command')) {
103
+
104
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-command')) {
105
+ customElements.define('surreal-shadcn-command', SurrealShadcnCommand);
106
+ }
107
+ }
108
+ export default SurrealShadcnCommand;
@@ -0,0 +1,95 @@
1
+ class SurrealShadcnContextMenu extends HTMLElement {
2
+ private triggerArea: HTMLElement | null = null;
3
+ private menuContent: HTMLElement | null = null;
4
+ private isOpen: boolean = false;
5
+
6
+ static get observedAttributes() {
7
+ return ['open'];
8
+ }
9
+
10
+ connectedCallback() {
11
+ this.render();
12
+ this.attachEventListeners();
13
+ }
14
+
15
+ disconnectedCallback() {
16
+ document.removeEventListener('pointerdown', this.handleOutsideClick);
17
+ document.removeEventListener('keydown', this.handleKeyDown);
18
+ }
19
+
20
+ attributeChangedCallback(name: string, oldValue: string, newValue: string) {
21
+ if (name === 'open' && oldValue !== newValue) {
22
+ this.isOpen = newValue !== null && newValue !== 'false';
23
+ this.updateMenuVisibility();
24
+ }
25
+ }
26
+
27
+ private render() {
28
+ this.triggerArea = this.querySelector('[data-slot="context-menu-trigger"]');
29
+ this.menuContent = this.querySelector('[data-slot="context-menu-content"]');
30
+ if (this.menuContent) {
31
+ this.menuContent.classList.add('hidden');
32
+ }
33
+ }
34
+
35
+ private attachEventListeners() {
36
+ this.addEventListener('contextmenu', (e: MouseEvent) => {
37
+ const target = e.target as HTMLElement;
38
+ if (this.triggerArea && (this.triggerArea === target || this.triggerArea.contains(target))) {
39
+ e.preventDefault();
40
+ this.openMenu(e.clientX, e.clientY);
41
+ }
42
+ });
43
+
44
+ document.addEventListener('pointerdown', this.handleOutsideClick);
45
+ document.addEventListener('keydown', this.handleKeyDown);
46
+ }
47
+
48
+ private handleOutsideClick = (e: MouseEvent) => {
49
+ if (this.isOpen && this.menuContent && !this.menuContent.contains(e.target as Node)) {
50
+ this.closeMenu();
51
+ }
52
+ };
53
+
54
+ private handleKeyDown = (e: KeyboardEvent) => {
55
+ if (e.key === 'Escape' && this.isOpen) {
56
+ this.closeMenu();
57
+ }
58
+ };
59
+
60
+ private openMenu(x: number, y: number) {
61
+ if (!this.menuContent) return;
62
+ this.isOpen = true;
63
+ this.menuContent.classList.remove('hidden');
64
+ this.menuContent.style.position = 'fixed';
65
+ this.menuContent.style.left = `${x}px`;
66
+ this.menuContent.style.top = `${y}px`;
67
+ this.menuContent.style.zIndex = '50';
68
+ this.dispatchEvent(new CustomEvent('openchange', { detail: { open: true } }));
69
+ }
70
+
71
+ private closeMenu() {
72
+ if (!this.menuContent) return;
73
+ this.isOpen = false;
74
+ this.menuContent.classList.add('hidden');
75
+ this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
76
+ }
77
+
78
+ private updateMenuVisibility() {
79
+ if (this.isOpen) {
80
+ this.menuContent?.classList.remove('hidden');
81
+ } else {
82
+ this.menuContent?.classList.add('hidden');
83
+ }
84
+ }
85
+ }
86
+
87
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-context-menu')) {
88
+
89
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-context-menu')) {
90
+ customElements.define('surreal-shadcn-context-menu', SurrealShadcnContextMenu);
91
+ }
92
+ };
93
+ export { SurrealShadcnContextMenu as ShadcnContextMenu, SurrealShadcnContextMenu };
94
+
95
+ export default SurrealShadcnContextMenu;
@@ -0,0 +1,100 @@
1
+ class SurrealShadcnDialog extends HTMLElement {
2
+ private _open = false;
3
+ private _showCloseButton = true;
4
+ private dialogEl: HTMLDialogElement | null = null;
5
+
6
+ static get observedAttributes() {
7
+ return ['open', 'show-close-button'];
8
+ }
9
+
10
+ get open(): boolean {
11
+ return this._open;
12
+ }
13
+
14
+ set open(val: boolean) {
15
+ if (this._open === val) return;
16
+ this._open = val;
17
+ if (val) {
18
+ this.setAttribute('open', '');
19
+ this.dialogEl?.showModal();
20
+ } else {
21
+ this.removeAttribute('open');
22
+ this.dialogEl?.close();
23
+ }
24
+ this.dispatchEvent(new CustomEvent('openchange', { detail: { open: val } }));
25
+ }
26
+
27
+ connectedCallback() {
28
+ this.render();
29
+ }
30
+
31
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
32
+ if (name === 'open') {
33
+ this.open = newValue !== null;
34
+ } else if (name === 'show-close-button') {
35
+ this._showCloseButton = newValue !== 'false';
36
+ }
37
+ }
38
+
39
+ private render() {
40
+ this.innerHTML = `
41
+ <div data-slot="dialog-trigger-wrapper" class="inline-block">
42
+ <slot name="trigger"></slot>
43
+ </div>
44
+ <dialog data-slot="dialog-native" class="backdrop:bg-black/10 backdrop:duration-100 backdrop:supports-backdrop-filter:backdrop-blur-xs fixed inset-0 m-0 h-full w-full max-h-none max-w-none bg-transparent p-0 border-none outline-none z-50 flex items-center justify-center">
45
+ <div data-slot="dialog-content" class="grid max-w-[calc(100%-2rem)] gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 sm:max-w-sm w-full relative outline-none shadow-lg">
46
+ <slot name="header">
47
+ <div data-slot="dialog-header" class="gap-2 flex flex-col">
48
+ <slot name="title"></slot>
49
+ <slot name="description"></slot>
50
+ </div>
51
+ </slot>
52
+ <slot></slot>
53
+ <slot name="footer"></slot>
54
+ ${
55
+ this._showCloseButton
56
+ ? `
57
+ <button type="button" data-slot="dialog-close-btn" aria-label="Close" class="absolute top-2 right-2 inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring outline-none transition-colors">
58
+ <svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
59
+ <span class="sr-only">Close</span>
60
+ </button>
61
+ `
62
+ : ''
63
+ }
64
+ </div>
65
+ </dialog>
66
+ `;
67
+
68
+ this.dialogEl = this.querySelector('dialog');
69
+ const triggerWrapper = this.querySelector('[data-slot="dialog-trigger-wrapper"]');
70
+ const closeBtn = this.querySelector('[data-slot="dialog-close-btn"]');
71
+
72
+ triggerWrapper?.addEventListener('click', () => {
73
+ this.open = true;
74
+ });
75
+
76
+ closeBtn?.addEventListener('click', () => {
77
+ this.open = false;
78
+ });
79
+
80
+ this.dialogEl?.addEventListener('click', (e) => {
81
+ if (e.target === this.dialogEl) {
82
+ this.open = false;
83
+ }
84
+ });
85
+
86
+ this.dialogEl?.addEventListener('cancel', () => {
87
+ this.open = false;
88
+ });
89
+ }
90
+ }
91
+
92
+ if (!customElements.get('surreal-dialog')) {
93
+
94
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-dialog')) {
95
+ customElements.define('surreal-shadcn-dialog', SurrealShadcnDialog);
96
+ }
97
+ }
98
+
99
+ export default SurrealShadcnDialog;;
100
+ export { SurrealShadcnDialog as ShadcnDialog, SurrealShadcnDialog };
@@ -0,0 +1,219 @@
1
+ class SurrealShadcnDrawer extends HTMLElement {
2
+ private _open = false;
3
+ private _direction: 'bottom' | 'top' | 'left' | 'right' = 'bottom';
4
+ private overlayEl: HTMLDivElement | null = null;
5
+ private contentEl: HTMLDivElement | null = null;
6
+
7
+ static get observedAttributes() {
8
+ return ['open', 'direction'];
9
+ }
10
+
11
+ get open() {
12
+ return this._open;
13
+ }
14
+
15
+ set open(val: boolean) {
16
+ if (val) {
17
+ this.setAttribute('open', '');
18
+ } else {
19
+ this.removeAttribute('open');
20
+ }
21
+ }
22
+
23
+ get direction() {
24
+ return this._direction;
25
+ }
26
+
27
+ set direction(val: 'bottom' | 'top' | 'left' | 'right') {
28
+ this.setAttribute('direction', val);
29
+ }
30
+
31
+ connectedCallback() {
32
+ this.render();
33
+ this.setupEvents();
34
+ }
35
+
36
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
37
+ if (oldValue === newValue) return;
38
+ if (name === 'open') {
39
+ this._open = newValue !== null;
40
+ this.updateVisibility();
41
+ } else if (name === 'direction') {
42
+ this._direction = (newValue as 'bottom' | 'top' | 'left' | 'right') || 'bottom';
43
+ this.updateDirectionClasses();
44
+ }
45
+ }
46
+
47
+ private render() {
48
+ if (this.querySelector('[data-drawer-rendered]')) return;
49
+ this.setAttribute('data-drawer-rendered', 'true');
50
+
51
+ const trigger = this.querySelector('[slot="trigger"]');
52
+ const header = this.querySelector('[slot="header"]');
53
+ const body =
54
+ this.querySelector('[slot="content"]') || this.querySelector('[data-slot="content"]');
55
+ const footer = this.querySelector('[slot="footer"]');
56
+
57
+ const wrapper = document.createElement('div');
58
+ wrapper.className = 'relative inline-block';
59
+
60
+ if (trigger) {
61
+ trigger.addEventListener('click', () => {
62
+ this.open = true;
63
+ });
64
+ wrapper.appendChild(trigger);
65
+ }
66
+
67
+ const overlay = document.createElement('div');
68
+ overlay.className =
69
+ 'fixed inset-0 z-50 bg-black/80 supports-backdrop-filter:backdrop-blur-xs transition-opacity duration-300 hidden opacity-0';
70
+ overlay.addEventListener('click', () => {
71
+ this.open = false;
72
+ });
73
+ this.overlayEl = overlay;
74
+
75
+ const content = document.createElement('div');
76
+ content.className =
77
+ 'fixed z-50 flex h-auto flex-col bg-popover text-sm text-popover-foreground shadow-lg transition-transform duration-300 ease-out hidden';
78
+ this.contentEl = content;
79
+
80
+ const handle = document.createElement('div');
81
+ handle.className = 'mx-auto mt-4 h-1.5 w-12 shrink-0 rounded-full bg-muted';
82
+ content.appendChild(handle);
83
+
84
+ if (header) content.appendChild(header);
85
+ if (body) content.appendChild(body);
86
+ if (footer) content.appendChild(footer);
87
+
88
+ this.querySelectorAll('[data-drawer-close]').forEach((btn) => {
89
+ btn.addEventListener('click', () => {
90
+ this.open = false;
91
+ });
92
+ });
93
+
94
+ document.body.appendChild(overlay);
95
+ document.body.appendChild(content);
96
+ this.appendChild(wrapper);
97
+
98
+ this.updateDirectionClasses();
99
+ this.updateVisibility();
100
+ }
101
+
102
+ private updateDirectionClasses() {
103
+ if (!this.contentEl) return;
104
+ this.contentEl.classList.remove(
105
+ 'inset-x-0',
106
+ 'bottom-0',
107
+ 'mt-24',
108
+ 'max-h-[80vh]',
109
+ 'rounded-t-xl',
110
+ 'border-t',
111
+ 'inset-x-0',
112
+ 'top-0',
113
+ 'mb-24',
114
+ 'max-h-[80vh]',
115
+ 'rounded-b-xl',
116
+ 'border-b',
117
+ 'inset-y-0',
118
+ 'left-0',
119
+ 'w-3/4',
120
+ 'max-w-sm',
121
+ 'rounded-r-xl',
122
+ 'border-r',
123
+ 'inset-y-0',
124
+ 'right-0',
125
+ 'w-3/4',
126
+ 'max-w-sm',
127
+ 'rounded-l-xl',
128
+ 'border-l',
129
+ );
130
+
131
+ if (this._direction === 'bottom') {
132
+ this.contentEl.classList.add(
133
+ 'inset-x-0',
134
+ 'bottom-0',
135
+ 'mt-24',
136
+ 'max-h-[80vh]',
137
+ 'rounded-t-xl',
138
+ 'border-t',
139
+ );
140
+ } else if (this._direction === 'top') {
141
+ this.contentEl.classList.add(
142
+ 'inset-x-0',
143
+ 'top-0',
144
+ 'mb-24',
145
+ 'max-h-[80vh]',
146
+ 'rounded-b-xl',
147
+ 'border-b',
148
+ );
149
+ } else if (this._direction === 'left') {
150
+ this.contentEl.classList.add(
151
+ 'inset-y-0',
152
+ 'left-0',
153
+ 'w-3/4',
154
+ 'max-w-sm',
155
+ 'rounded-r-xl',
156
+ 'border-r',
157
+ );
158
+ } else if (this._direction === 'right') {
159
+ this.contentEl.classList.add(
160
+ 'inset-y-0',
161
+ 'right-0',
162
+ 'w-3/4',
163
+ 'max-w-sm',
164
+ 'rounded-l-xl',
165
+ 'border-l',
166
+ );
167
+ }
168
+ }
169
+
170
+ private updateVisibility() {
171
+ if (!this.overlayEl || !this.contentEl) return;
172
+ if (this._open) {
173
+ this.overlayEl.classList.remove('hidden');
174
+ this.contentEl.classList.remove('hidden');
175
+ requestAnimationFrame(() => {
176
+ this.overlayEl?.classList.remove('opacity-0');
177
+ this.overlayEl?.classList.add('opacity-100');
178
+ });
179
+ this.dispatchEvent(new CustomEvent('openchange', { detail: { open: true } }));
180
+ } else {
181
+ this.overlayEl.classList.add('opacity-0');
182
+ this.overlayEl.classList.remove('opacity-100');
183
+ setTimeout(() => {
184
+ if (!this._open) {
185
+ this.overlayEl?.classList.add('hidden');
186
+ this.contentEl?.classList.add('hidden');
187
+ }
188
+ }, 300);
189
+ this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
190
+ }
191
+ }
192
+
193
+ private setupEvents() {
194
+ document.addEventListener('keydown', (e) => {
195
+ if (e.key === 'Escape' && this.open) {
196
+ this.open = false;
197
+ }
198
+ });
199
+ }
200
+
201
+ disconnectedCallback() {
202
+ if (this.overlayEl && this.overlayEl.parentNode) {
203
+ this.overlayEl.parentNode.removeChild(this.overlayEl);
204
+ }
205
+ if (this.contentEl && this.contentEl.parentNode) {
206
+ this.contentEl.parentNode.removeChild(this.contentEl);
207
+ }
208
+ }
209
+ }
210
+
211
+ if (!customElements.get('surreal-drawer')) {
212
+
213
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-drawer')) {
214
+ customElements.define('surreal-shadcn-drawer', SurrealShadcnDrawer);
215
+ }
216
+ };
217
+ export { SurrealShadcnDrawer as ShadcnDrawer, SurrealShadcnDrawer };
218
+
219
+ export default SurrealShadcnDrawer;