@carbon/ibm-products
Version:
Carbon for IBM Products
73 lines (66 loc) • 2.44 kB
JavaScript
/**
* 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.
*/
;
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var index = require('../../_virtual/index.js');
var cx = require('classnames');
var devtools = require('../../global/js/utils/devtools.js');
var settings = require('../../settings.js');
const blockClass = `${settings.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.
*/
exports.DelimitedList = /*#__PURE__*/React.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.createElement("div", _rollupPluginBabelHelpers.extends({}, rest, {
className: cx(blockClass, className, [truncate && `${blockClass}-truncate`]),
ref: ref
}, devtools.getDevtoolsProps(componentName)), items.length > 0 ? items.join(delimiter) : '–');
});
// Return a placeholder if not released and not enabled by feature flag
exports.DelimitedList = settings.pkg.checkComponentEnabled(exports.DelimitedList, componentName);
// The display name of the component, used by React. Note that displayName
// is used in preference to relying on function.name.
exports.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.
exports.DelimitedList.propTypes = {
/**
* Provide an optional class to be applied to the containing node.
*/
className: index.default.string,
/**
* The character(s) used to separate the items.
*/
delimiter: index.default.string,
/**
* Array of items to be listed.
*/
items: index.default.arrayOf(index.default.any),
/**
* Toggle the component's ability to truncate or not.
*/
truncate: index.default.bool
};