@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,162 @@
1
+ class SurrealShadcnSwitch extends HTMLElement {
2
+ static get observedAttributes() {
3
+ return ['checked', 'disabled', 'size', 'class'];
4
+ }
5
+
6
+ private _button: HTMLButtonElement;
7
+ private _thumb: HTMLSpanElement;
8
+
9
+ constructor() {
10
+ super();
11
+ this.attachShadow({ mode: 'open' });
12
+ this.shadowRoot!.innerHTML = `
13
+ <style>
14
+ :host {
15
+ display: inline-flex;
16
+ vertical-align: middle;
17
+ }
18
+ button {
19
+ box-sizing: border-box;
20
+ position: relative;
21
+ display: inline-flex;
22
+ align-items: center;
23
+ flex-shrink: 0;
24
+ border-radius: 9999px;
25
+ border: 1px solid transparent;
26
+ background-color: var(--input, #e4e4e7);
27
+ cursor: pointer;
28
+ user-select: none;
29
+ padding: 0;
30
+ outline: none;
31
+ transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1);
32
+ }
33
+ button:focus-visible {
34
+ box-shadow: 0 0 0 3px var(--ring, rgba(24, 24, 27, 0.5));
35
+ }
36
+ button[data-state="checked"] {
37
+ background-color: var(--primary, #18181b);
38
+ }
39
+ button:disabled {
40
+ cursor: not-allowed;
41
+ opacity: 0.5;
42
+ }
43
+ button[data-size="default"] {
44
+ height: 18.4px;
45
+ width: 32px;
46
+ }
47
+ button[data-size="sm"] {
48
+ height: 14px;
49
+ width: 24px;
50
+ }
51
+ .thumb {
52
+ pointer-events: none;
53
+ display: block;
54
+ border-radius: 9999px;
55
+ background-color: var(--background, #ffffff);
56
+ transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
57
+ }
58
+ button[data-size="default"] .thumb {
59
+ width: 16px;
60
+ height: 16px;
61
+ transform: translateX(0px);
62
+ }
63
+ button[data-size="default"][data-state="checked"] .thumb {
64
+ transform: translateX(14px);
65
+ }
66
+ button[data-size="sm"] .thumb {
67
+ width: 12px;
68
+ height: 12px;
69
+ transform: translateX(0px);
70
+ }
71
+ button[data-size="sm"][data-state="checked"] .thumb {
72
+ transform: translateX(10px);
73
+ }
74
+ </style>
75
+ <button type="button" role="switch" part="control">
76
+ <span class="thumb" part="thumb"></span>
77
+ </button>
78
+ `;
79
+ this._button = this.shadowRoot!.querySelector('button')!;
80
+ this._thumb = this.shadowRoot!.querySelector('.thumb')!;
81
+
82
+ this._button.addEventListener('click', () => this._toggle());
83
+ this._button.addEventListener('keydown', (e) => {
84
+ if (e.key === ' ' || e.key === 'Enter') {
85
+ e.preventDefault();
86
+ this._toggle();
87
+ }
88
+ });
89
+ }
90
+
91
+ get checked(): boolean {
92
+ return this.hasAttribute('checked');
93
+ }
94
+
95
+ set checked(val: boolean) {
96
+ if (val) {
97
+ this.setAttribute('checked', '');
98
+ } else {
99
+ this.removeAttribute('checked');
100
+ }
101
+ }
102
+
103
+ get disabled(): boolean {
104
+ return this.hasAttribute('disabled');
105
+ }
106
+
107
+ set disabled(val: boolean) {
108
+ if (val) {
109
+ this.setAttribute('disabled', '');
110
+ } else {
111
+ this.removeAttribute('disabled');
112
+ }
113
+ }
114
+
115
+ get size(): string {
116
+ return this.getAttribute('size') || 'default';
117
+ }
118
+
119
+ set size(val: string) {
120
+ this.setAttribute('size', val);
121
+ }
122
+
123
+ private _toggle() {
124
+ if (this.disabled) return;
125
+ this.checked = !this.checked;
126
+ this.dispatchEvent(
127
+ new CustomEvent('change', {
128
+ detail: { checked: this.checked },
129
+ bubbles: true,
130
+ composed: true,
131
+ }),
132
+ );
133
+ }
134
+
135
+ connectedCallback() {
136
+ this._update();
137
+ }
138
+
139
+ attributeChangedCallback() {
140
+ this._update();
141
+ }
142
+
143
+ private _update() {
144
+ const isChecked = this.checked;
145
+ const isDisabled = this.disabled;
146
+ const size = this.size;
147
+
148
+ this._button.setAttribute('data-state', isChecked ? 'checked' : 'unchecked');
149
+ this._button.setAttribute('aria-checked', String(isChecked));
150
+ this._button.setAttribute('data-size', size);
151
+ this._button.disabled = isDisabled;
152
+ }
153
+ }
154
+
155
+ if (!customElements.get('surreal-switch')) {
156
+
157
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-switch')) {
158
+ customElements.define('surreal-shadcn-switch', SurrealShadcnSwitch);
159
+ }
160
+ }
161
+ export { SurrealShadcnSwitch };
162
+ export default SurrealShadcnSwitch;
@@ -0,0 +1,94 @@
1
+ class SurrealShadcnTabs extends HTMLElement {
2
+ private _value: string = '';
3
+ private _orientation: string = 'horizontal';
4
+
5
+ static get observedAttributes() {
6
+ return ['value', 'orientation'];
7
+ }
8
+
9
+ connectedCallback() {
10
+ if (!this.getAttribute('data-slot')) {
11
+ this.setAttribute('data-slot', 'tabs');
12
+ }
13
+ this._value = this.getAttribute('value') || this.getAttribute('default-value') || '';
14
+ this._orientation = this.getAttribute('orientation') || 'horizontal';
15
+ this.updateClasses();
16
+ this.syncChildren();
17
+
18
+ this.addEventListener('click', this.handleClick.bind(this));
19
+ }
20
+
21
+ attributeChangedCallback(name: string, oldValue: string, newValue: string) {
22
+ if (oldValue === newValue) return;
23
+ if (name === 'value') {
24
+ this._value = newValue || '';
25
+ this.syncChildren();
26
+ } else if (name === 'orientation') {
27
+ this._orientation = newValue || 'horizontal';
28
+ this.updateClasses();
29
+ }
30
+ }
31
+
32
+ get value() {
33
+ return this._value;
34
+ }
35
+
36
+ set value(val: string) {
37
+ this._value = val;
38
+ this.setAttribute('value', val);
39
+ this.syncChildren();
40
+ }
41
+
42
+ private updateClasses() {
43
+ this.setAttribute('data-orientation', this._orientation);
44
+ const base = 'gap-2 group/tabs flex data-[orientation=horizontal]:flex-col';
45
+ const custom = this.getAttribute('class') || '';
46
+ if (!custom.includes('group/tabs')) {
47
+ this.className = `${base} ${custom}`.trim();
48
+ }
49
+ }
50
+
51
+ private handleClick(e: MouseEvent) {
52
+ const target = (e.target as HTMLElement).closest(
53
+ '[data-slot="tabs-trigger"]',
54
+ ) as HTMLElement | null;
55
+ if (target && this.contains(target) && !target.hasAttribute('disabled')) {
56
+ const nextVal = target.getAttribute('value') || target.getAttribute('data-value') || '';
57
+ if (nextVal && nextVal !== this._value) {
58
+ this.value = nextVal;
59
+ this.dispatchEvent(
60
+ new CustomEvent('change', { detail: { value: nextVal }, bubbles: true }),
61
+ );
62
+ }
63
+ }
64
+ }
65
+
66
+ private syncChildren() {
67
+ const triggers = this.querySelectorAll('[data-slot="tabs-trigger"]');
68
+ triggers.forEach((trigger) => {
69
+ const tVal = trigger.getAttribute('value') || trigger.getAttribute('data-value');
70
+ const isActive = tVal === this._value;
71
+ trigger.setAttribute('data-state', isActive ? 'active' : 'inactive');
72
+ trigger.setAttribute('aria-selected', isActive ? 'true' : 'false');
73
+ trigger.setAttribute('tabindex', isActive ? '0' : '-1');
74
+ });
75
+
76
+ const contents = this.querySelectorAll('[data-slot="tabs-content"]');
77
+ contents.forEach((content) => {
78
+ const cVal = content.getAttribute('value') || content.getAttribute('data-value');
79
+ const isActive = cVal === this._value;
80
+ content.setAttribute('data-state', isActive ? 'active' : 'inactive');
81
+ (content as HTMLElement).style.display = isActive ? '' : 'none';
82
+ });
83
+ }
84
+ }
85
+
86
+ if (typeof window !== 'undefined' && !customElements.get('surreal-tabs')) {
87
+
88
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-tabs')) {
89
+ customElements.define('surreal-shadcn-tabs', SurrealShadcnTabs);
90
+ }
91
+ };
92
+ export { SurrealShadcnTabs as ShadcnTabs, SurrealShadcnTabs };
93
+
94
+ export default SurrealShadcnTabs;
@@ -0,0 +1,96 @@
1
+ import { cn } from '@surreal-ui/core';
2
+
3
+ export class SurrealShadcnTextarea extends HTMLElement {
4
+ private _textarea: HTMLTextAreaElement;
5
+
6
+ static get observedAttributes() {
7
+ return [
8
+ 'placeholder',
9
+ 'disabled',
10
+ 'rows',
11
+ 'value',
12
+ 'name',
13
+ 'required',
14
+ 'aria-invalid',
15
+ 'class',
16
+ ];
17
+ }
18
+
19
+ constructor() {
20
+ super();
21
+ this._textarea = document.createElement('textarea');
22
+ this._textarea.setAttribute('data-slot', 'textarea');
23
+ this.updateClasses();
24
+ }
25
+
26
+ connectedCallback() {
27
+ if (!this.contains(this._textarea)) {
28
+ this.appendChild(this._textarea);
29
+ }
30
+ this.syncAllAttributes();
31
+ this._textarea.addEventListener('input', (e) => {
32
+ this.dispatchEvent(
33
+ new CustomEvent('input', {
34
+ bubbles: true,
35
+ composed: true,
36
+ detail: (e.target as HTMLTextAreaElement).value,
37
+ }),
38
+ );
39
+ });
40
+ this._textarea.addEventListener('change', (e) => {
41
+ this.dispatchEvent(
42
+ new CustomEvent('change', {
43
+ bubbles: true,
44
+ composed: true,
45
+ detail: (e.target as HTMLTextAreaElement).value,
46
+ }),
47
+ );
48
+ });
49
+ }
50
+
51
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
52
+ if (name === 'class') {
53
+ this.updateClasses();
54
+ } else if (name === 'value') {
55
+ this._textarea.value = newValue ?? '';
56
+ } else if (name === 'disabled') {
57
+ this._textarea.disabled = this.hasAttribute('disabled');
58
+ } else if (newValue === null) {
59
+ this._textarea.removeAttribute(name);
60
+ } else {
61
+ this._textarea.setAttribute(name, newValue);
62
+ }
63
+ }
64
+
65
+ private updateClasses() {
66
+ this._textarea.className = cn(
67
+ 'rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 flex field-sizing-content min-h-16 w-full outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
68
+ this.getAttribute('class'),
69
+ );
70
+ }
71
+
72
+ private syncAllAttributes() {
73
+ Array.from(this.attributes).forEach((attr) => {
74
+ if (attr.name !== 'class') {
75
+ this._textarea.setAttribute(attr.name, attr.value);
76
+ }
77
+ });
78
+ this.updateClasses();
79
+ }
80
+
81
+ get value(): string {
82
+ return this._textarea.value;
83
+ }
84
+
85
+ set value(val: string) {
86
+ this._textarea.value = val;
87
+ }
88
+ }
89
+
90
+ if (!customElements.get('surreal-textarea')) {
91
+
92
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-textarea')) {
93
+ customElements.define('surreal-shadcn-textarea', SurrealShadcnTextarea);
94
+ }
95
+ }
96
+ export default SurrealShadcnTextarea;
@@ -0,0 +1,101 @@
1
+ import { cn, cva } from '@surreal-ui/core';
2
+
3
+ const toggleVariants = cva(
4
+ "gap-1 rounded-lg text-sm font-medium transition-all hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted data-[state=on]:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 group/toggle inline-flex items-center justify-center whitespace-nowrap outline-none hover:bg-muted focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 cursor-pointer",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ default: 'bg-transparent',
9
+ outline: 'border border-input bg-transparent hover:bg-muted',
10
+ },
11
+ size: {
12
+ default:
13
+ 'h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
14
+ sm: "h-7 min-w-7 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
15
+ lg: 'h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
16
+ },
17
+ },
18
+ defaultVariants: {
19
+ variant: 'default',
20
+ size: 'default',
21
+ },
22
+ },
23
+ );
24
+
25
+ export class SurrealShadcnToggle extends HTMLElement {
26
+ static get observedAttributes() {
27
+ return ['pressed', 'variant', 'size', 'disabled'];
28
+ }
29
+
30
+ private button: HTMLButtonElement;
31
+
32
+ constructor() {
33
+ super();
34
+ this.button = document.createElement('button');
35
+ this.button.type = 'button';
36
+ this.button.setAttribute('data-slot', 'toggle');
37
+ }
38
+
39
+ connectedCallback() {
40
+ if (!this.button.parentNode) {
41
+ while (this.firstChild) {
42
+ this.button.appendChild(this.firstChild);
43
+ }
44
+ this.appendChild(this.button);
45
+ }
46
+ this.button.addEventListener('click', this.handleClick);
47
+ this.render();
48
+ }
49
+
50
+ disconnectedCallback() {
51
+ this.button.removeEventListener('click', this.handleClick);
52
+ }
53
+
54
+ attributeChangedCallback() {
55
+ this.render();
56
+ }
57
+
58
+ get pressed(): boolean {
59
+ return this.hasAttribute('pressed');
60
+ }
61
+
62
+ set pressed(value: boolean) {
63
+ if (value) {
64
+ this.setAttribute('pressed', '');
65
+ } else {
66
+ this.removeAttribute('pressed');
67
+ }
68
+ }
69
+
70
+ private handleClick = () => {
71
+ if (this.hasAttribute('disabled')) return;
72
+ this.pressed = !this.pressed;
73
+ this.dispatchEvent(
74
+ new CustomEvent('change', {
75
+ detail: { pressed: this.pressed },
76
+ bubbles: true,
77
+ composed: true,
78
+ }),
79
+ );
80
+ };
81
+
82
+ private render() {
83
+ const variant = (this.getAttribute('variant') as 'default' | 'outline') || 'default';
84
+ const size = (this.getAttribute('size') as 'default' | 'sm' | 'lg') || 'default';
85
+ const isPressed = this.pressed;
86
+ const disabled = this.hasAttribute('disabled');
87
+
88
+ this.button.className = cn(toggleVariants({ variant, size }), this.getAttribute('class') || '');
89
+ this.button.setAttribute('aria-pressed', String(isPressed));
90
+ this.button.setAttribute('data-state', isPressed ? 'on' : 'off');
91
+ this.button.disabled = disabled;
92
+ }
93
+ }
94
+
95
+ if (!customElements.get('surreal-toggle')) {
96
+
97
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-toggle')) {
98
+ customElements.define('surreal-shadcn-toggle', SurrealShadcnToggle);
99
+ }
100
+ }
101
+ export default SurrealShadcnToggle;
@@ -0,0 +1,171 @@
1
+ export class ToggleGroupComponent extends HTMLElement {
2
+ private _value: string | string[] = '';
3
+
4
+ static get observedAttributes() {
5
+ return ['type', 'value', 'variant', 'size', 'spacing', 'orientation', 'disabled'];
6
+ }
7
+
8
+ constructor() {
9
+ super();
10
+ }
11
+
12
+ connectedCallback() {
13
+ this.setAttribute('role', 'group');
14
+ this.setAttribute('data-slot', 'toggle-group');
15
+ this.updateClasses();
16
+ this.syncItems();
17
+ this.addEventListener('click', this.handleClick.bind(this));
18
+ }
19
+
20
+ attributeChangedCallback() {
21
+ this.updateClasses();
22
+ this.syncItems();
23
+ }
24
+
25
+ get type(): 'single' | 'multiple' {
26
+ return (this.getAttribute('type') as 'single' | 'multiple') || 'single';
27
+ }
28
+
29
+ get variant(): string {
30
+ return this.getAttribute('variant') || 'default';
31
+ }
32
+
33
+ get size(): string {
34
+ return this.getAttribute('size') || 'default';
35
+ }
36
+
37
+ get spacing(): string {
38
+ return this.getAttribute('spacing') || '0';
39
+ }
40
+
41
+ get orientation(): string {
42
+ return this.getAttribute('orientation') || 'horizontal';
43
+ }
44
+
45
+ get value(): string | string[] {
46
+ const attr = this.getAttribute('value');
47
+ if (this.type === 'multiple') {
48
+ return attr ? attr.split(',').map((s) => s.trim()) : [];
49
+ }
50
+ return attr || '';
51
+ }
52
+
53
+ set value(val: string | string[]) {
54
+ if (Array.isArray(val)) {
55
+ this.setAttribute('value', val.join(','));
56
+ } else {
57
+ this.setAttribute('value', val);
58
+ }
59
+ this.syncItems();
60
+ }
61
+
62
+ private updateClasses() {
63
+ const orientation = this.orientation;
64
+ const spacing = this.spacing;
65
+ const size = this.size;
66
+ const variant = this.variant;
67
+
68
+ this.setAttribute('data-variant', variant);
69
+ this.setAttribute('data-size', size);
70
+ this.setAttribute('data-spacing', spacing);
71
+ this.setAttribute('data-orientation', orientation);
72
+ this.style.gap = `${spacing}px`;
73
+
74
+ const baseClasses =
75
+ 'rounded-lg group/toggle-group flex w-fit flex-row items-center data-[orientation=vertical]:flex-col data-[orientation=vertical]:items-stretch';
76
+ this.className = baseClasses;
77
+ }
78
+
79
+ private handleClick(e: MouseEvent) {
80
+ const item = (e.target as HTMLElement).closest(
81
+ 'toggle-group-item',
82
+ ) as ToggleGroupItemComponent | null;
83
+ if (!item || item.hasAttribute('disabled') || this.hasAttribute('disabled')) return;
84
+
85
+ const itemValue = item.getAttribute('value') || '';
86
+ if (this.type === 'single') {
87
+ const next = this.value === itemValue ? '' : itemValue;
88
+ this.value = next;
89
+ this.dispatchEvent(new CustomEvent('change', { detail: { value: next } }));
90
+ } else {
91
+ const current = Array.isArray(this.value) ? [...this.value] : this.value ? [this.value] : [];
92
+ const idx = current.indexOf(itemValue);
93
+ if (idx > -1) {
94
+ current.splice(idx, 1);
95
+ } else {
96
+ current.push(itemValue);
97
+ }
98
+ this.value = current;
99
+ this.dispatchEvent(new CustomEvent('change', { detail: { value: current } }));
100
+ }
101
+ }
102
+
103
+ syncItems() {
104
+ const items = this.querySelectorAll('toggle-group-item');
105
+ const currentVal = this.value;
106
+ items.forEach((item) => {
107
+ const val = item.getAttribute('value') || '';
108
+ const isSelected = Array.isArray(currentVal) ? currentVal.includes(val) : currentVal === val;
109
+ item.setAttribute('data-state', isSelected ? 'on' : 'off');
110
+ item.setAttribute('aria-checked', isSelected ? 'true' : 'false');
111
+ if (!item.getAttribute('variant')) {
112
+ item.setAttribute('data-variant', this.variant);
113
+ }
114
+ if (!item.getAttribute('size')) {
115
+ item.setAttribute('data-size', this.size);
116
+ }
117
+ item.setAttribute('data-spacing', this.spacing);
118
+ (item as ToggleGroupItemComponent).updateState?.();
119
+ });
120
+ }
121
+ }
122
+
123
+ export class ToggleGroupItemComponent extends HTMLElement {
124
+ static get observedAttributes() {
125
+ return ['value', 'variant', 'size', 'disabled', 'data-state'];
126
+ }
127
+
128
+ connectedCallback() {
129
+ this.setAttribute('role', 'radio');
130
+ this.setAttribute('data-slot', 'toggle-group-item');
131
+ this.tabIndex = 0;
132
+ this.updateState();
133
+ }
134
+
135
+ attributeChangedCallback() {
136
+ this.updateState();
137
+ }
138
+
139
+ updateState() {
140
+ const variant = this.getAttribute('data-variant') || this.getAttribute('variant') || 'default';
141
+ const size = this.getAttribute('data-size') || this.getAttribute('size') || 'default';
142
+ const isOutline = variant === 'outline';
143
+ const isSm = size === 'sm';
144
+ const isLg = size === 'lg';
145
+
146
+ const base =
147
+ 'inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors cursor-pointer select-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-data-[spacing=0]/toggle-group:rounded-none group-data-[spacing=0]/toggle-group:px-2 group-data-horizontal/toggle-group:data-[spacing=0]:first:rounded-l-lg group-data-vertical/toggle-group:data-[spacing=0]:first:rounded-t-lg group-data-horizontal/toggle-group:data-[spacing=0]:last:rounded-r-lg group-data-vertical/toggle-group:data-[spacing=0]:last:rounded-b-lg shrink-0 focus:z-10 focus-visible:z-10';
148
+ const variantClasses = isOutline
149
+ ? 'border border-input bg-transparent hover:bg-accent hover:text-accent-foreground data-[state=on]:bg-accent data-[state=on]:text-accent-foreground group-data-horizontal/toggle-group:data-[spacing=0]:border-l-0 group-data-horizontal/toggle-group:data-[spacing=0]:first:border-l group-data-vertical/toggle-group:data-[spacing=0]:border-t-0 group-data-vertical/toggle-group:data-[spacing=0]:first:border-t'
150
+ : 'bg-transparent hover:bg-muted hover:text-muted-foreground data-[state=on]:bg-accent data-[state=on]:text-accent-foreground';
151
+ const sizeClasses = isSm
152
+ ? 'h-8 px-2 min-w-8 text-xs'
153
+ : isLg
154
+ ? 'h-10 px-3 min-w-10'
155
+ : 'h-9 px-3 min-w-9';
156
+
157
+ this.className = `${base} ${variantClasses} ${sizeClasses}`;
158
+ }
159
+ }
160
+
161
+ if (!customElements.get('toggle-group')) {
162
+
163
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-toggle-group')) {
164
+ customElements.define('surreal-shadcn-toggle-group', ToggleGroupComponent);
165
+ }
166
+ }
167
+
168
+ if (!customElements.get('toggle-group-item')) {
169
+ customElements.define('surreal-shadcn-toggle-group', ToggleGroupItemComponent);
170
+ }
171
+ export default ToggleGroupComponent;