Created
March 10, 2020 13:01
-
-
Save petrjasek/0512a7ad54e2173d6af016810f721832 to your computer and use it in GitHub Desktop.
Revisions
-
petrjasek created this gist
Mar 10, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,76 @@ export class Alert extends React.PureComponent<IProps, IState> { constructor(props: IProps) { super(props); this.state = { open: true, }; this.onToggle = this.onToggle.bind(this); } onToggle() { this.setState((state) => ({ open: !state.open, })); } render() { let classesAlert = classNames('sd-alert', { 'sd-alert--hollow': this.props.style === 'hollow', 'sd-alert--small': this.props.size === 'small', [`sd-alert--${this.props.type}`]: this.props.type, 'sd-alert--hidden': !this.state.open, }); let classesInfoBtn = classNames('sd-alert__info-btn sd-shadow--z2', { [`sd-alert__info-btn--${this.props.type}`]: this.props.type, 'sd-alert__info-btn--hidden': this.state.open, }); return ( <div className='sd-alert__container'> <div className={classesAlert}> {this.props.restoreIcon ? <button className='sd-alert__close' onClick={this.onToggle} ></button> : null} {this.props.children} </div> {this.props.restoreIcon ? <span className={classesInfoBtn} onClick={this.onToggle}> <i className={this.props.restoreIcon === 'help' ? 'icon-help-large' : 'icon-info-large'}></i> </span> : null } </div> ); } } // vs export function Alert () { const [open, setOpen] = useState(true); const toggle = () => setOpen(!open); let classesAlert = classNames('sd-alert', { 'sd-alert--hollow': this.props.style === 'hollow', 'sd-alert--small': this.props.size === 'small', [`sd-alert--${this.props.type}`]: this.props.type, 'sd-alert--hidden': !open, }); let classesInfoBtn = classNames('sd-alert__info-btn sd-shadow--z2', { [`sd-alert__info-btn--${this.props.type}`]: this.props.type, 'sd-alert__info-btn--hidden': open, }); return ( <div className='sd-alert__container'> <div className={classesAlert}> {this.props.restoreIcon ? <button className='sd-alert__close' onClick={toggle} ></button> : null} {this.props.children} </div> {this.props.restoreIcon ? <span className={classesInfoBtn} onClick={toggle}> <i className={this.props.restoreIcon === 'help' ? 'icon-help-large' : 'icon-info-large'}></i> </span> : null } </div> ); }