@carbon/ibm-products
Version:
Carbon for IBM Products
77 lines (75 loc) • 3.06 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 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.
*/
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../../node_modules/classnames/index.js");
const require_settings = require("../../settings.js");
const require_devtools = require("../../global/js/utils/devtools.js");
const require_uuidv4 = require("../../global/js/utils/uuidv4.js");
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react_icons = require("@carbon/react/icons");
//#region src/components/NonLinearReading/NonLinearReading.tsx
/**
* Copyright IBM Corp. 2023, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const blockClass = `${require_settings.pkg.prefix}--non-linear-reading`;
const componentName = "NonLinearReading";
/**
* Use non-linear reading when space is limited to share a
* brief, at-a-glance, summary of a concept that may require
* more explanation for some users.
*/
const NonLinearReading = react.default.forwardRef(({ children, className, definition, theme = "light", ...rest }, ref) => {
const [isOpen, setOpen] = (0, react.useState)(false);
const contentId = (0, react.useRef)(require_uuidv4.default()).current;
const handleToggle = () => {
setOpen((prevState) => !prevState);
};
return /* @__PURE__ */ react.default.createElement("span", {
...rest,
className: (0, import_classnames.default)(blockClass, `${blockClass}__${theme}`, className),
ref,
...require_devtools.getDevtoolsProps(componentName)
}, " ", /* @__PURE__ */ react.default.createElement("button", {
type: "button",
"aria-controls": contentId,
"aria-expanded": isOpen,
className: (0, import_classnames.default)(`${blockClass}__keyword`, [isOpen ? [`${blockClass}__keyword-open`] : [`${blockClass}__keyword-closed`]]),
onClick: handleToggle
}, children, /* @__PURE__ */ react.default.createElement(_carbon_react_icons.ChevronDown, { size: 16 })), " ", /* @__PURE__ */ react.default.createElement("span", {
id: contentId,
className: `${blockClass}__body`,
hidden: !isOpen
}, isOpen && definition), " ");
});
NonLinearReading.displayName = componentName;
NonLinearReading.propTypes = {
/**
* The keyword of the component appears as a pill.
*/
children: prop_types.default.node.isRequired,
/**
* Provide an optional class to be applied to the containing node.
*/
className: prop_types.default.string,
/**
* The content that appears when the keyword is toggled open.
*/
definition: prop_types.default.node.isRequired,
/**
* Determines the theme of the component.
*/
theme: prop_types.default.oneOf(["light", "dark"])
};
//#endregion
exports.NonLinearReading = NonLinearReading;