UNPKG

@vectara/vectara-ui

Version:

Vectara's design system, codified as a React and Sass component library

42 lines (41 loc) 2.86 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 { cloneElement } from "react"; import { BiCheck } from "react-icons/bi"; import classNames from "classnames"; import { VuiFlexContainer } from "../flex/FlexContainer"; import { VuiFlexItem } from "../flex/FlexItem"; import { VuiIcon } from "../icon/Icon"; import { useVuiContext } from "../context/Context"; export const colorIcon = (icon, color) => { return icon ? cloneElement(icon, { color, size: "s" }) : null; }; // https://github.com/typescript-eslint/typescript-eslint/issues/4062 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint export const VuiOptionsListItem = (_a) => { var { value, label, icon, color = "neutral", href, target, onClick, isSelectable, isSelected, testId } = _a, rest = __rest(_a, ["value", "label", "icon", "color", "href", "target", "onClick", "isSelectable", "isSelected", "testId"]); const { createLink } = useVuiContext(); const labelContent = icon ? (_jsxs(VuiFlexContainer, Object.assign({ alignItems: "center", spacing: "xs" }, { children: [_jsx(VuiFlexItem, Object.assign({ grow: false, shrink: false }, { children: colorIcon(icon, color) })), _jsx(VuiFlexItem, Object.assign({ grow: 1 }, { children: label }))] }))) : (label); const content = (_jsxs(VuiFlexContainer, Object.assign({ alignItems: "center", spacing: "xs" }, { children: [isSelectable && (_jsx(VuiFlexItem, Object.assign({ grow: false }, { children: _jsx(VuiIcon, Object.assign({ className: isSelected ? "" : "vuiOptionsListItem__selected--unselected", color: "subdued", size: "s" }, { children: _jsx(BiCheck, {}) })) }))), _jsx(VuiFlexItem, Object.assign({ grow: false }, { children: labelContent }))] }))); const classes = classNames("vuiOptionsListItem", `vuiOptionsListItem--${color}`); if (href) { return createLink(Object.assign({ className: classes, href, target, onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick(value), "data-testid": testId, children: content, role: "menuitem" }, rest)); } return (_jsx("button", Object.assign({ className: classes, onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick(value), "data-testid": testId, type: "button" }, rest, { role: "menuitem" }, { children: content }))); };