All files / src/components/forms SceneBackgroundTypeDropdown.tsx

100% Statements 13/13
100% Branches 6/6
100% Functions 3/3
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 551x 1x 1x 1x 1x 1x 1x             1x       2x 2x                 1x                         1x                            
import React from "react";
import l10n from "shared/lib/lang/l10n";
import entitiesActions from "store/features/entities/entitiesActions";
import { useAppDispatch } from "store/hooks";
import { DropdownButton } from "ui/buttons/DropdownButton";
import { CheckIcon, BlankIcon } from "ui/icons/Icons";
import { MenuItem } from "ui/menu/Menu";
 
interface SceneBackgroundTypeDropdownProps {
  sceneId: string;
  tilemapEnabled: boolean;
}
 
export const SceneBackgroundTypeDropdown = ({
  sceneId,
  tilemapEnabled,
}: SceneBackgroundTypeDropdownProps) => {
  const dispatch = useAppDispatch();
  return (
    <DropdownButton
      size="small"
      variant="transparent"
      showArrow={false}
      label={l10n(tilemapEnabled ? "FIELD_TILEMAP" : "FIELD_IMAGE")}
    >
      <MenuItem
        onClick={() =>
          dispatch(
            entitiesActions.setTilemapLayersEnabled({
              sceneId,
              enabled: true,
            }),
          )
        }
        icon={tilemapEnabled ? <CheckIcon /> : <BlankIcon />}
      >
        {l10n("FIELD_TILEMAP")}
      </MenuItem>
      <MenuItem
        onClick={() =>
          dispatch(
            entitiesActions.setTilemapLayersEnabled({
              sceneId,
              enabled: false,
            }),
          )
        }
        icon={!tilemapEnabled ? <CheckIcon /> : <BlankIcon />}
      >
        {l10n("FIELD_IMAGE")}
      </MenuItem>
    </DropdownButton>
  );
};