import classNames from 'clsx';
import * as React from 'react';
import { v4 as uuidv4 } from 'uuid';
import { SelectDropdown } from '../features/forms';
import Icon from './icon';
import { Select } from './ui';
const List: React.FC = ({ children }) => (
{children}
);
interface IListItem {
label: React.ReactNode,
hint?: React.ReactNode,
onClick?: () => void,
}
const ListItem: React.FC = ({ 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(() => {
return React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
const isSelect = child.type === SelectDropdown || child.type === Select;
return React.cloneElement(child, {
id: domId,
className: classNames({
'w-auto': isSelect,
}, child.props.className),
});
}
return null;
});
}, [children, domId]);
return (
{label}
{hint ? (
{hint}
) : null}
{onClick ? (
{children}
) : renderChildren()}
);
};
export { List as default, ListItem };