import { NavigationClose } from '@repay/cactus-icons' import { color, colorStyle, lineHeight, radius, space, textStyle } from '@repay/cactus-theme' import PropTypes from 'prop-types' import React from 'react' import styled from 'styled-components' import { margin, MarginProps } from 'styled-system' import { getOmittableProps } from '../helpers/omit' import { IconButton } from '../IconButton/IconButton' const closeTypes = ['no-button', 'button'] as const interface TagProps extends MarginProps, React.HTMLAttributes { closeOption?: boolean | typeof closeTypes[number] children: React.ReactNode onCloseIconClick?: React.MouseEventHandler } const TagBase = React.forwardRef( ({ closeOption, children, onCloseIconClick, ...props }, ref): React.ReactElement => { return ( {children} {(!!closeOption || typeof onCloseIconClick === 'function') && ( )} ) } ) const styleProps = getOmittableProps(margin) export const Tag = styled(TagBase).withConfig({ shouldForwardProp: (p) => !styleProps.has(p), })` ${colorStyle('standard')}; box-sizing: border-box; ${textStyle('small')}; padding: 0 ${space(3)}; border: 1px solid ${color('lightContrast')}; border-radius: ${radius(8)}; margin-right: ${space(1)}; display: inline-block; ${(p) => p.hidden && 'visibility: hidden;'} ${lineHeight('small', 'height')}; ${IconButton} { padding: 4px; } ${margin} ` Tag.propTypes = { id: PropTypes.string, closeOption: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(closeTypes)]), children: PropTypes.node.isRequired, hidden: PropTypes.bool, onCloseIconClick: PropTypes.func, } Tag.defaultProps = { closeOption: false, hidden: false, } export default Tag