aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/InfoBar.tsx
blob: f3f1adbe7e8984e243bedfedc6800fa454394db1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { Component, MouseEventHandler, ReactNode } from 'react';
import { observer } from 'mobx-react';
import classnames from 'classnames';
import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';

import { mdiClose } from '@mdi/js';
import { noop } from 'lodash';
import Loader from './loader/index';
import Appear from './effects/Appear';
import Icon from './icon';
import { DEFAULT_LOADER_COLOR } from '../../config';

const messages = defineMessages({
  hide: {
    id: 'infobar.hide',
    defaultMessage: 'Hide',
  },
});

interface IProps extends WrappedComponentProps {
  children: ReactNode;
  onClick?: MouseEventHandler<HTMLButtonElement>;
  type?: string;
  className?: string;
  ctaLabel?: string;
  ctaLoading?: boolean;
  position?: string;
  sticky?: boolean;
  onHide?: () => void;
}

@observer
class InfoBar extends Component<IProps> {
  render() {
    const {
      children,
      type = 'primary',
      onClick = noop,
      className = '',
      ctaLabel = '',
      ctaLoading = false,
      position = 'bottom',
      sticky = false,
      onHide = noop,
      intl,
    } = this.props;

    const transitionName = position === 'top' ? 'slideDown' : 'slideUp';

    return (
      <Appear
        transitionName={transitionName}
        className={classnames({
          'info-bar': true,
          [`info-bar--${type}`]: true,
          [`info-bar--${position}`]: true,
          [`${className}`]: true,
        })}
      >
        <div
          className={classnames({
            'info-bar': true,
            [`info-bar--${type}`]: true,
            [`info-bar--${position}`]: true,
            [`${className}`]: true,
          })}
        >
          {children}
          {ctaLabel && (
            <button type="button" className="info-bar__cta" onClick={onClick}>
              <div
                className="contentWrapper"
                style={{ display: 'flex', gap: '8px' }}
              >
                <Loader
                  size={18}
                  loaded={!ctaLoading}
                  color={DEFAULT_LOADER_COLOR}
                />
                {ctaLabel}
              </div>
            </button>
          )}
          {!sticky && (
            <button
              type="button"
              className="info-bar__close"
              onClick={onHide}
              aria-label={intl.formatMessage(messages.hide)}
            >
              <Icon icon={mdiClose} />
            </button>
          )}
        </div>
      </Appear>
    );
  }
}

export default injectIntl(InfoBar);