AddItemButton.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React from "react";
  2. import { useRecoilValue } from "recoil";
  3. import { useTranslation } from "react-i18next";
  4. import styled from "styled-components";
  5. import AvailableItems from "./AvailableItems";
  6. import NewItems from "./NewItems";
  7. import { AvailableItemListAtom } from "./Board/";
  8. import Touch from "../ui/Touch";
  9. import SidePanel from "../ui/SidePanel";
  10. const AvailableItemList = styled.div`
  11. margin-top: 2em;
  12. color: white;
  13. list-type: none;
  14. `;
  15. const AddItemButton = () => {
  16. const { t } = useTranslation();
  17. const availableItemList = useRecoilValue(AvailableItemListAtom);
  18. const [showAddPanel, setShowAddPanel] = React.useState(false);
  19. const [tab, setTab] = React.useState("standard");
  20. return (
  21. <>
  22. <Touch
  23. onClick={() => setShowAddPanel((prev) => !prev)}
  24. alt={t("Add item")}
  25. title={t("Add item")}
  26. label={t("Add")}
  27. icon={showAddPanel ? "cross" : "plus"}
  28. style={{ flex: 1 }}
  29. />
  30. {showAddPanel && (
  31. <SidePanel
  32. onClose={() => {
  33. setShowAddPanel(false);
  34. }}
  35. position="right"
  36. >
  37. <nav className="tabs">
  38. {
  39. // eslint-disable-next-line
  40. <a
  41. onClick={() => setTab("standard")}
  42. className={tab === "standard" ? "active" : ""}
  43. >
  44. {t("Standard")}
  45. </a>
  46. }
  47. {availableItemList && availableItemList.length > 0 && (
  48. // eslint-disable-next-line
  49. <a
  50. onClick={() => setTab("other")}
  51. className={tab === "other" ? "active" : ""}
  52. >
  53. {t("Other")}
  54. </a>
  55. )}
  56. </nav>
  57. <section className="content">
  58. {tab === "standard" && <NewItems />}
  59. {tab === "other" && (
  60. <AvailableItemList>
  61. <AvailableItems />
  62. </AvailableItemList>
  63. )}
  64. </section>
  65. </SidePanel>
  66. )}
  67. </>
  68. );
  69. };
  70. export default AddItemButton;