@surreal-ui/react 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.
Files changed (125) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/index.js +11307 -0
  3. package/package.json +38 -0
  4. package/src/components/GlassmorphismAlert.tsx +40 -0
  5. package/src/components/GlassmorphismButton.tsx +20 -0
  6. package/src/components/GlassmorphismCard.tsx +43 -0
  7. package/src/components/GlassmorphismEmptyState.tsx +20 -0
  8. package/src/components/GlassmorphismInputGroup.tsx +148 -0
  9. package/src/components/GlassmorphismMenubar.tsx +96 -0
  10. package/src/components/GlassmorphismScrollArea.tsx +67 -0
  11. package/src/components/GlassmorphismTable.tsx +61 -0
  12. package/src/components/GlassmorphismTypography.tsx +31 -0
  13. package/src/components/MinimalistAccordion.tsx +215 -0
  14. package/src/components/MinimalistAlert.tsx +40 -0
  15. package/src/components/MinimalistAlertDialog.tsx +317 -0
  16. package/src/components/MinimalistAspectRatio.tsx +30 -0
  17. package/src/components/MinimalistAvatar.tsx +149 -0
  18. package/src/components/MinimalistBadge.tsx +49 -0
  19. package/src/components/MinimalistBreadcrumb.tsx +105 -0
  20. package/src/components/MinimalistButton.tsx +86 -0
  21. package/src/components/MinimalistButtonGroup.tsx +85 -0
  22. package/src/components/MinimalistCalendar.tsx +352 -0
  23. package/src/components/MinimalistCard.tsx +89 -0
  24. package/src/components/MinimalistCarousel.tsx +266 -0
  25. package/src/components/MinimalistChart.tsx +296 -0
  26. package/src/components/MinimalistCheckbox.tsx +117 -0
  27. package/src/components/MinimalistCodeBlock.tsx +203 -0
  28. package/src/components/MinimalistCollapsible.tsx +134 -0
  29. package/src/components/MinimalistCommand.tsx +344 -0
  30. package/src/components/MinimalistContextMenu.tsx +400 -0
  31. package/src/components/MinimalistDialog.tsx +269 -0
  32. package/src/components/MinimalistDrawer.tsx +216 -0
  33. package/src/components/MinimalistDropdownMenu.tsx +431 -0
  34. package/src/components/MinimalistEmpty.tsx +105 -0
  35. package/src/components/MinimalistEmptyState.tsx +34 -0
  36. package/src/components/MinimalistField.tsx +275 -0
  37. package/src/components/MinimalistForm.tsx +203 -0
  38. package/src/components/MinimalistHoverCard.tsx +48 -0
  39. package/src/components/MinimalistInput.tsx +24 -0
  40. package/src/components/MinimalistInputGroup.tsx +180 -0
  41. package/src/components/MinimalistInputOtp.tsx +189 -0
  42. package/src/components/MinimalistItem.tsx +181 -0
  43. package/src/components/MinimalistKbd.tsx +46 -0
  44. package/src/components/MinimalistLabel.tsx +19 -0
  45. package/src/components/MinimalistMenubar.tsx +491 -0
  46. package/src/components/MinimalistNativeSelect.tsx +77 -0
  47. package/src/components/MinimalistNavigationMenu.tsx +198 -0
  48. package/src/components/MinimalistPagination.tsx +152 -0
  49. package/src/components/MinimalistPopover.tsx +228 -0
  50. package/src/components/MinimalistProgress.tsx +39 -0
  51. package/src/components/MinimalistRadioGroup.tsx +115 -0
  52. package/src/components/MinimalistRangeCalendar.tsx +396 -0
  53. package/src/components/MinimalistResizable.tsx +54 -0
  54. package/src/components/MinimalistScrollArea.tsx +41 -0
  55. package/src/components/MinimalistSelect.tsx +265 -0
  56. package/src/components/MinimalistSeparator.tsx +45 -0
  57. package/src/components/MinimalistSheet.tsx +247 -0
  58. package/src/components/MinimalistSidebar.tsx +637 -0
  59. package/src/components/MinimalistSkeleton.tsx +16 -0
  60. package/src/components/MinimalistSlider.tsx +213 -0
  61. package/src/components/MinimalistSonner.tsx +41 -0
  62. package/src/components/MinimalistSpinner.tsx +39 -0
  63. package/src/components/MinimalistSwitch.tsx +92 -0
  64. package/src/components/MinimalistTable.tsx +65 -0
  65. package/src/components/MinimalistTabs.tsx +166 -0
  66. package/src/components/MinimalistTextarea.tsx +24 -0
  67. package/src/components/MinimalistToggle.tsx +74 -0
  68. package/src/components/MinimalistToggleGroup.tsx +196 -0
  69. package/src/components/MinimalistTooltip.tsx +172 -0
  70. package/src/components/MinimalistTypography.tsx +33 -0
  71. package/src/components/NeubrutalismCard.tsx +3 -0
  72. package/src/components/NeubrutalismItem.tsx +48 -0
  73. package/src/components/ShadcnAccordion.tsx +215 -0
  74. package/src/components/ShadcnAlertDialog.tsx +317 -0
  75. package/src/components/ShadcnAspectRatio.tsx +30 -0
  76. package/src/components/ShadcnAvatar.tsx +149 -0
  77. package/src/components/ShadcnBadge.tsx +49 -0
  78. package/src/components/ShadcnBreadcrumb.tsx +105 -0
  79. package/src/components/ShadcnButton.tsx +86 -0
  80. package/src/components/ShadcnButtonGroup.tsx +85 -0
  81. package/src/components/ShadcnCalendar.tsx +352 -0
  82. package/src/components/ShadcnCarousel.tsx +266 -0
  83. package/src/components/ShadcnChart.tsx +296 -0
  84. package/src/components/ShadcnCheckbox.tsx +117 -0
  85. package/src/components/ShadcnCodeBlock.tsx +203 -0
  86. package/src/components/ShadcnCollapsible.tsx +134 -0
  87. package/src/components/ShadcnCommand.tsx +344 -0
  88. package/src/components/ShadcnContextMenu.tsx +400 -0
  89. package/src/components/ShadcnDialog.tsx +269 -0
  90. package/src/components/ShadcnDrawer.tsx +216 -0
  91. package/src/components/ShadcnDropdownMenu.tsx +431 -0
  92. package/src/components/ShadcnEmpty.tsx +105 -0
  93. package/src/components/ShadcnField.tsx +275 -0
  94. package/src/components/ShadcnForm.tsx +203 -0
  95. package/src/components/ShadcnHoverCard.tsx +48 -0
  96. package/src/components/ShadcnInput.tsx +24 -0
  97. package/src/components/ShadcnInputGroup.tsx +180 -0
  98. package/src/components/ShadcnInputOtp.tsx +189 -0
  99. package/src/components/ShadcnItem.tsx +181 -0
  100. package/src/components/ShadcnKbd.tsx +46 -0
  101. package/src/components/ShadcnLabel.tsx +19 -0
  102. package/src/components/ShadcnMenubar.tsx +491 -0
  103. package/src/components/ShadcnNativeSelect.tsx +77 -0
  104. package/src/components/ShadcnNavigationMenu.tsx +198 -0
  105. package/src/components/ShadcnPagination.tsx +152 -0
  106. package/src/components/ShadcnPopover.tsx +228 -0
  107. package/src/components/ShadcnProgress.tsx +39 -0
  108. package/src/components/ShadcnRadioGroup.tsx +115 -0
  109. package/src/components/ShadcnRangeCalendar.tsx +396 -0
  110. package/src/components/ShadcnSelect.tsx +265 -0
  111. package/src/components/ShadcnSeparator.tsx +45 -0
  112. package/src/components/ShadcnSheet.tsx +247 -0
  113. package/src/components/ShadcnSidebar.tsx +637 -0
  114. package/src/components/ShadcnSkeleton.tsx +16 -0
  115. package/src/components/ShadcnSlider.tsx +213 -0
  116. package/src/components/ShadcnSonner.tsx +41 -0
  117. package/src/components/ShadcnSpinner.tsx +39 -0
  118. package/src/components/ShadcnSwitch.tsx +92 -0
  119. package/src/components/ShadcnTabs.tsx +166 -0
  120. package/src/components/ShadcnTextarea.tsx +24 -0
  121. package/src/components/ShadcnToggle.tsx +74 -0
  122. package/src/components/ShadcnToggleGroup.tsx +196 -0
  123. package/src/components/ShadcnTooltip.tsx +172 -0
  124. package/src/index.ts +124 -0
  125. package/tsconfig.json +10 -0
