UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

73 lines (66 loc) 2.36 kB
/** * Copyright IBM Corp. 2020, 2025 * * 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 { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import React__default from 'react'; import PropTypes from '../../_virtual/index.js'; import cx from 'classnames'; import { getDevtoolsProps } from '../../global/js/utils/devtools.js'; import { pkg } from '../../settings.js'; const blockClass = `${pkg.prefix}--delimited-list`; const componentName = 'DelimitedList'; const defaults = { delimiter: ', ', items: [], truncate: true }; /** * `DelimitedList` converts an array of items into a single line of * comma-separated values. */ let DelimitedList = /*#__PURE__*/React__default.forwardRef((_ref, ref) => { let { // The component props, in alphabetical order (for consistency). className, /* add other props for DelimitedList, with default values if needed */ delimiter = defaults.delimiter, items = defaults.items, truncate = defaults.truncate, // Collect any other property values passed in. ...rest } = _ref; return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, { className: cx(blockClass, className, [truncate && `${blockClass}-truncate`]), ref: ref }, getDevtoolsProps(componentName)), items.length > 0 ? items.join(delimiter) : '–'); }); // Return a placeholder if not released and not enabled by feature flag DelimitedList = pkg.checkComponentEnabled(DelimitedList, componentName); // The display name of the component, used by React. Note that displayName // is used in preference to relying on function.name. DelimitedList.displayName = componentName; // The types and DocGen commentary for the component props, // in alphabetical order (for consistency). // See https://www.npmjs.com/package/prop-types#usage. DelimitedList.propTypes = { /** * Provide an optional class to be applied to the containing node. */ className: PropTypes.string, /** * The character(s) used to separate the items. */ delimiter: PropTypes.string, /** * Array of items to be listed. */ items: PropTypes.arrayOf(PropTypes.any), /** * Toggle the component's ability to truncate or not. */ truncate: PropTypes.bool }; export { DelimitedList };