export class Alert extends React.PureComponent { 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 (
{this.props.restoreIcon ? : null} {this.props.children}
{this.props.restoreIcon ? : null }
); } } // 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 (
{this.props.restoreIcon ? : null} {this.props.children}
{this.props.restoreIcon ? : null }
); }