@surreal-ui/react 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 (128) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +955 -7227
  3. package/dist/utils.d.ts +9 -0
  4. package/dist/utils.js +14 -0
  5. package/package.json +21 -4
  6. package/CHANGELOG.md +0 -149
  7. package/src/components/GlassmorphismAlert.tsx +0 -43
  8. package/src/components/GlassmorphismButton.tsx +0 -20
  9. package/src/components/GlassmorphismCard.tsx +0 -43
  10. package/src/components/GlassmorphismEmptyState.tsx +0 -20
  11. package/src/components/GlassmorphismInputGroup.tsx +0 -148
  12. package/src/components/GlassmorphismMenubar.tsx +0 -96
  13. package/src/components/GlassmorphismScrollArea.tsx +0 -67
  14. package/src/components/GlassmorphismTable.tsx +0 -61
  15. package/src/components/GlassmorphismTypography.tsx +0 -31
  16. package/src/components/MinimalistAccordion.tsx +0 -215
  17. package/src/components/MinimalistAlert.tsx +0 -43
  18. package/src/components/MinimalistAlertDialog.tsx +0 -318
  19. package/src/components/MinimalistAspectRatio.tsx +0 -30
  20. package/src/components/MinimalistAvatar.tsx +0 -149
  21. package/src/components/MinimalistBadge.tsx +0 -49
  22. package/src/components/MinimalistBreadcrumb.tsx +0 -109
  23. package/src/components/MinimalistButton.tsx +0 -86
  24. package/src/components/MinimalistButtonGroup.tsx +0 -86
  25. package/src/components/MinimalistCalendar.tsx +0 -355
  26. package/src/components/MinimalistCard.tsx +0 -89
  27. package/src/components/MinimalistCarousel.tsx +0 -266
  28. package/src/components/MinimalistChart.tsx +0 -296
  29. package/src/components/MinimalistCheckbox.tsx +0 -117
  30. package/src/components/MinimalistCodeBlock.tsx +0 -203
  31. package/src/components/MinimalistCollapsible.tsx +0 -134
  32. package/src/components/MinimalistCommand.tsx +0 -344
  33. package/src/components/MinimalistContextMenu.tsx +0 -408
  34. package/src/components/MinimalistDialog.tsx +0 -273
  35. package/src/components/MinimalistDrawer.tsx +0 -220
  36. package/src/components/MinimalistDropdownMenu.tsx +0 -431
  37. package/src/components/MinimalistEmpty.tsx +0 -105
  38. package/src/components/MinimalistEmptyState.tsx +0 -34
  39. package/src/components/MinimalistField.tsx +0 -275
  40. package/src/components/MinimalistForm.tsx +0 -205
  41. package/src/components/MinimalistHoverCard.tsx +0 -48
  42. package/src/components/MinimalistInput.tsx +0 -24
  43. package/src/components/MinimalistInputGroup.tsx +0 -180
  44. package/src/components/MinimalistInputOtp.tsx +0 -189
  45. package/src/components/MinimalistItem.tsx +0 -182
  46. package/src/components/MinimalistKbd.tsx +0 -46
  47. package/src/components/MinimalistLabel.tsx +0 -19
  48. package/src/components/MinimalistMenubar.tsx +0 -491
  49. package/src/components/MinimalistNativeSelect.tsx +0 -77
  50. package/src/components/MinimalistNavigationMenu.tsx +0 -198
  51. package/src/components/MinimalistPagination.tsx +0 -152
  52. package/src/components/MinimalistPopover.tsx +0 -229
  53. package/src/components/MinimalistProgress.tsx +0 -39
  54. package/src/components/MinimalistRadioGroup.tsx +0 -115
  55. package/src/components/MinimalistRangeCalendar.tsx +0 -396
  56. package/src/components/MinimalistResizable.tsx +0 -54
  57. package/src/components/MinimalistScrollArea.tsx +0 -41
  58. package/src/components/MinimalistSelect.tsx +0 -262
  59. package/src/components/MinimalistSeparator.tsx +0 -45
  60. package/src/components/MinimalistSheet.tsx +0 -247
  61. package/src/components/MinimalistSidebar.tsx +0 -638
  62. package/src/components/MinimalistSkeleton.tsx +0 -16
  63. package/src/components/MinimalistSlider.tsx +0 -213
  64. package/src/components/MinimalistSonner.tsx +0 -41
  65. package/src/components/MinimalistSpinner.tsx +0 -39
  66. package/src/components/MinimalistSwitch.tsx +0 -92
  67. package/src/components/MinimalistTable.tsx +0 -65
  68. package/src/components/MinimalistTabs.tsx +0 -171
  69. package/src/components/MinimalistTextarea.tsx +0 -24
  70. package/src/components/MinimalistToggle.tsx +0 -74
  71. package/src/components/MinimalistToggleGroup.tsx +0 -197
  72. package/src/components/MinimalistTooltip.tsx +0 -172
  73. package/src/components/MinimalistTypography.tsx +0 -33
  74. package/src/components/NeubrutalismCard.tsx +0 -84
  75. package/src/components/NeubrutalismItem.tsx +0 -48
  76. package/src/components/ShadcnAccordion.tsx +0 -215
  77. package/src/components/ShadcnAlertDialog.tsx +0 -318
  78. package/src/components/ShadcnAspectRatio.tsx +0 -30
  79. package/src/components/ShadcnAvatar.tsx +0 -149
  80. package/src/components/ShadcnBadge.tsx +0 -49
  81. package/src/components/ShadcnBreadcrumb.tsx +0 -109
  82. package/src/components/ShadcnButton.tsx +0 -86
  83. package/src/components/ShadcnButtonGroup.tsx +0 -86
  84. package/src/components/ShadcnCalendar.tsx +0 -355
  85. package/src/components/ShadcnCarousel.tsx +0 -266
  86. package/src/components/ShadcnChart.tsx +0 -296
  87. package/src/components/ShadcnCheckbox.tsx +0 -117
  88. package/src/components/ShadcnCodeBlock.tsx +0 -203
  89. package/src/components/ShadcnCollapsible.tsx +0 -134
  90. package/src/components/ShadcnCommand.tsx +0 -344
  91. package/src/components/ShadcnContextMenu.tsx +0 -408
  92. package/src/components/ShadcnDialog.tsx +0 -273
  93. package/src/components/ShadcnDrawer.tsx +0 -220
  94. package/src/components/ShadcnDropdownMenu.tsx +0 -431
  95. package/src/components/ShadcnEmpty.tsx +0 -105
  96. package/src/components/ShadcnField.tsx +0 -275
  97. package/src/components/ShadcnForm.tsx +0 -205
  98. package/src/components/ShadcnHoverCard.tsx +0 -48
  99. package/src/components/ShadcnInput.tsx +0 -24
  100. package/src/components/ShadcnInputGroup.tsx +0 -180
  101. package/src/components/ShadcnInputOtp.tsx +0 -189
  102. package/src/components/ShadcnItem.tsx +0 -182
  103. package/src/components/ShadcnKbd.tsx +0 -46
  104. package/src/components/ShadcnLabel.tsx +0 -19
  105. package/src/components/ShadcnMenubar.tsx +0 -491
  106. package/src/components/ShadcnNativeSelect.tsx +0 -77
  107. package/src/components/ShadcnNavigationMenu.tsx +0 -198
  108. package/src/components/ShadcnPagination.tsx +0 -152
  109. package/src/components/ShadcnPopover.tsx +0 -229
  110. package/src/components/ShadcnProgress.tsx +0 -39
  111. package/src/components/ShadcnRadioGroup.tsx +0 -115
  112. package/src/components/ShadcnRangeCalendar.tsx +0 -396
  113. package/src/components/ShadcnSelect.tsx +0 -262
  114. package/src/components/ShadcnSeparator.tsx +0 -45
  115. package/src/components/ShadcnSheet.tsx +0 -247
  116. package/src/components/ShadcnSidebar.tsx +0 -638
  117. package/src/components/ShadcnSkeleton.tsx +0 -16
  118. package/src/components/ShadcnSlider.tsx +0 -213
  119. package/src/components/ShadcnSonner.tsx +0 -41
  120. package/src/components/ShadcnSpinner.tsx +0 -39
  121. package/src/components/ShadcnSwitch.tsx +0 -92
  122. package/src/components/ShadcnTabs.tsx +0 -171
  123. package/src/components/ShadcnTextarea.tsx +0 -24
  124. package/src/components/ShadcnToggle.tsx +0 -74
  125. package/src/components/ShadcnToggleGroup.tsx +0 -197
  126. package/src/components/ShadcnTooltip.tsx +0 -172
  127. package/src/index.ts +0 -124
  128. package/tsconfig.json +0 -10
