@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,140 @@
|
|
|
1
|
+
export class SurrealShadcnNativeSelect extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ['size', 'disabled', 'value', 'name'];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
private wrapper: HTMLDivElement;
|
|
7
|
+
private selectEl: HTMLSelectElement;
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.attachShadow({ mode: 'open' });
|
|
12
|
+
|
|
13
|
+
this.wrapper = document.createElement('div');
|
|
14
|
+
this.wrapper.setAttribute('data-slot', 'native-select-wrapper');
|
|
15
|
+
this.wrapper.className = 'wrapper';
|
|
16
|
+
|
|
17
|
+
this.selectEl = document.createElement('select');
|
|
18
|
+
this.selectEl.setAttribute('data-slot', 'native-select');
|
|
19
|
+
|
|
20
|
+
const slot = document.createElement('slot');
|
|
21
|
+
this.selectEl.appendChild(slot);
|
|
22
|
+
|
|
23
|
+
const icon = document.createElement('div');
|
|
24
|
+
icon.className = 'icon';
|
|
25
|
+
icon.setAttribute('aria-hidden', 'true');
|
|
26
|
+
icon.innerHTML = `<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"><path d="m6 9 6 6 6-6"/></svg>`;
|
|
27
|
+
|
|
28
|
+
const style = document.createElement('style');
|
|
29
|
+
style.textContent = `
|
|
30
|
+
:host {
|
|
31
|
+
display: inline-block;
|
|
32
|
+
}
|
|
33
|
+
.wrapper {
|
|
34
|
+
position: relative;
|
|
35
|
+
width: fit-content;
|
|
36
|
+
display: inline-flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
}
|
|
39
|
+
.wrapper[data-disabled="true"] {
|
|
40
|
+
opacity: 0.5;
|
|
41
|
+
pointer-events: none;
|
|
42
|
+
}
|
|
43
|
+
select {
|
|
44
|
+
height: 2rem;
|
|
45
|
+
width: 100%;
|
|
46
|
+
min-width: 0;
|
|
47
|
+
appearance: none;
|
|
48
|
+
-webkit-appearance: none;
|
|
49
|
+
border-radius: var(--radius, 0.5rem);
|
|
50
|
+
border: 1px solid var(--input, #e4e4e7);
|
|
51
|
+
background-color: transparent;
|
|
52
|
+
padding: 0.25rem 2rem 0.25rem 0.625rem;
|
|
53
|
+
font-size: 0.875rem;
|
|
54
|
+
line-height: 1.25rem;
|
|
55
|
+
color: var(--foreground, #09090b);
|
|
56
|
+
outline: none;
|
|
57
|
+
box-sizing: border-box;
|
|
58
|
+
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
user-select: none;
|
|
61
|
+
}
|
|
62
|
+
.wrapper[data-size="sm"] select {
|
|
63
|
+
height: 1.75rem;
|
|
64
|
+
padding-top: 0.125rem;
|
|
65
|
+
padding-bottom: 0.125rem;
|
|
66
|
+
}
|
|
67
|
+
select:focus-visible {
|
|
68
|
+
border-color: var(--ring, #18181b);
|
|
69
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring, #18181b) 50%, transparent);
|
|
70
|
+
}
|
|
71
|
+
select:disabled {
|
|
72
|
+
cursor: not-allowed;
|
|
73
|
+
pointer-events: none;
|
|
74
|
+
}
|
|
75
|
+
.icon {
|
|
76
|
+
position: absolute;
|
|
77
|
+
right: 0.625rem;
|
|
78
|
+
top: 50%;
|
|
79
|
+
transform: translateY(-50%);
|
|
80
|
+
width: 1rem;
|
|
81
|
+
height: 1rem;
|
|
82
|
+
pointer-events: none;
|
|
83
|
+
color: var(--muted-foreground, #71717a);
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
}
|
|
88
|
+
::slotted(option) {
|
|
89
|
+
background: Canvas;
|
|
90
|
+
color: CanvasText;
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
this.wrapper.appendChild(this.selectEl);
|
|
95
|
+
this.wrapper.appendChild(icon);
|
|
96
|
+
this.shadowRoot!.appendChild(style);
|
|
97
|
+
this.shadowRoot!.appendChild(this.wrapper);
|
|
98
|
+
|
|
99
|
+
this.selectEl.addEventListener('change', (e) => {
|
|
100
|
+
this.dispatchEvent(
|
|
101
|
+
new CustomEvent('change', {
|
|
102
|
+
detail: { value: this.selectEl.value },
|
|
103
|
+
bubbles: true,
|
|
104
|
+
composed: true,
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get value() {
|
|
111
|
+
return this.selectEl.value;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
set value(val: string) {
|
|
115
|
+
this.selectEl.value = val;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
119
|
+
if (name === 'size') {
|
|
120
|
+
this.wrapper.setAttribute('data-size', newValue || 'default');
|
|
121
|
+
this.selectEl.setAttribute('data-size', newValue || 'default');
|
|
122
|
+
} else if (name === 'disabled') {
|
|
123
|
+
const isDisabled = newValue !== null;
|
|
124
|
+
this.selectEl.disabled = isDisabled;
|
|
125
|
+
this.wrapper.setAttribute('data-disabled', String(isDisabled));
|
|
126
|
+
} else if (name === 'value' && newValue !== null) {
|
|
127
|
+
this.selectEl.value = newValue;
|
|
128
|
+
} else if (name === 'name' && newValue !== null) {
|
|
129
|
+
this.selectEl.name = newValue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!customElements.get('surreal-native-select')) {
|
|
135
|
+
|
|
136
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-native-select')) {
|
|
137
|
+
customElements.define('surreal-shadcn-native-select', SurrealShadcnNativeSelect);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export default SurrealShadcnNativeSelect;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
class NavigationMenuElement extends HTMLElement {
|
|
2
|
+
private _openItem: string | null = null;
|
|
3
|
+
|
|
4
|
+
connectedCallback() {
|
|
5
|
+
this.setAttribute('data-slot', 'navigation-menu');
|
|
6
|
+
this.className =
|
|
7
|
+
'max-w-max group/navigation-menu relative flex flex-1 items-center justify-center ' +
|
|
8
|
+
(this.getAttribute('class') || '');
|
|
9
|
+
|
|
10
|
+
this.addEventListener('click', this.handleClick.bind(this));
|
|
11
|
+
document.addEventListener('click', this.handleOutsideClick.bind(this));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
disconnectedCallback() {
|
|
15
|
+
document.removeEventListener('click', this.handleOutsideClick.bind(this));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private handleClick(e: Event) {
|
|
19
|
+
const target = (e.target as HTMLElement).closest(
|
|
20
|
+
'[data-slot="navigation-menu-trigger"]',
|
|
21
|
+
) as HTMLElement | null;
|
|
22
|
+
if (!target) return;
|
|
23
|
+
|
|
24
|
+
const item = target.closest('[data-slot="navigation-menu-item"]') as HTMLElement | null;
|
|
25
|
+
if (!item) return;
|
|
26
|
+
|
|
27
|
+
const itemId =
|
|
28
|
+
item.getAttribute('data-value') ||
|
|
29
|
+
item.id ||
|
|
30
|
+
Array.from(this.querySelectorAll('[data-slot="navigation-menu-item"]'))
|
|
31
|
+
.indexOf(item)
|
|
32
|
+
.toString();
|
|
33
|
+
|
|
34
|
+
if (this._openItem === itemId) {
|
|
35
|
+
this.closeAll();
|
|
36
|
+
} else {
|
|
37
|
+
this.open(itemId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private handleOutsideClick(e: Event) {
|
|
42
|
+
if (!this.contains(e.target as Node)) {
|
|
43
|
+
this.closeAll();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private open(itemId: string) {
|
|
48
|
+
this._openItem = itemId;
|
|
49
|
+
const items = this.querySelectorAll('[data-slot="navigation-menu-item"]');
|
|
50
|
+
items.forEach((item, idx) => {
|
|
51
|
+
const id = item.getAttribute('data-value') || item.id || idx.toString();
|
|
52
|
+
const trigger = item.querySelector('[data-slot="navigation-menu-trigger"]');
|
|
53
|
+
const content = item.querySelector('[data-slot="navigation-menu-content"]');
|
|
54
|
+
const isOpen = id === itemId;
|
|
55
|
+
|
|
56
|
+
if (trigger) {
|
|
57
|
+
trigger.setAttribute('data-state', isOpen ? 'open' : 'closed');
|
|
58
|
+
trigger.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
|
|
59
|
+
}
|
|
60
|
+
if (content) {
|
|
61
|
+
content.setAttribute('data-state', isOpen ? 'open' : 'closed');
|
|
62
|
+
if (isOpen) {
|
|
63
|
+
content.classList.remove('hidden');
|
|
64
|
+
} else {
|
|
65
|
+
content.classList.add('hidden');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private closeAll() {
|
|
72
|
+
this._openItem = null;
|
|
73
|
+
const triggers = this.querySelectorAll('[data-slot="navigation-menu-trigger"]');
|
|
74
|
+
const contents = this.querySelectorAll('[data-slot="navigation-menu-content"]');
|
|
75
|
+
triggers.forEach((t) => {
|
|
76
|
+
t.setAttribute('data-state', 'closed');
|
|
77
|
+
t.setAttribute('aria-expanded', 'false');
|
|
78
|
+
});
|
|
79
|
+
contents.forEach((c) => {
|
|
80
|
+
c.setAttribute('data-state', 'closed');
|
|
81
|
+
c.classList.add('hidden');
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-navigation-menu')) {
|
|
87
|
+
|
|
88
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-navigation-menu')) {
|
|
89
|
+
customElements.define('surreal-shadcn-navigation-menu', NavigationMenuElement);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export { NavigationMenuElement as ShadcnNavigationMenu, NavigationMenuElement };
|
|
93
|
+
|
|
94
|
+
export default NavigationMenuElement;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
class SurrealShadcnPagination extends HTMLElement {
|
|
2
|
+
connectedCallback() {
|
|
3
|
+
this.setAttribute('role', 'navigation');
|
|
4
|
+
this.setAttribute('aria-label', 'pagination');
|
|
5
|
+
this.setAttribute('data-slot', 'pagination');
|
|
6
|
+
this.className =
|
|
7
|
+
'cn-pagination mx-auto flex w-full justify-center ' + (this.getAttribute('class') || '');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class SurrealShadcnPaginationContent extends HTMLElement {
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.setAttribute('data-slot', 'pagination-content');
|
|
14
|
+
this.className =
|
|
15
|
+
'gap-0.5 flex items-center list-none m-0 p-0 ' + (this.getAttribute('class') || '');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class SurrealShadcnPaginationItem extends HTMLElement {
|
|
20
|
+
connectedCallback() {
|
|
21
|
+
this.setAttribute('data-slot', 'pagination-item');
|
|
22
|
+
this.className = 'inline-flex ' + (this.getAttribute('class') || '');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class SurrealShadcnPaginationLink extends HTMLElement {
|
|
27
|
+
static get observedAttributes() {
|
|
28
|
+
return ['is-active', 'size', 'href'];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
this.render();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
attributeChangedCallback() {
|
|
36
|
+
this.render();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
render() {
|
|
40
|
+
const isActive = this.hasAttribute('is-active') && this.getAttribute('is-active') !== 'false';
|
|
41
|
+
const size = this.getAttribute('size') || 'icon';
|
|
42
|
+
const href = this.getAttribute('href') || '#';
|
|
43
|
+
const label = this.getAttribute('aria-label') || '';
|
|
44
|
+
const innerHtml = this.innerHTML;
|
|
45
|
+
|
|
46
|
+
const sizeClasses =
|
|
47
|
+
size === 'default'
|
|
48
|
+
? 'h-9 px-4 py-2'
|
|
49
|
+
: size === 'sm'
|
|
50
|
+
? 'h-8 rounded-md px-3 text-xs'
|
|
51
|
+
: size === 'lg'
|
|
52
|
+
? 'h-10 rounded-md px-8'
|
|
53
|
+
: 'h-9 w-9';
|
|
54
|
+
const variantClasses = isActive
|
|
55
|
+
? 'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground'
|
|
56
|
+
: 'hover:bg-accent hover:text-accent-foreground';
|
|
57
|
+
|
|
58
|
+
this.setAttribute('data-slot', 'pagination-link');
|
|
59
|
+
this.setAttribute('data-active', String(isActive));
|
|
60
|
+
this.setAttribute('data-size', size);
|
|
61
|
+
this.className = `inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring cursor-pointer ${variantClasses} ${sizeClasses} cn-pagination-link ${this.getAttribute('class') || ''}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class SurrealShadcnPaginationPrevious extends HTMLElement {
|
|
66
|
+
connectedCallback() {
|
|
67
|
+
this.setAttribute('data-slot', 'pagination-previous');
|
|
68
|
+
const href = this.getAttribute('href') || '#';
|
|
69
|
+
this.className =
|
|
70
|
+
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 pl-1.5! gap-1 cursor-pointer ' +
|
|
71
|
+
(this.getAttribute('class') || '');
|
|
72
|
+
if (!this.innerHTML.trim()) {
|
|
73
|
+
this.innerHTML = `
|
|
74
|
+
<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="m15 18-6-6 6-6"/></svg>
|
|
75
|
+
<span class="cn-pagination-previous-text hidden sm:block">Previous</span>
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
class SurrealShadcnPaginationNext extends HTMLElement {
|
|
82
|
+
connectedCallback() {
|
|
83
|
+
this.setAttribute('data-slot', 'pagination-next');
|
|
84
|
+
const href = this.getAttribute('href') || '#';
|
|
85
|
+
this.className =
|
|
86
|
+
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 pr-1.5! gap-1 cursor-pointer ' +
|
|
87
|
+
(this.getAttribute('class') || '');
|
|
88
|
+
if (!this.innerHTML.trim()) {
|
|
89
|
+
this.innerHTML = `
|
|
90
|
+
<span class="cn-pagination-next-text hidden sm:block">Next</span>
|
|
91
|
+
<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="m9 18 6-6-6-6"/></svg>
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
class SurrealShadcnPaginationEllipsis extends HTMLElement {
|
|
98
|
+
connectedCallback() {
|
|
99
|
+
this.setAttribute('aria-hidden', 'true');
|
|
100
|
+
this.setAttribute('data-slot', 'pagination-ellipsis');
|
|
101
|
+
this.className =
|
|
102
|
+
'size-8 items-center justify-center flex items-center justify-center ' +
|
|
103
|
+
(this.getAttribute('class') || '');
|
|
104
|
+
this.innerHTML = `
|
|
105
|
+
<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"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></svg>
|
|
106
|
+
<span class="sr-only">More pages</span>
|
|
107
|
+
`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!customElements.get('surreal-pagination')) {
|
|
112
|
+
|
|
113
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-pagination')) {
|
|
114
|
+
customElements.define('surreal-shadcn-pagination', SurrealShadcnPagination);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!customElements.get('surreal-pagination-content')) {
|
|
118
|
+
customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationContent);
|
|
119
|
+
}
|
|
120
|
+
if (!customElements.get('surreal-pagination-item')) {
|
|
121
|
+
customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationItem);
|
|
122
|
+
}
|
|
123
|
+
if (!customElements.get('surreal-pagination-link')) {
|
|
124
|
+
customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationLink);
|
|
125
|
+
}
|
|
126
|
+
if (!customElements.get('surreal-pagination-previous')) {
|
|
127
|
+
customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationPrevious);
|
|
128
|
+
}
|
|
129
|
+
if (!customElements.get('surreal-pagination-next')) {
|
|
130
|
+
customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationNext);
|
|
131
|
+
}
|
|
132
|
+
if (!customElements.get('surreal-pagination-ellipsis')) {
|
|
133
|
+
customElements.define('surreal-shadcn-pagination', SurrealShadcnPaginationEllipsis);
|
|
134
|
+
};
|
|
135
|
+
export { SurrealShadcnPagination as ShadcnPagination, SurrealShadcnPagination };
|
|
136
|
+
|
|
137
|
+
export default SurrealShadcnPagination;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
class SurrealShadcnPopover extends HTMLElement {
|
|
2
|
+
private _open = false;
|
|
3
|
+
private _trigger: HTMLElement | null = null;
|
|
4
|
+
private _content: HTMLElement | null = null;
|
|
5
|
+
private _handleOutsideClick: (e: MouseEvent) => void;
|
|
6
|
+
private _handleKeyDown: (e: KeyboardEvent) => void;
|
|
7
|
+
|
|
8
|
+
static get observedAttributes() {
|
|
9
|
+
return ['open'];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this._handleOutsideClick = (e: MouseEvent) => {
|
|
15
|
+
if (this._open && !this.contains(e.target as Node)) {
|
|
16
|
+
this.open = false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
this._handleKeyDown = (e: KeyboardEvent) => {
|
|
20
|
+
if (this._open && e.key === 'Escape') {
|
|
21
|
+
this.open = false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get open(): boolean {
|
|
27
|
+
return this._open;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
set open(val: boolean) {
|
|
31
|
+
const next = Boolean(val);
|
|
32
|
+
if (this._open !== next) {
|
|
33
|
+
this._open = next;
|
|
34
|
+
if (next) {
|
|
35
|
+
this.setAttribute('open', '');
|
|
36
|
+
} else {
|
|
37
|
+
this.removeAttribute('open');
|
|
38
|
+
}
|
|
39
|
+
this._updateState();
|
|
40
|
+
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: this._open } }));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
|
|
45
|
+
if (name === 'open') {
|
|
46
|
+
this._open = newValue !== null;
|
|
47
|
+
this._updateState();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
connectedCallback() {
|
|
52
|
+
this.classList.add('relative', 'inline-block');
|
|
53
|
+
this._bindElements();
|
|
54
|
+
document.addEventListener('click', this._handleOutsideClick);
|
|
55
|
+
document.addEventListener('keydown', this._handleKeyDown);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
disconnectedCallback() {
|
|
59
|
+
document.removeEventListener('click', this._handleOutsideClick);
|
|
60
|
+
document.removeEventListener('keydown', this._handleKeyDown);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private _bindElements() {
|
|
64
|
+
this._trigger = this.querySelector('[data-slot="popover-trigger"]');
|
|
65
|
+
this._content = this.querySelector('[data-slot="popover-content"]');
|
|
66
|
+
|
|
67
|
+
if (this._trigger) {
|
|
68
|
+
this._trigger.setAttribute('aria-haspopup', 'dialog');
|
|
69
|
+
this._trigger.setAttribute('aria-expanded', String(this._open));
|
|
70
|
+
this._trigger.addEventListener('click', () => {
|
|
71
|
+
this.open = !this.open;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const closeButtons = this.querySelectorAll('[data-slot="popover-close"]');
|
|
76
|
+
closeButtons.forEach((btn) => {
|
|
77
|
+
btn.addEventListener('click', () => {
|
|
78
|
+
this.open = false;
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
this._updateState();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private _updateState() {
|
|
86
|
+
if (this._trigger) {
|
|
87
|
+
this._trigger.setAttribute('aria-expanded', String(this._open));
|
|
88
|
+
}
|
|
89
|
+
if (this._content) {
|
|
90
|
+
if (this._open) {
|
|
91
|
+
this._content.removeAttribute('hidden');
|
|
92
|
+
this._content.setAttribute('data-open', '');
|
|
93
|
+
} else {
|
|
94
|
+
this._content.setAttribute('hidden', '');
|
|
95
|
+
this._content.removeAttribute('data-open');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-popover')) {
|
|
102
|
+
|
|
103
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-popover')) {
|
|
104
|
+
customElements.define('surreal-shadcn-popover', SurrealShadcnPopover);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
export { SurrealShadcnPopover as ShadcnPopover, SurrealShadcnPopover };
|
|
108
|
+
|
|
109
|
+
export default SurrealShadcnPopover;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { cn } from '@surreal-ui/core';
|
|
2
|
+
|
|
3
|
+
export class ProgressElement extends HTMLElement {
|
|
4
|
+
private _indicator: HTMLDivElement | null = null;
|
|
5
|
+
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return ['value', 'max', 'class'];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
connectedCallback() {
|
|
11
|
+
this.render();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
attributeChangedCallback() {
|
|
15
|
+
this.update();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get value(): number {
|
|
19
|
+
const val = this.getAttribute('value');
|
|
20
|
+
return val !== null ? Number(val) : 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
set value(val: number) {
|
|
24
|
+
this.setAttribute('value', String(val));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get max(): number {
|
|
28
|
+
const max = this.getAttribute('max');
|
|
29
|
+
return max !== null ? Number(max) : 100;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
set max(val: number) {
|
|
33
|
+
this.setAttribute('max', String(val));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private update() {
|
|
37
|
+
if (!this._indicator) return;
|
|
38
|
+
const value = this.value;
|
|
39
|
+
const max = this.max || 1;
|
|
40
|
+
const percentage = 100 - (100 * (value ?? 0)) / max;
|
|
41
|
+
this.setAttribute('role', 'progressbar');
|
|
42
|
+
this.setAttribute('aria-valuemin', '0');
|
|
43
|
+
this.setAttribute('aria-valuemax', String(max));
|
|
44
|
+
this.setAttribute('aria-valuenow', String(value));
|
|
45
|
+
this._indicator.style.transform = `translateX(-${percentage}%)`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private render() {
|
|
49
|
+
const customClass = this.getAttribute('class') || '';
|
|
50
|
+
this.className = cn(
|
|
51
|
+
'h-1 rounded-full bg-muted relative flex w-full items-center overflow-x-hidden',
|
|
52
|
+
customClass,
|
|
53
|
+
);
|
|
54
|
+
this.setAttribute('data-slot', 'progress');
|
|
55
|
+
this.innerHTML = `<div data-slot="progress-indicator" class="bg-primary size-full flex-1 transition-all duration-300"></div>`;
|
|
56
|
+
this._indicator = this.querySelector('[data-slot="progress-indicator"]');
|
|
57
|
+
this.update();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!customElements.get('ui-progress')) {
|
|
62
|
+
|
|
63
|
+
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-progress')) {
|
|
64
|
+
customElements.define('surreal-shadcn-progress', ProgressElement);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export default ProgressElement;
|