@@ -0,0 +1,213 @@
1
+ import * as React from 'react';
2
+ import { cn } from '@surreal-ui/core';
3
+
4
+ export interface ShadcnSliderProps extends React.HTMLAttributes<HTMLDivElement> {
5
+ value?: number[];
6
+ defaultValue?: number[];
7
+ min?: number;
8
+ max?: number;
9
+ step?: number;
10
+ orientation?: 'horizontal' | 'vertical';
11
+ disabled?: boolean;
12
+ onValueChange?: (val: number[]) => void;
13
+ onValueCommit?: (val: number[]) => void;
14
+ }
15
+
16
+ export const ShadcnSlider = React.forwardRef<HTMLDivElement, SliderProps>(
17
+ (
18
+ {
19
+ className,
20
+ value: controlledValue,
21
+ defaultValue = [0],
22
+ min = 0,
23
+ max = 100,
24
+ step = 1,
25
+ orientation = 'horizontal',
26
+ disabled = false,
27
+ onValueChange,
28
+ onValueCommit,
29
+ ...props
30
+ },
31
+ ref,
32
+ ) => {
33
+ const [internalValues, setInternalValues] = React.useState<number[]>(
34
+ controlledValue ?? defaultValue,
35
+ );
36
+ const [activeIndex, setActiveIndex] = React.useState<number | null>(null);
37
+ const trackRef = React.useRef<HTMLSpanElement | null>(null);
38
+
39
+ React.useEffect(() => {
40
+ if (controlledValue !== undefined) {
41
+ setInternalValues(controlledValue);
42
+ }
43
+ }, [controlledValue]);
44
+
45
+ const getPercentage = React.useCallback(
46
+ (val: number) => {
47
+ return Math.max(0, Math.min(100, ((val - min) / (max - min)) * 100));
48
+ },
49
+ [min, max],
50
+ );
51
+
52
+ const getValueFromPointer = React.useCallback(
53
+ (e: React.PointerEvent) => {
54
+ if (!trackRef.current) return min;
55
+ const rect = trackRef.current.getBoundingClientRect();
56
+ let percent = 0;
57
+ if (orientation === 'horizontal') {
58
+ percent = (e.clientX - rect.left) / rect.width;
59
+ } else {
60
+ percent = (rect.bottom - e.clientY) / rect.height;
61
+ }
62
+ percent = Math.max(0, Math.min(1, percent));
63
+ const rawVal = min + percent * (max - min);
64
+ const steppedVal = Math.round(rawVal / step) * step;
65
+ return Math.max(min, Math.min(max, steppedVal));
66
+ },
67
+ [min, max, step, orientation],
68
+ );
69
+
70
+ const updateValue = React.useCallback(
71
+ (index: number, newVal: number) => {
72
+ setInternalValues((prev) => {
73
+ const next = [...prev];
74
+ next[index] = newVal;
75
+ if (next.length === 2) {
76
+ if (index === 0 && next[0] > next[1]) next[0] = next[1];
77
+ if (index === 1 && next[1] < next[0]) next[1] = next[0];
78
+ }
79
+ if (onValueChange) onValueChange(next);
80
+ return next;
81
+ });
82
+ },
83
+ [onValueChange],
84
+ );
85
+
86
+ const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
87
+ if (disabled) return;
88
+ e.currentTarget.setPointerCapture(e.pointerId);
89
+ const pointerVal = getValueFromPointer(e);
90
+ let closestIdx = 0;
91
+ let minDiff = Infinity;
92
+ internalValues.forEach((val, idx) => {
93
+ const diff = Math.abs(val - pointerVal);
94
+ if (diff < minDiff) {
95
+ minDiff = diff;
96
+ closestIdx = idx;
97
+ }
98
+ });
99
+ setActiveIndex(closestIdx);
100
+ updateValue(closestIdx, pointerVal);
101
+ };
102
+
103
+ const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
104
+ if (disabled || activeIndex === null) return;
105
+ const pointerVal = getValueFromPointer(e);
106
+ updateValue(activeIndex, pointerVal);
107
+ };
108
+
109
+ const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
110
+ if (disabled || activeIndex === null) return;
111
+ e.currentTarget.releasePointerCapture(e.pointerId);
112
+ setActiveIndex(null);
113
+ if (onValueCommit) onValueCommit(internalValues);
114
+ };
115
+
116
+ const handleKeyDown = (e: React.KeyboardEvent, index: number) => {
117
+ if (disabled) return;
118
+ let delta = 0;
119
+ if (e.key === 'ArrowRight' || e.key === 'ArrowUp') delta = step;
120
+ else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') delta = -step;
121
+ else if (e.key === 'PageUp') delta = step * 10;
122
+ else if (e.key === 'PageDown') delta = -step * 10;
123
+ else if (e.key === 'Home') delta = min - internalValues[index];
124
+ else if (e.key === 'End') delta = max - internalValues[index];
125
+ else return;
126
+
127
+ e.preventDefault();
128
+ const newVal = Math.max(min, Math.min(max, internalValues[index] + delta));
129
+ updateValue(index, newVal);
130
+ if (onValueCommit) onValueCommit(internalValues);
131
+ };
132
+
133
+ const rangeStyle = React.useMemo(() => {
134
+ if (internalValues.length === 1) {
135
+ const pct = getPercentage(internalValues[0]);
136
+ return orientation === 'horizontal'
137
+ ? { left: '0%', width: `${pct}%` }
138
+ : { bottom: '0%', height: `${pct}%` };
139
+ } else {
140
+ const p1 = getPercentage(internalValues[0]);
141
+ const p2 = getPercentage(internalValues[1]);
142
+ const left = Math.min(p1, p2);
143
+ const size = Math.abs(p2 - p1);
144
+ return orientation === 'horizontal'
145
+ ? { left: `${left}%`, width: `${size}%` }
146
+ : { bottom: `${left}%`, height: `${size}%` };
147
+ }
148
+ }, [internalValues, getPercentage, orientation]);
149
+
150
+ return (
151
+ <div
152
+ ref={ref}
153
+ role="group"
154
+ data-slot="slider"
155
+ data-orientation={orientation}
156
+ data-disabled={disabled ? '' : undefined}
157
+ className={cn(
158
+ 'relative flex w-full touch-none select-none items-center',
159
+ orientation === 'vertical' ? 'h-full min-h-40 w-auto flex-col' : 'h-auto w-full flex-row',
160
+ disabled && 'opacity-50 pointer-events-none',
161
+ className,
162
+ )}
163
+ onPointerDown={handlePointerDown}
164
+ onPointerMove={handlePointerMove}
165
+ onPointerUp={handlePointerUp}
166
+ {...props}
167
+ >
168
+ <span
169
+ ref={trackRef}
170
+ data-slot="slider-track"
171
+ data-orientation={orientation}
172
+ className={cn(
173
+ 'relative grow overflow-hidden rounded-full bg-muted',
174
+ orientation === 'horizontal' ? 'h-1.5 w-full' : 'h-full w-1.5',
175
+ )}
176
+ >
177
+ <span
178
+ data-slot="slider-range"
179
+ data-orientation={orientation}
180
+ className="absolute bg-primary"
181
+ style={rangeStyle}
182
+ />
183
+ </span>
184
+ {internalValues.map((val, idx) => {
185
+ const pct = getPercentage(val);
186
+ return (
187
+ <span
188
+ key={idx}
189
+ role="slider"
190
+ tabIndex={disabled ? -1 : 0}
191
+ aria-valuemin={min}
192
+ aria-valuemax={max}
193
+ aria-valuenow={val}
194
+ aria-orientation={orientation}
195
+ aria-disabled={disabled}
196
+ data-slot="slider-thumb"
197
+ className="absolute block size-4 shrink-0 rounded-full border border-primary bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
198
+ style={
199
+ orientation === 'horizontal'
200
+ ? { left: `calc(${pct}% - 8px)`, top: '50%', transform: 'translateY(-50%)' }
201
+ : { bottom: `calc(${pct}% - 8px)`, left: '50%', transform: 'translateX(-50%)' }
202
+ }
203
+ onKeyDown={(e) => handleKeyDown(e, idx)}
204
+ />
205
+ );
206
+ })}
207
+ </div>
208
+ );
209
+ },
210
+ );
211
+ Slider.displayName = 'Slider';
212
+
213
+ export default ShadcnSlider;
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+ import { Toaster as Sonner, type ToasterProps } from 'sonner';
3
+ import { Loader2, CircleCheck, OctagonX, Info, TriangleAlert } from 'lucide-react';
4
+
5
+ export interface ToasterComponentProps extends ToasterProps {}
6
+
7
+ export function Toaster({ ...props }: ToasterComponentProps) {
8
+ return (
9
+ <Sonner
10
+ className="toaster group"
11
+ style={
12
+ {
13
+ '--normal-bg': 'var(--color-popover)',
14
+ '--normal-text': 'var(--color-popover-foreground)',
15
+ '--normal-border': 'var(--color-border)',
16
+ } as React.CSSProperties
17
+ }
18
+ icons={{
19
+ loading: <Loader2 className="size-4 animate-spin" />,
20
+ success: <CircleCheck className="size-4" />,
21
+ error: <OctagonX className="size-4" />,
22
+ info: <Info className="size-4" />,
23
+ warning: <TriangleAlert className="size-4" />,
24
+ }}
25
+ toastOptions={{
26
+ classNames: {
27
+ toast:
28
+ 'group toast group-[.toaster]:bg-popover group-[.toaster]:text-popover-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg',
29
+ description: 'group-[.toast]:text-muted-foreground',
30
+ actionButton: 'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',
31
+ cancelButton: 'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',
32
+ },
33
+ }}
34
+ {...props}
35
+ />
36
+ );
37
+ }
38
+
39
+ export { toast } from 'sonner';
40
+
41
+ export default ShadcnSonner;
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+
3
+ import { Loader2, type LucideProps } from 'lucide-react';
4
+ import { cn } from '@surreal-ui/core';
5
+
6
+ export interface ShadcnSpinnerProps extends LucideProps {
7
+ className?: string;
8
+ role?: string;
9
+ 'aria-label'?: string;
10
+ }
11
+
12
+ export const ShadcnSpinner = React.forwardRef<SVGSVGElement, SpinnerProps>(
13
+ (
14
+ {
15
+ className,
16
+ role = 'status',
17
+ 'aria-label': ariaLabel = 'Loading',
18
+ color,
19
+ strokeWidth,
20
+ ...props
21
+ },
22
+ ref,
23
+ ) => {
24
+ return (
25
+ <Loader2
26
+ ref={ref}
27
+ role={role}
28
+ aria-label={ariaLabel}
29
+ color={color === null ? undefined : color}
30
+ strokeWidth={strokeWidth === null ? undefined : strokeWidth}
31
+ className={cn('size-4 animate-spin', className)}
32
+ {...props}
33
+ />
34
+ );
35
+ },
36
+ );
37
+
38
+ Spinner.displayName = 'Spinner';
39
+ export default ShadcnSpinner;
@@ -0,0 +1,92 @@
1
+ import * as React from 'react';
2
+ import { cn } from '@surreal-ui/core';
3
+
4
+ export interface ShadcnSwitchProps extends Omit<
5
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
6
+ 'onChange'
7
+ > {
8
+ checked?: boolean;
9
+ defaultChecked?: boolean;
10
+ onCheckedChange?: (checked: boolean) => void;
11
+ size?: 'sm' | 'default';
12
+ }
13
+
14
+ export const ShadcnSwitch = React.forwardRef<HTMLButtonElement, SwitchProps>(
15
+ (
16
+ {
17
+ className,
18
+ checked: controlledChecked,
19
+ defaultChecked = false,
20
+ onCheckedChange,
21
+ disabled = false,
22
+ size = 'default',
23
+ onClick,
24
+ onKeyDown,
25
+ ...props
26
+ },
27
+ ref,
28
+ ) => {
29
+ const [uncontrolledChecked, setUncontrolledChecked] = React.useState(defaultChecked);
30
+ const isControlled = controlledChecked !== undefined;
31
+ const isChecked = isControlled ? controlledChecked : uncontrolledChecked;
32
+
33
+ const toggle = (e: React.MouseEvent<HTMLButtonElement>) => {
34
+ if (disabled) return;
35
+ const next = !isChecked;
36
+ if (!isControlled) {
37
+ setUncontrolledChecked(next);
38
+ }
39
+ onCheckedChange?.(next);
40
+ onClick?.(e);
41
+ };
42
+
43
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
44
+ if (e.key === ' ' || e.key === 'Enter') {
45
+ e.preventDefault();
46
+ if (!disabled) {
47
+ const next = !isChecked;
48
+ if (!isControlled) {
49
+ setUncontrolledChecked(next);
50
+ }
51
+ onCheckedChange?.(next);
52
+ }
53
+ }
54
+ onKeyDown?.(e);
55
+ };
56
+
57
+ return (
58
+ <button
59
+ type="button"
60
+ role="switch"
61
+ aria-checked={isChecked}
62
+ aria-disabled={disabled}
63
+ disabled={disabled}
64
+ ref={ref}
65
+ data-slot="switch"
66
+ data-state={isChecked ? 'checked' : 'unchecked'}
67
+ data-size={size}
68
+ onClick={toggle}
69
+ onKeyDown={handleKeyDown}
70
+ className={cn(
71
+ 'peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-colors outline-none cursor-pointer select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80',
72
+ className,
73
+ )}
74
+ {...props}
75
+ >
76
+ <span
77
+ data-slot="switch-thumb"
78
+ data-state={isChecked ? 'checked' : 'unchecked'}
79
+ className={cn(
80
+ 'pointer-events-none block rounded-full bg-background ring-0 transition-transform dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground',
81
+ size === 'sm'
82
+ ? 'size-3 data-[state=checked]:translate-x-[10px] data-[state=unchecked]:translate-x-0'
83
+ : 'size-4 data-[state=checked]:translate-x-[14px] data-[state=unchecked]:translate-x-0',
84
+ )}
85
+ />
86
+ </button>
87
+ );
88
+ },
89
+ );
90
+
91
+ Switch.displayName = 'Switch';
92
+ export default ShadcnSwitch;
@@ -0,0 +1,166 @@
1
+ import * as React from 'react';
2
+ import { cn, cva, type VariantProps } from '@surreal-ui/core';
3
+
4
+ export const tabsListVariants = cva(
5
+ 'rounded-lg p-[3px] group-data-horizontal/tabs:h-8 data-[variant=line]:rounded-none group/tabs-list inline-flex w-fit items-center justify-center text-muted-foreground group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col',
6
+ {
7
+ variants: {
8
+ variant: {
9
+ default: 'cn-tabs-list-variant-default bg-muted',
10
+ line: 'cn-tabs-list-variant-line gap-1 bg-transparent',
11
+ },
12
+ },
13
+ defaultVariants: {
14
+ variant: 'default',
15
+ },
16
+ },
17
+ );
18
+
19
+ export type TabsListVariant = VariantProps<typeof tabsListVariants>['variant'];
20
+
21
+ interface TabsContextValue {
22
+ value: string;
23
+ setValue: (value: string) => void;
24
+ orientation: 'horizontal' | 'vertical';
25
+ }
26
+
27
+ const TabsContext = React.createContext<TabsContextValue | null>(null);
28
+
29
+ function useTabs() {
30
+ const context = React.useContext(TabsContext);
31
+ if (!context) {
32
+ throw new Error('Tabs compound components must be rendered inside <Tabs>');
33
+ }
34
+ return context;
35
+ }
36
+
37
+ export interface ShadcnTabsProps extends React.ComponentProps<'div'> {
38
+ value?: string;
39
+ defaultValue?: string;
40
+ onValueChange?: (value: string) => void;
41
+ orientation?: 'horizontal' | 'vertical';
42
+ }
43
+
44
+ export function ShadcnTabs({
45
+ value: controlledValue,
46
+ defaultValue = '',
47
+ onValueChange,
48
+ orientation = 'horizontal',
49
+ className,
50
+ children,
51
+ ...props
52
+ }: TabsProps) {
53
+ const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue);
54
+ const isControlled = controlledValue !== undefined;
55
+ const currentValue = isControlled ? controlledValue : uncontrolledValue;
56
+
57
+ const setValue = React.useCallback(
58
+ (val: string) => {
59
+ if (!isControlled) {
60
+ setUncontrolledValue(val);
61
+ }
62
+ onValueChange?.(val);
63
+ },
64
+ [isControlled, onValueChange],
65
+ );
66
+
67
+ return (
68
+ <TabsContext.Provider value={{ value: currentValue, setValue, orientation }}>
69
+ <div
70
+ data-slot="tabs"
71
+ data-orientation={orientation}
72
+ className={cn('gap-2 group/tabs flex data-[orientation=horizontal]:flex-col', className)}
73
+ {...props}
74
+ >
75
+ {children}
76
+ </div>
77
+ </TabsContext.Provider>
78
+ );
79
+ }
80
+
81
+ export interface ShadcnTabsListProps
82
+ extends React.ComponentProps<'div'>, VariantProps<typeof tabsListVariants> {}
83
+
84
+ export function ShadcnTabsList({ className, variant = 'default', children, ...props }: TabsListProps) {
85
+ return (
86
+ <div
87
+ data-slot="tabs-list"
88
+ data-variant={variant}
89
+ className={cn(tabsListVariants({ variant }), className)}
90
+ {...props}
91
+ >
92
+ {children}
93
+ </div>
94
+ );
95
+ }
96
+
97
+ export interface ShadcnTabsTriggerProps extends React.ComponentProps<'button'> {
98
+ value: string;
99
+ }
100
+
101
+ export function ShadcnTabsTrigger({
102
+ className,
103
+ value: triggerValue,
104
+ disabled,
105
+ children,
106
+ ...props
107
+ }: TabsTriggerProps) {
108
+ const { value, setValue } = useTabs();
109
+ const isActive = value === triggerValue;
110
+
111
+ return (
112
+ <button
113
+ type="button"
114
+ role="tab"
115
+ aria-selected={isActive}
116
+ data-slot="tabs-trigger"
117
+ data-state={isActive ? 'active' : 'inactive'}
118
+ disabled={disabled}
119
+ tabIndex={isActive ? 0 : -1}
120
+ onClick={() => setValue(triggerValue)}
121
+ className={cn(
122
+ "gap-1.5 rounded-md border border-transparent px-2.5 py-1 text-xs font-medium has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none [&_svg:not([class*='size-'])]:size-3.5 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-muted-foreground transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
123
+ 'group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent',
124
+ 'data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-xs dark:data-[state=active]:border-border/50 dark:data-[state=active]:bg-background dark:data-[state=active]:text-foreground',
125
+ 'after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100',
126
+ className,
127
+ )}
128
+ {...props}
129
+ >
130
+ {children}
131
+ </button>
132
+ );
133
+ }
134
+
135
+ export interface ShadcnTabsContentProps extends React.ComponentProps<'div'> {
136
+ value: string;
137
+ }
138
+
139
+ export function ShadcnTabsContent({
140
+ className,
141
+ value: contentValue,
142
+ children,
143
+ ...props
144
+ }: TabsContentProps) {
145
+ const { value } = useTabs();
146
+ const isActive = value === contentValue;
147
+
148
+ if (!isActive) return null;
149
+
150
+ return (
151
+ <div
152
+ role="tabpanel"
153
+ tabIndex={0}
154
+ data-slot="tabs-content"
155
+ data-state={isActive ? 'active' : 'inactive'}
156
+ className={cn('text-sm flex-1 outline-none', className)}
157
+ {...props}
158
+ >
159
+ {children}
160
+ </div>
161
+ );
162
+ }
163
+
164
+ export { ShadcnTabs as Root, TabsContent as Content, TabsList as List, TabsTrigger as Trigger };
165
+
166
+ export default ShadcnTabs;
@@ -0,0 +1,24 @@
1
+ import * as React from 'react';
2
+ import { cn } from '@surreal-ui/core';
3
+
4
+ export interface ShadcnTextareaProps extends React.ComponentProps<'textarea'> {}
5
+
6
+ export const ShadcnTextarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
7
+ ({ className, 'data-slot': dataSlot = 'textarea', ...props }, ref) => {
8
+ return (
9
+ <textarea
10
+ ref={ref}
11
+ data-slot={dataSlot}
12
+ className={cn(
13
+ 'rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors 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 flex field-sizing-content min-h-16 w-full outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
14
+ className,
15
+ )}
16
+ {...props}
17
+ />
18
+ );
19
+ },
20
+ );
21
+
22
+ Textarea.displayName = 'Textarea';
23
+
24
+ export default ShadcnTextarea;
@@ -0,0 +1,74 @@
1
+ import * as React from 'react';
2
+ import { cn, cva, type VariantProps } from '@surreal-ui/core';
3
+
4
+ export const shadcnToggleVariants = cva(
5
+ "gap-1 rounded-lg text-sm font-medium transition-all hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted data-[state=on]:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 group/toggle inline-flex items-center justify-center whitespace-nowrap outline-none hover:bg-muted focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
6
+ {
7
+ variants: {
8
+ variant: {
9
+ default: 'bg-transparent',
10
+ outline: 'border border-input bg-transparent hover:bg-muted',
11
+ },
12
+ size: {
13
+ default:
14
+ 'h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
15
+ sm: "h-7 min-w-7 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
16
+ lg: 'h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
17
+ },
18
+ },
19
+ defaultVariants: {
20
+ variant: 'default',
21
+ size: 'default',
22
+ },
23
+ },
24
+ );
25
+
26
+ export interface ShadcnToggleProps
27
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof toggleVariants> {
28
+ pressed?: boolean;
29
+ defaultPressed?: boolean;
30
+ onPressedChange?: (pressed: boolean) => void;
31
+ }
32
+
33
+ export const ShadcnToggle = React.forwardRef<HTMLButtonElement, ToggleProps>(
34
+ (
35
+ {
36
+ className,
37
+ variant,
38
+ size,
39
+ pressed: controlledPressed,
40
+ defaultPressed = false,
41
+ onPressedChange,
42
+ onClick,
43
+ ...props
44
+ },
45
+ ref,
46
+ ) => {
47
+ const [uncontrolledPressed, setUncontrolledPressed] = React.useState(defaultPressed);
48
+ const isPressed = controlledPressed !== undefined ? controlledPressed : uncontrolledPressed;
49
+
50
+ const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
51
+ if (controlledPressed === undefined) {
52
+ setUncontrolledPressed(!uncontrolledPressed);
53
+ }
54
+ onPressedChange?.(!isPressed);
55
+ onClick?.(e);
56
+ };
57
+
58
+ return (
59
+ <button
60
+ ref={ref}
61
+ type="button"
62
+ aria-pressed={isPressed}
63
+ data-state={isPressed ? 'on' : 'off'}
64
+ data-slot="toggle"
65
+ className={cn(shadcnToggleVariants({ variant, size, className }))}
66
+ onClick={handleClick}
67
+ {...props}
68
+ />
69
+ );
70
+ },
71
+ );
72
+ Toggle.displayName = 'Toggle';
73
+
74
+ export default ShadcnToggle;