@kopexa/chip
Version:
A Chip is a small block of essential information that represent an input, attribute, or action.
131 lines (129 loc) • 4.12 kB
JavaScript
"use client";
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/chip.tsx
var chip_exports = {};
__export(chip_exports, {
Chip: () => Chip
});
module.exports = __toCommonJS(chip_exports);
var import_icons = require("@kopexa/icons");
var import_shared_utils = require("@kopexa/shared-utils");
var import_theme = require("@kopexa/theme");
var import_react = require("react");
var import_jsx_runtime = require("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 = (0, import_theme.chip)({
size,
radius,
variant,
disabled,
color,
indicator,
indicatorColor,
indicatorVariant,
isCloseable,
className
});
const start = (0, import_react.useMemo)(() => {
if (indicator) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.indicator({ class: classNames == null ? void 0 : classNames.indicator }), children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"span",
{
className: styles.indicatorPulse({
class: classNames == null ? void 0 : classNames.indicatorPulse
})
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"span",
{
className: styles.indicatorDot({
class: classNames == null ? void 0 : classNames.indicatorDot
})
}
)
] });
}
return startContent;
}, [startContent, indicator, styles, classNames]);
const end = (0, import_react.useMemo)(() => {
if (isCloseable) {
return (
// biome-ignore lint/a11y/useSemanticElements: we use a span here
/* @__PURE__ */ (0, import_jsx_runtime.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__ */ (0, import_jsx_runtime.jsx)(import_icons.CloseIcon, {})
}
)
);
}
return endContent;
}, [endContent, isCloseable, styles, classNames, onClose]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"div",
{
className: styles.root({
className: (0, import_shared_utils.cn)(classNames == null ? void 0 : classNames.root, className)
}),
...rest,
children: [
start,
status && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: styles.status({ class: classNames == null ? void 0 : classNames.status }), children: status }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: styles.content({ class: classNames == null ? void 0 : classNames.content }), children }),
end
]
}
);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Chip
});