import { Meter as KMeter } from "@kobalte/core/meter"; import { splitProps, type ComponentProps } from "solid-js"; import { tv, type VariantProps } from "tailwind-variants"; // TODO 1. 格式 const meterStyles = tv( { slots: { root: "flex flex-col gap-2 w-full antialiased", labelContainer: "flex justify-between items-center text-sm font-medium text-main", track: "h-2.5 w-full rounded-full bg-foreground overflow-hidden", fill: "h-full transition-all duration-500 ease-out rounded-full", }, variants: { color: { primary: { fill: "bg-primary" }, success: { fill: "bg-success" }, warning: { fill: "bg-warning" }, danger: { fill: "bg-danger" }, }, }, defaultVariants: { color: "primary", }, }, { twMerge: true, }, ); type MeterVariants = VariantProps; export const Meter = Object.assign( (props: ComponentProps & MeterVariants) => { const [local, variantProps, others] = splitProps( props, ["class"], ["color"] ); const s = () => meterStyles({ color: variantProps.color }); return ( {others.children} ); }, { Label: (props: ComponentProps) => { const [local, others] = splitProps(props, ["class"]); return ( ); }, ValueLabel: (props: ComponentProps) => { const [local, others] = splitProps(props, ["class"]); return ( ); }, Track: (props: ComponentProps) => { const [local, others] = splitProps(props, ["class"]); return ( ); }, Fill: (props: ComponentProps) => { const [local, others] = splitProps(props, ["class"]); // 注意:Fill 不需要手动设置宽度,Kobalte 会通过 style 注入百分比 return ( ); }, } );