260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋
This commit is contained in:
62
src/components/gwcf/StatusPill.tsx
Normal file
62
src/components/gwcf/StatusPill.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
"use client";
|
||||
|
||||
import {MouseEvent, ReactNode} from "react";
|
||||
import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from "@/components/ui/tooltip";
|
||||
import {cn} from "@/lib/utils";
|
||||
|
||||
export type StatusPillVariant = "default" | "danger" | "pending" | "inprogress" | "departed" | "arrived" | "done";
|
||||
|
||||
const variantClassName: Record<StatusPillVariant, string> = {
|
||||
default: "border-primary/30 bg-primary/10 text-primary",
|
||||
danger: "gwcf-status-badge--danger",
|
||||
pending: "gwcf-status-badge--pending",
|
||||
inprogress: "gwcf-status-badge--inprogress",
|
||||
departed: "gwcf-status-badge--departed",
|
||||
arrived: "gwcf-status-badge--arrived",
|
||||
done: "gwcf-status-badge--done",
|
||||
};
|
||||
|
||||
export function StatusPill({
|
||||
children,
|
||||
onClick,
|
||||
variant = "default",
|
||||
tooltip,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
onClick?: () => void;
|
||||
variant?: StatusPillVariant;
|
||||
tooltip?: ReactNode;
|
||||
}) {
|
||||
const className = cn(
|
||||
"inline-flex min-w-14 items-center justify-center rounded-full border px-2 py-1 text-xs font-semibold",
|
||||
variant !== "default" && "gwcf-status-badge",
|
||||
variantClassName[variant],
|
||||
onClick && "cursor-pointer hover:opacity-80"
|
||||
);
|
||||
|
||||
const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
|
||||
event.stopPropagation();
|
||||
onClick?.();
|
||||
};
|
||||
|
||||
const pill = onClick ? (
|
||||
<button type="button" className={className} onClick={handleClick}>
|
||||
{children || "-"}
|
||||
</button>
|
||||
) : (
|
||||
<span className={className}>
|
||||
{children || "-"}
|
||||
</span>
|
||||
);
|
||||
|
||||
if (!tooltip) return pill;
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{pill}</TooltipTrigger>
|
||||
<TooltipContent sideOffset={6}>{tooltip}</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user