import * as React from 'react'; import { themr, ThemedComponentClass } from '@friendsofreactjs/react-css-themr'; import { classNames } from '@shopify/react-utilities/styles'; import { CHIP } from '../ThemeIdentifiers'; import * as baseTheme from './Chip.scss'; import Icon, { IconList } from '../Icon'; import Button from '../Button'; export interface Props { // Makes the chips body area clickable. clickable?: boolean; // Enables the deletion of chips through the remove icon or the Delete/Backspace key. removable?: boolean; // The image url and alt tag that will be shown in the chip. image?: { url: string, alt?: string, }; // Make the chip transparent. transparent?: boolean; // Theme to be injected via css-themr theme?: any; // Fired when remove button on chip is clicked. onRemove?(event: React.FormEvent): void; // Makes the chips body area clickable. onClick?(event: React.FormEvent): void; // The content to display inside chip. children?: string | React.ReactNode; // Icon replace default cancel icon icon?: keyof typeof IconList; // Icon click handler onIconClick?(): void; label?: string; outlined?: boolean } export interface State { iconHover: boolean; } class Chip extends React.PureComponent { constructor(props: Props) { super(props); this.state = { iconHover:false }; } onKeyDown = (item: React.FormEvent, e: KeyboardEvent) => { if (e.keyCode === 8 || e.keyCode === 46) { return this.props.onRemove ? this.props.onRemove(item) : null; } } render() { const { clickable = false, removable = false, image, transparent = false, theme, onRemove, onClick, children, label, outlined, } = this.props; const className = classNames( theme.Chip, outlined && theme.outlinedChip, transparent && theme.transparent); const firstIconComponent = ( image && image.url ? (typeof image.url === 'object' ? : {image.alt} ) : '' ); const chipTextComponent = ( this.setState({iconHover:true})} style={{paddingRight: !removable? 0 : 9}} className={theme.chipContent} key="2"> {(firstIconComponent || label) && } {children && this.setState({iconHover:false})} onMouseLeave={()=>this.setState({iconHover:true})} className={removable ? theme.ChipChildSpace : theme.ChipChild}>{children} } {removable && this.setState({iconHover:false})} onMouseLeave={()=>this.setState({iconHover:true})}> } ); // const isRemovable = removable && // ( // ); return (
{chipTextComponent} {/* {isRemovable} */}
); } } export default themr(CHIP, baseTheme)(Chip) as ThemedComponentClass;