import classNames from 'classnames';
import PropTypes from 'prop-types';
import * as React from 'react';
import { v4 as uuidv4 } from 'uuid';
import Icon from './icon';
const List = ({ children }) => (
{children}
);
List.propTypes = {
children: PropTypes.node,
};
const ListItem = ({ label, hint, children, onClick }) => {
const id = uuidv4();
const domId = `list-group-${id}`;
const Comp = onClick ? 'a' : 'div';
const LabelComp = onClick ? 'span' : 'label';
const linkProps = onClick ? { onClick } : {};
const renderChildren = React.useCallback(() =>
React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
return React.cloneElement(child, {
id: domId,
});
}
return null;
})
, [children, domId]);
return (
{label}
{hint ? (
{hint}
) : null}
{onClick ? (
{children}
) : renderChildren()}
);
};
ListItem.propTypes = {
label: PropTypes.node.isRequired,
hint: PropTypes.node,
children: PropTypes.node,
onClick: PropTypes.func,
};
export { List as default, ListItem };