import { mdiClose } from '@mdi/js'; import classnames from 'classnames'; import { Component, ReactNode } from 'react'; import injectStyle, { WithStylesProps } from 'react-jss'; import { Theme } from '../../../themes'; import Icon from '../icon'; interface IProps extends WithStylesProps { icon?: string; type?: string; dismissable?: boolean; onDismiss?: () => void; onUnmount?: () => void; ctaOnClick?: () => void; ctaLabel?: string; children: ReactNode; className: string; } interface IState { isDismissing: boolean; dismissed: boolean; } const buttonStyles = (theme: Theme) => { const styles = {}; Object.keys(theme.styleTypes).map(style => { Object.assign(styles, { [style]: { background: theme.styleTypes[style].accent, color: theme.styleTypes[style].contrast, border: theme.styleTypes[style].border, '& svg': { fill: theme.styleTypes[style].contrast, }, }, }); }); return styles; }; const infoBoxTransition: string = 'none'; const ctaTransition: string = 'none'; // TODO: Not sure why, but this location alone, the `dinwo` is not defined - and it throws an error thus aborting the startup sequence of ferdium // if (window && window.matchMedia('(prefers-reduced-motion: no-preference)')) { // infoBoxTransition = 'all 0.5s'; // ctaTransition = 'opacity 0.3s'; // } const styles = (theme: Theme) => ({ wrapper: { position: 'relative', overflow: 'hidden', height: 'auto', }, infobox: { alignItems: 'center', borderRadius: theme.borderRadiusSmall, display: 'flex', height: 'auto', padding: '15px 20px', top: 0, transition: infoBoxTransition, opacity: 1, marginBottom: 30, }, dismissing: { // position: 'absolute', marginTop: -100, opacity: 0, }, content: { flex: 1, }, icon: { marginRight: 10, }, close: { color: (props: IProps) => theme.styleTypes[props.type || 'primary'].contrast, marginRight: -5, border: 0, background: 'none', }, cta: { borderColor: (props: IProps) => theme.styleTypes[props.type || 'primary'].contrast, borderRadius: theme.borderRadiusSmall, borderStyle: 'solid', borderWidth: 1, background: 'none', color: (props: IProps) => theme.styleTypes[props.type || 'primary'].contrast, marginLeft: 15, padding: [4, 10], fontSize: theme.uiFontSize, transition: ctaTransition, '&:hover': { opacity: 0.6, }, }, ...buttonStyles(theme), }); class InfoboxComponent extends Component { public static defaultProps = { type: 'primary', dismissable: false, ctaOnClick: () => {}, onDismiss: () => {}, ctaLabel: '', }; state = { isDismissing: false, dismissed: false, }; dismiss() { const { onDismiss } = this.props; this.setState({ isDismissing: true, }); if (onDismiss) { onDismiss(); } setTimeout(() => { this.setState({ dismissed: true, }); }, 3000); } componentWillUnmount(): void { const { onUnmount } = this.props; if (onUnmount) onUnmount(); } render() { const { classes, children, icon, type, ctaLabel, ctaOnClick, dismissable, className, } = this.props; const { isDismissing, dismissed } = this.state; if (dismissed) { return null; } return (
{icon && }
{children}
{ctaLabel && ( )} {dismissable && ( )}
); } } export default injectStyle(styles, { injectTheme: true })( InfoboxComponent, );