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 | 2x 2x 2x 2x 2x 2x 2x | import React from "react";
import styled, { css } from "styled-components";
export type PaletteBlockType = "tile" | "sprite" | "sgb";
type PaletteBlockProps = {
colors: string[];
size?: number;
type?: PaletteBlockType;
highlight?: boolean;
};
type WrapperProps = {
$type?: PaletteBlockType;
$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" || props.$type === "sgb" ? spriteStyles : ""}
`;
const spriteStyles = css`
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr;
`;
const Color = styled.div``;
const PaletteBlock = ({
colors,
size = 24,
type = "tile",
highlight,
}: PaletteBlockProps) => (
<Wrapper
$type={type}
$highlight={highlight}
style={{
width: size,
height: size,
}}
>
{colors.map((color, index) => {
if (type === "sgb" && index === 0) {
return null;
}
if (type === "sprite" && index === 2) {
return null;
}
return (
<Color
key={index}
style={{
backgroundColor: `#${color}`,
}}
/>
);
})}
</Wrapper>
);
export default React.memo<PaletteBlockProps>(PaletteBlock);
|