UNPKG

@kopexa/chip

Version:

A Chip is a small block of essential information that represent an input, attribute, or action.

110 lines (107 loc) 2.8 kB
"use client"; // src/chip.tsx import { CloseIcon } from "@kopexa/icons"; import { cn } from "@kopexa/shared-utils"; import { chip } from "@kopexa/theme"; import { useMemo } from "react"; import { jsx, jsxs } from "react/jsx-runtime"; var Chip = (props) => { const { className, children, startContent, endContent, classNames, size, disabled, radius, variant, color, indicator, indicatorColor, indicatorVariant, status, isCloseable, onClose, ...rest } = props; const styles = chip({ size, radius, variant, disabled, color, indicator, indicatorColor, indicatorVariant, isCloseable, className }); const start = useMemo(() => { if (indicator) { return /* @__PURE__ */ jsxs("div", { className: styles.indicator({ class: classNames == null ? void 0 : classNames.indicator }), children: [ /* @__PURE__ */ jsx( "span", { className: styles.indicatorPulse({ class: classNames == null ? void 0 : classNames.indicatorPulse }) } ), /* @__PURE__ */ jsx( "span", { className: styles.indicatorDot({ class: classNames == null ? void 0 : classNames.indicatorDot }) } ) ] }); } return startContent; }, [startContent, indicator, styles, classNames]); const end = useMemo(() => { if (isCloseable) { return ( // biome-ignore lint/a11y/useSemanticElements: we use a span here /* @__PURE__ */ jsx( "span", { role: "button", tabIndex: 0, "aria-label": "Close", className: styles.closeButton({ class: classNames == null ? void 0 : classNames.closeButton }), onClick: onClose, onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ") { onClose == null ? void 0 : onClose(); } }, children: endContent || /* @__PURE__ */ jsx(CloseIcon, {}) } ) ); } return endContent; }, [endContent, isCloseable, styles, classNames, onClose]); return /* @__PURE__ */ jsxs( "div", { className: styles.root({ className: cn(classNames == null ? void 0 : classNames.root, className) }), ...rest, children: [ start, status && /* @__PURE__ */ jsx("span", { className: styles.status({ class: classNames == null ? void 0 : classNames.status }), children: status }), /* @__PURE__ */ jsx("span", { className: styles.content({ class: classNames == null ? void 0 : classNames.content }), children }), end ] } ); }; export { Chip };