@use "@styles/abstracts/functions" as fun; .wrapper { width: min(calc(100vw - (var(--spacing-md) * 2)), fun.convert-px(500)); margin: auto; } .title { width: max-content; margin-left: auto; margin-right: auto; } title='Atom feed' href='https://git.armand.philippot.eu/www.armandphilippot.com/atom/src/components/Buttons/ButtonToolbar/ButtonToolbar.tsx?h=main' type='application/atom+xml'/>
aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Buttons/ButtonToolbar/ButtonToolbar.tsx
blob: e9f60798eac525a4d0c8e43ddd633f1ee8b51d60 (plain)
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
import { CloseIcon, CogIcon, SearchIcon } from '@components/Icons';
import { ForwardedRef, forwardRef, SetStateAction } from 'react';
import { useIntl } from 'react-intl';
import styles from '../Buttons.module.scss';

type ButtonType = 'search' | 'settings';

const ButtonToolbar = (
  {
    type,
    isActivated,
    setIsActivated,
  }: {
    type: ButtonType;
    isActivated: boolean;
    setIsActivated: (value: SetStateAction<boolean>) => void;
  },
  ref: ForwardedRef<HTMLButtonElement>
) => {
  const intl = useIntl();
  const ButtonIcon = () => (type === 'search' ? <SearchIcon /> : <CogIcon />);
  const btnClasses = isActivated
    ? `${styles.toolbar} ${styles['toolbar--activated']}`
    : styles.toolbar;

  return (
    <button
      ref={ref}
      className={btnClasses}
      type="button"
      onClick={() => setIsActivated(!isActivated)}
    >
      <span className={styles.icon}>
        <span className={styles.front}>
          <ButtonIcon />
        </span>
        <span className={styles.back}>
          <CloseIcon />
        </span>
      </span>
      {isActivated ? (
        <span className="screen-reader-text">
          {intl.formatMessage(
            {
              defaultMessage: 'Close {type}',
              description: 'ButtonToolbar: Close button',
            },
            {
              type,
            }
          )}
        </span>
      ) : (
        <span className="screen-reader-text">
          {intl.formatMessage(
            {
              defaultMessage: 'Open {type}',
              description: 'ButtonToolbar: Open button',
            },
            {
              type,
            }
          )}
        </span>
      )}
    </button>
  );
};

export default forwardRef(ButtonToolbar);