lite-math 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +19 -0
- package/.prettierrc +10 -0
- package/CHANGELOG.md +22 -0
- package/CONTRIBUTING.md +51 -0
- package/LICENSE +21 -0
- package/README.md +213 -0
- package/app/globals.css +125 -0
- package/app/layout.tsx +27 -0
- package/app/page.tsx +7 -0
- package/components/theme-provider.tsx +11 -0
- package/components/ui/accordion.tsx +66 -0
- package/components/ui/alert-dialog.tsx +157 -0
- package/components/ui/alert.tsx +66 -0
- package/components/ui/aspect-ratio.tsx +11 -0
- package/components/ui/avatar.tsx +53 -0
- package/components/ui/badge.tsx +46 -0
- package/components/ui/breadcrumb.tsx +109 -0
- package/components/ui/button-group.tsx +83 -0
- package/components/ui/button.tsx +60 -0
- package/components/ui/calendar.tsx +213 -0
- package/components/ui/card.tsx +92 -0
- package/components/ui/carousel.tsx +241 -0
- package/components/ui/chart.tsx +353 -0
- package/components/ui/checkbox.tsx +32 -0
- package/components/ui/collapsible.tsx +33 -0
- package/components/ui/command.tsx +184 -0
- package/components/ui/context-menu.tsx +252 -0
- package/components/ui/dialog.tsx +143 -0
- package/components/ui/drawer.tsx +135 -0
- package/components/ui/dropdown-menu.tsx +257 -0
- package/components/ui/empty.tsx +104 -0
- package/components/ui/field.tsx +244 -0
- package/components/ui/form.tsx +167 -0
- package/components/ui/hover-card.tsx +44 -0
- package/components/ui/input-group.tsx +169 -0
- package/components/ui/input-otp.tsx +77 -0
- package/components/ui/input.tsx +21 -0
- package/components/ui/item.tsx +193 -0
- package/components/ui/kbd.tsx +28 -0
- package/components/ui/label.tsx +24 -0
- package/components/ui/menubar.tsx +276 -0
- package/components/ui/navigation-menu.tsx +166 -0
- package/components/ui/pagination.tsx +127 -0
- package/components/ui/popover.tsx +48 -0
- package/components/ui/progress.tsx +31 -0
- package/components/ui/radio-group.tsx +45 -0
- package/components/ui/resizable.tsx +56 -0
- package/components/ui/scroll-area.tsx +58 -0
- package/components/ui/select.tsx +185 -0
- package/components/ui/separator.tsx +28 -0
- package/components/ui/sheet.tsx +139 -0
- package/components/ui/sidebar.tsx +726 -0
- package/components/ui/skeleton.tsx +13 -0
- package/components/ui/slider.tsx +63 -0
- package/components/ui/sonner.tsx +25 -0
- package/components/ui/spinner.tsx +16 -0
- package/components/ui/switch.tsx +31 -0
- package/components/ui/table.tsx +116 -0
- package/components/ui/tabs.tsx +66 -0
- package/components/ui/textarea.tsx +18 -0
- package/components/ui/toast.tsx +129 -0
- package/components/ui/toaster.tsx +35 -0
- package/components/ui/toggle-group.tsx +73 -0
- package/components/ui/toggle.tsx +47 -0
- package/components/ui/tooltip.tsx +61 -0
- package/components/ui/use-mobile.tsx +19 -0
- package/components/ui/use-toast.ts +191 -0
- package/components.json +21 -0
- package/dist/advanced/cube-root.d.ts +2 -0
- package/dist/advanced/cube-root.d.ts.map +1 -0
- package/dist/advanced/cube-root.js +4 -0
- package/dist/advanced/cube-root.js.map +1 -0
- package/dist/advanced/factorial.d.ts +2 -0
- package/dist/advanced/factorial.d.ts.map +1 -0
- package/dist/advanced/factorial.js +11 -0
- package/dist/advanced/factorial.js.map +1 -0
- package/dist/advanced/fibonacci.d.ts +2 -0
- package/dist/advanced/fibonacci.d.ts.map +1 -0
- package/dist/advanced/fibonacci.js +15 -0
- package/dist/advanced/fibonacci.js.map +1 -0
- package/dist/advanced/gcd.d.ts +2 -0
- package/dist/advanced/gcd.d.ts.map +1 -0
- package/dist/advanced/gcd.js +10 -0
- package/dist/advanced/gcd.js.map +1 -0
- package/dist/advanced/lcm.d.ts +2 -0
- package/dist/advanced/lcm.d.ts.map +1 -0
- package/dist/advanced/lcm.js +13 -0
- package/dist/advanced/lcm.js.map +1 -0
- package/dist/advanced/power.d.ts +2 -0
- package/dist/advanced/power.d.ts.map +1 -0
- package/dist/advanced/power.js +4 -0
- package/dist/advanced/power.js.map +1 -0
- package/dist/advanced/prime-check.d.ts +2 -0
- package/dist/advanced/prime-check.d.ts.map +1 -0
- package/dist/advanced/prime-check.js +14 -0
- package/dist/advanced/prime-check.js.map +1 -0
- package/dist/advanced/prime-list.d.ts +2 -0
- package/dist/advanced/prime-list.d.ts.map +1 -0
- package/dist/advanced/prime-list.js +14 -0
- package/dist/advanced/prime-list.js.map +1 -0
- package/dist/advanced/sqrt.d.ts +2 -0
- package/dist/advanced/sqrt.d.ts.map +1 -0
- package/dist/advanced/sqrt.js +6 -0
- package/dist/advanced/sqrt.js.map +1 -0
- package/dist/algebra/circle-area.d.ts +2 -0
- package/dist/algebra/circle-area.d.ts.map +1 -0
- package/dist/algebra/circle-area.js +4 -0
- package/dist/algebra/circle-area.js.map +1 -0
- package/dist/algebra/distance.d.ts +2 -0
- package/dist/algebra/distance.d.ts.map +1 -0
- package/dist/algebra/distance.js +4 -0
- package/dist/algebra/distance.js.map +1 -0
- package/dist/algebra/midpoint.d.ts +2 -0
- package/dist/algebra/midpoint.d.ts.map +1 -0
- package/dist/algebra/midpoint.js +4 -0
- package/dist/algebra/midpoint.js.map +1 -0
- package/dist/algebra/slope.d.ts +2 -0
- package/dist/algebra/slope.d.ts.map +1 -0
- package/dist/algebra/slope.js +6 -0
- package/dist/algebra/slope.js.map +1 -0
- package/dist/algebra/solve-linear.d.ts +2 -0
- package/dist/algebra/solve-linear.d.ts.map +1 -0
- package/dist/algebra/solve-linear.js +6 -0
- package/dist/algebra/solve-linear.js.map +1 -0
- package/dist/algebra/solve-quadratic.d.ts +2 -0
- package/dist/algebra/solve-quadratic.d.ts.map +1 -0
- package/dist/algebra/solve-quadratic.js +12 -0
- package/dist/algebra/solve-quadratic.js.map +1 -0
- package/dist/algebra/triangle-area.d.ts +2 -0
- package/dist/algebra/triangle-area.d.ts.map +1 -0
- package/dist/algebra/triangle-area.js +5 -0
- package/dist/algebra/triangle-area.js.map +1 -0
- package/dist/arithmetic/add.d.ts +2 -0
- package/dist/arithmetic/add.d.ts.map +1 -0
- package/dist/arithmetic/add.js +4 -0
- package/dist/arithmetic/add.js.map +1 -0
- package/dist/arithmetic/ceil.d.ts +2 -0
- package/dist/arithmetic/ceil.d.ts.map +1 -0
- package/dist/arithmetic/ceil.js +4 -0
- package/dist/arithmetic/ceil.js.map +1 -0
- package/dist/arithmetic/clamp.d.ts +2 -0
- package/dist/arithmetic/clamp.d.ts.map +1 -0
- package/dist/arithmetic/clamp.js +4 -0
- package/dist/arithmetic/clamp.js.map +1 -0
- package/dist/arithmetic/divide.d.ts +2 -0
- package/dist/arithmetic/divide.d.ts.map +1 -0
- package/dist/arithmetic/divide.js +6 -0
- package/dist/arithmetic/divide.js.map +1 -0
- package/dist/arithmetic/floor.d.ts +2 -0
- package/dist/arithmetic/floor.d.ts.map +1 -0
- package/dist/arithmetic/floor.js +4 -0
- package/dist/arithmetic/floor.js.map +1 -0
- package/dist/arithmetic/modulo.d.ts +2 -0
- package/dist/arithmetic/modulo.d.ts.map +1 -0
- package/dist/arithmetic/modulo.js +4 -0
- package/dist/arithmetic/modulo.js.map +1 -0
- package/dist/arithmetic/multiply.d.ts +2 -0
- package/dist/arithmetic/multiply.d.ts.map +1 -0
- package/dist/arithmetic/multiply.js +4 -0
- package/dist/arithmetic/multiply.js.map +1 -0
- package/dist/arithmetic/percentage.d.ts +2 -0
- package/dist/arithmetic/percentage.d.ts.map +1 -0
- package/dist/arithmetic/percentage.js +4 -0
- package/dist/arithmetic/percentage.js.map +1 -0
- package/dist/arithmetic/round.d.ts +2 -0
- package/dist/arithmetic/round.d.ts.map +1 -0
- package/dist/arithmetic/round.js +5 -0
- package/dist/arithmetic/round.js.map +1 -0
- package/dist/arithmetic/subtract.d.ts +2 -0
- package/dist/arithmetic/subtract.d.ts.map +1 -0
- package/dist/arithmetic/subtract.js +4 -0
- package/dist/arithmetic/subtract.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +277 -0
- package/dist/cli.js.map +1 -0
- package/dist/convert/c-to-f.d.ts +2 -0
- package/dist/convert/c-to-f.d.ts.map +1 -0
- package/dist/convert/c-to-f.js +4 -0
- package/dist/convert/c-to-f.js.map +1 -0
- package/dist/convert/deg-to-rad.d.ts +2 -0
- package/dist/convert/deg-to-rad.d.ts.map +1 -0
- package/dist/convert/deg-to-rad.js +4 -0
- package/dist/convert/deg-to-rad.js.map +1 -0
- package/dist/convert/f-to-c.d.ts +2 -0
- package/dist/convert/f-to-c.d.ts.map +1 -0
- package/dist/convert/f-to-c.js +4 -0
- package/dist/convert/f-to-c.js.map +1 -0
- package/dist/convert/km-to-miles.d.ts +2 -0
- package/dist/convert/km-to-miles.d.ts.map +1 -0
- package/dist/convert/km-to-miles.js +4 -0
- package/dist/convert/km-to-miles.js.map +1 -0
- package/dist/convert/miles-to-km.d.ts +2 -0
- package/dist/convert/miles-to-km.d.ts.map +1 -0
- package/dist/convert/miles-to-km.js +4 -0
- package/dist/convert/miles-to-km.js.map +1 -0
- package/dist/convert/rad-to-deg.d.ts +2 -0
- package/dist/convert/rad-to-deg.d.ts.map +1 -0
- package/dist/convert/rad-to-deg.js +4 -0
- package/dist/convert/rad-to-deg.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/random/random-array.d.ts +2 -0
- package/dist/random/random-array.d.ts.map +1 -0
- package/dist/random/random-array.js +4 -0
- package/dist/random/random-array.js.map +1 -0
- package/dist/random/random-float.d.ts +2 -0
- package/dist/random/random-float.d.ts.map +1 -0
- package/dist/random/random-float.js +4 -0
- package/dist/random/random-float.js.map +1 -0
- package/dist/random/random-from-array.d.ts +2 -0
- package/dist/random/random-from-array.d.ts.map +1 -0
- package/dist/random/random-from-array.js +4 -0
- package/dist/random/random-from-array.js.map +1 -0
- package/dist/random/random-int.d.ts +2 -0
- package/dist/random/random-int.d.ts.map +1 -0
- package/dist/random/random-int.js +4 -0
- package/dist/random/random-int.js.map +1 -0
- package/dist/statistics/mean.d.ts +2 -0
- package/dist/statistics/mean.d.ts.map +1 -0
- package/dist/statistics/mean.js +6 -0
- package/dist/statistics/mean.js.map +1 -0
- package/dist/statistics/median.d.ts +2 -0
- package/dist/statistics/median.d.ts.map +1 -0
- package/dist/statistics/median.js +8 -0
- package/dist/statistics/median.js.map +1 -0
- package/dist/statistics/mode.d.ts +2 -0
- package/dist/statistics/mode.d.ts.map +1 -0
- package/dist/statistics/mode.js +13 -0
- package/dist/statistics/mode.js.map +1 -0
- package/dist/statistics/product-array.d.ts +2 -0
- package/dist/statistics/product-array.d.ts.map +1 -0
- package/dist/statistics/product-array.js +4 -0
- package/dist/statistics/product-array.js.map +1 -0
- package/dist/statistics/range.d.ts +2 -0
- package/dist/statistics/range.d.ts.map +1 -0
- package/dist/statistics/range.js +6 -0
- package/dist/statistics/range.js.map +1 -0
- package/dist/statistics/std-dev.d.ts +2 -0
- package/dist/statistics/std-dev.d.ts.map +1 -0
- package/dist/statistics/std-dev.js +10 -0
- package/dist/statistics/std-dev.js.map +1 -0
- package/dist/statistics/sum-array.d.ts +2 -0
- package/dist/statistics/sum-array.d.ts.map +1 -0
- package/dist/statistics/sum-array.js +4 -0
- package/dist/statistics/sum-array.js.map +1 -0
- package/dist/statistics/variance.d.ts +2 -0
- package/dist/statistics/variance.d.ts.map +1 -0
- package/dist/statistics/variance.js +7 -0
- package/dist/statistics/variance.js.map +1 -0
- package/examples/advanced-examples.ts +31 -0
- package/examples/algebra-examples.ts +24 -0
- package/examples/arithmetic-examples.ts +24 -0
- package/examples/conversion-examples.ts +24 -0
- package/examples/statistics-examples.ts +29 -0
- package/hooks/use-mobile.ts +19 -0
- package/hooks/use-toast.ts +191 -0
- package/jest.config.js +15 -0
- package/lib/utils.ts +6 -0
- package/next.config.mjs +11 -0
- package/package.json +110 -0
- package/postcss.config.mjs +8 -0
- package/public/apple-icon.png +0 -0
- package/public/icon-dark-32x32.png +0 -0
- package/public/icon-light-32x32.png +0 -0
- package/public/icon.svg +26 -0
- package/public/placeholder-logo.png +0 -0
- package/public/placeholder-logo.svg +1 -0
- package/public/placeholder-user.jpg +0 -0
- package/public/placeholder.jpg +0 -0
- package/public/placeholder.svg +1 -0
- package/src/advanced/cube-root.ts +8 -0
- package/src/advanced/factorial.ts +12 -0
- package/src/advanced/fibonacci.ts +16 -0
- package/src/advanced/gcd.ts +14 -0
- package/src/advanced/lcm.ts +18 -0
- package/src/advanced/power.ts +9 -0
- package/src/advanced/prime-check.ts +14 -0
- package/src/advanced/prime-list.ts +16 -0
- package/src/advanced/sqrt.ts +9 -0
- package/src/algebra/circle-area.ts +8 -0
- package/src/algebra/distance.ts +11 -0
- package/src/algebra/midpoint.ts +11 -0
- package/src/algebra/slope.ts +12 -0
- package/src/algebra/solve-linear.ts +10 -0
- package/src/algebra/solve-quadratic.ts +15 -0
- package/src/algebra/triangle-area.ts +11 -0
- package/src/arithmetic/add.ts +9 -0
- package/src/arithmetic/ceil.ts +8 -0
- package/src/arithmetic/clamp.ts +10 -0
- package/src/arithmetic/divide.ts +11 -0
- package/src/arithmetic/floor.ts +8 -0
- package/src/arithmetic/modulo.ts +9 -0
- package/src/arithmetic/multiply.ts +9 -0
- package/src/arithmetic/percentage.ts +9 -0
- package/src/arithmetic/round.ts +10 -0
- package/src/arithmetic/subtract.ts +9 -0
- package/src/cli.ts +321 -0
- package/src/convert/c-to-f.ts +8 -0
- package/src/convert/deg-to-rad.ts +8 -0
- package/src/convert/f-to-c.ts +8 -0
- package/src/convert/km-to-miles.ts +8 -0
- package/src/convert/miles-to-km.ts +8 -0
- package/src/convert/rad-to-deg.ts +8 -0
- package/src/index.ts +49 -0
- package/src/random/random-array.ts +10 -0
- package/src/random/random-float.ts +9 -0
- package/src/random/random-from-array.ts +8 -0
- package/src/random/random-int.ts +9 -0
- package/src/statistics/mean.ts +9 -0
- package/src/statistics/median.ts +11 -0
- package/src/statistics/mode.ts +16 -0
- package/src/statistics/product-array.ts +8 -0
- package/src/statistics/range.ts +9 -0
- package/src/statistics/std-dev.ts +14 -0
- package/src/statistics/sum-array.ts +8 -0
- package/src/statistics/variance.ts +10 -0
- package/styles/globals.css +125 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import * as RechartsPrimitive from 'recharts'
|
|
5
|
+
|
|
6
|
+
import { cn } from '@/lib/utils'
|
|
7
|
+
|
|
8
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
9
|
+
const THEMES = { light: '', dark: '.dark' } as const
|
|
10
|
+
|
|
11
|
+
export type ChartConfig = {
|
|
12
|
+
[k in string]: {
|
|
13
|
+
label?: React.ReactNode
|
|
14
|
+
icon?: React.ComponentType
|
|
15
|
+
} & (
|
|
16
|
+
| { color?: string; theme?: never }
|
|
17
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ChartContextProps = {
|
|
22
|
+
config: ChartConfig
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null)
|
|
26
|
+
|
|
27
|
+
function useChart() {
|
|
28
|
+
const context = React.useContext(ChartContext)
|
|
29
|
+
|
|
30
|
+
if (!context) {
|
|
31
|
+
throw new Error('useChart must be used within a <ChartContainer />')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return context
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function ChartContainer({
|
|
38
|
+
id,
|
|
39
|
+
className,
|
|
40
|
+
children,
|
|
41
|
+
config,
|
|
42
|
+
...props
|
|
43
|
+
}: React.ComponentProps<'div'> & {
|
|
44
|
+
config: ChartConfig
|
|
45
|
+
children: React.ComponentProps<
|
|
46
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
47
|
+
>['children']
|
|
48
|
+
}) {
|
|
49
|
+
const uniqueId = React.useId()
|
|
50
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<ChartContext.Provider value={{ config }}>
|
|
54
|
+
<div
|
|
55
|
+
data-slot="chart"
|
|
56
|
+
data-chart={chartId}
|
|
57
|
+
className={cn(
|
|
58
|
+
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
|
|
59
|
+
className,
|
|
60
|
+
)}
|
|
61
|
+
{...props}
|
|
62
|
+
>
|
|
63
|
+
<ChartStyle id={chartId} config={config} />
|
|
64
|
+
<RechartsPrimitive.ResponsiveContainer>
|
|
65
|
+
{children}
|
|
66
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
67
|
+
</div>
|
|
68
|
+
</ChartContext.Provider>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
73
|
+
const colorConfig = Object.entries(config).filter(
|
|
74
|
+
([, config]) => config.theme || config.color,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if (!colorConfig.length) {
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<style
|
|
83
|
+
dangerouslySetInnerHTML={{
|
|
84
|
+
__html: Object.entries(THEMES)
|
|
85
|
+
.map(
|
|
86
|
+
([theme, prefix]) => `
|
|
87
|
+
${prefix} [data-chart=${id}] {
|
|
88
|
+
${colorConfig
|
|
89
|
+
.map(([key, itemConfig]) => {
|
|
90
|
+
const color =
|
|
91
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
|
92
|
+
itemConfig.color
|
|
93
|
+
return color ? ` --color-${key}: ${color};` : null
|
|
94
|
+
})
|
|
95
|
+
.join('\n')}
|
|
96
|
+
}
|
|
97
|
+
`,
|
|
98
|
+
)
|
|
99
|
+
.join('\n'),
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const ChartTooltip = RechartsPrimitive.Tooltip
|
|
106
|
+
|
|
107
|
+
function ChartTooltipContent({
|
|
108
|
+
active,
|
|
109
|
+
payload,
|
|
110
|
+
className,
|
|
111
|
+
indicator = 'dot',
|
|
112
|
+
hideLabel = false,
|
|
113
|
+
hideIndicator = false,
|
|
114
|
+
label,
|
|
115
|
+
labelFormatter,
|
|
116
|
+
labelClassName,
|
|
117
|
+
formatter,
|
|
118
|
+
color,
|
|
119
|
+
nameKey,
|
|
120
|
+
labelKey,
|
|
121
|
+
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
122
|
+
React.ComponentProps<'div'> & {
|
|
123
|
+
hideLabel?: boolean
|
|
124
|
+
hideIndicator?: boolean
|
|
125
|
+
indicator?: 'line' | 'dot' | 'dashed'
|
|
126
|
+
nameKey?: string
|
|
127
|
+
labelKey?: string
|
|
128
|
+
}) {
|
|
129
|
+
const { config } = useChart()
|
|
130
|
+
|
|
131
|
+
const tooltipLabel = React.useMemo(() => {
|
|
132
|
+
if (hideLabel || !payload?.length) {
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const [item] = payload
|
|
137
|
+
const key = `${labelKey || item?.dataKey || item?.name || 'value'}`
|
|
138
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
139
|
+
const value =
|
|
140
|
+
!labelKey && typeof label === 'string'
|
|
141
|
+
? config[label as keyof typeof config]?.label || label
|
|
142
|
+
: itemConfig?.label
|
|
143
|
+
|
|
144
|
+
if (labelFormatter) {
|
|
145
|
+
return (
|
|
146
|
+
<div className={cn('font-medium', labelClassName)}>
|
|
147
|
+
{labelFormatter(value, payload)}
|
|
148
|
+
</div>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!value) {
|
|
153
|
+
return null
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return <div className={cn('font-medium', labelClassName)}>{value}</div>
|
|
157
|
+
}, [
|
|
158
|
+
label,
|
|
159
|
+
labelFormatter,
|
|
160
|
+
payload,
|
|
161
|
+
hideLabel,
|
|
162
|
+
labelClassName,
|
|
163
|
+
config,
|
|
164
|
+
labelKey,
|
|
165
|
+
])
|
|
166
|
+
|
|
167
|
+
if (!active || !payload?.length) {
|
|
168
|
+
return null
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const nestLabel = payload.length === 1 && indicator !== 'dot'
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<div
|
|
175
|
+
className={cn(
|
|
176
|
+
'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
|
+
className,
|
|
178
|
+
)}
|
|
179
|
+
>
|
|
180
|
+
{!nestLabel ? tooltipLabel : null}
|
|
181
|
+
<div className="grid gap-1.5">
|
|
182
|
+
{payload.map((item, index) => {
|
|
183
|
+
const key = `${nameKey || item.name || item.dataKey || 'value'}`
|
|
184
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
185
|
+
const indicatorColor = color || item.payload.fill || item.color
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div
|
|
189
|
+
key={item.dataKey}
|
|
190
|
+
className={cn(
|
|
191
|
+
'[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5',
|
|
192
|
+
indicator === 'dot' && 'items-center',
|
|
193
|
+
)}
|
|
194
|
+
>
|
|
195
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
196
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
197
|
+
) : (
|
|
198
|
+
<>
|
|
199
|
+
{itemConfig?.icon ? (
|
|
200
|
+
<itemConfig.icon />
|
|
201
|
+
) : (
|
|
202
|
+
!hideIndicator && (
|
|
203
|
+
<div
|
|
204
|
+
className={cn(
|
|
205
|
+
'shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)',
|
|
206
|
+
{
|
|
207
|
+
'h-2.5 w-2.5': indicator === 'dot',
|
|
208
|
+
'w-1': indicator === 'line',
|
|
209
|
+
'w-0 border-[1.5px] border-dashed bg-transparent':
|
|
210
|
+
indicator === 'dashed',
|
|
211
|
+
'my-0.5': nestLabel && indicator === 'dashed',
|
|
212
|
+
},
|
|
213
|
+
)}
|
|
214
|
+
style={
|
|
215
|
+
{
|
|
216
|
+
'--color-bg': indicatorColor,
|
|
217
|
+
'--color-border': indicatorColor,
|
|
218
|
+
} as React.CSSProperties
|
|
219
|
+
}
|
|
220
|
+
/>
|
|
221
|
+
)
|
|
222
|
+
)}
|
|
223
|
+
<div
|
|
224
|
+
className={cn(
|
|
225
|
+
'flex flex-1 justify-between leading-none',
|
|
226
|
+
nestLabel ? 'items-end' : 'items-center',
|
|
227
|
+
)}
|
|
228
|
+
>
|
|
229
|
+
<div className="grid gap-1.5">
|
|
230
|
+
{nestLabel ? tooltipLabel : null}
|
|
231
|
+
<span className="text-muted-foreground">
|
|
232
|
+
{itemConfig?.label || item.name}
|
|
233
|
+
</span>
|
|
234
|
+
</div>
|
|
235
|
+
{item.value && (
|
|
236
|
+
<span className="text-foreground font-mono font-medium tabular-nums">
|
|
237
|
+
{item.value.toLocaleString()}
|
|
238
|
+
</span>
|
|
239
|
+
)}
|
|
240
|
+
</div>
|
|
241
|
+
</>
|
|
242
|
+
)}
|
|
243
|
+
</div>
|
|
244
|
+
)
|
|
245
|
+
})}
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const ChartLegend = RechartsPrimitive.Legend
|
|
252
|
+
|
|
253
|
+
function ChartLegendContent({
|
|
254
|
+
className,
|
|
255
|
+
hideIcon = false,
|
|
256
|
+
payload,
|
|
257
|
+
verticalAlign = 'bottom',
|
|
258
|
+
nameKey,
|
|
259
|
+
}: React.ComponentProps<'div'> &
|
|
260
|
+
Pick<RechartsPrimitive.LegendProps, 'payload' | 'verticalAlign'> & {
|
|
261
|
+
hideIcon?: boolean
|
|
262
|
+
nameKey?: string
|
|
263
|
+
}) {
|
|
264
|
+
const { config } = useChart()
|
|
265
|
+
|
|
266
|
+
if (!payload?.length) {
|
|
267
|
+
return null
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return (
|
|
271
|
+
<div
|
|
272
|
+
className={cn(
|
|
273
|
+
'flex items-center justify-center gap-4',
|
|
274
|
+
verticalAlign === 'top' ? 'pb-3' : 'pt-3',
|
|
275
|
+
className,
|
|
276
|
+
)}
|
|
277
|
+
>
|
|
278
|
+
{payload.map((item) => {
|
|
279
|
+
const key = `${nameKey || item.dataKey || 'value'}`
|
|
280
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<div
|
|
284
|
+
key={item.value}
|
|
285
|
+
className={
|
|
286
|
+
'[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3'
|
|
287
|
+
}
|
|
288
|
+
>
|
|
289
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
290
|
+
<itemConfig.icon />
|
|
291
|
+
) : (
|
|
292
|
+
<div
|
|
293
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
294
|
+
style={{
|
|
295
|
+
backgroundColor: item.color,
|
|
296
|
+
}}
|
|
297
|
+
/>
|
|
298
|
+
)}
|
|
299
|
+
{itemConfig?.label}
|
|
300
|
+
</div>
|
|
301
|
+
)
|
|
302
|
+
})}
|
|
303
|
+
</div>
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Helper to extract item config from a payload.
|
|
308
|
+
function getPayloadConfigFromPayload(
|
|
309
|
+
config: ChartConfig,
|
|
310
|
+
payload: unknown,
|
|
311
|
+
key: string,
|
|
312
|
+
) {
|
|
313
|
+
if (typeof payload !== 'object' || payload === null) {
|
|
314
|
+
return undefined
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const payloadPayload =
|
|
318
|
+
'payload' in payload &&
|
|
319
|
+
typeof payload.payload === 'object' &&
|
|
320
|
+
payload.payload !== null
|
|
321
|
+
? payload.payload
|
|
322
|
+
: undefined
|
|
323
|
+
|
|
324
|
+
let configLabelKey: string = key
|
|
325
|
+
|
|
326
|
+
if (
|
|
327
|
+
key in payload &&
|
|
328
|
+
typeof payload[key as keyof typeof payload] === 'string'
|
|
329
|
+
) {
|
|
330
|
+
configLabelKey = payload[key as keyof typeof payload] as string
|
|
331
|
+
} else if (
|
|
332
|
+
payloadPayload &&
|
|
333
|
+
key in payloadPayload &&
|
|
334
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'
|
|
335
|
+
) {
|
|
336
|
+
configLabelKey = payloadPayload[
|
|
337
|
+
key as keyof typeof payloadPayload
|
|
338
|
+
] as string
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return configLabelKey in config
|
|
342
|
+
? config[configLabelKey]
|
|
343
|
+
: config[key as keyof typeof config]
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export {
|
|
347
|
+
ChartContainer,
|
|
348
|
+
ChartTooltip,
|
|
349
|
+
ChartTooltipContent,
|
|
350
|
+
ChartLegend,
|
|
351
|
+
ChartLegendContent,
|
|
352
|
+
ChartStyle,
|
|
353
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
|
|
5
|
+
import { CheckIcon } from 'lucide-react'
|
|
6
|
+
|
|
7
|
+
import { cn } from '@/lib/utils'
|
|
8
|
+
|
|
9
|
+
function Checkbox({
|
|
10
|
+
className,
|
|
11
|
+
...props
|
|
12
|
+
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
13
|
+
return (
|
|
14
|
+
<CheckboxPrimitive.Root
|
|
15
|
+
data-slot="checkbox"
|
|
16
|
+
className={cn(
|
|
17
|
+
'peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50',
|
|
18
|
+
className,
|
|
19
|
+
)}
|
|
20
|
+
{...props}
|
|
21
|
+
>
|
|
22
|
+
<CheckboxPrimitive.Indicator
|
|
23
|
+
data-slot="checkbox-indicator"
|
|
24
|
+
className="flex items-center justify-center text-current transition-none"
|
|
25
|
+
>
|
|
26
|
+
<CheckIcon className="size-3.5" />
|
|
27
|
+
</CheckboxPrimitive.Indicator>
|
|
28
|
+
</CheckboxPrimitive.Root>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { Checkbox }
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible'
|
|
4
|
+
|
|
5
|
+
function Collapsible({
|
|
6
|
+
...props
|
|
7
|
+
}: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
|
|
8
|
+
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function CollapsibleTrigger({
|
|
12
|
+
...props
|
|
13
|
+
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
|
|
14
|
+
return (
|
|
15
|
+
<CollapsiblePrimitive.CollapsibleTrigger
|
|
16
|
+
data-slot="collapsible-trigger"
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function CollapsibleContent({
|
|
23
|
+
...props
|
|
24
|
+
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
|
|
25
|
+
return (
|
|
26
|
+
<CollapsiblePrimitive.CollapsibleContent
|
|
27
|
+
data-slot="collapsible-content"
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { Collapsible, CollapsibleTrigger, CollapsibleContent }
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Command as CommandPrimitive } from 'cmdk'
|
|
5
|
+
import { SearchIcon } from 'lucide-react'
|
|
6
|
+
|
|
7
|
+
import { cn } from '@/lib/utils'
|
|
8
|
+
import {
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogContent,
|
|
11
|
+
DialogDescription,
|
|
12
|
+
DialogHeader,
|
|
13
|
+
DialogTitle,
|
|
14
|
+
} from '@/components/ui/dialog'
|
|
15
|
+
|
|
16
|
+
function Command({
|
|
17
|
+
className,
|
|
18
|
+
...props
|
|
19
|
+
}: React.ComponentProps<typeof CommandPrimitive>) {
|
|
20
|
+
return (
|
|
21
|
+
<CommandPrimitive
|
|
22
|
+
data-slot="command"
|
|
23
|
+
className={cn(
|
|
24
|
+
'bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md',
|
|
25
|
+
className,
|
|
26
|
+
)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function CommandDialog({
|
|
33
|
+
title = 'Command Palette',
|
|
34
|
+
description = 'Search for a command to run...',
|
|
35
|
+
children,
|
|
36
|
+
className,
|
|
37
|
+
showCloseButton = true,
|
|
38
|
+
...props
|
|
39
|
+
}: React.ComponentProps<typeof Dialog> & {
|
|
40
|
+
title?: string
|
|
41
|
+
description?: string
|
|
42
|
+
className?: string
|
|
43
|
+
showCloseButton?: boolean
|
|
44
|
+
}) {
|
|
45
|
+
return (
|
|
46
|
+
<Dialog {...props}>
|
|
47
|
+
<DialogHeader className="sr-only">
|
|
48
|
+
<DialogTitle>{title}</DialogTitle>
|
|
49
|
+
<DialogDescription>{description}</DialogDescription>
|
|
50
|
+
</DialogHeader>
|
|
51
|
+
<DialogContent
|
|
52
|
+
className={cn('overflow-hidden p-0', className)}
|
|
53
|
+
showCloseButton={showCloseButton}
|
|
54
|
+
>
|
|
55
|
+
<Command className="[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
|
56
|
+
{children}
|
|
57
|
+
</Command>
|
|
58
|
+
</DialogContent>
|
|
59
|
+
</Dialog>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function CommandInput({
|
|
64
|
+
className,
|
|
65
|
+
...props
|
|
66
|
+
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
data-slot="command-input-wrapper"
|
|
70
|
+
className="flex h-9 items-center gap-2 border-b px-3"
|
|
71
|
+
>
|
|
72
|
+
<SearchIcon className="size-4 shrink-0 opacity-50" />
|
|
73
|
+
<CommandPrimitive.Input
|
|
74
|
+
data-slot="command-input"
|
|
75
|
+
className={cn(
|
|
76
|
+
'placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50',
|
|
77
|
+
className,
|
|
78
|
+
)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function CommandList({
|
|
86
|
+
className,
|
|
87
|
+
...props
|
|
88
|
+
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
|
89
|
+
return (
|
|
90
|
+
<CommandPrimitive.List
|
|
91
|
+
data-slot="command-list"
|
|
92
|
+
className={cn(
|
|
93
|
+
'max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto',
|
|
94
|
+
className,
|
|
95
|
+
)}
|
|
96
|
+
{...props}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function CommandEmpty({
|
|
102
|
+
...props
|
|
103
|
+
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
|
104
|
+
return (
|
|
105
|
+
<CommandPrimitive.Empty
|
|
106
|
+
data-slot="command-empty"
|
|
107
|
+
className="py-6 text-center text-sm"
|
|
108
|
+
{...props}
|
|
109
|
+
/>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function CommandGroup({
|
|
114
|
+
className,
|
|
115
|
+
...props
|
|
116
|
+
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
|
117
|
+
return (
|
|
118
|
+
<CommandPrimitive.Group
|
|
119
|
+
data-slot="command-group"
|
|
120
|
+
className={cn(
|
|
121
|
+
'text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium',
|
|
122
|
+
className,
|
|
123
|
+
)}
|
|
124
|
+
{...props}
|
|
125
|
+
/>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function CommandSeparator({
|
|
130
|
+
className,
|
|
131
|
+
...props
|
|
132
|
+
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
|
133
|
+
return (
|
|
134
|
+
<CommandPrimitive.Separator
|
|
135
|
+
data-slot="command-separator"
|
|
136
|
+
className={cn('bg-border -mx-1 h-px', className)}
|
|
137
|
+
{...props}
|
|
138
|
+
/>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function CommandItem({
|
|
143
|
+
className,
|
|
144
|
+
...props
|
|
145
|
+
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
|
146
|
+
return (
|
|
147
|
+
<CommandPrimitive.Item
|
|
148
|
+
data-slot="command-item"
|
|
149
|
+
className={cn(
|
|
150
|
+
"data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
151
|
+
className,
|
|
152
|
+
)}
|
|
153
|
+
{...props}
|
|
154
|
+
/>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function CommandShortcut({
|
|
159
|
+
className,
|
|
160
|
+
...props
|
|
161
|
+
}: React.ComponentProps<'span'>) {
|
|
162
|
+
return (
|
|
163
|
+
<span
|
|
164
|
+
data-slot="command-shortcut"
|
|
165
|
+
className={cn(
|
|
166
|
+
'text-muted-foreground ml-auto text-xs tracking-widest',
|
|
167
|
+
className,
|
|
168
|
+
)}
|
|
169
|
+
{...props}
|
|
170
|
+
/>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
Command,
|
|
176
|
+
CommandDialog,
|
|
177
|
+
CommandInput,
|
|
178
|
+
CommandList,
|
|
179
|
+
CommandEmpty,
|
|
180
|
+
CommandGroup,
|
|
181
|
+
CommandItem,
|
|
182
|
+
CommandShortcut,
|
|
183
|
+
CommandSeparator,
|
|
184
|
+
}
|