summaryrefslogtreecommitdiffstats
path: root/src/components/organisms/toolbar/search.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-04-14 22:14:35 +0200
committerArmand Philippot <git@armandphilippot.com>2022-04-14 22:14:35 +0200
commit88b575b0d81e97531b70e90c1e124719b547614b (patch)
tree67a9b196b44c26e56310cf2338c7192b96807ec0 /src/components/organisms/toolbar/search.tsx
parentb94b9b41f113da17f232a7d1044dedadd87e0c89 (diff)
chore: add a Search component
Diffstat (limited to 'src/components/organisms/toolbar/search.tsx')
-rw-r--r--src/components/organisms/toolbar/search.tsx66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/components/organisms/toolbar/search.tsx b/src/components/organisms/toolbar/search.tsx
new file mode 100644
index 0000000..070bce0
--- /dev/null
+++ b/src/components/organisms/toolbar/search.tsx
@@ -0,0 +1,66 @@
+import Checkbox, { CheckboxProps } from '@components/atoms/forms/checkbox';
+import Label from '@components/atoms/forms/label';
+import MagnifyingGlass from '@components/atoms/icons/magnifying-glass';
+import { VFC } from 'react';
+import { useIntl } from 'react-intl';
+import SearchModal from '../modals/search-modal';
+import sharedStyles from './toolbar-items.module.scss';
+import searchStyles from './search.module.scss';
+
+export type SearchProps = {
+ /**
+ * Set additional classnames to the modal wrapper.
+ */
+ className?: string;
+ /**
+ * The button state.
+ */
+ isActive: CheckboxProps['value'];
+ /**
+ * A callback function to handle button state.
+ */
+ setIsActive: CheckboxProps['setValue'];
+};
+
+const Search: VFC<SearchProps> = ({
+ className = '',
+ isActive,
+ setIsActive,
+}) => {
+ const intl = useIntl();
+ const label = isActive
+ ? intl.formatMessage({
+ defaultMessage: 'Close search',
+ id: 'LDDUNO',
+ description: 'Search: Close label',
+ })
+ : intl.formatMessage({
+ defaultMessage: 'Open search',
+ id: 'Xj+WXB',
+ description: 'Search: Open label',
+ });
+
+ return (
+ <div className={`${sharedStyles.item} ${searchStyles.item}`}>
+ <Checkbox
+ id="search-button"
+ name="search-button"
+ value={isActive}
+ setValue={setIsActive}
+ className={`${sharedStyles.checkbox} ${searchStyles.checkbox}`}
+ />
+ <Label
+ htmlFor="search-button"
+ aria-label={label}
+ className={`${sharedStyles.label} ${searchStyles.label}`}
+ >
+ <MagnifyingGlass />
+ </Label>
+ <SearchModal
+ className={`${sharedStyles.modal} ${searchStyles.modal} ${className}`}
+ />
+ </div>
+ );
+};
+
+export default Search;