All files / src/components/forms PaletteBlock.tsx

0% Statements 0/16
0% Branches 0/11
0% Functions 0/5
0% Lines 0/16

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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                                                                                                                                                           
import React from "react";
import PropTypes from "prop-types";
import styled, { css } from "styled-components";
 
type PaletteBlockProps = {
  colors: string[];
  size?: number;
  type?: "tile" | "sprite";
  highlight?: boolean;
};
 
type WrapperProps = {
  $type?: "tile" | "sprite";
  $highlight?: boolean;
};
 
const Wrapper = styled.div<WrapperProps>`
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0px 0px;
  border: 1px solid
    ${(props) =>
      props.$highlight
        ? props.theme.colors.highlight
        : props.theme.colors.input.background};
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
  transition: border 0.2s ease-in-out;
  transition-delay: ${(props) => (props.$highlight ? "0.5s" : "0")};
  ${(props) => (props.$type === "sprite" ? spriteStyles : "")}
`;
 
const spriteStyles = css`
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr;
`;
 
const Color = styled.div``;
 
const PaletteBlock: React.FC<PaletteBlockProps> = ({
  colors,
  size = 24,
  type = "tile",
  highlight,
}) => (
  <Wrapper
    $type={type}
    $highlight={highlight}
    style={{
      width: size,
      height: size,
    }}
  >
    {colors.map((color, index) => {
      Iif (type === "sprite" && index === 2) {
        return null;
      }
      return (
        <Color
          key={index}
          style={{
            backgroundColor: `#${color}`,
          }}
        />
      );
    })}
  </Wrapper>
);
 
PaletteBlock.propTypes = {
  colors: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired,
  size: PropTypes.number,
};
 
export default PaletteBlock;