Last active
April 16, 2023 17:37
-
-
Save jkohlin/1cd9d5b94bcae174b5b1929f3f41790a to your computer and use it in GitHub Desktop.
svgColorBoxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function svgColorSwatches(colors, size = 64, vertical = false) { | |
let svg = vertical | |
? `<svg width="${size}" height="${colors.length * size}" viewBox="0 0 ${size} ${colors.length * size}" fill="none" xmlns="http://www.w3.org/2000/svg">` | |
: `<svg width="${colors.length * size}" height="${size}" viewBox="0 0 ${colors.length * size} ${size}" fill="none" xmlns="http://www.w3.org/2000/svg">`; | |
let x = 0, y = 0; | |
for (let shade of colors) { | |
svg += ` | |
<rect width="${size}" height="${size}" fill="${shade}" x="${x}" y="${y}"/>`; | |
x += vertical ? 0 : size; | |
y += vertical ? size : 0; | |
} | |
svg += ` | |
</svg>`; | |
return svg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment