import React, { FC, HTMLAttributes, ReactNode, useCallback, MouseEvent } from 'react'; import { classNames } from '../../lib/classNames'; import { Icon16Cancel } from '@vkontakte/icons'; import { getTitleFromChildren, hasReactNode, noop } from '../../lib/utils'; import Caption from '../Typography/Caption/Caption'; type ChipValue = string | number; export interface ChipProps extends HTMLAttributes { value: ChipValue; onRemove?: (event?: MouseEvent, value?: ChipValue) => void; removable?: boolean; before?: ReactNode; after?: ReactNode; } const Chip: FC = (props: ChipProps) => { const { value, onRemove, removable, className, before, after, children, ...restProps } = props; const onRemoveWrapper = useCallback((event: MouseEvent) => { onRemove(event, value); }, [onRemove, value]); const title = getTitleFromChildren(children); return (
{hasReactNode(before) &&
{before}
} {children} {hasReactNode(after) &&
{after}
} {removable &&
}
); }; Chip.defaultProps = { removable: true, before: null, value: '', onRemove: noop, }; export default Chip;