@@ -1,266 +0,0 @@
1
- import * as React from 'react';
2
- import { ChevronLeft, ChevronRight } from 'lucide-react';
3
- import { cn } from '@surreal-ui/core';
4
-
5
- type CarouselOrientation = 'horizontal' | 'vertical';
6
-
7
- interface CarouselContextType {
8
- carouselRef: React.RefObject<HTMLDivElement | null>;
9
- scrollPrev: () => void;
10
- scrollNext: () => void;
11
- canScrollPrev: boolean;
12
- canScrollNext: boolean;
13
- orientation: CarouselOrientation;
14
- handleKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
15
- }
16
-
17
- const CarouselContext = React.createContext<CarouselContextType | null>(null);
18
-
19
- export function useCarousel() {
20
- const context = React.useContext(CarouselContext);
21
- if (!context) {
22
- throw new Error('useCarousel must be used within a <Carousel />');
23
- }
24
- return context;
25
- }
26
-
27
- export interface ShadcnCarouselProps extends React.HTMLAttributes<HTMLDivElement> {
28
- orientation?: CarouselOrientation;
29
- opts?: Record<string, unknown>;
30
- plugins?: unknown[];
31
- setApi?: (api: unknown) => void;
32
- }
33
-
34
- export const ShadcnCarousel = React.forwardRef<HTMLDivElement, CarouselProps>(
35
- ({ orientation = 'horizontal', opts, setApi, plugins, className, children, ...props }, ref) => {
36
- const carouselRef = React.useRef<HTMLDivElement>(null);
37
- const [canScrollPrev, setCanScrollPrev] = React.useState(false);
38
- const [canScrollNext, setCanScrollNext] = React.useState(false);
39
-
40
- const checkScrollability = React.useCallback(() => {
41
- const el = carouselRef.current;
42
- if (!el) return;
43
- if (orientation === 'horizontal') {
44
- setCanScrollPrev(el.scrollLeft > 0);
45
- setCanScrollNext(el.scrollLeft < el.scrollWidth - el.clientWidth - 1);
46
- } else {
47
- setCanScrollPrev(el.scrollTop > 0);
48
- setCanScrollNext(el.scrollTop < el.scrollHeight - el.clientHeight - 1);
49
- }
50
- }, [orientation]);
51
-
52
- React.useEffect(() => {
53
- checkScrollability();
54
- const el = carouselRef.current;
55
- if (el) {
56
- el.addEventListener('scroll', checkScrollability);
57
- window.addEventListener('resize', checkScrollability);
58
- return () => {
59
- el.removeEventListener('scroll', checkScrollability);
60
- window.removeEventListener('resize', checkScrollability);
61
- };
62
- }
63
- }, [checkScrollability]);
64
-
65
- const scrollPrev = React.useCallback(() => {
66
- const el = carouselRef.current;
67
- if (!el) return;
68
- if (orientation === 'horizontal') {
69
- el.scrollBy({ left: -el.clientWidth, behavior: 'smooth' });
70
- } else {
71
- el.scrollBy({ top: -el.clientHeight, behavior: 'smooth' });
72
- }
73
- }, [orientation]);
74
-
75
- const scrollNext = React.useCallback(() => {
76
- const el = carouselRef.current;
77
- if (!el) return;
78
- if (orientation === 'horizontal') {
79
- el.scrollBy({ left: el.clientWidth, behavior: 'smooth' });
80
- } else {
81
- el.scrollBy({ top: el.clientHeight, behavior: 'smooth' });
82
- }
83
- }, [orientation]);
84
-
85
- const handleKeyDown = React.useCallback(
86
- (event: React.KeyboardEvent<HTMLElement>) => {
87
- if (event.key === 'ArrowLeft' || (orientation === 'vertical' && event.key === 'ArrowUp')) {
88
- event.preventDefault();
89
- scrollPrev();
90
- } else if (
91
- event.key === 'ArrowRight' ||
92
- (orientation === 'vertical' && event.key === 'ArrowDown')
93
- ) {
94
- event.preventDefault();
95
- scrollNext();
96
- }
97
- },
98
- [orientation, scrollPrev, scrollNext]
99
- );
100
-
101
- return (
102
- <CarouselContext.Provider
103
- value={{
104
- carouselRef,
105
- scrollPrev,
106
- scrollNext,
107
- canScrollPrev,
108
- canScrollNext,
109
- orientation,
110
- handleKeyDown
111
- }}
112
- >
113
- <div
114
- ref={ref}
115
- onKeyDownCapture={handleKeyDown}
116
- className={cn('relative', className)}
117
- role="region"
118
- aria-roledescription="carousel"
119
- data-slot="carousel"
120
- {...props}
121
- >
122
- {children}
123
- </div>
124
- </CarouselContext.Provider>
125
- );
126
- }
127
- );
128
- Carousel.displayName = 'Carousel';
129
-
130
- export interface ShadcnCarouselContentProps extends React.HTMLAttributes<HTMLDivElement> {}
131
-
132
- export const ShadcnCarouselContent = React.forwardRef<HTMLDivElement, CarouselContentProps>(
133
- ({ className, children, ...props }, ref) => {
134
- const { carouselRef, orientation } = useCarousel();
135
-
136
- return (
137
- <div data-slot="carousel-content" className="overflow-hidden">
138
- <div
139
- ref={(node) => {
140
- // @ts-ignore
141
- carouselRef.current = node;
142
- if (typeof ref === 'function') ref(node);
143
- else if (ref) (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;
144
- }}
145
- className={cn(
146
- 'flex scroll-smooth select-none no-scrollbar',
147
- orientation === 'horizontal'
148
- ? '-ms-4 overflow-x-auto snap-x snap-mandatory'
149
- : '-mt-4 flex-col overflow-y-auto snap-y snap-mandatory',
150
- className
151
- )}
152
- data-embla-container=""
153
- {...props}
154
- >
155
- {children}
156
- </div>
157
- </div>
158
- );
159
- }
160
- );
161
- CarouselContent.displayName = 'CarouselContent';
162
-
163
- export interface ShadcnCarouselItemProps extends React.HTMLAttributes<HTMLDivElement> {}
164
-
165
- export const ShadcnCarouselItem = React.forwardRef<HTMLDivElement, CarouselItemProps>(
166
- ({ className, children, ...props }, ref) => {
167
- const { orientation } = useCarousel();
168
-
169
- return (
170
- <div
171
- ref={ref}
172
- role="group"
173
- aria-roledescription="slide"
174
- data-slot="carousel-item"
175
- className={cn(
176
- 'min-w-0 shrink-0 grow-0 basis-full snap-start',
177
- orientation === 'horizontal' ? 'ps-4' : 'pt-4',
178
- className
179
- )}
180
- data-embla-slide=""
181
- {...props}
182
- >
183
- {children}
184
- </div>
185
- );
186
- }
187
- );
188
- CarouselItem.displayName = 'CarouselItem';
189
-
190
- export interface ShadcnCarouselPreviousProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
191
- variant?: 'outline' | 'default' | 'secondary' | 'ghost';
192
- size?: 'icon-sm' | 'icon' | 'default';
193
- }
194
-
195
- export const ShadcnCarouselPrevious = React.forwardRef<HTMLButtonElement, CarouselPreviousProps>(
196
- ({ className, variant = 'outline', size = 'icon-sm', children, ...props }, ref) => {
197
- const { orientation, scrollPrev, canScrollPrev } = useCarousel();
198
-
199
- return (
200
- <button
201
- ref={ref}
202
- type="button"
203
- data-slot="carousel-previous"
204
- aria-disabled={!canScrollPrev}
205
- disabled={!canScrollPrev}
206
- className={cn(
207
- 'inline-flex items-center justify-center rounded-full text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-xs hover:bg-accent hover:text-accent-foreground h-8 w-8 absolute touch-manipulation z-10',
208
- orientation === 'horizontal'
209
- ? 'inset-y-0 -start-12 my-auto'
210
- : 'start-1/2 -top-12 -translate-x-1/2 rotate-90',
211
- className
212
- )}
213
- onClick={scrollPrev}
214
- {...props}
215
- >
216
- {children ?? <ChevronLeft className="h-4 w-4" />}
217
- <span className="sr-only">Previous slide</span>
218
- </button>
219
- );
220
- }
221
- );
222
- CarouselPrevious.displayName = 'CarouselPrevious';
223
-
224
- export interface ShadcnCarouselNextProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
225
- variant?: 'outline' | 'default' | 'secondary' | 'ghost';
226
- size?: 'icon-sm' | 'icon' | 'default';
227
- }
228
-
229
- export const ShadcnCarouselNext = React.forwardRef<HTMLButtonElement, CarouselNextProps>(
230
- ({ className, variant = 'outline', size = 'icon-sm', children, ...props }, ref) => {
231
- const { orientation, scrollNext, canScrollNext } = useCarousel();
232
-
233
- return (
234
- <button
235
- ref={ref}
236
- type="button"
237
- data-slot="carousel-next"
238
- aria-disabled={!canScrollNext}
239
- disabled={!canScrollNext}
240
- className={cn(
241
- 'inline-flex items-center justify-center rounded-full text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-xs hover:bg-accent hover:text-accent-foreground h-8 w-8 absolute touch-manipulation z-10',
242
- orientation === 'horizontal'
243
- ? 'inset-y-0 -end-12 my-auto'
244
- : 'start-1/2 -bottom-12 -translate-x-1/2 rotate-90',
245
- className
246
- )}
247
- onClick={scrollNext}
248
- {...props}
249
- >
250
- {children ?? <ChevronRight className="h-4 w-4" />}
251
- <span className="sr-only">Next slide</span>
252
- </button>
253
- );
254
- }
255
- );
256
- CarouselNext.displayName = 'CarouselNext';
257
-
258
- export {
259
- ShadcnCarousel as Root,
260
- CarouselContent as Content,
261
- CarouselItem as Item,
262
- CarouselPrevious as Previous,
263
- CarouselNext as Next
264
- };
265
-
266
- export default ShadcnCarousel;
@@ -1,296 +0,0 @@
1
- import * as React from 'react';
2
- import { cn } from '@surreal-ui/core';
3
-
4
- export const THEMES = { light: '', dark: '.dark' } as const;
5
-
6
- export type ChartConfig = {
7
- [k in string]: {
8
- label?: React.ReactNode;
9
- icon?: React.ComponentType;
10
- } & (
11
- | { color?: string; theme?: never }
12
- | { color?: never; theme: Record<keyof typeof THEMES, string> }
13
- );
14
- };
15
-
16
- interface ChartContextProps {
17
- config: ChartConfig;
18
- }
19
-
20
- const ChartContext = React.createContext<ChartContextProps | null>(null);
21
-
22
- export function useChart() {
23
- const context = React.useContext(ChartContext);
24
- if (!context) {
25
- throw new Error('useChart must be used within a <ChartContainer />');
26
- }
27
- return context;
28
- }
29
-
30
- export interface ChartContainerProps extends React.ComponentProps<'div'> {
31
- config: ChartConfig;
32
- children: React.ReactNode;
33
- }
34
-
35
- export const ChartContainer = React.forwardRef<HTMLDivElement, ChartContainerProps>(
36
- ({ id, className, children, config, ...props }, ref) => {
37
- const uniqueId = React.useId();
38
- const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`;
39
-
40
- return (
41
- <ChartContext.Provider value={{ config }}>
42
- <div
43
- data-chart={chartId}
44
- data-slot="chart"
45
- ref={ref}
46
- className={cn(
47
- 'flex aspect-video justify-center overflow-visible text-xs',
48
- '[&_.lc-highlight-point]:stroke-transparent',
49
- '[&_.lc-line]:stroke-border/50',
50
- '[&_.lc-highlight-line]:stroke-0',
51
- '[&_.lc-area-path]:opacity-100 [&_.lc-highlight-line]:opacity-100 [&_.lc-highlight-point]:opacity-100 [&_.lc-spline-path]:opacity-100 [&_.lc-text]:text-xs [&_.lc-text-svg]:overflow-visible',
52
- '[&_.lc-axis-tick]:stroke-0',
53
- '[&_.lc-rule-x-line:not(.lc-grid-x-rule)]:stroke-0 [&_.lc-rule-y-line:not(.lc-grid-y-rule)]:stroke-0',
54
- '[&_.lc-grid-x-radial-circle]:stroke-border [&_.lc-grid-x-radial-line]:stroke-border',
55
- '[&_.lc-grid-y-radial-circle]:stroke-border [&_.lc-grid-y-radial-line]:stroke-border',
56
- '[&_.lc-legend-swatch-button]:items-center [&_.lc-legend-swatch-button]:gap-1.5',
57
- '[&_.lc-legend-swatch-group]:items-center [&_.lc-legend-swatch-group]:gap-4',
58
- '[&_.lc-legend-swatch]:size-2.5 [&_.lc-legend-swatch]:rounded-[2px]',
59
- '[&_.lc-labels-text:not([fill])]:fill-foreground [&_text]:stroke-transparent',
60
- '[&_.lc-axis-tick-label]:fill-muted-foreground [&_.lc-axis-tick-label]:font-normal',
61
- '[&_.lc-tooltip-rects-g]:fill-transparent',
62
- '[&_.lc-layout-svg-g]:fill-transparent',
63
- '[&_.lc-root-container]:w-full',
64
- className
65
- )}
66
- {...props}
67
- >
68
- <ChartStyle id={chartId} config={config} />
69
- {children}
70
- </div>
71
- </ChartContext.Provider>
72
- );
73
- }
74
- );
75
- ChartContainer.displayName = 'ChartContainer';
76
-
77
- export const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
78
- const colorConfig = Object.entries(config).filter(
79
- ([, itemConfig]) => itemConfig.theme || itemConfig.color
80
- );
81
-
82
- if (!colorConfig.length) {
83
- return null;
84
- }
85
-
86
- return (
87
- <style
88
- dangerouslySetInnerHTML={{
89
- __html: Object.entries(THEMES)
90
- .map(([theme, prefix]) => {
91
- const declarations = colorConfig
92
- .map(([key, itemConfig]) => {
93
- const color =
94
- itemConfig.theme?.[theme as keyof typeof itemConfig.theme] || itemConfig.color;
95
- return color ? ` --color-${key}: ${color};` : null;
96
- })
97
- .filter(Boolean)
98
- .join('\n');
99
- return `${prefix} [data-chart=${id}] {\n${declarations}\n}`;
100
- })
101
- .join('\n')
102
- }}
103
- />
104
- );
105
- };
106
-
107
- export interface ChartTooltipPayloadItem {
108
- key?: string;
109
- name?: string;
110
- label?: string;
111
- value?: number | string;
112
- color?: string;
113
- dataKey?: string;
114
- config?: { color?: string; label?: string };
115
- payload?: Record<string, unknown>;
116
- [key: string]: unknown;
117
- }
118
-
119
- export function getPayloadConfigFromPayload(
120
- config: ChartConfig,
121
- payload: ChartTooltipPayloadItem,
122
- key: string
123
- ) {
124
- if (typeof payload !== 'object' || payload === null) return undefined;
125
-
126
- const payloadPayload =
127
- 'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null
128
- ? payload.payload
129
- : undefined;
130
-
131
- let configLabelKey: string = key;
132
-
133
- if (key in payload && typeof payload[key] === 'string') {
134
- configLabelKey = payload[key] as string;
135
- } else if (payloadPayload && key in payloadPayload && typeof payloadPayload[key] === 'string') {
136
- configLabelKey = payloadPayload[key] as string;
137
- }
138
-
139
- return configLabelKey in config ? config[configLabelKey] : config[key];
140
- }
141
-
142
- export interface ChartTooltipContentProps extends React.ComponentProps<'div'> {
143
- active?: boolean;
144
- payload?: ChartTooltipPayloadItem[];
145
- label?: React.ReactNode;
146
- hideLabel?: boolean;
147
- hideIndicator?: boolean;
148
- indicator?: 'line' | 'dot' | 'dashed';
149
- nameKey?: string;
150
- labelKey?: string;
151
- labelFormatter?: (label: React.ReactNode, payload: ChartTooltipPayloadItem[]) => React.ReactNode;
152
- formatter?: (
153
- value: unknown,
154
- name: string,
155
- item: ChartTooltipPayloadItem,
156
- index: number,
157
- payload: ChartTooltipPayloadItem[]
158
- ) => React.ReactNode;
159
- color?: string;
160
- }
161
-
162
- export const ChartTooltipContent = React.forwardRef<HTMLDivElement, ChartTooltipContentProps>(
163
- (
164
- {
165
- active,
166
- payload,
167
- className,
168
- indicator = 'dot',
169
- hideLabel = false,
170
- hideIndicator = false,
171
- label,
172
- labelFormatter,
173
- labelClassName,
174
- formatter,
175
- color,
176
- nameKey,
177
- labelKey,
178
- ...props
179
- }: ChartTooltipContentProps & { labelClassName?: string },
180
- ref
181
- ) => {
182
- const { config } = useChart();
183
-
184
- const tooltipLabel = React.useMemo(() => {
185
- if (hideLabel || !payload?.length) {
186
- return null;
187
- }
188
-
189
- const [item] = payload;
190
- const key = `${labelKey || item?.dataKey || item?.name || 'value'}`;
191
- const itemConfig = getPayloadConfigFromPayload(config, item, key);
192
- const value =
193
- !labelKey && typeof label === 'string'
194
- ? config[label as keyof typeof config]?.label || label
195
- : itemConfig?.label;
196
-
197
- if (labelFormatter) {
198
- return (
199
- <div className={cn('font-medium', labelClassName)}>{labelFormatter(value, payload)}</div>
200
- );
201
- }
202
-
203
- if (!value) {
204
- return null;
205
- }
206
-
207
- return <div className={cn('font-medium', labelClassName)}>{value}</div>;
208
- }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
209
-
210
- if (active === false || !payload?.length) {
211
- return null;
212
- }
213
-
214
- const nestLabel = payload.length === 1 && indicator !== 'dot';
215
-
216
- return (
217
- <div
218
- ref={ref}
219
- data-slot="chart-tooltip"
220
- className={cn(
221
- 'grid min-w-[9rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl',
222
- className
223
- )}
224
- {...props}
225
- >
226
- {!nestLabel ? tooltipLabel : null}
227
- <div className="grid gap-1.5">
228
- {payload.map((item, index) => {
229
- const key = `${nameKey || item.name || item.dataKey || 'value'}`;
230
- const itemConfig = getPayloadConfigFromPayload(config, item, key);
231
- const indicatorColor = color || item.color || itemConfig?.color;
232
-
233
- return (
234
- <div
235
- key={item.dataKey || item.name || index}
236
- className={cn(
237
- 'flex w-full items-center gap-2 [&>svg]:size-2.5 [&>svg]:text-muted-foreground',
238
- indicator === 'dot' && 'items-center'
239
- )}
240
- >
241
- {formatter && item?.value !== undefined && item.name ? (
242
- formatter(item.value, item.name, item, index, payload)
243
- ) : (
244
- <>
245
- {!hideIndicator && (
246
- <div
247
- className={cn(
248
- 'shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)',
249
- {
250
- 'size-2.5': indicator === 'dot',
251
- 'h-3.5 w-1': indicator === 'line',
252
- 'w-0 border-[1.5px] border-dashed bg-transparent':
253
- indicator === 'dashed',
254
- 'my-0.5': nestLabel && indicator === 'dashed'
255
- }
256
- )}
257
- style={
258
- {
259
- '--color-bg': indicatorColor,
260
- '--color-border': indicatorColor
261
- } as React.CSSProperties
262
- }
263
- />
264
- )}
265
- <div
266
- className={cn(
267
- 'flex flex-1 justify-between items-center leading-none',
268
- nestLabel ? 'items-end' : 'items-center'
269
- )}
270
- >
271
- <div className="grid gap-1.5">
272
- {nestLabel ? tooltipLabel : null}
273
- <span className="text-muted-foreground">
274
- {itemConfig?.label || item.name}
275
- </span>
276
- </div>
277
- {item.value !== undefined && (
278
- <span className="font-mono font-medium text-foreground tabular-nums">
279
- {Number(item.value).toLocaleString()}
280
- </span>
281
- )}
282
- </div>
283
- </>
284
- )}
285
- </div>
286
- );
287
- })}
288
- </div>
289
- </div>
290
- );
291
- }
292
- );
293
- ChartTooltipContent.displayName = 'ChartTooltipContent';
294
-
295
- export const ChartTooltip = ChartTooltipContent;
296
- export default ShadcnChart;
@@ -1,117 +0,0 @@
1
- import * as React from 'react';
2
-
3
- import { Check, Minus } from 'lucide-react';
4
- import { cn } from '@surreal-ui/core';
5
-
6
- export interface ShadcnCheckboxProps extends Omit<
7
- React.ButtonHTMLAttributes<HTMLButtonElement>,
8
- 'checked' | 'onChange'
9
- > {
10
- checked?: boolean | 'indeterminate';
11
- indeterminate?: boolean;
12
- onCheckedChange?: (checked: boolean | 'indeterminate') => void;
13
- name?: string;
14
- value?: string;
15
- required?: boolean;
16
- }
17
-
18
- export const ShadcnCheckbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(
19
- (
20
- {
21
- className,
22
- checked: checkedProp,
23
- indeterminate = false,
24
- onCheckedChange,
25
- disabled = false,
26
- required = false,
27
- name,
28
- value = 'on',
29
- onClick,
30
- onKeyDown,
31
- ...props
32
- },
33
- ref
34
- ) => {
35
- const [uncontrolledChecked, setUncontrolledChecked] = React.useState<boolean | 'indeterminate'>(
36
- indeterminate ? 'indeterminate' : false
37
- );
38
-
39
- const isControlled = checkedProp !== undefined;
40
- const currentChecked = isControlled ? checkedProp : uncontrolledChecked;
41
- const isIndeterminate = indeterminate || currentChecked === 'indeterminate';
42
- const isChecked = !isIndeterminate && Boolean(currentChecked);
43
-
44
- const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
45
- onClick?.(event);
46
- if (event.defaultPrevented || disabled) return;
47
-
48
- const nextChecked = isIndeterminate ? true : !isChecked;
49
- if (!isControlled) {
50
- setUncontrolledChecked(nextChecked);
51
- }
52
- onCheckedChange?.(nextChecked);
53
- };
54
-
55
- const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
56
- onKeyDown?.(event);
57
- if (event.defaultPrevented || disabled) return;
58
- if (event.key === ' ') {
59
- event.preventDefault();
60
- const nextChecked = isIndeterminate ? true : !isChecked;
61
- if (!isControlled) {
62
- setUncontrolledChecked(nextChecked);
63
- }
64
- onCheckedChange?.(nextChecked);
65
- }
66
- };
67
-
68
- return (
69
- <>
70
- <button
71
- type="button"
72
- role="checkbox"
73
- ref={ref}
74
- aria-checked={isIndeterminate ? 'mixed' : isChecked}
75
- aria-required={required}
76
- data-slot="checkbox"
77
- data-state={isIndeterminate ? 'indeterminate' : isChecked ? 'checked' : 'unchecked'}
78
- data-disabled={disabled ? '' : undefined}
79
- disabled={disabled}
80
- className={cn(
81
- 'peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors group-has-disabled/field:opacity-50 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50',
82
- className
83
- )}
84
- onClick={handleClick}
85
- onKeyDown={handleKeyDown}
86
- {...props}
87
- >
88
- <div
89
- data-slot="checkbox-indicator"
90
- className="[&>svg]:size-3.5 grid place-content-center text-current transition-none"
91
- >
92
- {isChecked && <Check className="size-3.5 stroke-[2.5]" />}
93
- {isIndeterminate && <Minus className="size-3.5 stroke-[2.5]" />}
94
- </div>
95
- </button>
96
- {name && (
97
- <input
98
- type="checkbox"
99
- name={name}
100
- value={value}
101
- checked={isChecked}
102
- disabled={disabled}
103
- required={required}
104
- tabIndex={-1}
105
- aria-hidden="true"
106
- className="sr-only pointer-events-none"
107
- readOnly
108
- />
109
- )}
110
- </>
111
- );
112
- }
113
- );
114
-
115
- Checkbox.displayName = 'Checkbox';
116
-
117
- export default ShadcnCheckbox;