@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,221 +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 ShadcnRadioGroup, SurrealShadcnRadioGroup };
220
-
221
- export default SurrealShadcnRadioGroup;
@@ -1,265 +0,0 @@
1
- class RangeCalendarComponent extends HTMLElement {
2
- private _startDate: Date | null = null;
3
- private _endDate: Date | null = null;
4
- private _hoveredDate: Date | null = null;
5
- private _currentMonth: Date = new Date();
6
- private _numberOfMonths: number = 1;
7
- private _locale: string = 'en-US';
8
-
9
- static get observedAttributes() {
10
- return ['start-date', 'end-date', 'number-of-months', 'locale'];
11
- }
12
-
13
- connectedCallback() {
14
- this.render();
15
- }
16
-
17
- attributeChangedCallback(name: string, oldValue: string, newValue: string) {
18
- if (oldValue === newValue) return;
19
- if (name === 'start-date' && newValue) this._startDate = new Date(newValue);
20
- if (name === 'end-date' && newValue) this._endDate = new Date(newValue);
21
- if (name === 'number-of-months') this._numberOfMonths = parseInt(newValue, 10) || 1;
22
- if (name === 'locale' && newValue) this._locale = newValue;
23
- this.render();
24
- }
25
-
26
- private isSameDay(d1: Date | null, d2: Date | null): boolean {
27
- if (!d1 || !d2) return false;
28
- return (
29
- d1.getFullYear() === d2.getFullYear() &&
30
- d1.getMonth() === d2.getMonth() &&
31
- d1.getDate() === d2.getDate()
32
- );
33
- }
34
-
35
- private isBeforeDay(d1: Date, d2: Date): boolean {
36
- const t1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()).getTime();
37
- const t2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()).getTime();
38
- return t1 < t2;
39
- }
40
-
41
- private isAfterDay(d1: Date, d2: Date): boolean {
42
- const t1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()).getTime();
43
- const t2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()).getTime();
44
- return t1 > t2;
45
- }
46
-
47
- private isBetween(d: Date, start: Date | null, end: Date | null): boolean {
48
- if (!start || !end) return false;
49
- return this.isAfterDay(d, start) && this.isBeforeDay(d, end);
50
- }
51
-
52
- private selectDate(date: Date) {
53
- if (!this._startDate || (this._startDate && this._endDate)) {
54
- this._startDate = date;
55
- this._endDate = null;
56
- } else {
57
- if (this.isBeforeDay(date, this._startDate)) {
58
- this._endDate = this._startDate;
59
- this._startDate = date;
60
- } else {
61
- this._endDate = date;
62
- }
63
- }
64
- this.dispatchEvent(
65
- new CustomEvent('range-change', {
66
- detail: { start: this._startDate, end: this._endDate },
67
- bubbles: true
68
- })
69
- );
70
- this.render();
71
- }
72
-
73
- private getMonthMatrix(year: number, month: number) {
74
- const firstDay = new Date(year, month, 1).getDay();
75
- const daysInMonth = new Date(year, month + 1, 0).getDate();
76
- const daysInPrevMonth = new Date(year, month, 0).getDate();
77
-
78
- const matrix: { date: Date; outside: boolean }[][] = [];
79
- let week: { date: Date; outside: boolean }[] = [];
80
-
81
- for (let i = firstDay - 1; i >= 0; i--) {
82
- week.push({ date: new Date(year, month - 1, daysInPrevMonth - i), outside: true });
83
- }
84
- for (let d = 1; d <= daysInMonth; d++) {
85
- if (week.length === 7) {
86
- matrix.push(week);
87
- week = [];
88
- }
89
- week.push({ date: new Date(year, month, d), outside: false });
90
- }
91
- let nextD = 1;
92
- while (week.length > 0 && week.length < 7) {
93
- week.push({ date: new Date(year, month + 1, nextD++), outside: true });
94
- }
95
- if (week.length > 0) matrix.push(week);
96
- return matrix;
97
- }
98
-
99
- render() {
100
- const weekdays = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
101
- let monthsHtml = '';
102
-
103
- for (let m = 0; m < this._numberOfMonths; m++) {
104
- const target = new Date(
105
- this._currentMonth.getFullYear(),
106
- this._currentMonth.getMonth() + m,
107
- 1
108
- );
109
- const matrix = this.getMonthMatrix(target.getFullYear(), target.getMonth());
110
- const monthTitle = new Intl.DateTimeFormat(this._locale, {
111
- month: 'long',
112
- year: 'numeric'
113
- }).format(target);
114
-
115
- const rowsHtml = matrix
116
- .map(
117
- (week) => `
118
- <tr class="flex w-full">
119
- ${week
120
- .map((cell) => {
121
- const isStart = this.isSameDay(cell.date, this._startDate);
122
- const isEnd = this.isSameDay(cell.date, this._endDate);
123
- const effectiveEnd =
124
- this._endDate ||
125
- (this._startDate &&
126
- this._hoveredDate &&
127
- this.isAfterDay(this._hoveredDate, this._startDate)
128
- ? this._hoveredDate
129
- : null);
130
- const isMiddle = this.isBetween(cell.date, this._startDate, effectiveEnd);
131
- const isToday = this.isSameDay(cell.date, new Date());
132
-
133
- let cellWrapClass = 'relative size-9 p-0 text-center text-sm focus-within:z-20';
134
- if (isStart && !isEnd && this._endDate) cellWrapClass += ' rounded-s-md bg-accent';
135
- if (isEnd && !isStart) cellWrapClass += ' rounded-e-md bg-accent';
136
- if (isMiddle) cellWrapClass += ' bg-accent rounded-none';
137
- if (isStart && isEnd) cellWrapClass += ' rounded-md';
138
-
139
- let btnClass =
140
- 'inline-flex size-9 items-center justify-center rounded-md text-sm font-normal transition-colors select-none';
141
- if (cell.outside) btnClass += ' text-muted-foreground opacity-50';
142
- if (isToday && !isStart && !isEnd)
143
- btnClass += ' bg-accent text-accent-foreground font-semibold';
144
- if (isStart || isEnd) {
145
- btnClass +=
146
- ' bg-primary text-primary-foreground font-semibold hover:bg-primary hover:text-primary-foreground';
147
- } else if (isMiddle) {
148
- btnClass += ' text-foreground rounded-none hover:bg-accent';
149
- } else {
150
- btnClass += ' hover:bg-accent hover:text-accent-foreground';
151
- }
152
-
153
- return `
154
- <td class="${cellWrapClass}">
155
- <button
156
- type="button"
157
- data-date="${cell.date.toISOString()}"
158
- class="${btnClass}"
159
- >
160
- ${cell.date.getDate()}
161
- </button>
162
- </td>
163
- `;
164
- })
165
- .join('')}
166
- </tr>
167
- `
168
- )
169
- .join('');
170
-
171
- monthsHtml += `
172
- <div class="flex flex-col gap-3">
173
- <div class="flex h-7 items-center justify-center">
174
- <span class="text-sm font-medium text-foreground">${monthTitle}</span>
175
- </div>
176
- <table class="w-full border-collapse space-y-1">
177
- <thead>
178
- <tr class="flex">
179
- ${weekdays
180
- .map(
181
- (w) =>
182
- `<th class="w-9 rounded-md text-[0.8rem] font-normal text-muted-foreground text-center">${w}</th>`
183
- )
184
- .join('')}
185
- </tr>
186
- </thead>
187
- <tbody class="flex flex-col gap-1 mt-2">
188
- ${rowsHtml}
189
- </tbody>
190
- </table>
191
- </div>
192
- `;
193
- }
194
-
195
- this.className = 'inline-block select-none';
196
- this.innerHTML = `
197
- <div data-slot="range-calendar" class="p-3 bg-background border border-border rounded-lg shadow-sm w-fit">
198
- <div class="relative flex flex-col gap-4 md:flex-row">
199
- <nav class="absolute inset-x-0 top-0 flex w-full items-center justify-between pointer-events-none z-10">
200
- <button
201
- type="button"
202
- id="prev-btn"
203
- aria-label="Previous Month"
204
- class="pointer-events-auto inline-flex size-7 items-center justify-center rounded-md border border-input bg-transparent text-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
205
- >
206
- <svg class="size-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" /></svg>
207
- </button>
208
- <button
209
- type="button"
210
- id="next-btn"
211
- aria-label="Next Month"
212
- class="pointer-events-auto inline-flex size-7 items-center justify-center rounded-md border border-input bg-transparent text-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
213
- >
214
- <svg class="size-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" /></svg>
215
- </button>
216
- </nav>
217
- ${monthsHtml}
218
- </div>
219
- </div>
220
- `;
221
-
222
- this.querySelector('#prev-btn')?.addEventListener('click', () => {
223
- this._currentMonth = new Date(
224
- this._currentMonth.getFullYear(),
225
- this._currentMonth.getMonth() - 1,
226
- 1
227
- );
228
- this.render();
229
- });
230
-
231
- this.querySelector('#next-btn')?.addEventListener('click', () => {
232
- this._currentMonth = new Date(
233
- this._currentMonth.getFullYear(),
234
- this._currentMonth.getMonth() + 1,
235
- 1
236
- );
237
- this.render();
238
- });
239
-
240
- this.querySelectorAll('button[data-date]').forEach((btn) => {
241
- const dateStr = btn.getAttribute('data-date');
242
- if (!dateStr) return;
243
- const d = new Date(dateStr);
244
- btn.addEventListener('click', () => this.selectDate(d));
245
- btn.addEventListener('mouseenter', () => {
246
- if (this._startDate && !this._endDate) {
247
- this._hoveredDate = d;
248
- this.render();
249
- }
250
- });
251
- });
252
- }
253
- }
254
-
255
- if (!customElements.get('range-calendar')) {
256
- if (
257
- typeof customElements !== 'undefined' &&
258
- !customElements.get('surreal-shadcn-range-calendar')
259
- ) {
260
- customElements.define('surreal-shadcn-range-calendar', RangeCalendarComponent);
261
- }
262
- }
263
- export { RangeCalendarComponent as ShadcnRangeCalendar, RangeCalendarComponent };
264
-
265
- export default RangeCalendarComponent;
@@ -1,99 +0,0 @@
1
- class SurrealShadcnSelect extends HTMLElement {
2
- private _open: boolean = false;
3
- private _value: string = '';
4
-
5
- static get observedAttributes() {
6
- return ['open', 'value', 'size'];
7
- }
8
-
9
- constructor() {
10
- super();
11
- this.attachShadow({ mode: 'open' });
12
- }
13
-
14
- connectedCallback() {
15
- this.render();
16
- this.setupListeners();
17
- }
18
-
19
- attributeChangedCallback(name: string, oldValue: string, newValue: string) {
20
- if (oldValue !== newValue) {
21
- if (name === 'open') this._open = this.hasAttribute('open');
22
- if (name === 'value') this._value = newValue || '';
23
- this.render();
24
- }
25
- }
26
-
27
- get value(): string {
28
- return this._value;
29
- }
30
-
31
- set value(val: string) {
32
- this._value = val;
33
- this.setAttribute('value', val);
34
- }
35
-
36
- get open(): boolean {
37
- return this._open;
38
- }
39
-
40
- set open(val: boolean) {
41
- this._open = val;
42
- if (val) this.setAttribute('open', '');
43
- else this.removeAttribute('open');
44
- }
45
-
46
- private setupListeners() {
47
- this.shadowRoot?.addEventListener('click', (e) => {
48
- const target = e.target as HTMLElement;
49
- const trigger = target.closest('[data-slot="select-trigger"]');
50
- if (trigger) {
51
- this.open = !this.open;
52
- return;
53
- }
54
- const item = target.closest('[data-slot="select-item"]') as HTMLElement;
55
- if (item && !item.hasAttribute('data-disabled')) {
56
- const val = item.getAttribute('data-value') || '';
57
- this.value = val;
58
- this.open = false;
59
- this.dispatchEvent(new CustomEvent('change', { detail: { value: val }, bubbles: true }));
60
- }
61
- });
62
- }
63
-
64
- private render() {
65
- if (!this.shadowRoot) return;
66
- const size = this.getAttribute('size') || 'default';
67
- const isOpen = this.hasAttribute('open');
68
-
69
- this.shadowRoot.innerHTML = `
70
- <div class="relative inline-block text-left">
71
- <button
72
- type="button"
73
- data-slot="select-trigger"
74
- data-size="${size}"
75
- class="gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm transition-colors select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 data-[size=default]:h-8 data-[size=sm]:h-7 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50"
76
- >
77
- <slot name="trigger-value"><span>${this._value || 'Select an option'}</span></slot>
78
- <svg class="size-4 text-muted-foreground pointer-events-none" 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="m6 9 6 6 6-6"/></svg>
79
- </button>
80
- <div
81
- data-slot="select-content"
82
- style="display: ${isOpen ? 'block' : 'none'};"
83
- class="min-w-36 rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 absolute z-50 overflow-x-hidden overflow-y-auto mt-1 p-1"
84
- >
85
- <slot></slot>
86
- </div>
87
- </div>
88
- `;
89
- }
90
- }
91
-
92
- if (!customElements.get('surreal-select')) {
93
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-select')) {
94
- customElements.define('surreal-shadcn-select', SurrealShadcnSelect);
95
- }
96
- }
97
- export { SurrealShadcnSelect as ShadcnSelect, SurrealShadcnSelect };
98
-
99
- export default SurrealShadcnSelect;
@@ -1,48 +0,0 @@
1
- import { cn } from '@surreal-ui/core';
2
-
3
- export class SurrealShadcnSeparator extends HTMLElement {
4
- static get observedAttributes() {
5
- return ['orientation', 'decorative', 'class'];
6
- }
7
-
8
- connectedCallback() {
9
- this.render();
10
- }
11
-
12
- attributeChangedCallback() {
13
- this.render();
14
- }
15
-
16
- render() {
17
- const orientation = this.getAttribute('orientation') || 'horizontal';
18
- const decorative = this.getAttribute('decorative') !== 'false';
19
- const customClass = this.getAttribute('class') || '';
20
-
21
- this.setAttribute('data-slot', 'separator');
22
- this.setAttribute('data-orientation', orientation);
23
-
24
- if (decorative) {
25
- this.setAttribute('role', 'none');
26
- this.removeAttribute('aria-orientation');
27
- } else {
28
- this.setAttribute('role', 'separator');
29
- if (orientation === 'vertical') {
30
- this.setAttribute('aria-orientation', 'vertical');
31
- } else {
32
- this.removeAttribute('aria-orientation');
33
- }
34
- }
35
-
36
- this.className = cn(
37
- 'shrink-0 bg-border block data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px data-[orientation=vertical]:h-full',
38
- customClass
39
- );
40
- }
41
- }
42
-
43
- if (!customElements.get('surreal-separator')) {
44
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-separator')) {
45
- customElements.define('surreal-shadcn-separator', SurrealShadcnSeparator);
46
- }
47
- }
48
- export default SurrealShadcnSeparator;