Files
HiveGrid-Wireframes/hivegrid-cloud/apps/web/app/components/entities/rows/cells/RowBooleanCell.tsx
T

45 lines
1.6 KiB
TypeScript

import { TFunction, t as i18nT } from "i18next";
import { useTranslation } from "react-i18next";
import { Colors } from "~/application/enums/shared/Colors";
import SimpleBadge from "~/components/ui/badges/SimpleBadge";
import CheckIcon from "~/components/ui/icons/CheckIcon";
import XIcon from "~/components/ui/icons/XIcon";
import { BooleanFormatType } from "~/utils/shared/BooleanUtils";
export function getBooleanAsStringValue({ value, format, t }: { value?: boolean; format?: BooleanFormatType; t?: TFunction }) {
const translate = t ?? i18nT;
return !format || format === "yesNo"
? value
? translate("shared.yes")
: translate("shared.no")
: format === "trueFalse"
? value
? translate("shared.true")
: translate("shared.false")
: format === "enabledDisabled"
? value
? translate("shared.enabled")
: translate("shared.disabled")
: format === "onOff"
? value
? translate("shared.on")
: translate("shared.off")
: format === "activeInactive"
? value
? translate("shared.active")
: translate("shared.inactive")
: "";
}
export default function RowBooleanCell({ value, format }: { value?: boolean; format?: BooleanFormatType }) {
const { t } = useTranslation();
return (
<>
{!format ? (
<div>{value ? <CheckIcon className="h-4 w-4 text-teal-500" /> : <XIcon className="text-muted-foreground h-4 w-4" />}</div>
) : (
<SimpleBadge title={getBooleanAsStringValue({ value, format, t })} color={value ? Colors.GREEN : Colors.GRAY} />
)}
</>
);
}