From 9a5b313ea12bdb9dc3e3873ca3a2639bd7483e46 Mon Sep 17 00:00:00 2001
From: Stefan Malzner <stefan@adlk.io>
Date: Mon, 28 Jan 2019 11:35:25 +0100
Subject: Update packages

---
 packages/ui/src/infobox/index.tsx | 194 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 194 insertions(+)
 create mode 100644 packages/ui/src/infobox/index.tsx

(limited to 'packages/ui/src/infobox/index.tsx')

diff --git a/packages/ui/src/infobox/index.tsx b/packages/ui/src/infobox/index.tsx
new file mode 100644
index 000000000..bf985ea9c
--- /dev/null
+++ b/packages/ui/src/infobox/index.tsx
@@ -0,0 +1,194 @@
+import { Theme } from '@meetfranz/theme';
+import classnames from 'classnames';
+import { observer } from 'mobx-react';
+import React, { Component } from 'react';
+import injectStyle from 'react-jss';
+// import Loader from 'react-loader';
+
+import { Icon } from '../';
+import { IWithStyle } from '../typings/generic';
+
+interface IProps extends IWithStyle {
+  icon?: string;
+  type?: string;
+  dismissable?: boolean;
+  onDismiss?: () => void;
+  ctaOnClick?: () => void;
+  ctaLabel?: string;
+  ctaLoading?: boolean;
+  children: React.ReactNode;
+}
+
+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 styles = (theme: Theme) => ({
+  wrapper: {
+    position: 'relative',
+    overflow: 'hidden',
+  },
+  infobox: {
+    alignItems: 'center',
+    borderRadius: theme.borderRadiusSmall,
+    display: 'flex',
+    height: 'auto',
+    marginBottom: 30,
+    padding: '15px 20px',
+    top: 0,
+    transition: 'all 0.5s',
+    opacity: 1,
+  },
+  dismissing: {
+    // position: 'absolute',
+    marginTop: -100,
+    opacity: 0,
+  },
+  content: {
+    flex: 1,
+  },
+  icon: {
+    marginRight: 10,
+  },
+  close: {
+    color: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast,
+    marginRight: -5,
+    border: 0,
+    background: 'none',
+  },
+  cta: {
+    borderColor: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast,
+    borderRadius: theme.borderRadiusSmall,
+    borderStyle: 'solid',
+    borderWidth: 1,
+    background: 'none',
+    color: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast,
+    marginLeft: 15,
+    padding: [4, 10],
+    fontSize: theme.uiFontSize,
+    transition: 'opacity 0.3s',
+
+    '&:hover': {
+      opacity: 0.6,
+    },
+  },
+  ...buttonStyles(theme),
+});
+
+@observer
+class InfoboxComponent extends Component<IProps, IState> {
+  public static defaultProps = {
+    type: 'primary',
+    dismissable: false,
+    ctaOnClick: () => {},
+    onDismiss: () => {},
+    ctaLabel: '',
+    ctaLoading: false,
+  };
+
+  state = {
+    isDismissing: false,
+    dismissed: false,
+  };
+
+  dismiss() {
+    const {
+      onDismiss,
+    } = this.props;
+
+    this.setState({
+      isDismissing: true,
+    });
+
+    if (onDismiss) {
+      onDismiss();
+    }
+
+    setTimeout(() => {
+      this.setState({
+        dismissed: true,
+      });
+    },         3000);
+  }
+
+  render() {
+    const {
+      classes,
+      children,
+      icon,
+      type,
+      ctaLabel,
+      ctaLoading,
+      ctaOnClick,
+      dismissable,
+    } = this.props;
+
+    const {
+      isDismissing,
+      dismissed,
+    } = this.state;
+
+    if (dismissed) {
+      return null;
+    }
+
+    return (
+      <div className={classes.wrapper}>
+        <div
+          className={classnames({
+            [classes.infobox]: true,
+            [classes[`${type}`]]: type,
+            [classes.dismissing]: isDismissing,
+          })}
+        >
+          {icon && (
+            <Icon icon={icon} className={classes.icon} />
+          )}
+          <div className={classes.content}>
+            {children}
+          </div>
+          {ctaLabel && (
+            <button
+              className={classes.cta}
+              onClick={ctaOnClick}
+              type="button"
+            >
+              {ctaLabel}
+            </button>
+          )}
+          {dismissable && (
+            <button
+              type="button"
+              onClick={this.dismiss.bind(this)}
+              className={classes.close}
+            >
+              <Icon icon="mdiClose" />
+            </button>
+          )}
+        </div>
+      </div>
+    );
+  }
+}
+
+export const Infobox = injectStyle(styles)(InfoboxComponent);
-- 
cgit v1.2.3-70-g09d2

