@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.
- package/CHANGELOG.md +69 -0
- package/dist/index.js +12075 -0
- package/package.json +27 -0
- package/src/components/GlassmorphismAlert.ts +116 -0
- package/src/components/GlassmorphismButton.ts +19 -0
- package/src/components/GlassmorphismCard.ts +33 -0
- package/src/components/GlassmorphismEmptyState.ts +29 -0
- package/src/components/GlassmorphismInputGroup.ts +202 -0
- package/src/components/GlassmorphismMenubar.ts +36 -0
- package/src/components/GlassmorphismScrollArea.ts +83 -0
- package/src/components/GlassmorphismTable.ts +52 -0
- package/src/components/GlassmorphismTypography.ts +67 -0
- package/src/components/MinimalistAccordion.ts +248 -0
- package/src/components/MinimalistAlert.ts +99 -0
- package/src/components/MinimalistAlertDialog.ts +100 -0
- package/src/components/MinimalistAspectRatio.ts +34 -0
- package/src/components/MinimalistAvatar.ts +98 -0
- package/src/components/MinimalistBadge.ts +71 -0
- package/src/components/MinimalistBreadcrumb.ts +92 -0
- package/src/components/MinimalistButton.ts +111 -0
- package/src/components/MinimalistButtonGroup.ts +110 -0
- package/src/components/MinimalistCalendar.ts +282 -0
- package/src/components/MinimalistCard.ts +131 -0
- package/src/components/MinimalistCarousel.ts +122 -0
- package/src/components/MinimalistChart.ts +151 -0
- package/src/components/MinimalistCheckbox.ts +179 -0
- package/src/components/MinimalistCodeBlock.ts +113 -0
- package/src/components/MinimalistCollapsible.ts +155 -0
- package/src/components/MinimalistCommand.ts +112 -0
- package/src/components/MinimalistContextMenu.ts +99 -0
- package/src/components/MinimalistDialog.ts +104 -0
- package/src/components/MinimalistDrawer.ts +223 -0
- package/src/components/MinimalistDropdownMenu.ts +120 -0
- package/src/components/MinimalistEmpty.ts +98 -0
- package/src/components/MinimalistEmptyState.ts +38 -0
- package/src/components/MinimalistField.ts +171 -0
- package/src/components/MinimalistForm.ts +101 -0
- package/src/components/MinimalistHoverCard.ts +150 -0
- package/src/components/MinimalistInput.ts +105 -0
- package/src/components/MinimalistInputGroup.ts +93 -0
- package/src/components/MinimalistInputOtp.ts +155 -0
- package/src/components/MinimalistItem.ts +160 -0
- package/src/components/MinimalistKbd.ts +38 -0
- package/src/components/MinimalistLabel.ts +54 -0
- package/src/components/MinimalistMenubar.ts +82 -0
- package/src/components/MinimalistNativeSelect.ts +144 -0
- package/src/components/MinimalistNavigationMenu.ts +98 -0
- package/src/components/MinimalistPagination.ts +141 -0
- package/src/components/MinimalistPopover.ts +113 -0
- package/src/components/MinimalistProgress.ts +71 -0
- package/src/components/MinimalistRadioGroup.ts +226 -0
- package/src/components/MinimalistRangeCalendar.ts +267 -0
- package/src/components/MinimalistResizable.ts +44 -0
- package/src/components/MinimalistScrollArea.ts +11 -0
- package/src/components/MinimalistSelect.ts +104 -0
- package/src/components/MinimalistSeparator.ts +53 -0
- package/src/components/MinimalistSheet.ts +166 -0
- package/src/components/MinimalistSidebar.ts +75 -0
- package/src/components/MinimalistSkeleton.ts +33 -0
- package/src/components/MinimalistSlider.ts +237 -0
- package/src/components/MinimalistSonner.ts +94 -0
- package/src/components/MinimalistSpinner.ts +53 -0
- package/src/components/MinimalistSwitch.ts +166 -0
- package/src/components/MinimalistTable.ts +35 -0
- package/src/components/MinimalistTabs.ts +98 -0
- package/src/components/MinimalistTextarea.ts +100 -0
- package/src/components/MinimalistToggle.ts +105 -0
- package/src/components/MinimalistToggleGroup.ts +175 -0
- package/src/components/MinimalistTooltip.ts +83 -0
- package/src/components/MinimalistTypography.ts +107 -0
- package/src/components/NeubrutalismCard.ts +35 -0
- package/src/components/NeubrutalismItem.ts +67 -0
- package/src/components/ShadcnAccordion.ts +244 -0
- package/src/components/ShadcnAlertDialog.ts +96 -0
- package/src/components/ShadcnAspectRatio.ts +30 -0
- package/src/components/ShadcnAvatar.ts +94 -0
- package/src/components/ShadcnBadge.ts +67 -0
- package/src/components/ShadcnBreadcrumb.ts +88 -0
- package/src/components/ShadcnButton.ts +107 -0
- package/src/components/ShadcnButtonGroup.ts +106 -0
- package/src/components/ShadcnCalendar.ts +278 -0
- package/src/components/ShadcnCarousel.ts +118 -0
- package/src/components/ShadcnChart.ts +147 -0
- package/src/components/ShadcnCheckbox.ts +175 -0
- package/src/components/ShadcnCodeBlock.ts +109 -0
- package/src/components/ShadcnCollapsible.ts +151 -0
- package/src/components/ShadcnCommand.ts +108 -0
- package/src/components/ShadcnContextMenu.ts +95 -0
- package/src/components/ShadcnDialog.ts +100 -0
- package/src/components/ShadcnDrawer.ts +219 -0
- package/src/components/ShadcnDropdownMenu.ts +116 -0
- package/src/components/ShadcnEmpty.ts +94 -0
- package/src/components/ShadcnField.ts +167 -0
- package/src/components/ShadcnForm.ts +97 -0
- package/src/components/ShadcnHoverCard.ts +146 -0
- package/src/components/ShadcnInput.ts +101 -0
- package/src/components/ShadcnInputGroup.ts +89 -0
- package/src/components/ShadcnInputOtp.ts +151 -0
- package/src/components/ShadcnItem.ts +156 -0
- package/src/components/ShadcnKbd.ts +34 -0
- package/src/components/ShadcnLabel.ts +50 -0
- package/src/components/ShadcnMenubar.ts +78 -0
- package/src/components/ShadcnNativeSelect.ts +140 -0
- package/src/components/ShadcnNavigationMenu.ts +94 -0
- package/src/components/ShadcnPagination.ts +137 -0
- package/src/components/ShadcnPopover.ts +109 -0
- package/src/components/ShadcnProgress.ts +67 -0
- package/src/components/ShadcnRadioGroup.ts +222 -0
- package/src/components/ShadcnRangeCalendar.ts +263 -0
- package/src/components/ShadcnSelect.ts +100 -0
- package/src/components/ShadcnSeparator.ts +49 -0
- package/src/components/ShadcnSheet.ts +162 -0
- package/src/components/ShadcnSidebar.ts +71 -0
- package/src/components/ShadcnSkeleton.ts +29 -0
- package/src/components/ShadcnSlider.ts +233 -0
- package/src/components/ShadcnSonner.ts +90 -0
- package/src/components/ShadcnSpinner.ts +49 -0
- package/src/components/ShadcnSwitch.ts +162 -0
- package/src/components/ShadcnTabs.ts +94 -0
- package/src/components/ShadcnTextarea.ts +96 -0
- package/src/components/ShadcnToggle.ts +101 -0
- package/src/components/ShadcnToggleGroup.ts +171 -0
- package/src/components/ShadcnTooltip.ts +79 -0
- package/src/index.ts +124 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
class SurrealShadcnAccordion extends HTMLElement {
|
|
2
|
+
private _type: 'single' | 'multiple' = 'single';
|
|
3
|
+
private _collapsible = true;
|
|
4
|
+
private _openValues = new Set<string>();
|
|
5
|
+
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return ['type', 'collapsible', 'value'];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.attachShadow({ mode: 'open' });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
connectedCallback() {
|
|
16
|
+
this.render();
|
|
17
|
+
this.updateAttributes();
|
|
18
|
+
this.shadowRoot?.addEventListener('accordion-toggle', ((
|
|
19
|
+
e: CustomEvent<{ value: string; disabled: boolean }>,
|
|
20
|
+
) => {
|
|
21
|
+
e.stopPropagation();
|
|
22
|
+
const { value, disabled } = e.detail;
|
|
23
|
+
if (disabled) return;
|
|
24
|
+
this.toggleItem(value);
|
|
25
|
+
}) as EventListener);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
29
|
+
if (oldValue === newValue) return;
|
|
30
|
+
if (name === 'type') {
|
|
31
|
+
this._type = newValue === 'multiple' ? 'multiple' : 'single';
|
|
32
|
+
} else if (name === 'collapsible') {
|
|
33
|
+
this._collapsible = newValue !== 'false';
|
|
34
|
+
} else if (name === 'value' && newValue !== null) {
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(newValue);
|
|
37
|
+
this._openValues = new Set(Array.isArray(parsed) ? parsed : [parsed]);
|
|
38
|
+
} catch {
|
|
39
|
+
this._openValues = new Set(newValue ? [newValue] : []);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
this.updateChildItems();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private updateAttributes() {
|
|
46
|
+
if (this.hasAttribute('type')) {
|
|
47
|
+
this._type = this.getAttribute('type') === 'multiple' ? 'multiple' : 'single';
|
|
48
|
+
}
|
|
49
|
+
if (this.hasAttribute('collapsible')) {
|
|
50
|
+
this._collapsible = this.getAttribute('collapsible') !== 'false';
|
|
51
|
+
}
|
|
52
|
+
if (this.hasAttribute('value')) {
|
|
53
|
+
const val = this.getAttribute('value');
|
|
54
|
+
if (val) {
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(val);
|
|
57
|
+
this._openValues = new Set(Array.isArray(parsed) ? parsed : [parsed]);
|
|
58
|
+
} catch {
|
|
59
|
+
this._openValues = new Set([val]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private toggleItem(itemValue: string) {
|
|
66
|
+
const isOpen = this._openValues.has(itemValue);
|
|
67
|
+
if (this._type === 'single') {
|
|
68
|
+
if (isOpen) {
|
|
69
|
+
if (this._collapsible) {
|
|
70
|
+
this._openValues.clear();
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
this._openValues.clear();
|
|
74
|
+
this._openValues.add(itemValue);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
if (isOpen) {
|
|
78
|
+
this._openValues.delete(itemValue);
|
|
79
|
+
} else {
|
|
80
|
+
this._openValues.add(itemValue);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.updateChildItems();
|
|
85
|
+
const valueArray = Array.from(this._openValues);
|
|
86
|
+
this.dispatchEvent(
|
|
87
|
+
new CustomEvent('change', {
|
|
88
|
+
detail: { value: this._type === 'single' ? valueArray[0] || '' : valueArray },
|
|
89
|
+
bubbles: true,
|
|
90
|
+
composed: true,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private updateChildItems() {
|
|
96
|
+
const items = this.querySelectorAll('surreal-accordion-item');
|
|
97
|
+
items.forEach((item) => {
|
|
98
|
+
const val = item.getAttribute('value') || '';
|
|
99
|
+
const isOpen = this._openValues.has(val);
|
|
100
|
+
if (isOpen) {
|
|
101
|
+
item.setAttribute('data-state', 'open');
|
|
102
|
+
} else {
|
|
103
|
+
item.setAttribute('data-state', 'closed');
|
|
104
|
+
}
|
|
105
|
+
const trigger = item.querySelector('surreal-accordion-trigger');
|
|
106
|
+
const content = item.querySelector('surreal-accordion-content');
|
|
107
|
+
trigger?.setAttribute('data-state', isOpen ? 'open' : 'closed');
|
|
108
|
+
content?.setAttribute('data-state', isOpen ? 'open' : 'closed');
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private render() {
|
|
113
|
+
if (!this.shadowRoot) return;
|
|
114
|
+
this.shadowRoot.innerHTML = `
|
|
115
|
+
<style>
|
|
116
|
+
:host {
|
|
117
|
+
display: block;
|
|
118
|
+
width: 100%;
|
|
119
|
+
}
|
|
120
|
+
.root {
|
|
121
|
+
display: flex;
|
|
122
|
+
flex-direction: column;
|
|
123
|
+
width: 100%;
|
|
124
|
+
}
|
|
125
|
+
</style>
|
|
126
|
+
<div class="root">
|
|
127
|
+
<slot></slot>
|
|
128
|
+
</div>
|
|
129
|
+
`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class SurrealShadcnAccordionItem extends HTMLElement {
|
|
134
|
+
static get observedAttributes() {
|
|
135
|
+
return ['value', 'disabled', 'data-state'];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
connectedCallback() {
|
|
139
|
+
if (!this.hasAttribute('data-state')) {
|
|
140
|
+
this.setAttribute('data-state', 'closed');
|
|
141
|
+
}
|
|
142
|
+
this.className = 'border-b border-border last:border-b-0 block';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
class SurrealShadcnAccordionTrigger extends HTMLElement {
|
|
147
|
+
private buttonEl: HTMLButtonElement | null = null;
|
|
148
|
+
|
|
149
|
+
static get observedAttributes() {
|
|
150
|
+
return ['data-state', 'disabled'];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
connectedCallback() {
|
|
154
|
+
this.render();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
attributeChangedCallback(name: string, _old: string | null, val: string | null) {
|
|
158
|
+
if (!this.buttonEl) return;
|
|
159
|
+
if (name === 'data-state') {
|
|
160
|
+
this.buttonEl.setAttribute('data-state', val || 'closed');
|
|
161
|
+
this.buttonEl.setAttribute('aria-expanded', val === 'open' ? 'true' : 'false');
|
|
162
|
+
} else if (name === 'disabled') {
|
|
163
|
+
this.buttonEl.disabled = val !== null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private render() {
|
|
168
|
+
const text = this.innerHTML;
|
|
169
|
+
this.innerHTML = '';
|
|
170
|
+
const state = this.getAttribute('data-state') || 'closed';
|
|
171
|
+
const disabled = this.hasAttribute('disabled');
|
|
172
|
+
|
|
173
|
+
const h3 = document.createElement('h3');
|
|
174
|
+
h3.className = 'flex m-0 p-0';
|
|
175
|
+
|
|
176
|
+
const btn = document.createElement('button');
|
|
177
|
+
btn.type = 'button';
|
|
178
|
+
btn.className =
|
|
179
|
+
'flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left text-foreground [&[data-state=open]>svg]:rotate-180 disabled:pointer-events-none disabled:opacity-50 cursor-pointer bg-transparent border-none w-full p-0';
|
|
180
|
+
btn.setAttribute('data-state', state);
|
|
181
|
+
btn.setAttribute('aria-expanded', state === 'open' ? 'true' : 'false');
|
|
182
|
+
btn.disabled = disabled;
|
|
183
|
+
|
|
184
|
+
btn.innerHTML = `
|
|
185
|
+
<span>${text}</span>
|
|
186
|
+
<svg class="size-4 shrink-0 text-muted-foreground transition-transform duration-200 ${state === 'open' ? 'rotate-180' : ''}" 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>
|
|
187
|
+
`;
|
|
188
|
+
|
|
189
|
+
btn.onclick = () => {
|
|
190
|
+
const item = this.closest('surreal-accordion-item');
|
|
191
|
+
const val = item?.getAttribute('value') || '';
|
|
192
|
+
const isItemDisabled = item?.hasAttribute('disabled') || disabled;
|
|
193
|
+
this.dispatchEvent(
|
|
194
|
+
new CustomEvent('accordion-toggle', {
|
|
195
|
+
detail: { value: val, disabled: isItemDisabled },
|
|
196
|
+
bubbles: true,
|
|
197
|
+
composed: true,
|
|
198
|
+
}),
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
this.buttonEl = btn;
|
|
203
|
+
h3.appendChild(btn);
|
|
204
|
+
this.appendChild(h3);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
class SurrealShadcnAccordionContent extends HTMLElement {
|
|
209
|
+
static get observedAttributes() {
|
|
210
|
+
return ['data-state'];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
connectedCallback() {
|
|
214
|
+
this.updateClasses();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
attributeChangedCallback() {
|
|
218
|
+
this.updateClasses();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private updateClasses() {
|
|
222
|
+
const isOpen = this.getAttribute('data-state') === 'open';
|
|
223
|
+
this.className = `grid transition-all duration-200 ease-out text-sm text-muted-foreground ${isOpen ? 'grid-rows-[1fr] opacity-100 block' : 'grid-rows-[0fr] opacity-0 invisible h-0 hidden'}`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!customElements.get('surreal-accordion')) {
|
|
228
|
+
|
|
229
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-accordion')) {
|
|
230
|
+
customElements.define('surreal-shadcn-accordion', SurrealShadcnAccordion);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (!customElements.get('surreal-accordion-item')) {
|
|
234
|
+
customElements.define('surreal-shadcn-accordion', SurrealShadcnAccordionItem);
|
|
235
|
+
}
|
|
236
|
+
if (!customElements.get('surreal-accordion-trigger')) {
|
|
237
|
+
customElements.define('surreal-shadcn-accordion', SurrealShadcnAccordionTrigger);
|
|
238
|
+
}
|
|
239
|
+
if (!customElements.get('surreal-accordion-content')) {
|
|
240
|
+
customElements.define('surreal-shadcn-accordion', SurrealShadcnAccordionContent);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export { SurrealShadcnAccordion, SurrealShadcnAccordionItem, SurrealShadcnAccordionTrigger, SurrealShadcnAccordionContent };
|
|
244
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-accordion')) {
|
|
245
|
+
customElements.define('surreal-minimalist-accordion', SurrealShadcnAccordion);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export default SurrealShadcnAccordion;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
class ModernAlertElement extends HTMLElement {
|
|
2
|
+
private _successMessage: string = '';
|
|
3
|
+
private _createdComponent: { id: string; title: string; currentVersion: string | number } | null =
|
|
4
|
+
null;
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.attachShadow({ mode: 'open' });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
set successMessage(val: string) {
|
|
12
|
+
this._successMessage = val;
|
|
13
|
+
this.render();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
set createdComponent(val: any) {
|
|
17
|
+
this._createdComponent = typeof val === 'string' ? JSON.parse(val) : val;
|
|
18
|
+
this.render();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
connectedCallback() {
|
|
22
|
+
if (this.hasAttribute('success-message')) {
|
|
23
|
+
this._successMessage = this.getAttribute('success-message') || '';
|
|
24
|
+
}
|
|
25
|
+
const compAttr = this.getAttribute('created-component');
|
|
26
|
+
if (compAttr) {
|
|
27
|
+
try {
|
|
28
|
+
this._createdComponent = JSON.parse(compAttr);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
this._createdComponent = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
this.render();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private render() {
|
|
37
|
+
if (!this._successMessage || !this._createdComponent) {
|
|
38
|
+
this.shadowRoot!.innerHTML = '';
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.shadowRoot!.innerHTML = `
|
|
43
|
+
<style>
|
|
44
|
+
@import "https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/tailwind.min.css";
|
|
45
|
+
:host { display: block; }
|
|
46
|
+
.p-6 { padding: 1.5rem; }
|
|
47
|
+
.bg-emerald-500-10 { background-color: rgba(16, 185, 129, 0.1); }
|
|
48
|
+
.border-emerald-500-30 { border-color: rgba(16, 185, 129, 0.3); }
|
|
49
|
+
.border { border-width: 1px; border-style: solid; }
|
|
50
|
+
.rounded-2xl { border-radius: 1rem; }
|
|
51
|
+
.space-y-4 > * + * { margin-top: 1rem; }
|
|
52
|
+
.flex { display: flex; }
|
|
53
|
+
.items-center { align-items: center; }
|
|
54
|
+
.gap-3 { gap: 0.75rem; }
|
|
55
|
+
.text-emerald-300 { color: #6ee7b7; }
|
|
56
|
+
.font-bold { font-weight: 700; }
|
|
57
|
+
.text-lg { font-size: 1.125rem; }
|
|
58
|
+
.text-slate-300 { color: #cbd5e1; }
|
|
59
|
+
.text-sm { font-size: 0.875rem; }
|
|
60
|
+
.inline-flex { display: inline-flex; }
|
|
61
|
+
.gap-2 { gap: 0.5rem; }
|
|
62
|
+
.px-5 { padding-left: 1.25rem; padding-right: 1.25rem; }
|
|
63
|
+
.py-2.5 { padding-top: 0.625rem; padding-bottom: 0.625rem; }
|
|
64
|
+
.bg-emerald-600 { background-color: #059669; }
|
|
65
|
+
.text-white { color: #ffffff; }
|
|
66
|
+
.font-semibold { font-weight: 600; }
|
|
67
|
+
.rounded-xl { border-radius: 0.75rem; }
|
|
68
|
+
</style>
|
|
69
|
+
<div class="p-6 bg-emerald-500-10 border border-emerald-500-30 rounded-2xl space-y-4">
|
|
70
|
+
<div class="flex items-center gap-3 text-emerald-300 font-bold text-lg">
|
|
71
|
+
<span>✓</span>
|
|
72
|
+
<span>${this._successMessage}</span>
|
|
73
|
+
</div>
|
|
74
|
+
<p class="text-slate-300 text-sm">
|
|
75
|
+
View your new component v${this._createdComponent.currentVersion} in the Surreal UI catalog:
|
|
76
|
+
</p>
|
|
77
|
+
<a
|
|
78
|
+
href="/components/${this._createdComponent.id}"
|
|
79
|
+
class="inline-flex items-center gap-2 px-5 py-2.5 bg-emerald-600 text-white font-semibold text-sm rounded-xl"
|
|
80
|
+
>
|
|
81
|
+
<span>Open ${this._createdComponent.title} in Playground</span>
|
|
82
|
+
<span>→</span>
|
|
83
|
+
</a>
|
|
84
|
+
</div>
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-modern-alert')) {
|
|
91
|
+
customElements.define('surreal-modern-alert', ModernAlertElement);
|
|
92
|
+
};
|
|
93
|
+
export { ModernAlertElement as MinimalistAlert, ModernAlertElement };
|
|
94
|
+
|
|
95
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-alert')) {
|
|
96
|
+
customElements.define('surreal-minimalist-alert', ModernAlertElement);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default ModernAlertElement;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
class SurrealShadcnAlertDialog extends HTMLElement {
|
|
2
|
+
private _open = false;
|
|
3
|
+
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['open'];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get open() {
|
|
9
|
+
return this._open;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
set open(val: boolean) {
|
|
13
|
+
if (this._open !== val) {
|
|
14
|
+
this._open = val;
|
|
15
|
+
if (val) {
|
|
16
|
+
this.setAttribute('open', '');
|
|
17
|
+
} else {
|
|
18
|
+
this.removeAttribute('open');
|
|
19
|
+
}
|
|
20
|
+
this.render();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
connectedCallback() {
|
|
25
|
+
this._open = this.hasAttribute('open');
|
|
26
|
+
this.addEventListener('click', this.handleGlobalClick.bind(this));
|
|
27
|
+
window.addEventListener('keydown', this.handleKeyDown.bind(this));
|
|
28
|
+
this.render();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
disconnectedCallback() {
|
|
32
|
+
window.removeEventListener('keydown', this.handleKeyDown.bind(this));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
36
|
+
if (name === 'open' && oldValue !== newValue) {
|
|
37
|
+
this._open = newValue !== null;
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private handleKeyDown = (e: KeyboardEvent) => {
|
|
43
|
+
if (e.key === 'Escape' && this.open) {
|
|
44
|
+
this.open = false;
|
|
45
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
private handleGlobalClick = (e: MouseEvent) => {
|
|
50
|
+
const target = e.target as HTMLElement;
|
|
51
|
+
const trigger = target.closest('[data-slot="alert-dialog-trigger"]');
|
|
52
|
+
if (trigger) {
|
|
53
|
+
this.open = true;
|
|
54
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: true } }));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const cancel = target.closest(
|
|
59
|
+
'[data-slot="alert-dialog-cancel"], [data-slot="alert-dialog-action"]',
|
|
60
|
+
);
|
|
61
|
+
if (cancel) {
|
|
62
|
+
this.open = false;
|
|
63
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const overlay = target.closest('[data-slot="alert-dialog-overlay"]');
|
|
68
|
+
if (overlay && target === overlay) {
|
|
69
|
+
this.open = false;
|
|
70
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
private render() {
|
|
75
|
+
let overlay = this.querySelector('[data-slot="alert-dialog-overlay"]') as HTMLElement;
|
|
76
|
+
let content = this.querySelector('[data-slot="alert-dialog-content"]') as HTMLElement;
|
|
77
|
+
|
|
78
|
+
if (this.open) {
|
|
79
|
+
if (overlay) overlay.style.display = 'block';
|
|
80
|
+
if (content) content.style.display = 'grid';
|
|
81
|
+
} else {
|
|
82
|
+
if (overlay) overlay.style.display = 'none';
|
|
83
|
+
if (content) content.style.display = 'none';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!customElements.get('surreal-alert-dialog')) {
|
|
89
|
+
|
|
90
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-alert-dialog')) {
|
|
91
|
+
customElements.define('surreal-shadcn-alert-dialog', SurrealShadcnAlertDialog);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
export { SurrealShadcnAlertDialog as MinimalistAlertDialog, SurrealShadcnAlertDialog };
|
|
95
|
+
|
|
96
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-alert-dialog')) {
|
|
97
|
+
customElements.define('surreal-minimalist-alert-dialog', SurrealShadcnAlertDialog);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default SurrealShadcnAlertDialog;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class AspectRatioElement extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ['ratio'];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
connectedCallback() {
|
|
7
|
+
this.render();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
attributeChangedCallback() {
|
|
11
|
+
this.render();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private render() {
|
|
15
|
+
const ratio = this.getAttribute('ratio') || '16 / 9';
|
|
16
|
+
this.dataset.slot = 'aspect-ratio';
|
|
17
|
+
this.style.position = 'relative';
|
|
18
|
+
this.style.width = '100%';
|
|
19
|
+
this.style.display = 'block';
|
|
20
|
+
this.style.aspectRatio = ratio;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-aspect-ratio')) {
|
|
25
|
+
|
|
26
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-aspect-ratio')) {
|
|
27
|
+
customElements.define('surreal-shadcn-aspect-ratio', AspectRatioElement);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-aspect-ratio')) {
|
|
31
|
+
customElements.define('surreal-minimalist-aspect-ratio', AspectRatioElement);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default AspectRatioElement;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export class SurrealShadcnAvatar extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ['size', 'src', 'alt', 'fallback'];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
private img: HTMLImageElement | null = null;
|
|
7
|
+
private fallbackEl: HTMLSpanElement | null = null;
|
|
8
|
+
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
this.render();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
attributeChangedCallback() {
|
|
14
|
+
this.render();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private render() {
|
|
18
|
+
const size = this.getAttribute('size') || 'default';
|
|
19
|
+
const src = this.getAttribute('src');
|
|
20
|
+
const alt = this.getAttribute('alt') || '';
|
|
21
|
+
const fallbackText = this.getAttribute('fallback') || '';
|
|
22
|
+
|
|
23
|
+
this.setAttribute('data-slot', 'avatar');
|
|
24
|
+
this.setAttribute('data-size', size);
|
|
25
|
+
|
|
26
|
+
const sizeClasses = size === 'lg' ? 'size-10' : size === 'sm' ? 'size-6' : 'size-8';
|
|
27
|
+
this.className = `rounded-full after:rounded-full group/avatar relative flex shrink-0 select-none after:absolute after:inset-0 after:border after:border-border after:mix-blend-darken dark:after:mix-blend-lighten ${sizeClasses}`;
|
|
28
|
+
|
|
29
|
+
this.innerHTML = '';
|
|
30
|
+
|
|
31
|
+
if (src) {
|
|
32
|
+
const img = document.createElement('img');
|
|
33
|
+
img.src = src;
|
|
34
|
+
img.alt = alt;
|
|
35
|
+
img.setAttribute('data-slot', 'avatar-image');
|
|
36
|
+
img.className = 'rounded-full aspect-square size-full object-cover hidden';
|
|
37
|
+
|
|
38
|
+
const fallback = document.createElement('span');
|
|
39
|
+
fallback.setAttribute('data-slot', 'avatar-fallback');
|
|
40
|
+
fallback.className = `rounded-full bg-muted text-muted-foreground flex size-full items-center justify-center ${size === 'sm' ? 'text-xs' : 'text-sm'}`;
|
|
41
|
+
fallback.textContent = fallbackText;
|
|
42
|
+
|
|
43
|
+
img.onload = () => {
|
|
44
|
+
img.classList.remove('hidden');
|
|
45
|
+
fallback.classList.add('hidden');
|
|
46
|
+
};
|
|
47
|
+
img.onerror = () => {
|
|
48
|
+
img.remove();
|
|
49
|
+
fallback.classList.remove('hidden');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
this.appendChild(img);
|
|
53
|
+
this.appendChild(fallback);
|
|
54
|
+
} else {
|
|
55
|
+
const fallback = document.createElement('span');
|
|
56
|
+
fallback.setAttribute('data-slot', 'avatar-fallback');
|
|
57
|
+
fallback.className = `rounded-full bg-muted text-muted-foreground flex size-full items-center justify-center ${size === 'sm' ? 'text-xs' : 'text-sm'}`;
|
|
58
|
+
fallback.textContent = fallbackText;
|
|
59
|
+
this.appendChild(fallback);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!customElements.get('surreal-avatar')) {
|
|
65
|
+
|
|
66
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-avatar')) {
|
|
67
|
+
customElements.define('surreal-shadcn-avatar', SurrealShadcnAvatar);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class SurrealShadcnAvatarGroup extends HTMLElement {
|
|
72
|
+
connectedCallback() {
|
|
73
|
+
this.setAttribute('data-slot', 'avatar-group');
|
|
74
|
+
this.className =
|
|
75
|
+
'cn-avatar-group group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!customElements.get('surreal-avatar-group')) {
|
|
80
|
+
customElements.define('surreal-shadcn-avatar', SurrealShadcnAvatarGroup);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class SurrealShadcnAvatarGroupCount extends HTMLElement {
|
|
84
|
+
connectedCallback() {
|
|
85
|
+
this.setAttribute('data-slot', 'avatar-group-count');
|
|
86
|
+
this.className =
|
|
87
|
+
'size-8 rounded-full bg-muted text-sm text-muted-foreground group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3 relative flex shrink-0 items-center justify-center ring-2 ring-background';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!customElements.get('surreal-avatar-group-count')) {
|
|
92
|
+
customElements.define('surreal-shadcn-avatar', SurrealShadcnAvatarGroupCount);
|
|
93
|
+
}
|
|
94
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-avatar')) {
|
|
95
|
+
customElements.define('surreal-minimalist-avatar', SurrealShadcnAvatar);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default SurrealShadcnAvatar;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { cn, cva } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
const badgeVariants = cva(
|
|
4
|
+
'h-5 gap-1 rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! group/badge inline-flex w-fit shrink-0 items-center justify-center overflow-hidden whitespace-nowrap transition-colors focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none',
|
|
5
|
+
{
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
default: 'bg-primary text-primary-foreground [a]:hover:bg-primary/80',
|
|
9
|
+
secondary: 'bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80',
|
|
10
|
+
destructive:
|
|
11
|
+
'bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20',
|
|
12
|
+
outline: 'border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground',
|
|
13
|
+
ghost: 'hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50',
|
|
14
|
+
link: 'text-primary underline-offset-4 hover:underline',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
variant: 'default',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export class UiBadge extends HTMLElement {
|
|
24
|
+
static get observedAttributes() {
|
|
25
|
+
return ['variant', 'href', 'class'];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private _element: HTMLElement | null = null;
|
|
29
|
+
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
this.render();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
attributeChangedCallback() {
|
|
35
|
+
this.render();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private render() {
|
|
39
|
+
const href = this.getAttribute('href');
|
|
40
|
+
const variant = (this.getAttribute('variant') || 'default') as any;
|
|
41
|
+
const customClass = this.getAttribute('class') || '';
|
|
42
|
+
|
|
43
|
+
const tagName = href ? 'a' : 'span';
|
|
44
|
+
if (!this._element || this._element.tagName.toLowerCase() !== tagName) {
|
|
45
|
+
this.innerHTML = '';
|
|
46
|
+
this._element = document.createElement(tagName);
|
|
47
|
+
this._element.setAttribute('data-slot', 'badge');
|
|
48
|
+
const slot = document.createElement('slot');
|
|
49
|
+
this._element.appendChild(slot);
|
|
50
|
+
this.appendChild(this._element);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (href && this._element instanceof HTMLAnchorElement) {
|
|
54
|
+
this._element.href = href;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this._element.className = cn(badgeVariants({ variant }), customClass);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!customElements.get('ui-badge')) {
|
|
62
|
+
|
|
63
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-badge')) {
|
|
64
|
+
customElements.define('surreal-shadcn-badge', UiBadge);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-badge')) {
|
|
68
|
+
customElements.define('surreal-minimalist-badge', UiBadge);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default UiBadge;
|