Board.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from "react";
  2. import { useTranslation } from "react-i18next";
  3. import { ItemList, SubscribeItemEvents } from "./Items";
  4. import Selector from "./Selector";
  5. import ActionPane from "./ActionPane";
  6. import CursorPane from "./Cursors/CursorPane";
  7. import PanZoomRotate from "./PanZoomRotate";
  8. import styled from "styled-components";
  9. import { useRecoilValue } from "recoil";
  10. import { BoardConfigAtom } from "./game/atoms";
  11. const Placeholder = styled.p`
  12. position: fixed;
  13. top: 40vh;
  14. width: 100vw;
  15. text-align: center;
  16. color: hsl(0, 0%, 70%);
  17. `;
  18. const StyledBoard = styled.div.attrs(() => ({ className: "board" }))`
  19. position: relative;
  20. background: radial-gradient(closest-corner, #3954848a, #0d101547 120%),
  21. url(/board.png);
  22. width: ${({ size }) => size}px;
  23. height: ${({ size }) => size}px;
  24. border-radius: 2px;
  25. box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px,
  26. rgba(10, 37, 64, 0.35) 0px -2px 6px 0px inset;
  27. `;
  28. export const Board = ({ user, users, getComponent, moveFirst = true }) => {
  29. const { t } = useTranslation();
  30. const config = useRecoilValue(BoardConfigAtom);
  31. if (!config.size) {
  32. return <Placeholder>{t("Please select or load a game")}</Placeholder>;
  33. }
  34. return (
  35. <>
  36. <SubscribeItemEvents />
  37. <PanZoomRotate moveFirst={moveFirst}>
  38. <Selector moveFirst={moveFirst}>
  39. <ActionPane>
  40. <CursorPane user={user} users={users}>
  41. <StyledBoard size={config.size}>
  42. <ItemList getComponent={getComponent} />
  43. </StyledBoard>
  44. </CursorPane>
  45. </ActionPane>
  46. </Selector>
  47. </PanZoomRotate>
  48. </>
  49. );
  50. };
  51. export default Board;