summaryrefslogtreecommitdiffstats
path: root/src/components/Buttons/ButtonSearch/ButtonSearch.tsx
blob: a2635aac7ac68706bf56a70b6c6859899e475e46 (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
import CloseIcon from '@assets/images/icon-close.svg';
import SearchIcon from '@assets/images/icon-search.svg';
import { t } from '@lingui/macro';
import { SetStateAction } from 'react';
import styles from '../Buttons.module.scss';

const ButtonSearch = ({
  isActivated,
  setIsActivated,
}: {
  isActivated: boolean;
  setIsActivated: (value: SetStateAction<boolean>) => void;
}) => {
  const btnClasses = isActivated
    ? `${styles.search} ${styles['search--opened']}`
    : styles.search;

  return (
    <button
      className={btnClasses}
      type="button"
      onClick={() => setIsActivated(!isActivated)}
    >
      <span className={styles.icon}>
        <span className={styles.front}>
          <SearchIcon />
        </span>
        <span className={styles.back}>
          <CloseIcon />
        </span>
      </span>
      {isActivated ? (
        <span className="screen-reader-text">{t`Close search`}</span>
      ) : (
        <span className="screen-reader-text">{t`Open search`}</span>
      )}
    </button>
  );
};

export default ButtonSearch;