@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,118 @@
|
|
|
1
|
+
class SurrealShadcnCarousel extends HTMLElement {
|
|
2
|
+
private container: HTMLElement | null = null;
|
|
3
|
+
private prevButton: HTMLElement | null = null;
|
|
4
|
+
private nextButton: HTMLElement | null = null;
|
|
5
|
+
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return ['orientation'];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get orientation(): 'horizontal' | 'vertical' {
|
|
15
|
+
return (this.getAttribute('orientation') as 'horizontal' | 'vertical') || 'horizontal';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
this.setAttribute('data-slot', 'carousel');
|
|
20
|
+
this.setAttribute('role', 'region');
|
|
21
|
+
this.setAttribute('aria-roledescription', 'carousel');
|
|
22
|
+
this.classList.add('relative', 'block');
|
|
23
|
+
|
|
24
|
+
this.setupListeners();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private setupListeners() {
|
|
28
|
+
this.container = this.querySelector(
|
|
29
|
+
'[data-slot="carousel-content"] > [data-embla-container], [data-embla-container]',
|
|
30
|
+
);
|
|
31
|
+
this.prevButton = this.querySelector('[data-slot="carousel-previous"]');
|
|
32
|
+
this.nextButton = this.querySelector('[data-slot="carousel-next"]');
|
|
33
|
+
|
|
34
|
+
if (this.prevButton) {
|
|
35
|
+
this.prevButton.addEventListener('click', () => this.scrollPrev());
|
|
36
|
+
}
|
|
37
|
+
if (this.nextButton) {
|
|
38
|
+
this.nextButton.addEventListener('click', () => this.scrollNext());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this.container) {
|
|
42
|
+
this.container.addEventListener('scroll', () => this.updateScrollState());
|
|
43
|
+
this.updateScrollState();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
47
|
+
if (e.key === 'ArrowLeft' || (this.orientation === 'vertical' && e.key === 'ArrowUp')) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
this.scrollPrev();
|
|
50
|
+
} else if (
|
|
51
|
+
e.key === 'ArrowRight' ||
|
|
52
|
+
(this.orientation === 'vertical' && e.key === 'ArrowDown')
|
|
53
|
+
) {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
this.scrollNext();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public scrollPrev() {
|
|
61
|
+
if (!this.container) return;
|
|
62
|
+
if (this.orientation === 'horizontal') {
|
|
63
|
+
this.container.scrollBy({ left: -this.container.clientWidth, behavior: 'smooth' });
|
|
64
|
+
} else {
|
|
65
|
+
this.container.scrollBy({ top: -this.container.clientHeight, behavior: 'smooth' });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public scrollNext() {
|
|
70
|
+
if (!this.container) return;
|
|
71
|
+
if (this.orientation === 'horizontal') {
|
|
72
|
+
this.container.scrollBy({ left: this.container.clientWidth, behavior: 'smooth' });
|
|
73
|
+
} else {
|
|
74
|
+
this.container.scrollBy({ top: this.container.clientHeight, behavior: 'smooth' });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private updateScrollState() {
|
|
79
|
+
if (!this.container) return;
|
|
80
|
+
const isHoriz = this.orientation === 'horizontal';
|
|
81
|
+
const canPrev = isHoriz ? this.container.scrollLeft > 2 : this.container.scrollTop > 2;
|
|
82
|
+
const maxScroll = isHoriz
|
|
83
|
+
? this.container.scrollWidth - this.container.clientWidth
|
|
84
|
+
: this.container.scrollHeight - this.container.clientHeight;
|
|
85
|
+
const canNext = isHoriz
|
|
86
|
+
? this.container.scrollLeft < maxScroll - 2
|
|
87
|
+
: this.container.scrollTop < maxScroll - 2;
|
|
88
|
+
|
|
89
|
+
if (this.prevButton) {
|
|
90
|
+
if (canPrev) {
|
|
91
|
+
this.prevButton.removeAttribute('disabled');
|
|
92
|
+
this.prevButton.setAttribute('aria-disabled', 'false');
|
|
93
|
+
} else {
|
|
94
|
+
this.prevButton.setAttribute('disabled', 'true');
|
|
95
|
+
this.prevButton.setAttribute('aria-disabled', 'true');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (this.nextButton) {
|
|
99
|
+
if (canNext) {
|
|
100
|
+
this.nextButton.removeAttribute('disabled');
|
|
101
|
+
this.nextButton.setAttribute('aria-disabled', 'false');
|
|
102
|
+
} else {
|
|
103
|
+
this.nextButton.setAttribute('disabled', 'true');
|
|
104
|
+
this.nextButton.setAttribute('aria-disabled', 'true');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!customElements.get('surreal-carousel')) {
|
|
111
|
+
|
|
112
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-carousel')) {
|
|
113
|
+
customElements.define('surreal-shadcn-carousel', SurrealShadcnCarousel);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
export { SurrealShadcnCarousel as ShadcnCarousel, SurrealShadcnCarousel };
|
|
117
|
+
|
|
118
|
+
export default SurrealShadcnCarousel;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
class SurrealShadcnChartContainer extends HTMLElement {
|
|
2
|
+
private styleTag: HTMLStyleElement | null = null;
|
|
3
|
+
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['config', 'chart-id'];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
connectedCallback() {
|
|
9
|
+
this.render();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
attributeChangedCallback() {
|
|
13
|
+
this.applyConfigStyles();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private get configData() {
|
|
17
|
+
try {
|
|
18
|
+
const attr = this.getAttribute('config');
|
|
19
|
+
return attr ? JSON.parse(attr) : {};
|
|
20
|
+
} catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private applyConfigStyles() {
|
|
26
|
+
const id = this.getAttribute('chart-id') || 'chart-root';
|
|
27
|
+
this.setAttribute('data-chart', id);
|
|
28
|
+
this.setAttribute('data-slot', 'chart');
|
|
29
|
+
|
|
30
|
+
const config = this.configData;
|
|
31
|
+
const entries = Object.entries(config);
|
|
32
|
+
|
|
33
|
+
if (!this.styleTag) {
|
|
34
|
+
this.styleTag = document.createElement('style');
|
|
35
|
+
this.prepend(this.styleTag);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!entries.length) {
|
|
39
|
+
this.styleTag.textContent = '';
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let css = `[data-chart="${id}"] {\n`;
|
|
44
|
+
for (const [key, val] of entries) {
|
|
45
|
+
const item = val as { color?: string; theme?: Record<string, string> };
|
|
46
|
+
if (item.color) {
|
|
47
|
+
css += ` --color-${key}: ${item.color};\n`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
css += '}\n';
|
|
51
|
+
|
|
52
|
+
css += `.dark [data-chart="${id}"] {\n`;
|
|
53
|
+
for (const [key, val] of entries) {
|
|
54
|
+
const item = val as { color?: string; theme?: Record<string, string> };
|
|
55
|
+
const darkColor = item.theme?.dark || item.color;
|
|
56
|
+
if (darkColor) {
|
|
57
|
+
css += ` --color-${key}: ${darkColor};\n`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
css += '}\n';
|
|
61
|
+
|
|
62
|
+
this.styleTag.textContent = css;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
render() {
|
|
66
|
+
this.className = [
|
|
67
|
+
'flex aspect-video justify-center overflow-visible text-xs w-full',
|
|
68
|
+
this.className,
|
|
69
|
+
].join(' ');
|
|
70
|
+
this.applyConfigStyles();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class SurrealShadcnChartTooltip extends HTMLElement {
|
|
75
|
+
static get observedAttributes() {
|
|
76
|
+
return ['label', 'payload', 'indicator'];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
connectedCallback() {
|
|
80
|
+
this.render();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
attributeChangedCallback() {
|
|
84
|
+
this.render();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
render() {
|
|
88
|
+
const label = this.getAttribute('label') || '';
|
|
89
|
+
const indicator = this.getAttribute('indicator') || 'dot';
|
|
90
|
+
let payload: Array<{ key?: string; name?: string; value?: number; color?: string }> = [];
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const rawPayload = this.getAttribute('payload');
|
|
94
|
+
if (rawPayload) payload = JSON.parse(rawPayload);
|
|
95
|
+
} catch {}
|
|
96
|
+
|
|
97
|
+
this.setAttribute('data-slot', 'chart-tooltip');
|
|
98
|
+
this.className = [
|
|
99
|
+
'grid min-w-[9rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl',
|
|
100
|
+
this.className,
|
|
101
|
+
].join(' ');
|
|
102
|
+
|
|
103
|
+
let html = '';
|
|
104
|
+
if (label) {
|
|
105
|
+
html += `<div class="font-medium text-foreground">${label}</div>`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
html += '<div class="grid gap-1.5">';
|
|
109
|
+
payload.forEach((item) => {
|
|
110
|
+
const itemName = item.name || item.key || 'value';
|
|
111
|
+
const itemVal = item.value !== undefined ? Number(item.value).toLocaleString() : '';
|
|
112
|
+
const color = item.color || 'var(--primary)';
|
|
113
|
+
|
|
114
|
+
let indicatorClass = 'size-2.5 rounded-[2px] shrink-0';
|
|
115
|
+
if (indicator === 'line') indicatorClass = 'h-3.5 w-1 rounded-[2px] shrink-0';
|
|
116
|
+
if (indicator === 'dashed')
|
|
117
|
+
indicatorClass = 'w-0 border-[1.5px] border-dashed bg-transparent shrink-0';
|
|
118
|
+
|
|
119
|
+
html += `
|
|
120
|
+
<div class="flex w-full items-center gap-2">
|
|
121
|
+
<div class="${indicatorClass}" style="background-color: ${indicator === 'dashed' ? 'transparent' : color}; border-color: ${color};"></div>
|
|
122
|
+
<div class="flex flex-1 justify-between items-center leading-none">
|
|
123
|
+
<span class="text-muted-foreground">${itemName}</span>
|
|
124
|
+
<span class="font-mono font-medium text-foreground tabular-nums">${itemVal}</span>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
`;
|
|
128
|
+
});
|
|
129
|
+
html += '</div>';
|
|
130
|
+
|
|
131
|
+
this.innerHTML = html;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!customElements.get('surreal-chart-container')) {
|
|
136
|
+
|
|
137
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-chart')) {
|
|
138
|
+
customElements.define('surreal-shadcn-chart', SurrealShadcnChartContainer);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!customElements.get('surreal-chart-tooltip')) {
|
|
143
|
+
customElements.define('surreal-shadcn-chart', SurrealShadcnChartTooltip);
|
|
144
|
+
};
|
|
145
|
+
export { SurrealShadcnChartContainer as ShadcnChart, SurrealShadcnChartContainer };
|
|
146
|
+
|
|
147
|
+
export default SurrealShadcnChartContainer;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
class SurrealShadcnCheckbox extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ['checked', 'indeterminate', 'disabled', 'required', 'name', 'value', 'class'];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
private _button: HTMLButtonElement;
|
|
7
|
+
private _indicator: HTMLDivElement;
|
|
8
|
+
private _hiddenInput: HTMLInputElement | null = null;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._button = document.createElement('button');
|
|
13
|
+
this._indicator = document.createElement('div');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
connectedCallback() {
|
|
17
|
+
this.render();
|
|
18
|
+
this._button.addEventListener('click', this._handleClick);
|
|
19
|
+
this._button.addEventListener('keydown', this._handleKeyDown);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
disconnectedCallback() {
|
|
23
|
+
this._button.removeEventListener('click', this._handleClick);
|
|
24
|
+
this._button.removeEventListener('keydown', this._handleKeyDown);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
28
|
+
if (oldValue !== newValue) {
|
|
29
|
+
this.updateState();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get checked(): boolean {
|
|
34
|
+
return this.hasAttribute('checked') && this.getAttribute('checked') !== 'false';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
set checked(val: boolean) {
|
|
38
|
+
if (val) {
|
|
39
|
+
this.setAttribute('checked', '');
|
|
40
|
+
} else {
|
|
41
|
+
this.removeAttribute('checked');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get indeterminate(): boolean {
|
|
46
|
+
return this.hasAttribute('indeterminate');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
set indeterminate(val: boolean) {
|
|
50
|
+
if (val) {
|
|
51
|
+
this.setAttribute('indeterminate', '');
|
|
52
|
+
} else {
|
|
53
|
+
this.removeAttribute('indeterminate');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get disabled(): boolean {
|
|
58
|
+
return this.hasAttribute('disabled');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
set disabled(val: boolean) {
|
|
62
|
+
if (val) {
|
|
63
|
+
this.setAttribute('disabled', '');
|
|
64
|
+
} else {
|
|
65
|
+
this.removeAttribute('disabled');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private _handleClick = (e: MouseEvent) => {
|
|
70
|
+
if (this.disabled) {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const nextChecked = this.indeterminate ? true : !this.checked;
|
|
76
|
+
this.indeterminate = false;
|
|
77
|
+
this.checked = nextChecked;
|
|
78
|
+
|
|
79
|
+
this.dispatchEvent(
|
|
80
|
+
new CustomEvent('change', {
|
|
81
|
+
detail: { checked: this.checked },
|
|
82
|
+
bubbles: true,
|
|
83
|
+
composed: true,
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
private _handleKeyDown = (e: KeyboardEvent) => {
|
|
89
|
+
if (e.key === ' ') {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
this._handleClick(e as unknown as MouseEvent);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
private updateState() {
|
|
96
|
+
const isIndeterminate = this.indeterminate;
|
|
97
|
+
const isChecked = !isIndeterminate && this.checked;
|
|
98
|
+
const isDisabled = this.disabled;
|
|
99
|
+
const isRequired = this.hasAttribute('required');
|
|
100
|
+
const extraClasses = this.getAttribute('class') || '';
|
|
101
|
+
|
|
102
|
+
this._button.type = 'button';
|
|
103
|
+
this._button.setAttribute('role', 'checkbox');
|
|
104
|
+
this._button.setAttribute(
|
|
105
|
+
'aria-checked',
|
|
106
|
+
isIndeterminate ? 'mixed' : isChecked ? 'true' : 'false',
|
|
107
|
+
);
|
|
108
|
+
this._button.setAttribute('aria-required', isRequired ? 'true' : 'false');
|
|
109
|
+
this._button.setAttribute('data-slot', 'checkbox');
|
|
110
|
+
this._button.setAttribute(
|
|
111
|
+
'data-state',
|
|
112
|
+
isIndeterminate ? 'indeterminate' : isChecked ? 'checked' : 'unchecked',
|
|
113
|
+
);
|
|
114
|
+
this._button.disabled = isDisabled;
|
|
115
|
+
if (isDisabled) {
|
|
116
|
+
this._button.setAttribute('data-disabled', '');
|
|
117
|
+
} else {
|
|
118
|
+
this._button.removeAttribute('data-disabled');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this._button.className =
|
|
122
|
+
`peer relative inline-flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors group-has-disabled/field:opacity-50 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50 ${extraClasses}`.trim();
|
|
123
|
+
|
|
124
|
+
this._indicator.setAttribute('data-slot', 'checkbox-indicator');
|
|
125
|
+
this._indicator.className =
|
|
126
|
+
'[&>svg]:size-3.5 grid place-content-center text-current transition-none';
|
|
127
|
+
|
|
128
|
+
if (isChecked) {
|
|
129
|
+
this._indicator.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="size-3.5"><polyline points="20 6 9 17 4 12"/></svg>`;
|
|
130
|
+
} else if (isIndeterminate) {
|
|
131
|
+
this._indicator.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="size-3.5"><line x1="5" y1="12" x2="19" y2="12"/></svg>`;
|
|
132
|
+
} else {
|
|
133
|
+
this._indicator.innerHTML = '';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const name = this.getAttribute('name');
|
|
137
|
+
if (name) {
|
|
138
|
+
if (!this._hiddenInput) {
|
|
139
|
+
this._hiddenInput = document.createElement('input');
|
|
140
|
+
this._hiddenInput.type = 'checkbox';
|
|
141
|
+
this._hiddenInput.tabIndex = -1;
|
|
142
|
+
this._hiddenInput.setAttribute('aria-hidden', 'true');
|
|
143
|
+
this._hiddenInput.className = 'sr-only pointer-events-none';
|
|
144
|
+
this.appendChild(this._hiddenInput);
|
|
145
|
+
}
|
|
146
|
+
this._hiddenInput.name = name;
|
|
147
|
+
this._hiddenInput.value = this.getAttribute('value') || 'on';
|
|
148
|
+
this._hiddenInput.checked = isChecked;
|
|
149
|
+
this._hiddenInput.disabled = isDisabled;
|
|
150
|
+
this._hiddenInput.required = isRequired;
|
|
151
|
+
} else if (this._hiddenInput) {
|
|
152
|
+
this._hiddenInput.remove();
|
|
153
|
+
this._hiddenInput = null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private render() {
|
|
158
|
+
if (!this.contains(this._button)) {
|
|
159
|
+
this.innerHTML = '';
|
|
160
|
+
this._button.appendChild(this._indicator);
|
|
161
|
+
this.appendChild(this._button);
|
|
162
|
+
}
|
|
163
|
+
this.updateState();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-checkbox')) {
|
|
168
|
+
|
|
169
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-checkbox')) {
|
|
170
|
+
customElements.define('surreal-shadcn-checkbox', SurrealShadcnCheckbox);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { SurrealShadcnCheckbox };
|
|
175
|
+
export default SurrealShadcnCheckbox;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
class SurrealShadcnCodeBlock extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ['code', 'language', 'show-line-numbers', 'wrap'];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this._code = '';
|
|
9
|
+
this._language = 'plaintext';
|
|
10
|
+
this._showLineNumbers = false;
|
|
11
|
+
this._wrap = false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get code() {
|
|
15
|
+
return this._code;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
set code(val) {
|
|
19
|
+
this._code = val;
|
|
20
|
+
this.setAttribute('code', val);
|
|
21
|
+
this.render();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
connectedCallback() {
|
|
25
|
+
this._code = this.getAttribute('code') || this.textContent || '';
|
|
26
|
+
this._language = this.getAttribute('language') || 'plaintext';
|
|
27
|
+
this._showLineNumbers = this.hasAttribute('show-line-numbers');
|
|
28
|
+
this._wrap = this.hasAttribute('wrap');
|
|
29
|
+
this.render();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
33
|
+
if (oldValue === newValue) return;
|
|
34
|
+
if (name === 'code') this._code = newValue || '';
|
|
35
|
+
if (name === 'language') this._language = newValue || 'plaintext';
|
|
36
|
+
if (name === 'show-line-numbers') this._showLineNumbers = newValue !== null;
|
|
37
|
+
if (name === 'wrap') this._wrap = newValue !== null;
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
const escaped = (this._code || '')
|
|
43
|
+
.replace(/&/g, '&')
|
|
44
|
+
.replace(/</g, '<')
|
|
45
|
+
.replace(/>/g, '>');
|
|
46
|
+
|
|
47
|
+
const lines = escaped.split('\n');
|
|
48
|
+
const formattedLines = this._showLineNumbers
|
|
49
|
+
? lines
|
|
50
|
+
.map(
|
|
51
|
+
(line, idx) =>
|
|
52
|
+
`<span class="inline-block min-w-10 mr-4 text-right select-none text-muted-foreground">${idx + 1}</span>${line}`,
|
|
53
|
+
)
|
|
54
|
+
.join('\n')
|
|
55
|
+
: escaped;
|
|
56
|
+
|
|
57
|
+
const wrapClass = this._wrap ? 'whitespace-pre-wrap break-words' : 'overflow-x-auto';
|
|
58
|
+
|
|
59
|
+
this.className =
|
|
60
|
+
'group relative block w-full overflow-hidden rounded-md border border-border bg-background text-foreground font-mono text-sm';
|
|
61
|
+
this.innerHTML = `
|
|
62
|
+
<div class="relative">
|
|
63
|
+
<div class="overflow-auto p-4 text-sm font-mono ${wrapClass}">
|
|
64
|
+
<pre class="m-0 text-foreground font-mono text-sm"><code>${formattedLines}</code></pre>
|
|
65
|
+
</div>
|
|
66
|
+
<div class="absolute top-2 right-2 flex items-center gap-2 z-10">
|
|
67
|
+
<slot name="actions">
|
|
68
|
+
<button type="button" class="surreal-code-copy-btn inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground h-8 w-8 text-muted-foreground hover:text-foreground" title="Copy to clipboard">
|
|
69
|
+
<svg class="copy-icon h-4 w-4" 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"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
|
|
70
|
+
<svg class="check-icon h-4 w-4 text-emerald-500 hidden" 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"><path d="M20 6 9 17l-5-5"/></svg>
|
|
71
|
+
</button>
|
|
72
|
+
</slot>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
`;
|
|
76
|
+
|
|
77
|
+
const copyBtn = this.querySelector('.surreal-code-copy-btn');
|
|
78
|
+
if (copyBtn) {
|
|
79
|
+
copyBtn.addEventListener('click', async () => {
|
|
80
|
+
try {
|
|
81
|
+
await navigator.clipboard.writeText(this._code);
|
|
82
|
+
const copyIcon = copyBtn.querySelector('.copy-icon');
|
|
83
|
+
const checkIcon = copyBtn.querySelector('.check-icon');
|
|
84
|
+
if (copyIcon && checkIcon) {
|
|
85
|
+
copyIcon.classList.add('hidden');
|
|
86
|
+
checkIcon.classList.remove('hidden');
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
copyIcon.classList.remove('hidden');
|
|
89
|
+
checkIcon.classList.add('hidden');
|
|
90
|
+
}, 2000);
|
|
91
|
+
}
|
|
92
|
+
this.dispatchEvent(new CustomEvent('copy', { detail: { code: this._code } }));
|
|
93
|
+
} catch (err) {
|
|
94
|
+
this.dispatchEvent(new CustomEvent('error', { detail: err }));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-code-block')) {
|
|
102
|
+
|
|
103
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-code-block')) {
|
|
104
|
+
customElements.define('surreal-shadcn-code-block', SurrealShadcnCodeBlock);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
export { SurrealShadcnCodeBlock as ShadcnCodeBlock, SurrealShadcnCodeBlock };
|
|
108
|
+
|
|
109
|
+
export default SurrealShadcnCodeBlock;
|