@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,103 +0,0 @@
1
- class NavigationMenuElement extends HTMLElement {
2
- private _openItem: string | null = null;
3
-
4
- connectedCallback() {
5
- this.setAttribute('data-slot', 'navigation-menu');
6
- this.className =
7
- 'max-w-max group/navigation-menu relative flex flex-1 items-center justify-center ' +
8
- (this.getAttribute('class') || '');
9
-
10
- this.addEventListener('click', this.handleClick.bind(this));
11
- document.addEventListener('click', this.handleOutsideClick.bind(this));
12
- }
13
-
14
- disconnectedCallback() {
15
- document.removeEventListener('click', this.handleOutsideClick.bind(this));
16
- }
17
-
18
- private handleClick(e: Event) {
19
- const target = (e.target as HTMLElement).closest(
20
- '[data-slot="navigation-menu-trigger"]'
21
- ) as HTMLElement | null;
22
- if (!target) return;
23
-
24
- const item = target.closest('[data-slot="navigation-menu-item"]') as HTMLElement | null;
25
- if (!item) return;
26
-
27
- const itemId =
28
- item.getAttribute('data-value') ||
29
- item.id ||
30
- Array.from(this.querySelectorAll('[data-slot="navigation-menu-item"]'))
31
- .indexOf(item)
32
- .toString();
33
-
34
- if (this._openItem === itemId) {
35
- this.closeAll();
36
- } else {
37
- this.open(itemId);
38
- }
39
- }
40
-
41
- private handleOutsideClick(e: Event) {
42
- if (!this.contains(e.target as Node)) {
43
- this.closeAll();
44
- }
45
- }
46
-
47
- private open(itemId: string) {
48
- this._openItem = itemId;
49
- const items = this.querySelectorAll('[data-slot="navigation-menu-item"]');
50
- items.forEach((item, idx) => {
51
- const id = item.getAttribute('data-value') || item.id || idx.toString();
52
- const trigger = item.querySelector('[data-slot="navigation-menu-trigger"]');
53
- const content = item.querySelector('[data-slot="navigation-menu-content"]');
54
- const isOpen = id === itemId;
55
-
56
- if (trigger) {
57
- trigger.setAttribute('data-state', isOpen ? 'open' : 'closed');
58
- trigger.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
59
- }
60
- if (content) {
61
- content.setAttribute('data-state', isOpen ? 'open' : 'closed');
62
- if (isOpen) {
63
- content.classList.remove('hidden');
64
- } else {
65
- content.classList.add('hidden');
66
- }
67
- }
68
- });
69
- }
70
-
71
- private closeAll() {
72
- this._openItem = null;
73
- const triggers = this.querySelectorAll('[data-slot="navigation-menu-trigger"]');
74
- const contents = this.querySelectorAll('[data-slot="navigation-menu-content"]');
75
- triggers.forEach((t) => {
76
- t.setAttribute('data-state', 'closed');
77
- t.setAttribute('aria-expanded', 'false');
78
- });
79
- contents.forEach((c) => {
80
- c.setAttribute('data-state', 'closed');
81
- c.classList.add('hidden');
82
- });
83
- }
84
- }
85
-
86
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-navigation-menu')) {
87
- if (
88
- typeof customElements !== 'undefined' &&
89
- !customElements.get('surreal-shadcn-navigation-menu')
90
- ) {
91
- customElements.define('surreal-shadcn-navigation-menu', NavigationMenuElement);
92
- }
93
- }
94
- export { NavigationMenuElement as MinimalistNavigationMenu, NavigationMenuElement };
95
-
96
- if (
97
- typeof customElements !== 'undefined' &&
98
- !customElements.get('surreal-minimalist-navigation-menu')
99
- ) {
100
- customElements.define('surreal-minimalist-navigation-menu', NavigationMenuElement);
101
- }
102
-
103
- export default NavigationMenuElement;
@@ -1,140 +0,0 @@
1
- class SurrealShadcnPagination extends HTMLElement {
2
- connectedCallback() {
3
- this.setAttribute('role', 'navigation');
4
- this.setAttribute('aria-label', 'pagination');
5
- this.setAttribute('data-slot', 'pagination');
6
- this.className =
7
- 'cn-pagination mx-auto flex w-full justify-center ' + (this.getAttribute('class') || '');
8
- }
9
- }
10
-
11
- class SurrealShadcnPaginationContent extends HTMLElement {
12
- connectedCallback() {
13
- this.setAttribute('data-slot', 'pagination-content');
14
- this.className =
15
- 'gap-0.5 flex items-center list-none m-0 p-0 ' + (this.getAttribute('class') || '');
16
- }
17
- }
18
-
19
- class SurrealShadcnPaginationItem extends HTMLElement {
20
- connectedCallback() {
21
- this.setAttribute('data-slot', 'pagination-item');
22
- this.className = 'inline-flex ' + (this.getAttribute('class') || '');
23
- }
24
- }
25
-
26
- class SurrealShadcnPaginationLink extends HTMLElement {
27
- static get observedAttributes() {
28
- return ['is-active', 'size', 'href'];
29
- }
30
-
31
- connectedCallback() {
32
- this.render();
33
- }
34
-
35
- attributeChangedCallback() {
36
- this.render();
37
- }
38
-
39
- render() {
40
- const isActive = this.hasAttribute('is-active') && this.getAttribute('is-active') !== 'false';
41
- const size = this.getAttribute('size') || 'icon';
42
- const href = this.getAttribute('href') || '#';
43
- const label = this.getAttribute('aria-label') || '';
44
- const innerHtml = this.innerHTML;
45
-
46
- const sizeClasses =
47
- size === 'default'
48
- ? 'h-9 px-4 py-2'
49
- : size === 'sm'
50
- ? 'h-8 rounded-md px-3 text-xs'
51
- : size === 'lg'
52
- ? 'h-10 rounded-md px-8'
53
- : 'h-9 w-9';
54
- const variantClasses = isActive
55
- ? 'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground'
56
- : 'hover:bg-accent hover:text-accent-foreground';
57
-
58
- this.setAttribute('data-slot', 'pagination-link');
59
- this.setAttribute('data-active', String(isActive));
60
- this.setAttribute('data-size', size);
61
- this.className = `inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring cursor-pointer ${variantClasses} ${sizeClasses} cn-pagination-link ${this.getAttribute('class') || ''}`;
62
- }
63
- }
64
-
65
- class SurrealShadcnPaginationPrevious extends HTMLElement {
66
- connectedCallback() {
67
- this.setAttribute('data-slot', 'pagination-previous');
68
- const href = this.getAttribute('href') || '#';
69
- this.className =
70
- 'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 pl-1.5! gap-1 cursor-pointer ' +
71
- (this.getAttribute('class') || '');
72
- if (!this.innerHTML.trim()) {
73
- this.innerHTML = `
74
- <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"><path d="m15 18-6-6 6-6"/></svg>
75
- <span class="cn-pagination-previous-text hidden sm:block">Previous</span>
76
- `;
77
- }
78
- }
79
- }
80
-
81
- class SurrealShadcnPaginationNext extends HTMLElement {
82
- connectedCallback() {
83
- this.setAttribute('data-slot', 'pagination-next');
84
- const href = this.getAttribute('href') || '#';
85
- this.className =
86
- 'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 pr-1.5! gap-1 cursor-pointer ' +
87
- (this.getAttribute('class') || '');
88
- if (!this.innerHTML.trim()) {
89
- this.innerHTML = `
90
- <span class="cn-pagination-next-text hidden sm:block">Next</span>
91
- <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"><path d="m9 18 6-6-6-6"/></svg>
92
- `;
93
- }
94
- }
95
- }
96
-
97
- class SurrealShadcnPaginationEllipsis extends HTMLElement {
98
- connectedCallback() {
99
- this.setAttribute('aria-hidden', 'true');
100
- this.setAttribute('data-slot', 'pagination-ellipsis');
101
- this.className =
102
- 'size-8 items-center justify-center flex items-center justify-center ' +
103
- (this.getAttribute('class') || '');
104
- this.innerHTML = `
105
- <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>
106
- <span class="sr-only">More pages</span>
107
- `;
108
- }
109
- }
110
-
111
- if (!customElements.get('surreal-pagination')) {
112
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-pagination')) {
113
- customElements.define('surreal-shadcn-pagination', SurrealShadcnPagination);
114
- }
115
- }
116
- if (!customElements.get('surreal-pagination-content')) {
117
- customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationContent);
118
- }
119
- if (!customElements.get('surreal-pagination-item')) {
120
- customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationItem);
121
- }
122
- if (!customElements.get('surreal-pagination-link')) {
123
- customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationLink);
124
- }
125
- if (!customElements.get('surreal-pagination-previous')) {
126
- customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationPrevious);
127
- }
128
- if (!customElements.get('surreal-pagination-next')) {
129
- customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationNext);
130
- }
131
- if (!customElements.get('surreal-pagination-ellipsis')) {
132
- customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationEllipsis);
133
- }
134
- export { SurrealShadcnPagination as MinimalistPagination, SurrealShadcnPagination };
135
-
136
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-pagination')) {
137
- customElements.define('surreal-minimalist-pagination', SurrealShadcnPagination);
138
- }
139
-
140
- export default SurrealShadcnPagination;
@@ -1,112 +0,0 @@
1
- class SurrealShadcnPopover extends HTMLElement {
2
- private _open = false;
3
- private _trigger: HTMLElement | null = null;
4
- private _content: HTMLElement | null = null;
5
- private _handleOutsideClick: (e: MouseEvent) => void;
6
- private _handleKeyDown: (e: KeyboardEvent) => void;
7
-
8
- static get observedAttributes() {
9
- return ['open'];
10
- }
11
-
12
- constructor() {
13
- super();
14
- this._handleOutsideClick = (e: MouseEvent) => {
15
- if (this._open && !this.contains(e.target as Node)) {
16
- this.open = false;
17
- }
18
- };
19
- this._handleKeyDown = (e: KeyboardEvent) => {
20
- if (this._open && e.key === 'Escape') {
21
- this.open = false;
22
- }
23
- };
24
- }
25
-
26
- get open(): boolean {
27
- return this._open;
28
- }
29
-
30
- set open(val: boolean) {
31
- const next = Boolean(val);
32
- if (this._open !== next) {
33
- this._open = next;
34
- if (next) {
35
- this.setAttribute('open', '');
36
- } else {
37
- this.removeAttribute('open');
38
- }
39
- this._updateState();
40
- this.dispatchEvent(new CustomEvent('openchange', { detail: { open: this._open } }));
41
- }
42
- }
43
-
44
- attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
45
- if (name === 'open') {
46
- this._open = newValue !== null;
47
- this._updateState();
48
- }
49
- }
50
-
51
- connectedCallback() {
52
- this.classList.add('relative', 'inline-block');
53
- this._bindElements();
54
- document.addEventListener('click', this._handleOutsideClick);
55
- document.addEventListener('keydown', this._handleKeyDown);
56
- }
57
-
58
- disconnectedCallback() {
59
- document.removeEventListener('click', this._handleOutsideClick);
60
- document.removeEventListener('keydown', this._handleKeyDown);
61
- }
62
-
63
- private _bindElements() {
64
- this._trigger = this.querySelector('[data-slot="popover-trigger"]');
65
- this._content = this.querySelector('[data-slot="popover-content"]');
66
-
67
- if (this._trigger) {
68
- this._trigger.setAttribute('aria-haspopup', 'dialog');
69
- this._trigger.setAttribute('aria-expanded', String(this._open));
70
- this._trigger.addEventListener('click', () => {
71
- this.open = !this.open;
72
- });
73
- }
74
-
75
- const closeButtons = this.querySelectorAll('[data-slot="popover-close"]');
76
- closeButtons.forEach((btn) => {
77
- btn.addEventListener('click', () => {
78
- this.open = false;
79
- });
80
- });
81
-
82
- this._updateState();
83
- }
84
-
85
- private _updateState() {
86
- if (this._trigger) {
87
- this._trigger.setAttribute('aria-expanded', String(this._open));
88
- }
89
- if (this._content) {
90
- if (this._open) {
91
- this._content.removeAttribute('hidden');
92
- this._content.setAttribute('data-open', '');
93
- } else {
94
- this._content.setAttribute('hidden', '');
95
- this._content.removeAttribute('data-open');
96
- }
97
- }
98
- }
99
- }
100
-
101
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-popover')) {
102
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-popover')) {
103
- customElements.define('surreal-shadcn-popover', SurrealShadcnPopover);
104
- }
105
- }
106
- export { SurrealShadcnPopover as MinimalistPopover, SurrealShadcnPopover };
107
-
108
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-popover')) {
109
- customElements.define('surreal-minimalist-popover', SurrealShadcnPopover);
110
- }
111
-
112
- export default SurrealShadcnPopover;
@@ -1,70 +0,0 @@
1
- import { cn } from '@surreal-ui/core';
2
-
3
- export class ProgressElement extends HTMLElement {
4
- private _indicator: HTMLDivElement | null = null;
5
-
6
- static get observedAttributes() {
7
- return ['value', 'max', 'class'];
8
- }
9
-
10
- connectedCallback() {
11
- this.render();
12
- }
13
-
14
- attributeChangedCallback() {
15
- this.update();
16
- }
17
-
18
- get value(): number {
19
- const val = this.getAttribute('value');
20
- return val !== null ? Number(val) : 0;
21
- }
22
-
23
- set value(val: number) {
24
- this.setAttribute('value', String(val));
25
- }
26
-
27
- get max(): number {
28
- const max = this.getAttribute('max');
29
- return max !== null ? Number(max) : 100;
30
- }
31
-
32
- set max(val: number) {
33
- this.setAttribute('max', String(val));
34
- }
35
-
36
- private update() {
37
- if (!this._indicator) return;
38
- const value = this.value;
39
- const max = this.max || 1;
40
- const percentage = 100 - (100 * (value ?? 0)) / max;
41
- this.setAttribute('role', 'progressbar');
42
- this.setAttribute('aria-valuemin', '0');
43
- this.setAttribute('aria-valuemax', String(max));
44
- this.setAttribute('aria-valuenow', String(value));
45
- this._indicator.style.transform = `translateX(-${percentage}%)`;
46
- }
47
-
48
- private render() {
49
- const customClass = this.getAttribute('class') || '';
50
- this.className = cn(
51
- 'h-1 rounded-full bg-muted relative flex w-full items-center overflow-x-hidden',
52
- customClass
53
- );
54
- this.setAttribute('data-slot', 'progress');
55
- this.innerHTML = `<div data-slot="progress-indicator" class="bg-primary size-full flex-1 transition-all duration-300"></div>`;
56
- this._indicator = this.querySelector('[data-slot="progress-indicator"]');
57
- this.update();
58
- }
59
- }
60
-
61
- if (!customElements.get('ui-progress')) {
62
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-progress')) {
63
- customElements.define('surreal-shadcn-progress', ProgressElement);
64
- }
65
- }
66
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-progress')) {
67
- customElements.define('surreal-minimalist-progress', ProgressElement);
68
- }
69
-
70
- export default ProgressElement;
@@ -1,228 +0,0 @@
1
- class SurrealShadcnRadioGroup extends HTMLElement {
2
- static get observedAttributes() {
3
- return ['value', 'disabled', 'name'];
4
- }
5
-
6
- constructor() {
7
- super();
8
- this.attachShadow({ mode: 'open' });
9
- this._value = this.getAttribute('value') || '';
10
- this._disabled = this.hasAttribute('disabled');
11
- this._name = this.getAttribute('name') || '';
12
- this._items = [];
13
- }
14
-
15
- connectedCallback() {
16
- this.render();
17
- this.setAttribute('role', 'radiogroup');
18
- this.setAttribute('data-slot', 'radio-group');
19
- this.className = `grid gap-2 w-full ${this.getAttribute('class') || ''}`.trim();
20
- this.shadowRoot.querySelector('slot').addEventListener('slotchange', () => this.syncItems());
21
- this.addEventListener('item-selected', (e: CustomEvent) => {
22
- this.value = e.detail.value;
23
- });
24
- this.syncItems();
25
- }
26
-
27
- attributeChangedCallback(name, oldValue, newValue) {
28
- if (oldValue === newValue) return;
29
- if (name === 'value') {
30
- this._value = newValue || '';
31
- this.syncItems();
32
- } else if (name === 'disabled') {
33
- this._disabled = this.hasAttribute('disabled');
34
- this.syncItems();
35
- } else if (name === 'name') {
36
- this._name = newValue || '';
37
- }
38
- }
39
-
40
- get value() {
41
- return this._value;
42
- }
43
-
44
- set value(val) {
45
- this._value = val;
46
- this.setAttribute('value', val);
47
- this.syncItems();
48
- this.dispatchEvent(new CustomEvent('change', { detail: { value: val }, bubbles: true }));
49
- }
50
-
51
- get disabled() {
52
- return this._disabled;
53
- }
54
-
55
- set disabled(val) {
56
- this._disabled = Boolean(val);
57
- if (this._disabled) {
58
- this.setAttribute('disabled', '');
59
- } else {
60
- this.removeAttribute('disabled');
61
- }
62
- this.syncItems();
63
- }
64
-
65
- syncItems() {
66
- const slot = this.shadowRoot.querySelector('slot');
67
- if (!slot) return;
68
- const assigned = slot.assignedElements({ flatten: true });
69
- const items = assigned.filter((el) => el.tagName.toLowerCase() === 'surreal-radio-item');
70
- items.forEach((item: any) => {
71
- item.checked = item.getAttribute('value') === this._value;
72
- if (this._disabled) {
73
- item.disabled = true;
74
- }
75
- });
76
- }
77
-
78
- render() {
79
- this.shadowRoot.innerHTML = `
80
- <style>
81
- :host { display: grid; gap: 0.5rem; width: 100%; }
82
- </style>
83
- <slot></slot>
84
- `;
85
- }
86
- }
87
-
88
- class SurrealRadioItem extends HTMLElement {
89
- static get observedAttributes() {
90
- return ['value', 'checked', 'disabled'];
91
- }
92
-
93
- constructor() {
94
- super();
95
- this.attachShadow({ mode: 'open' });
96
- this._checked = this.hasAttribute('checked');
97
- this._disabled = this.hasAttribute('disabled');
98
- this._value = this.getAttribute('value') || '';
99
- }
100
-
101
- connectedCallback() {
102
- this.render();
103
- this.shadowRoot.querySelector('button')?.addEventListener('click', () => {
104
- if (!this._disabled) {
105
- this.dispatchEvent(
106
- new CustomEvent('item-selected', {
107
- detail: { value: this._value },
108
- bubbles: true,
109
- composed: true
110
- })
111
- );
112
- }
113
- });
114
- }
115
-
116
- attributeChangedCallback(name, oldValue, newValue) {
117
- if (oldValue === newValue) return;
118
- if (name === 'checked') {
119
- this._checked = this.hasAttribute('checked');
120
- this.render();
121
- } else if (name === 'disabled') {
122
- this._disabled = this.hasAttribute('disabled');
123
- this.render();
124
- } else if (name === 'value') {
125
- this._value = newValue || '';
126
- }
127
- }
128
-
129
- get checked() {
130
- return this._checked;
131
- }
132
-
133
- set checked(val) {
134
- this._checked = Boolean(val);
135
- if (this._checked) {
136
- this.setAttribute('checked', '');
137
- } else {
138
- this.removeAttribute('checked');
139
- }
140
- this.render();
141
- }
142
-
143
- get disabled() {
144
- return this._disabled;
145
- }
146
-
147
- set disabled(val) {
148
- this._disabled = Boolean(val);
149
- if (this._disabled) {
150
- this.setAttribute('disabled', '');
151
- } else {
152
- this.removeAttribute('disabled');
153
- }
154
- this.render();
155
- }
156
-
157
- render() {
158
- this.shadowRoot.innerHTML = `
159
- <style>
160
- :host { display: inline-flex; align-items: center; justify-content: center; }
161
- button {
162
- all: unset;
163
- display: flex;
164
- width: 1rem;
165
- height: 1rem;
166
- border-radius: 9999px;
167
- border: 1px solid var(--input, #e4e4e7);
168
- align-items: center;
169
- justify-content: center;
170
- box-sizing: border-box;
171
- cursor: pointer;
172
- position: relative;
173
- background-color: transparent;
174
- outline: none;
175
- }
176
- button:focus-visible {
177
- outline: 2px solid var(--ring, #18181b);
178
- outline-offset: 2px;
179
- }
180
- button[data-state="checked"] {
181
- border-color: var(--primary, #18181b);
182
- background-color: var(--primary, #18181b);
183
- color: var(--primary-foreground, #fafafa);
184
- }
185
- button[disabled] {
186
- cursor: not-allowed;
187
- opacity: 0.5;
188
- }
189
- .indicator {
190
- display: ${this._checked ? 'block' : 'none'};
191
- width: 0.5rem;
192
- height: 0.5rem;
193
- border-radius: 9999px;
194
- background-color: currentColor;
195
- }
196
- </style>
197
- <button
198
- type="button"
199
- role="radio"
200
- aria-checked="${this._checked}"
201
- data-state="${this._checked ? 'checked' : 'unchecked'}"
202
- data-slot="radio-group-item"
203
- ${this._disabled ? 'disabled' : ''}
204
- >
205
- <span class="indicator" data-slot="radio-group-indicator"></span>
206
- </button>
207
- `;
208
- }
209
- }
210
-
211
- if (!customElements.get('surreal-radio-group')) {
212
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-radio-group')) {
213
- customElements.define('surreal-shadcn-radio-group', SurrealShadcnRadioGroup);
214
- }
215
- }
216
- if (!customElements.get('surreal-radio-item')) {
217
- customElements.define('surreal-shadcn-radio-group', SurrealRadioItem);
218
- }
219
- export { SurrealShadcnRadioGroup as MinimalistRadioGroup, SurrealShadcnRadioGroup };
220
-
221
- if (
222
- typeof customElements !== 'undefined' &&
223
- !customElements.get('surreal-minimalist-radio-group')
224
- ) {
225
- customElements.define('surreal-minimalist-radio-group', SurrealShadcnRadioGroup);
226
- }
227
-
228
- export default SurrealShadcnRadioGroup;