UNPKG

@codeworker.br/govbr-tw-react

Version:

Biblioteca de componentes React usando Tailwind CSS que implementa o Padrão Digital de Governo.

76 lines (75 loc) 3.67 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Avatar } from "../Avatar"; import { cn } from "../../libs/utils"; import BASE_CLASSNAMES from "../../config/baseClassNames"; const CATEGORY_PRESETS = { EX: { label: "Extinct", className: "bg-govbr-pure-100 text-red-500", }, EW: { label: "Extinct in the Wild", className: "bg-govbr-pure-100 text-govbr-pure-0", }, CR: { label: "Critically Endangered", className: "bg-red-600 text-red-200", }, EN: { label: "Endangered", className: "bg-orange-500 text-orange-200", }, VU: { label: "Vulnerable", className: "bg-yellow-400 text-yellow-200", }, NT: { label: "Near Threatened", className: "bg-emerald-700 text-emerald-200", }, LC: { label: "Least Concern", className: "bg-emerald-700 text-govbr-pure-0", }, DD: { label: "Data Deficient", className: "bg-neutral-400 text-neutral-600", }, NE: { label: "Not Evaluated", className: "bg-neutral-200 text-neutral-400", }, }; const isIucnCategoryCode = (value) => Object.prototype.hasOwnProperty.call(CATEGORY_PRESETS, value); const IucnCategory = (_a) => { var _b, _c, _d, _e; var { category, label, labels, showLabel = false, className, children, title, labelClassName, wrapperClassName } = _a, avatarProps = __rest(_a, ["category", "label", "labels", "showLabel", "className", "children", "title", "labelClassName", "wrapperClassName"]); const normalizedCategory = String(category).toUpperCase(); const resolvedCategory = isIucnCategoryCode(normalizedCategory) ? normalizedCategory : "NE"; const preset = CATEGORY_PRESETS[resolvedCategory]; const resolvedLabel = (_b = label !== null && label !== void 0 ? label : labels === null || labels === void 0 ? void 0 : labels[resolvedCategory]) !== null && _b !== void 0 ? _b : preset.label; const finalTitle = title !== null && title !== void 0 ? title : resolvedLabel; const content = children !== null && children !== void 0 ? children : resolvedCategory; const { ["aria-label"]: ariaLabel } = avatarProps, restAvatarProps = __rest(avatarProps, ["aria-label"]); const finalAriaLabel = ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : resolvedLabel; const avatarElement = (_jsx(Avatar, Object.assign({}, restAvatarProps, { className: cn(preset.className, (_c = BASE_CLASSNAMES.iucnCategory) === null || _c === void 0 ? void 0 : _c.root, className), title: finalTitle, "aria-label": finalAriaLabel, children: content }))); if (!showLabel) { return avatarElement; } return (_jsxs("span", { className: cn("inline-flex items-center gap-2", (_d = BASE_CLASSNAMES.iucnCategory) === null || _d === void 0 ? void 0 : _d.wrapper, wrapperClassName), children: [avatarElement, _jsx("span", { className: cn("text-xs text-govbr-gray-80", (_e = BASE_CLASSNAMES.iucnCategory) === null || _e === void 0 ? void 0 : _e.label, labelClassName), children: resolvedLabel })] })); }; export { IucnCategory }; export default IucnCategory;