@surreal-ui/web 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +832 -6249
  3. package/dist/utils.d.ts +9 -0
  4. package/dist/utils.js +14 -0
  5. package/package.json +14 -3
  6. package/CHANGELOG.md +0 -149
  7. package/src/components/GlassmorphismAlert.ts +0 -115
  8. package/src/components/GlassmorphismButton.ts +0 -18
  9. package/src/components/GlassmorphismCard.ts +0 -36
  10. package/src/components/GlassmorphismEmptyState.ts +0 -35
  11. package/src/components/GlassmorphismInputGroup.ts +0 -205
  12. package/src/components/GlassmorphismMenubar.ts +0 -36
  13. package/src/components/GlassmorphismScrollArea.ts +0 -86
  14. package/src/components/GlassmorphismTable.ts +0 -52
  15. package/src/components/GlassmorphismTypography.ts +0 -70
  16. package/src/components/MinimalistAccordion.ts +0 -252
  17. package/src/components/MinimalistAlert.ts +0 -98
  18. package/src/components/MinimalistAlertDialog.ts +0 -102
  19. package/src/components/MinimalistAspectRatio.ts +0 -36
  20. package/src/components/MinimalistAvatar.ts +0 -97
  21. package/src/components/MinimalistBadge.ts +0 -70
  22. package/src/components/MinimalistBreadcrumb.ts +0 -92
  23. package/src/components/MinimalistButton.ts +0 -110
  24. package/src/components/MinimalistButtonGroup.ts +0 -112
  25. package/src/components/MinimalistCalendar.ts +0 -281
  26. package/src/components/MinimalistCard.ts +0 -130
  27. package/src/components/MinimalistCarousel.ts +0 -121
  28. package/src/components/MinimalistChart.ts +0 -150
  29. package/src/components/MinimalistCheckbox.ts +0 -178
  30. package/src/components/MinimalistCodeBlock.ts +0 -112
  31. package/src/components/MinimalistCollapsible.ts +0 -160
  32. package/src/components/MinimalistCommand.ts +0 -111
  33. package/src/components/MinimalistContextMenu.ts +0 -101
  34. package/src/components/MinimalistDialog.ts +0 -103
  35. package/src/components/MinimalistDrawer.ts +0 -222
  36. package/src/components/MinimalistDropdownMenu.ts +0 -125
  37. package/src/components/MinimalistEmpty.ts +0 -97
  38. package/src/components/MinimalistEmptyState.ts +0 -41
  39. package/src/components/MinimalistField.ts +0 -176
  40. package/src/components/MinimalistForm.ts +0 -102
  41. package/src/components/MinimalistHoverCard.ts +0 -149
  42. package/src/components/MinimalistInput.ts +0 -104
  43. package/src/components/MinimalistInputGroup.ts +0 -95
  44. package/src/components/MinimalistInputOtp.ts +0 -154
  45. package/src/components/MinimalistItem.ts +0 -159
  46. package/src/components/MinimalistKbd.ts +0 -37
  47. package/src/components/MinimalistLabel.ts +0 -53
  48. package/src/components/MinimalistMenubar.ts +0 -81
  49. package/src/components/MinimalistNativeSelect.ts +0 -149
  50. package/src/components/MinimalistNavigationMenu.ts +0 -103
  51. package/src/components/MinimalistPagination.ts +0 -140
  52. package/src/components/MinimalistPopover.ts +0 -112
  53. package/src/components/MinimalistProgress.ts +0 -70
  54. package/src/components/MinimalistRadioGroup.ts +0 -228
  55. package/src/components/MinimalistRangeCalendar.ts +0 -272
  56. package/src/components/MinimalistResizable.ts +0 -44
  57. package/src/components/MinimalistScrollArea.ts +0 -42
  58. package/src/components/MinimalistSelect.ts +0 -103
  59. package/src/components/MinimalistSeparator.ts +0 -52
  60. package/src/components/MinimalistSheet.ts +0 -165
  61. package/src/components/MinimalistSidebar.ts +0 -74
  62. package/src/components/MinimalistSkeleton.ts +0 -32
  63. package/src/components/MinimalistSlider.ts +0 -236
  64. package/src/components/MinimalistSonner.ts +0 -93
  65. package/src/components/MinimalistSpinner.ts +0 -52
  66. package/src/components/MinimalistSwitch.ts +0 -165
  67. package/src/components/MinimalistTable.ts +0 -35
  68. package/src/components/MinimalistTabs.ts +0 -97
  69. package/src/components/MinimalistTextarea.ts +0 -99
  70. package/src/components/MinimalistToggle.ts +0 -104
  71. package/src/components/MinimalistToggleGroup.ts +0 -177
  72. package/src/components/MinimalistTooltip.ts +0 -82
  73. package/src/components/MinimalistTypography.ts +0 -106
  74. package/src/components/NeubrutalismCard.ts +0 -35
  75. package/src/components/NeubrutalismItem.ts +0 -67
  76. package/src/components/ShadcnAccordion.ts +0 -248
  77. package/src/components/ShadcnAlertDialog.ts +0 -95
  78. package/src/components/ShadcnAspectRatio.ts +0 -29
  79. package/src/components/ShadcnAvatar.ts +0 -93
  80. package/src/components/ShadcnBadge.ts +0 -66
  81. package/src/components/ShadcnBreadcrumb.ts +0 -88
  82. package/src/components/ShadcnButton.ts +0 -106
  83. package/src/components/ShadcnButtonGroup.ts +0 -105
  84. package/src/components/ShadcnCalendar.ts +0 -277
  85. package/src/components/ShadcnCarousel.ts +0 -117
  86. package/src/components/ShadcnChart.ts +0 -146
  87. package/src/components/ShadcnCheckbox.ts +0 -174
  88. package/src/components/ShadcnCodeBlock.ts +0 -108
  89. package/src/components/ShadcnCollapsible.ts +0 -153
  90. package/src/components/ShadcnCommand.ts +0 -107
  91. package/src/components/ShadcnContextMenu.ts +0 -94
  92. package/src/components/ShadcnDialog.ts +0 -99
  93. package/src/components/ShadcnDrawer.ts +0 -218
  94. package/src/components/ShadcnDropdownMenu.ts +0 -118
  95. package/src/components/ShadcnEmpty.ts +0 -93
  96. package/src/components/ShadcnField.ts +0 -172
  97. package/src/components/ShadcnForm.ts +0 -98
  98. package/src/components/ShadcnHoverCard.ts +0 -145
  99. package/src/components/ShadcnInput.ts +0 -100
  100. package/src/components/ShadcnInputGroup.ts +0 -88
  101. package/src/components/ShadcnInputOtp.ts +0 -150
  102. package/src/components/ShadcnItem.ts +0 -155
  103. package/src/components/ShadcnKbd.ts +0 -33
  104. package/src/components/ShadcnLabel.ts +0 -49
  105. package/src/components/ShadcnMenubar.ts +0 -77
  106. package/src/components/ShadcnNativeSelect.ts +0 -142
  107. package/src/components/ShadcnNavigationMenu.ts +0 -96
  108. package/src/components/ShadcnPagination.ts +0 -136
  109. package/src/components/ShadcnPopover.ts +0 -108
  110. package/src/components/ShadcnProgress.ts +0 -66
  111. package/src/components/ShadcnRadioGroup.ts +0 -221
  112. package/src/components/ShadcnRangeCalendar.ts +0 -265
  113. package/src/components/ShadcnSelect.ts +0 -99
  114. package/src/components/ShadcnSeparator.ts +0 -48
  115. package/src/components/ShadcnSheet.ts +0 -161
  116. package/src/components/ShadcnSidebar.ts +0 -70
  117. package/src/components/ShadcnSkeleton.ts +0 -28
  118. package/src/components/ShadcnSlider.ts +0 -232
  119. package/src/components/ShadcnSonner.ts +0 -89
  120. package/src/components/ShadcnSpinner.ts +0 -48
  121. package/src/components/ShadcnSwitch.ts +0 -161
  122. package/src/components/ShadcnTabs.ts +0 -93
  123. package/src/components/ShadcnTextarea.ts +0 -95
  124. package/src/components/ShadcnToggle.ts +0 -100
  125. package/src/components/ShadcnToggleGroup.ts +0 -170
  126. package/src/components/ShadcnTooltip.ts +0 -78
  127. package/src/index.ts +0 -124
