@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,141 @@
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
+
113
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-pagination')) {
114
+ customElements.define('surreal-shadcn-pagination', SurrealShadcnPagination);
115
+ }
116
+ }
117
+ if (!customElements.get('surreal-pagination-content')) {
118
+ customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationContent);
119
+ }
120
+ if (!customElements.get('surreal-pagination-item')) {
121
+ customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationItem);
122
+ }
123
+ if (!customElements.get('surreal-pagination-link')) {
124
+ customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationLink);
125
+ }
126
+ if (!customElements.get('surreal-pagination-previous')) {
127
+ customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationPrevious);
128
+ }
129
+ if (!customElements.get('surreal-pagination-next')) {
130
+ customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationNext);
131
+ }
132
+ if (!customElements.get('surreal-pagination-ellipsis')) {
133
+ customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationEllipsis);
134
+ };
135
+ export { SurrealShadcnPagination as MinimalistPagination, SurrealShadcnPagination };
136
+
137
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-pagination')) {
138
+ customElements.define('surreal-minimalist-pagination', SurrealShadcnPagination);
139
+ }
140
+
141
+ export default SurrealShadcnPagination;
@@ -0,0 +1,113 @@
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
+
103
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-popover')) {
104
+ customElements.define('surreal-shadcn-popover', SurrealShadcnPopover);
105
+ }
106
+ };
107
+ export { SurrealShadcnPopover as MinimalistPopover, SurrealShadcnPopover };
108
+
109
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-popover')) {
110
+ customElements.define('surreal-minimalist-popover', SurrealShadcnPopover);
111
+ }
112
+
113
+ export default SurrealShadcnPopover;
@@ -0,0 +1,71 @@
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
+
63
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-progress')) {
64
+ customElements.define('surreal-shadcn-progress', ProgressElement);
65
+ }
66
+ }
67
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-progress')) {
68
+ customElements.define('surreal-minimalist-progress', ProgressElement);
69
+ }
70
+
71
+ export default ProgressElement;
@@ -0,0 +1,226 @@
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
+
213
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-radio-group')) {
214
+ customElements.define('surreal-shadcn-radio-group', SurrealShadcnRadioGroup);
215
+ }
216
+ }
217
+ if (!customElements.get('surreal-radio-item')) {
218
+ customElements.define('surreal-shadcn-radio-group', SurrealRadioItem);
219
+ };
220
+ export { SurrealShadcnRadioGroup as MinimalistRadioGroup, SurrealShadcnRadioGroup };
221
+
222
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-radio-group')) {
223
+ customElements.define('surreal-minimalist-radio-group', SurrealShadcnRadioGroup);
224
+ }
225
+
226
+ export default SurrealShadcnRadioGroup;