import * as React from 'react'; import { autobind } from '@shopify/javascript-utilities/decorators'; import { themr, ThemedComponentClass } from '@friendsofreactjs/react-css-themr'; import { classNames } from '@shopify/react-utilities/styles'; import { ACCORDION } from '../ThemeIdentifiers'; import * as baseTheme from './Accordion.scss'; import Icon from '../Icon'; export interface State { activeDelete?: boolean; deleteIconOnHover?: boolean } export interface Props { // Define accordion item is active or not active?: boolean; clickHandler?(event: React.FormEvent): void; // Click handler for children items childrenClickHandler?(event: React.FormEvent): void; // Item of accordion component to be displayed children: React.ReactElement; componentClass?: string; // Header of accordion item to be displayed header: React.ReactElement; index: number; style?: any; // Make accordion item active or inactive. toggle?(index: number): void; theme?: any; position?: string; icon?: string; isDelete?: boolean; activeDelete?: boolean; onDeleteClick?: any; rotate?: any; key?:any; } class AccordionItem extends React.PureComponent { deleteIconOnHover?: boolean; constructor(props: Props) { super(props); this.state = { activeDelete: false, deleteIconOnHover: false }; } handleClick = (event: React.FormEvent) => { if (this.props.clickHandler) { this.props.clickHandler(event); } } handleClickChildren = (event: React.FormEvent) => { if (this.props.childrenClickHandler) { this.props.childrenClickHandler(event); } } render() { const { activeDelete } = this.state; const { componentClass = '', header, active, style, theme, position = 'right', isDelete, icon = 'chevronDown', onDeleteClick, children, rotate, key, } = this.props; const containerClass = classNames( componentClass, theme.accordionItem ); const headerClass = classNames( theme.header, active && theme.active ); return ( //
//
this.setState({ activeDelete : true })} onMouseLeave ={()=> this.setState({ activeDelete : false })}> // {header} // {position === 'left' ? : } // {/* {position === 'right' ? : null} */} // {isDelete && activeDelete &&
delete
} //
//
// {active && children} //
//
{position === 'right' ?
{header}
:
this.setState({ activeDelete: true })} onMouseLeave={() => this.setState({ activeDelete: false })}>
{header}
{isDelete && activeDelete &&
this.setState({ deleteIconOnHover: true })} onMouseLeave={() => this.setState({ deleteIconOnHover: false })} > onDeleteClick(key)}/>
}
}
{active && children}
); } @autobind private clickHandler(event: any) { if (typeof this.props.toggle !== 'undefined') { this.props.toggle(this.props.index); } this.handleClick(event); } } export default themr(ACCORDION, baseTheme)(AccordionItem) as ThemedComponentClass;