UNPKG

@stratakit/react

Version:

A React component library for StrataKit

48 lines (47 loc) 1.5 kB
import { jsx, jsxs } from "react/jsx-runtime"; import * as React from "react"; import { useEventHandlers } from "@stratakit/foundations/secret-internals"; import * as Chip from "@stratakit/structures/Chip"; import { useCompatProps } from "./~utils.js"; const Tag = React.forwardRef((props, forwardedRef) => { const { onClick, children, onRemove, removeButtonProps, // biome-ignore lint/correctness/noUnusedVariables: NOT IMPLEMENTED variant, labelProps, ...rest } = useCompatProps(props); const onDismissClick = useEventHandlers(removeButtonProps?.onClick, onRemove); const onLabelClick = useEventHandlers(labelProps?.onClick, onClick); if (onRemove) { return /* @__PURE__ */ jsxs(Chip.Root, { render: /* @__PURE__ */ jsx("span", {}), ...rest, ref: forwardedRef, children: [ /* @__PURE__ */ jsx( Chip.Label, { render: onClick ? /* @__PURE__ */ jsx("button", {}) : void 0, ...labelProps, onClick: onLabelClick, children } ), /* @__PURE__ */ jsx(Chip.DismissButton, { ...removeButtonProps, onClick: onDismissClick }) ] }); } return /* @__PURE__ */ jsx( Chip.Root, { render: onClick ? /* @__PURE__ */ jsx("button", {}) : /* @__PURE__ */ jsx("span", {}), ...rest, onClick, ref: forwardedRef, children: /* @__PURE__ */ jsx(Chip.Label, { ...labelProps, children }) } ); }); DEV: Tag.displayName = "Tag"; export { Tag };