@arolariu/components 0.1.0 → 0.1.2
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/EXAMPLES.md +1035 -1035
- package/LICENSE.md +21 -21
- package/changelog.md +9 -0
- package/dist/components/ui/bubble-background.js.map +1 -1
- package/dist/components/ui/chart.d.ts +25 -11
- package/dist/components/ui/chart.d.ts.map +1 -1
- package/dist/components/ui/chart.js +14 -11
- package/dist/components/ui/chart.js.map +1 -1
- package/dist/components/ui/dropdrawer.js +1 -1
- package/dist/components/ui/dropdrawer.js.map +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/sidebar.js.map +1 -1
- package/dist/components/ui/typewriter.d.ts +18 -0
- package/dist/components/ui/typewriter.d.ts.map +1 -0
- package/dist/components/ui/typewriter.js +128 -0
- package/dist/components/ui/typewriter.js.map +1 -0
- package/dist/hooks/{use-mobile.d.ts → useIsMobile.d.ts} +1 -1
- package/dist/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/hooks/useIsMobile.js +19 -0
- package/dist/hooks/useIsMobile.js.map +1 -0
- package/dist/hooks/useWindowSize.d.ts +30 -0
- package/dist/hooks/useWindowSize.d.ts.map +1 -0
- package/dist/hooks/useWindowSize.js +28 -0
- package/dist/hooks/useWindowSize.js.map +1 -0
- package/dist/index.css +67 -25
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/lib/utils.js.map +1 -1
- package/package.json +52 -42
- package/src/components/ui/bubble-background.tsx +189 -189
- package/src/components/ui/chart.tsx +67 -35
- package/src/components/ui/dropdrawer.tsx +973 -973
- package/src/components/ui/sidebar.tsx +1 -1
- package/src/components/ui/typewriter.tsx +188 -0
- package/src/hooks/{use-mobile.tsx → useIsMobile.tsx} +45 -44
- package/src/hooks/useWindowSize.tsx +72 -0
- package/src/index.ts +408 -400
- package/src/lib/utils.ts +10 -10
- package/dist/hooks/use-mobile.d.ts.map +0 -1
- package/dist/hooks/use-mobile.js +0 -18
- package/dist/hooks/use-mobile.js.map +0 -1
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import * as RechartsPrimitive from "recharts";
|
|
5
5
|
|
|
6
|
+
import type { LegendPayload } from "recharts/types/component/DefaultLegendContent";
|
|
7
|
+
import {
|
|
8
|
+
NameType,
|
|
9
|
+
Payload,
|
|
10
|
+
ValueType,
|
|
11
|
+
} from "recharts/types/component/DefaultTooltipContent";
|
|
12
|
+
import type { Props as LegendProps } from "recharts/types/component/Legend";
|
|
13
|
+
import { TooltipContentProps } from "recharts/types/component/Tooltip";
|
|
14
|
+
|
|
6
15
|
import { cn } from "@/lib/utils";
|
|
7
16
|
|
|
8
17
|
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
@@ -22,6 +31,36 @@ type ChartContextProps = {
|
|
|
22
31
|
config: ChartConfig;
|
|
23
32
|
};
|
|
24
33
|
|
|
34
|
+
export type CustomTooltipProps = TooltipContentProps<ValueType, NameType> & {
|
|
35
|
+
className?: string;
|
|
36
|
+
hideLabel?: boolean;
|
|
37
|
+
hideIndicator?: boolean;
|
|
38
|
+
indicator?: "line" | "dot" | "dashed";
|
|
39
|
+
nameKey?: string;
|
|
40
|
+
labelKey?: string;
|
|
41
|
+
labelFormatter?: (
|
|
42
|
+
label: TooltipContentProps<number, string>["label"],
|
|
43
|
+
payload: TooltipContentProps<number, string>["payload"],
|
|
44
|
+
) => React.ReactNode;
|
|
45
|
+
formatter?: (
|
|
46
|
+
value: number | string,
|
|
47
|
+
name: string,
|
|
48
|
+
item: Payload<number | string, string>,
|
|
49
|
+
index: number,
|
|
50
|
+
payload: ReadonlyArray<Payload<number | string, string>>,
|
|
51
|
+
) => React.ReactNode;
|
|
52
|
+
labelClassName?: string;
|
|
53
|
+
color?: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type ChartLegendContentProps = {
|
|
57
|
+
className?: string;
|
|
58
|
+
hideIcon?: boolean;
|
|
59
|
+
verticalAlign?: LegendProps["verticalAlign"];
|
|
60
|
+
payload?: LegendPayload[];
|
|
61
|
+
nameKey?: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
25
64
|
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
|
26
65
|
|
|
27
66
|
function useChart() {
|
|
@@ -84,17 +123,17 @@ const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
|
84
123
|
__html: Object.entries(THEMES)
|
|
85
124
|
.map(
|
|
86
125
|
([theme, prefix]) => `
|
|
87
|
-
${prefix} [data-chart=${id}] {
|
|
88
|
-
${colorConfig
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
`,
|
|
126
|
+
${prefix} [data-chart=${id}] {
|
|
127
|
+
${colorConfig
|
|
128
|
+
.map(([key, itemConfig]) => {
|
|
129
|
+
const color =
|
|
130
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
|
131
|
+
itemConfig.color;
|
|
132
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
133
|
+
})
|
|
134
|
+
.join("\n")}
|
|
135
|
+
}
|
|
136
|
+
`,
|
|
98
137
|
)
|
|
99
138
|
.join("\n"),
|
|
100
139
|
}}
|
|
@@ -107,25 +146,18 @@ const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
|
107
146
|
function ChartTooltipContent({
|
|
108
147
|
active,
|
|
109
148
|
payload,
|
|
149
|
+
label,
|
|
110
150
|
className,
|
|
111
151
|
indicator = "dot",
|
|
112
152
|
hideLabel = false,
|
|
113
153
|
hideIndicator = false,
|
|
114
|
-
label,
|
|
115
154
|
labelFormatter,
|
|
116
|
-
labelClassName,
|
|
117
155
|
formatter,
|
|
156
|
+
labelClassName,
|
|
118
157
|
color,
|
|
119
158
|
nameKey,
|
|
120
159
|
labelKey,
|
|
121
|
-
}:
|
|
122
|
-
React.ComponentProps<"div"> & {
|
|
123
|
-
hideLabel?: boolean;
|
|
124
|
-
hideIndicator?: boolean;
|
|
125
|
-
indicator?: "line" | "dot" | "dashed";
|
|
126
|
-
nameKey?: string;
|
|
127
|
-
labelKey?: string;
|
|
128
|
-
}) {
|
|
160
|
+
}: CustomTooltipProps) {
|
|
129
161
|
const { config } = useChart();
|
|
130
162
|
|
|
131
163
|
const tooltipLabel = React.useMemo(() => {
|
|
@@ -136,10 +168,14 @@ function ChartTooltipContent({
|
|
|
136
168
|
const [item] = payload;
|
|
137
169
|
const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
|
|
138
170
|
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
139
|
-
const value =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
171
|
+
const value = (() => {
|
|
172
|
+
const v =
|
|
173
|
+
!labelKey && typeof label === "string"
|
|
174
|
+
? (config[label as keyof typeof config]?.label ?? label)
|
|
175
|
+
: itemConfig?.label;
|
|
176
|
+
|
|
177
|
+
return typeof v === "string" || typeof v === "number" ? v : undefined;
|
|
178
|
+
})();
|
|
143
179
|
|
|
144
180
|
if (labelFormatter) {
|
|
145
181
|
return (
|
|
@@ -173,7 +209,7 @@ function ChartTooltipContent({
|
|
|
173
209
|
return (
|
|
174
210
|
<div
|
|
175
211
|
className={cn(
|
|
176
|
-
"border-
|
|
212
|
+
"border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
|
|
177
213
|
className,
|
|
178
214
|
)}
|
|
179
215
|
>
|
|
@@ -188,7 +224,7 @@ function ChartTooltipContent({
|
|
|
188
224
|
<div
|
|
189
225
|
key={item.dataKey}
|
|
190
226
|
className={cn(
|
|
191
|
-
"[&>svg]:text-
|
|
227
|
+
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
|
|
192
228
|
indicator === "dot" && "items-center",
|
|
193
229
|
)}
|
|
194
230
|
>
|
|
@@ -228,12 +264,12 @@ function ChartTooltipContent({
|
|
|
228
264
|
>
|
|
229
265
|
<div className="grid gap-1.5">
|
|
230
266
|
{nestLabel ? tooltipLabel : null}
|
|
231
|
-
<span className="text-
|
|
267
|
+
<span className="text-muted-foreground">
|
|
232
268
|
{itemConfig?.label || item.name}
|
|
233
269
|
</span>
|
|
234
270
|
</div>
|
|
235
271
|
{item.value && (
|
|
236
|
-
<span className="text-
|
|
272
|
+
<span className="text-foreground font-mono font-medium tabular-nums">
|
|
237
273
|
{item.value.toLocaleString()}
|
|
238
274
|
</span>
|
|
239
275
|
)}
|
|
@@ -256,11 +292,7 @@ function ChartLegendContent({
|
|
|
256
292
|
payload,
|
|
257
293
|
verticalAlign = "bottom",
|
|
258
294
|
nameKey,
|
|
259
|
-
}:
|
|
260
|
-
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
|
261
|
-
hideIcon?: boolean;
|
|
262
|
-
nameKey?: string;
|
|
263
|
-
}) {
|
|
295
|
+
}: ChartLegendContentProps) {
|
|
264
296
|
const { config } = useChart();
|
|
265
297
|
|
|
266
298
|
if (!payload?.length) {
|
|
@@ -283,7 +315,7 @@ function ChartLegendContent({
|
|
|
283
315
|
<div
|
|
284
316
|
key={item.value}
|
|
285
317
|
className={cn(
|
|
286
|
-
"[&>svg]:text-
|
|
318
|
+
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3",
|
|
287
319
|
)}
|
|
288
320
|
>
|
|
289
321
|
{itemConfig?.icon && !hideIcon ? (
|