UNPKG

@carbon/react

Version:

React components for the Carbon Design System

59 lines (57 loc) 2.09 kB
/** * Copyright IBM Corp. 2016, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { usePrefix } from "../../../internal/usePrefix.js"; import { LayoutConstraint } from "../../Layout/index.js"; import classNames from "classnames"; import "react"; import PropTypes from "prop-types"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; //#region src/components/ContainedList/ContainedListItem/ContainedListItem.tsx const ContainedListItem = ({ action, children, className, disabled = false, onClick, renderIcon: IconElement, ...rest }) => { const prefix = usePrefix(); const isClickable = onClick !== void 0; const classes = classNames(`${prefix}--contained-list-item`, className, { [`${prefix}--contained-list-item--clickable`]: isClickable, [`${prefix}--contained-list-item--with-icon`]: IconElement, [`${prefix}--contained-list-item--with-action`]: action }); const content = /* @__PURE__ */ jsxs(Fragment, { children: [IconElement && /* @__PURE__ */ jsx("div", { className: `${prefix}--contained-list-item__icon`, children: /* @__PURE__ */ jsx(IconElement, {}) }), /* @__PURE__ */ jsx("div", { children })] }); return /* @__PURE__ */ jsxs("li", { className: classes, ...rest, children: [isClickable ? /* @__PURE__ */ jsx("button", { className: `${prefix}--contained-list-item__content`, type: "button", disabled, onClick, children: content }) : /* @__PURE__ */ jsx("div", { className: `${prefix}--contained-list-item__content`, children: content }), action && /* @__PURE__ */ jsx(LayoutConstraint, { size: { min: "sm", max: "lg" }, className: `${prefix}--contained-list-item__action`, children: action })] }); }; ContainedListItem.propTypes = { action: PropTypes.node, children: PropTypes.node, className: PropTypes.string, disabled: PropTypes.bool, onClick: PropTypes.func, renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) }; //#endregion export { ContainedListItem as default };