@@ -1,93 +0,0 @@
1
- import { cn, cva } from '@surreal-ui/core';
2
-
3
- const emptyMediaVariants = cva(
4
- 'mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0',
5
- {
6
- variants: {
7
- variant: {
8
- default: 'bg-transparent',
9
- icon: "flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-4"
10
- }
11
- },
12
- defaultVariants: {
13
- variant: 'default'
14
- }
15
- }
16
- );
17
-
18
- export class UiEmpty extends HTMLElement {
19
- connectedCallback() {
20
- this.setAttribute('data-slot', 'empty');
21
- this.className = cn(
22
- 'gap-4 rounded-xl border border-dashed p-6 flex w-full min-w-0 flex-1 flex-col items-center justify-center text-center text-balance',
23
- this.className
24
- );
25
- }
26
- }
27
-
28
- export class UiEmptyHeader extends HTMLElement {
29
- connectedCallback() {
30
- this.setAttribute('data-slot', 'empty-header');
31
- this.className = cn('gap-2 flex max-w-sm flex-col items-center', this.className);
32
- }
33
- }
34
-
35
- export class UiEmptyMedia extends HTMLElement {
36
- static get observedAttributes() {
37
- return ['variant'];
38
- }
39
-
40
- connectedCallback() {
41
- this.render();
42
- }
43
-
44
- attributeChangedCallback() {
45
- this.render();
46
- }
47
-
48
- render() {
49
- const variant = (this.getAttribute('variant') || 'default') as 'default' | 'icon';
50
- this.setAttribute('data-slot', 'empty-icon');
51
- this.setAttribute('data-variant', variant);
52
- this.className = cn(emptyMediaVariants({ variant }), this.getAttribute('class') || '');
53
- }
54
- }
55
-
56
- export class UiEmptyTitle extends HTMLElement {
57
- connectedCallback() {
58
- this.setAttribute('data-slot', 'empty-title');
59
- this.className = cn('text-sm font-medium tracking-tight', this.className);
60
- }
61
- }
62
-
63
- export class UiEmptyDescription extends HTMLElement {
64
- connectedCallback() {
65
- this.setAttribute('data-slot', 'empty-description');
66
- this.className = cn(
67
- 'text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary',
68
- this.className
69
- );
70
- }
71
- }
72
-
73
- export class UiEmptyContent extends HTMLElement {
74
- connectedCallback() {
75
- this.setAttribute('data-slot', 'empty-content');
76
- this.className = cn(
77
- 'gap-2.5 text-sm flex w-full max-w-sm min-w-0 flex-col items-center text-balance',
78
- this.className
79
- );
80
- }
81
- }
82
-
83
- if (!customElements.get('ui-empty')) {
84
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-empty')) {
85
- customElements.define('surreal-shadcn-empty', UiEmpty);
86
- }
87
- customElements.define('surreal-shadcn-empty', UiEmptyHeader);
88
- customElements.define('surreal-shadcn-empty', UiEmptyMedia);
89
- customElements.define('surreal-shadcn-empty', UiEmptyTitle);
90
- customElements.define('surreal-shadcn-empty', UiEmptyDescription);
91
- customElements.define('surreal-shadcn-empty', UiEmptyContent);
92
- }
93
- export default UiEmpty;
@@ -1,172 +0,0 @@
1
- import { cn, cva } from '@surreal-ui/core';
2
-
3
- const fieldVariants = cva('gap-2 data-[invalid=true]:text-destructive group/field flex w-full', {
4
- variants: {
5
- orientation: {
6
- vertical: 'cn-field-orientation-vertical flex-col [&>*]:w-full [&>.sr-only]:w-auto',
7
- horizontal:
8
- 'cn-field-orientation-horizontal flex-row items-center has-[>[data-slot=field-content]]:items-start [&>[data-slot=field-label]]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
9
- responsive:
10
- 'cn-field-orientation-responsive flex-col @md/field-group:flex-row @md/field-group:items-center @md/field-group:has-[>[data-slot=field-content]]:items-start [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto @md/field-group:[&>[data-slot=field-label]]:flex-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px'
11
- }
12
- },
13
- defaultVariants: {
14
- orientation: 'vertical'
15
- }
16
- });
17
-
18
- export class UIField extends HTMLElement {
19
- static get observedAttributes() {
20
- return ['orientation', 'invalid', 'class'];
21
- }
22
- connectedCallback() {
23
- this.render();
24
- }
25
- attributeChangedCallback() {
26
- this.render();
27
- }
28
- render() {
29
- const orientation = (this.getAttribute('orientation') || 'vertical') as
30
- 'vertical' | 'horizontal' | 'responsive';
31
- const invalid = this.hasAttribute('invalid') && this.getAttribute('invalid') !== 'false';
32
- const userClass = this.getAttribute('class') || '';
33
- this.setAttribute('role', 'group');
34
- this.setAttribute('data-slot', 'field');
35
- this.setAttribute('data-orientation', orientation);
36
- if (invalid) {
37
- this.setAttribute('data-invalid', 'true');
38
- } else {
39
- this.removeAttribute('data-invalid');
40
- }
41
- this.className = cn(fieldVariants({ orientation }), userClass);
42
- }
43
- }
44
- if (!customElements.get('ui-field'))
45
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-field')) {
46
- customElements.define('surreal-shadcn-field', UIField);
47
- }
48
-
49
- export class UIFieldGroup extends HTMLElement {
50
- connectedCallback() {
51
- this.setAttribute('data-slot', 'field-group');
52
- this.className = cn(
53
- 'gap-5 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4 group/field-group @container/field-group flex w-full flex-col',
54
- this.getAttribute('class') || ''
55
- );
56
- }
57
- }
58
- if (!customElements.get('ui-field-group'))
59
- customElements.define('surreal-shadcn-field', UIFieldGroup);
60
-
61
- export class UIFieldSet extends HTMLElement {
62
- connectedCallback() {
63
- this.setAttribute('data-slot', 'field-set');
64
- this.className = cn(
65
- 'gap-4 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3 flex flex-col border-0 p-0 m-0',
66
- this.getAttribute('class') || ''
67
- );
68
- }
69
- }
70
- if (!customElements.get('ui-field-set')) customElements.define('surreal-shadcn-field', UIFieldSet);
71
-
72
- export class UIFieldContent extends HTMLElement {
73
- connectedCallback() {
74
- this.setAttribute('data-slot', 'field-content');
75
- this.className = cn(
76
- 'gap-0.5 group/field-content flex flex-1 flex-col leading-snug',
77
- this.getAttribute('class') || ''
78
- );
79
- }
80
- }
81
- if (!customElements.get('ui-field-content'))
82
- customElements.define('surreal-shadcn-field', UIFieldContent);
83
-
84
- export class UIFieldLabel extends HTMLElement {
85
- connectedCallback() {
86
- this.setAttribute('data-slot', 'field-label');
87
- this.className = cn(
88
- 'gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:border-primary/30 has-data-checked:bg-primary/5 has-[>[data-slot=field]]:rounded-lg has-[>[data-slot=field]]:border *:data-[slot=field]:p-2.5 dark:has-data-checked:border-primary/20 dark:has-data-checked:bg-primary/10 group/field-label peer/field-label flex w-fit cursor-pointer text-sm font-medium text-foreground has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col',
89
- this.getAttribute('class') || ''
90
- );
91
- }
92
- }
93
- if (!customElements.get('ui-field-label'))
94
- customElements.define('surreal-shadcn-field', UIFieldLabel);
95
-
96
- export class UIFieldLegend extends HTMLElement {
97
- static get observedAttributes() {
98
- return ['variant', 'class'];
99
- }
100
- connectedCallback() {
101
- this.render();
102
- }
103
- attributeChangedCallback() {
104
- this.render();
105
- }
106
- render() {
107
- const variant = this.getAttribute('variant') || 'legend';
108
- this.setAttribute('data-slot', 'field-legend');
109
- this.setAttribute('data-variant', variant);
110
- this.className = cn(
111
- 'mb-1.5 font-medium data-[variant=label]:text-sm data-[variant=legend]:text-base text-foreground block',
112
- this.getAttribute('class') || ''
113
- );
114
- }
115
- }
116
- if (!customElements.get('ui-field-legend'))
117
- customElements.define('surreal-shadcn-field', UIFieldLegend);
118
-
119
- export class UIFieldTitle extends HTMLElement {
120
- connectedCallback() {
121
- this.setAttribute('data-slot', 'field-label');
122
- this.className = cn(
123
- 'gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50 flex w-fit items-center text-foreground',
124
- this.getAttribute('class') || ''
125
- );
126
- }
127
- }
128
- if (!customElements.get('ui-field-title'))
129
- customElements.define('surreal-shadcn-field', UIFieldTitle);
130
-
131
- export class UIFieldDescription extends HTMLElement {
132
- connectedCallback() {
133
- this.setAttribute('data-slot', 'field-description');
134
- this.className = cn(
135
- 'text-left text-sm text-muted-foreground [[data-variant=legend]+&]:-mt-1.5 leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance last:mt-0 nth-last-2:-mt-1 [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary block',
136
- this.getAttribute('class') || ''
137
- );
138
- }
139
- }
140
- if (!customElements.get('ui-field-description'))
141
- customElements.define('surreal-shadcn-field', UIFieldDescription);
142
-
143
- export class UIFieldError extends HTMLElement {
144
- connectedCallback() {
145
- this.setAttribute('role', 'alert');
146
- this.setAttribute('data-slot', 'field-error');
147
- this.className = cn(
148
- 'text-sm text-destructive font-normal block',
149
- this.getAttribute('class') || ''
150
- );
151
- }
152
- }
153
- if (!customElements.get('ui-field-error'))
154
- customElements.define('surreal-shadcn-field', UIFieldError);
155
-
156
- export class UIFieldSeparator extends HTMLElement {
157
- connectedCallback() {
158
- this.setAttribute('data-slot', 'field-separator');
159
- const content = this.innerHTML.trim();
160
- this.className = cn(
161
- '-my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2 relative flex items-center justify-center',
162
- this.getAttribute('class') || ''
163
- );
164
- this.innerHTML = `
165
- <div class="absolute inset-0 top-1/2 -translate-y-1/2 border-t border-border w-full"></div>
166
- ${content ? `<span class="px-2 text-muted-foreground relative bg-background text-xs uppercase tracking-wider" data-slot="field-separator-content">${content}</span>` : ''}
167
- `;
168
- }
169
- }
170
- if (!customElements.get('ui-field-separator'))
171
- customElements.define('surreal-shadcn-field', UIFieldSeparator);
172
- export default UIField;
@@ -1,98 +0,0 @@
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'))
84
- customElements.define('surreal-shadcn-form', FormItemElement);
85
- if (!customElements.get('ui-form-label'))
86
- customElements.define('surreal-shadcn-form', FormLabelElement);
87
- if (!customElements.get('ui-form-description'))
88
- customElements.define('surreal-shadcn-form', FormDescriptionElement);
89
- if (!customElements.get('ui-form-message'))
90
- customElements.define('surreal-shadcn-form', FormMessageElement);
91
- if (!customElements.get('ui-form-fieldset'))
92
- customElements.define('surreal-shadcn-form', FormFieldsetElement);
93
- if (!customElements.get('ui-form-legend'))
94
- customElements.define('surreal-shadcn-form', FormLegendElement);
95
- if (!customElements.get('ui-form-button'))
96
- customElements.define('surreal-shadcn-form', FormButtonElement);
97
- }
98
- export default FormElement;
@@ -1,145 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-hover-card')) {
140
- customElements.define('surreal-shadcn-hover-card', SurrealShadcnHoverCard);
141
- }
142
- }
143
-
144
- export { SurrealShadcnHoverCard };
145
- export default SurrealShadcnHoverCard;
@@ -1,100 +0,0 @@
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
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-input')) {
97
- customElements.define('surreal-shadcn-input', SurrealShadcnInput);
98
- }
99
- }
100
- export default SurrealShadcnInput;