@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,101 @@
|
|
|
1
|
+
import { cn } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
export class FormElement extends HTMLElement {
|
|
4
|
+
connectedCallback() {
|
|
5
|
+
this.className = cn('block space-y-6', this.className);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class FormItemElement extends HTMLElement {
|
|
10
|
+
connectedCallback() {
|
|
11
|
+
this.className = cn('block space-y-2', this.className);
|
|
12
|
+
this.setAttribute('data-slot', 'form-item');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class FormLabelElement extends HTMLElement {
|
|
17
|
+
connectedCallback() {
|
|
18
|
+
const isError = this.hasAttribute('error');
|
|
19
|
+
this.className = cn(
|
|
20
|
+
'block text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
|
|
21
|
+
isError && 'text-destructive',
|
|
22
|
+
this.className,
|
|
23
|
+
);
|
|
24
|
+
this.setAttribute('data-slot', 'form-label');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class FormDescriptionElement extends HTMLElement {
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
this.className = cn('block text-sm text-muted-foreground', this.className);
|
|
31
|
+
this.setAttribute('data-slot', 'form-description');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class FormMessageElement extends HTMLElement {
|
|
36
|
+
connectedCallback() {
|
|
37
|
+
this.className = cn('block text-sm font-medium text-destructive', this.className);
|
|
38
|
+
this.setAttribute('data-slot', 'form-message');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class FormFieldsetElement extends HTMLElement {
|
|
43
|
+
connectedCallback() {
|
|
44
|
+
this.className = cn('block space-y-2 border-0 p-0 m-0', this.className);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class FormLegendElement extends HTMLElement {
|
|
49
|
+
connectedCallback() {
|
|
50
|
+
const isError = this.hasAttribute('error');
|
|
51
|
+
this.className = cn(
|
|
52
|
+
'block text-sm leading-none font-medium',
|
|
53
|
+
isError && 'text-destructive',
|
|
54
|
+
this.className,
|
|
55
|
+
);
|
|
56
|
+
this.setAttribute('data-slot', 'form-legend');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class FormButtonElement extends HTMLElement {
|
|
61
|
+
connectedCallback() {
|
|
62
|
+
const variant = this.getAttribute('variant') || 'default';
|
|
63
|
+
this.className = cn(
|
|
64
|
+
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 h-9 px-4 py-2 shadow cursor-pointer',
|
|
65
|
+
variant === 'default' && 'bg-primary text-primary-foreground hover:bg-primary/90',
|
|
66
|
+
variant === 'destructive' &&
|
|
67
|
+
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
|
|
68
|
+
variant === 'outline' &&
|
|
69
|
+
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
|
|
70
|
+
variant === 'secondary' && 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
|
71
|
+
variant === 'ghost' && 'hover:bg-accent hover:text-accent-foreground',
|
|
72
|
+
variant === 'link' && 'text-primary underline-offset-4 hover:underline',
|
|
73
|
+
this.className,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (typeof customElements !== 'undefined') {
|
|
79
|
+
if (!customElements.get('ui-form'))
|
|
80
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-form')) {
|
|
81
|
+
customElements.define('surreal-shadcn-form', FormElement);
|
|
82
|
+
}
|
|
83
|
+
if (!customElements.get('ui-form-item')) customElements.define('surreal-shadcn-form', FormItemElement);
|
|
84
|
+
if (!customElements.get('ui-form-label'))
|
|
85
|
+
customElements.define('surreal-shadcn-form', FormLabelElement);
|
|
86
|
+
if (!customElements.get('ui-form-description'))
|
|
87
|
+
customElements.define('surreal-shadcn-form', FormDescriptionElement);
|
|
88
|
+
if (!customElements.get('ui-form-message'))
|
|
89
|
+
customElements.define('surreal-shadcn-form', FormMessageElement);
|
|
90
|
+
if (!customElements.get('ui-form-fieldset'))
|
|
91
|
+
customElements.define('surreal-shadcn-form', FormFieldsetElement);
|
|
92
|
+
if (!customElements.get('ui-form-legend'))
|
|
93
|
+
customElements.define('surreal-shadcn-form', FormLegendElement);
|
|
94
|
+
if (!customElements.get('ui-form-button'))
|
|
95
|
+
customElements.define('surreal-shadcn-form', FormButtonElement);
|
|
96
|
+
}
|
|
97
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-form')) {
|
|
98
|
+
customElements.define('surreal-minimalist-form', FormElement);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default FormElement;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
class SurrealShadcnHoverCard extends HTMLElement {
|
|
2
|
+
private openTimeout: number | null = null;
|
|
3
|
+
private closeTimeout: number | null = null;
|
|
4
|
+
private openDelay = 300;
|
|
5
|
+
private closeDelay = 300;
|
|
6
|
+
private isOpen = false;
|
|
7
|
+
|
|
8
|
+
static get observedAttributes() {
|
|
9
|
+
return ['open-delay', 'close-delay', 'open'];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.attachShadow({ mode: 'open' });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
connectedCallback() {
|
|
18
|
+
if (this.hasAttribute('open-delay')) {
|
|
19
|
+
this.openDelay = parseInt(this.getAttribute('open-delay') || '300', 10);
|
|
20
|
+
}
|
|
21
|
+
if (this.hasAttribute('close-delay')) {
|
|
22
|
+
this.closeDelay = parseInt(this.getAttribute('close-delay') || '300', 10);
|
|
23
|
+
}
|
|
24
|
+
this.render();
|
|
25
|
+
this.attachListeners();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
disconnectedCallback() {
|
|
29
|
+
this.clearTimeouts();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
33
|
+
if (oldValue === newValue) return;
|
|
34
|
+
if (name === 'open-delay') {
|
|
35
|
+
this.openDelay = parseInt(newValue || '300', 10);
|
|
36
|
+
} else if (name === 'close-delay') {
|
|
37
|
+
this.closeDelay = parseInt(newValue || '300', 10);
|
|
38
|
+
} else if (name === 'open') {
|
|
39
|
+
this.isOpen = newValue !== null && newValue !== 'false';
|
|
40
|
+
this.updateState();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private clearTimeouts() {
|
|
45
|
+
if (this.openTimeout) clearTimeout(this.openTimeout);
|
|
46
|
+
if (this.closeTimeout) clearTimeout(this.closeTimeout);
|
|
47
|
+
this.openTimeout = null;
|
|
48
|
+
this.closeTimeout = null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private show() {
|
|
52
|
+
this.clearTimeouts();
|
|
53
|
+
this.openTimeout = window.setTimeout(() => {
|
|
54
|
+
this.isOpen = true;
|
|
55
|
+
this.setAttribute('open', '');
|
|
56
|
+
this.updateState();
|
|
57
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: true } }));
|
|
58
|
+
}, this.openDelay);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private hide() {
|
|
62
|
+
this.clearTimeouts();
|
|
63
|
+
this.closeTimeout = window.setTimeout(() => {
|
|
64
|
+
this.isOpen = false;
|
|
65
|
+
this.removeAttribute('open');
|
|
66
|
+
this.updateState();
|
|
67
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
|
|
68
|
+
}, this.closeDelay);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private updateState() {
|
|
72
|
+
const content = this.shadowRoot?.querySelector("[data-slot='hover-card-content']");
|
|
73
|
+
if (content) {
|
|
74
|
+
if (this.isOpen) {
|
|
75
|
+
content.classList.remove('hidden');
|
|
76
|
+
content.setAttribute('data-state', 'open');
|
|
77
|
+
} else {
|
|
78
|
+
content.classList.add('hidden');
|
|
79
|
+
content.setAttribute('data-state', 'closed');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private attachListeners() {
|
|
85
|
+
this.addEventListener('mouseenter', () => this.show());
|
|
86
|
+
this.addEventListener('mouseleave', () => this.hide());
|
|
87
|
+
this.addEventListener('focusin', () => this.show());
|
|
88
|
+
this.addEventListener('focusout', () => this.hide());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private render() {
|
|
92
|
+
if (!this.shadowRoot) return;
|
|
93
|
+
this.shadowRoot.innerHTML = `
|
|
94
|
+
<style>
|
|
95
|
+
:host {
|
|
96
|
+
display: inline-block;
|
|
97
|
+
position: relative;
|
|
98
|
+
}
|
|
99
|
+
.hidden {
|
|
100
|
+
display: none !important;
|
|
101
|
+
}
|
|
102
|
+
.hover-card-content {
|
|
103
|
+
position: absolute;
|
|
104
|
+
top: calc(100% + 4px);
|
|
105
|
+
left: 50%;
|
|
106
|
+
transform: translateX(-50%);
|
|
107
|
+
z-index: 50;
|
|
108
|
+
width: 16rem;
|
|
109
|
+
border-radius: 0.5rem;
|
|
110
|
+
background-color: var(--color-popover, #ffffff);
|
|
111
|
+
color: var(--color-popover-foreground, #09090b);
|
|
112
|
+
padding: 0.625rem;
|
|
113
|
+
font-size: 0.875rem;
|
|
114
|
+
line-height: 1.25rem;
|
|
115
|
+
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
|
116
|
+
outline: 1px solid rgb(0 0 0 / 0.1);
|
|
117
|
+
animation: fadeIn 100ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
118
|
+
}
|
|
119
|
+
@keyframes fadeIn {
|
|
120
|
+
from { opacity: 0; transform: translate(-50%, -4px) scale(0.95); }
|
|
121
|
+
to { opacity: 1; transform: translate(-50%, 0) scale(1); }
|
|
122
|
+
}
|
|
123
|
+
</style>
|
|
124
|
+
<div data-slot="hover-card-trigger">
|
|
125
|
+
<slot name="trigger"></slot>
|
|
126
|
+
</div>
|
|
127
|
+
<div
|
|
128
|
+
data-slot="hover-card-content"
|
|
129
|
+
class="hover-card-content ${this.isOpen ? '' : 'hidden'}"
|
|
130
|
+
data-state="${this.isOpen ? 'open' : 'closed'}"
|
|
131
|
+
>
|
|
132
|
+
<slot></slot>
|
|
133
|
+
</div>
|
|
134
|
+
`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!customElements.get('surreal-hover-card')) {
|
|
139
|
+
|
|
140
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-hover-card')) {
|
|
141
|
+
customElements.define('surreal-shadcn-hover-card', SurrealShadcnHoverCard);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { SurrealShadcnHoverCard };
|
|
146
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-hover-card')) {
|
|
147
|
+
customElements.define('surreal-minimalist-hover-card', SurrealShadcnHoverCard);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export default SurrealShadcnHoverCard;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { cn } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
export class SurrealShadcnInput extends HTMLElement {
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['type', 'value', 'placeholder', 'disabled', 'class', 'name', 'aria-invalid'];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
private inputElement: HTMLInputElement;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.attachShadow({ mode: 'open' });
|
|
13
|
+
this.inputElement = document.createElement('input');
|
|
14
|
+
this.shadowRoot?.appendChild(this.inputElement);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
connectedCallback() {
|
|
18
|
+
this.render();
|
|
19
|
+
this.inputElement.addEventListener('input', this.handleInput);
|
|
20
|
+
this.inputElement.addEventListener('change', this.handleChange);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
disconnectedCallback() {
|
|
24
|
+
this.inputElement.removeEventListener('input', this.handleInput);
|
|
25
|
+
this.inputElement.removeEventListener('change', this.handleChange);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
29
|
+
if (oldValue !== newValue) {
|
|
30
|
+
this.render();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private handleInput = (e: Event) => {
|
|
35
|
+
const target = e.target as HTMLInputElement;
|
|
36
|
+
this.setAttribute('value', target.value);
|
|
37
|
+
this.dispatchEvent(
|
|
38
|
+
new CustomEvent('input', { detail: { value: target.value }, bubbles: true, composed: true }),
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
private handleChange = (e: Event) => {
|
|
43
|
+
const target = e.target as HTMLInputElement;
|
|
44
|
+
this.dispatchEvent(
|
|
45
|
+
new CustomEvent('change', {
|
|
46
|
+
detail: { value: target.value, files: target.files },
|
|
47
|
+
bubbles: true,
|
|
48
|
+
composed: true,
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
get value(): string {
|
|
54
|
+
return this.inputElement.value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
set value(val: string) {
|
|
58
|
+
this.inputElement.value = val;
|
|
59
|
+
this.setAttribute('value', val);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get files(): FileList | null {
|
|
63
|
+
return this.inputElement.files;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
render() {
|
|
67
|
+
const type = this.getAttribute('type') || 'text';
|
|
68
|
+
const value = this.getAttribute('value') ?? '';
|
|
69
|
+
const placeholder = this.getAttribute('placeholder') || '';
|
|
70
|
+
const disabled = this.hasAttribute('disabled');
|
|
71
|
+
const name = this.getAttribute('name') || '';
|
|
72
|
+
const ariaInvalid = this.getAttribute('aria-invalid');
|
|
73
|
+
const className = this.getAttribute('class') || '';
|
|
74
|
+
|
|
75
|
+
this.inputElement.type = type;
|
|
76
|
+
if (type !== 'file') {
|
|
77
|
+
this.inputElement.value = value;
|
|
78
|
+
}
|
|
79
|
+
this.inputElement.placeholder = placeholder;
|
|
80
|
+
this.inputElement.disabled = disabled;
|
|
81
|
+
if (name) this.inputElement.name = name;
|
|
82
|
+
if (ariaInvalid) {
|
|
83
|
+
this.inputElement.setAttribute('aria-invalid', ariaInvalid);
|
|
84
|
+
} else {
|
|
85
|
+
this.inputElement.removeAttribute('aria-invalid');
|
|
86
|
+
}
|
|
87
|
+
this.inputElement.setAttribute('data-slot', 'input');
|
|
88
|
+
this.inputElement.className = cn(
|
|
89
|
+
'h-8 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors file:h-6 file:text-sm file:font-medium 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 w-full min-w-0 outline-none file:inline-flex file:border-0 file:bg-transparent file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
|
|
90
|
+
className,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!customElements.get('surreal-input')) {
|
|
96
|
+
|
|
97
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-input')) {
|
|
98
|
+
customElements.define('surreal-shadcn-input', SurrealShadcnInput);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-input')) {
|
|
102
|
+
customElements.define('surreal-minimalist-input', SurrealShadcnInput);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default SurrealShadcnInput;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
class InputGroupElement extends HTMLElement {
|
|
2
|
+
connectedCallback() {
|
|
3
|
+
this.setAttribute('data-slot', 'input-group');
|
|
4
|
+
this.setAttribute('role', 'group');
|
|
5
|
+
this.className =
|
|
6
|
+
`group/input-group h-8 rounded-lg border border-input transition-colors in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5 relative flex w-full min-w-0 items-center outline-none has-[>textarea]:h-auto ${this.getAttribute('class') || ''}`.trim();
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class InputGroupAddonElement extends HTMLElement {
|
|
11
|
+
connectedCallback() {
|
|
12
|
+
const align = this.getAttribute('align') || 'inline-start';
|
|
13
|
+
this.setAttribute('data-slot', 'input-group-addon');
|
|
14
|
+
this.setAttribute('data-align', align);
|
|
15
|
+
this.setAttribute('role', 'group');
|
|
16
|
+
|
|
17
|
+
const alignClasses =
|
|
18
|
+
{
|
|
19
|
+
'inline-start': 'pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem] order-first',
|
|
20
|
+
'inline-end': 'pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem] order-last',
|
|
21
|
+
'block-start':
|
|
22
|
+
'px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2 order-first w-full justify-start',
|
|
23
|
+
'block-end':
|
|
24
|
+
'px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2 order-last w-full justify-start',
|
|
25
|
+
}[align] || 'pl-2 order-first';
|
|
26
|
+
|
|
27
|
+
this.className =
|
|
28
|
+
`h-auto gap-2 py-1.5 text-sm font-medium text-muted-foreground group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4 flex cursor-text items-center justify-center select-none ${alignClasses} ${this.getAttribute('class') || ''}`.trim();
|
|
29
|
+
|
|
30
|
+
this.onclick = (e) => {
|
|
31
|
+
if ((e.target as HTMLElement).closest('button')) return;
|
|
32
|
+
this.parentElement?.querySelector('input, textarea')?.focus();
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class InputGroupButtonElement extends HTMLElement {
|
|
38
|
+
connectedCallback() {
|
|
39
|
+
const size = this.getAttribute('size') || 'xs';
|
|
40
|
+
const sizeClasses =
|
|
41
|
+
{
|
|
42
|
+
xs: "h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
|
|
43
|
+
sm: 'h-7 gap-1.5 rounded-md px-2 text-xs',
|
|
44
|
+
'icon-xs': 'size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0',
|
|
45
|
+
'icon-sm': 'size-8 p-0 has-[>svg]:p-0',
|
|
46
|
+
}[size] || '';
|
|
47
|
+
|
|
48
|
+
this.setAttribute('data-size', size);
|
|
49
|
+
this.className =
|
|
50
|
+
`gap-2 text-sm flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 shadow-none hover:bg-accent hover:text-accent-foreground ${sizeClasses} ${this.getAttribute('class') || ''}`.trim();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class InputGroupInputElement extends HTMLElement {
|
|
55
|
+
connectedCallback() {
|
|
56
|
+
this.setAttribute('data-slot', 'input-group-control');
|
|
57
|
+
this.className =
|
|
58
|
+
`flex-1 rounded-none border-0 bg-transparent px-2.5 py-1 text-sm shadow-none ring-0 outline-none placeholder:text-muted-foreground focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent ${this.getAttribute('class') || ''}`.trim();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
class InputGroupTextElement extends HTMLElement {
|
|
63
|
+
connectedCallback() {
|
|
64
|
+
this.className =
|
|
65
|
+
`gap-2 text-sm text-muted-foreground [&_svg:not([class*='size-'])]:size-4 flex items-center [&_svg]:pointer-events-none ${this.getAttribute('class') || ''}`.trim();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!customElements.get('input-group')) {
|
|
70
|
+
|
|
71
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-input-group')) {
|
|
72
|
+
customElements.define('surreal-shadcn-input-group', InputGroupElement);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!customElements.get('input-group-addon')) {
|
|
76
|
+
customElements.define('surreal-shadcn-input-group', InputGroupAddonElement);
|
|
77
|
+
}
|
|
78
|
+
if (!customElements.get('input-group-button')) {
|
|
79
|
+
customElements.define('surreal-shadcn-input-group', InputGroupButtonElement);
|
|
80
|
+
}
|
|
81
|
+
if (!customElements.get('input-group-input')) {
|
|
82
|
+
customElements.define('surreal-shadcn-input-group', InputGroupInputElement);
|
|
83
|
+
}
|
|
84
|
+
if (!customElements.get('input-group-text')) {
|
|
85
|
+
customElements.define('surreal-shadcn-input-group', InputGroupTextElement);
|
|
86
|
+
};
|
|
87
|
+
export { InputGroupElement as MinimalistInputGroup, InputGroupElement };
|
|
88
|
+
|
|
89
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-input-group')) {
|
|
90
|
+
customElements.define('surreal-minimalist-input-group', InputGroupElement);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default InputGroupElement;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
class SurrealInputOTP extends HTMLElement {
|
|
2
|
+
private _value = '';
|
|
3
|
+
private _maxLength = 6;
|
|
4
|
+
private _disabled = false;
|
|
5
|
+
private _inputEl: HTMLInputElement | null = null;
|
|
6
|
+
private _isFocused = false;
|
|
7
|
+
|
|
8
|
+
static get observedAttributes() {
|
|
9
|
+
return ['value', 'maxlength', 'disabled'];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.setAttribute('data-slot', 'input-otp');
|
|
14
|
+
this.className =
|
|
15
|
+
'relative inline-flex items-center gap-2 has-disabled:opacity-50 select-none ' +
|
|
16
|
+
(this.getAttribute('class') || '');
|
|
17
|
+
this.render();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
21
|
+
if (oldValue === newValue) return;
|
|
22
|
+
if (name === 'value') {
|
|
23
|
+
this._value = newValue || '';
|
|
24
|
+
this.syncSlots();
|
|
25
|
+
} else if (name === 'maxlength') {
|
|
26
|
+
this._maxLength = parseInt(newValue || '6', 10);
|
|
27
|
+
} else if (name === 'disabled') {
|
|
28
|
+
this._disabled = newValue !== null;
|
|
29
|
+
if (this._inputEl) this._inputEl.disabled = this._disabled;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get value(): string {
|
|
34
|
+
return this._value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
set value(val: string) {
|
|
38
|
+
this._value = val || '';
|
|
39
|
+
this.setAttribute('value', this._value);
|
|
40
|
+
if (this._inputEl) this._inputEl.value = this._value;
|
|
41
|
+
this.syncSlots();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private render() {
|
|
45
|
+
if (this.querySelector('input[data-otp-input]')) return;
|
|
46
|
+
const input = document.createElement('input');
|
|
47
|
+
input.type = 'text';
|
|
48
|
+
input.inputMode = 'numeric';
|
|
49
|
+
input.autocomplete = 'one-time-code';
|
|
50
|
+
input.maxLength = this._maxLength;
|
|
51
|
+
input.value = this._value;
|
|
52
|
+
input.disabled = this._disabled;
|
|
53
|
+
input.setAttribute('data-otp-input', '');
|
|
54
|
+
input.className =
|
|
55
|
+
'absolute inset-0 h-full w-full opacity-0 cursor-pointer disabled:cursor-not-allowed z-20';
|
|
56
|
+
|
|
57
|
+
input.addEventListener('input', () => {
|
|
58
|
+
this._value = input.value.slice(0, this._maxLength);
|
|
59
|
+
this.dispatchEvent(
|
|
60
|
+
new CustomEvent('change', { detail: { value: this._value }, bubbles: true }),
|
|
61
|
+
);
|
|
62
|
+
if (this._value.length === this._maxLength) {
|
|
63
|
+
this.dispatchEvent(
|
|
64
|
+
new CustomEvent('complete', { detail: { value: this._value }, bubbles: true }),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
this.syncSlots();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
input.addEventListener('focus', () => {
|
|
71
|
+
this._isFocused = true;
|
|
72
|
+
this.syncSlots();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
input.addEventListener('blur', () => {
|
|
76
|
+
this._isFocused = false;
|
|
77
|
+
this.syncSlots();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this._inputEl = input;
|
|
81
|
+
this.prepend(input);
|
|
82
|
+
this.syncSlots();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public syncSlots() {
|
|
86
|
+
const activeIndex = this._isFocused ? Math.min(this._value.length, this._maxLength - 1) : -1;
|
|
87
|
+
const slots = this.querySelectorAll('surreal-input-otp-slot, [data-slot="input-otp-slot"]');
|
|
88
|
+
slots.forEach((slotEl, idx) => {
|
|
89
|
+
const char = this._value[idx] || '';
|
|
90
|
+
const isActive = this._isFocused && activeIndex === idx;
|
|
91
|
+
slotEl.textContent = char;
|
|
92
|
+
if (isActive) {
|
|
93
|
+
slotEl.setAttribute('data-active', '');
|
|
94
|
+
slotEl.classList.add('ring-1', 'ring-ring', 'border-ring');
|
|
95
|
+
} else {
|
|
96
|
+
slotEl.removeAttribute('data-active');
|
|
97
|
+
slotEl.classList.remove('ring-1', 'ring-ring', 'border-ring');
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class SurrealInputOTPGroup extends HTMLElement {
|
|
104
|
+
connectedCallback() {
|
|
105
|
+
this.setAttribute('data-slot', 'input-otp-group');
|
|
106
|
+
this.className = 'flex items-center ' + (this.getAttribute('class') || '');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
class SurrealInputOTPSlot extends HTMLElement {
|
|
111
|
+
connectedCallback() {
|
|
112
|
+
this.setAttribute('data-slot', 'input-otp-slot');
|
|
113
|
+
this.setAttribute('role', 'presentation');
|
|
114
|
+
this.className =
|
|
115
|
+
'relative flex h-9 w-9 items-center justify-center border-y border-r border-input text-sm shadow-xs transition-all first:rounded-l-md border-l-0 first:border-l last:rounded-r-md ' +
|
|
116
|
+
(this.getAttribute('class') || '');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
class SurrealInputOTPSeparator extends HTMLElement {
|
|
121
|
+
connectedCallback() {
|
|
122
|
+
this.setAttribute('data-slot', 'input-otp-separator');
|
|
123
|
+
this.setAttribute('role', 'separator');
|
|
124
|
+
this.className =
|
|
125
|
+
'text-muted-foreground px-1 flex items-center justify-center ' +
|
|
126
|
+
(this.getAttribute('class') || '');
|
|
127
|
+
if (!this.innerHTML.trim()) {
|
|
128
|
+
this.innerHTML =
|
|
129
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="size-4"><path d="M5 12h14"/></svg>';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!customElements.get('surreal-input-otp')) {
|
|
135
|
+
|
|
136
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-input-otp')) {
|
|
137
|
+
customElements.define('surreal-shadcn-input-otp', SurrealInputOTP);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!customElements.get('surreal-input-otp-group')) {
|
|
141
|
+
customElements.define('surreal-shadcn-input-otp', SurrealInputOTPGroup);
|
|
142
|
+
}
|
|
143
|
+
if (!customElements.get('surreal-input-otp-slot')) {
|
|
144
|
+
customElements.define('surreal-shadcn-input-otp', SurrealInputOTPSlot);
|
|
145
|
+
}
|
|
146
|
+
if (!customElements.get('surreal-input-otp-separator')) {
|
|
147
|
+
customElements.define('surreal-shadcn-input-otp', SurrealInputOTPSeparator);
|
|
148
|
+
};
|
|
149
|
+
export { SurrealInputOTP as MinimalistInputOtp, SurrealInputOTP };
|
|
150
|
+
|
|
151
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-input-otp')) {
|
|
152
|
+
customElements.define('surreal-minimalist-input-otp', SurrealInputOTP);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export default SurrealInputOTP;
|