Skip to content

Instantly share code, notes, and snippets.

@jordienr
Created July 15, 2023 09:10
Show Gist options
  • Star 64 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save jordienr/abb847bc1649b3259d5aec1381583fd1 to your computer and use it in GitHub Desktop.
Save jordienr/abb847bc1649b3259d5aec1381583fd1 to your computer and use it in GitHub Desktop.
Tailwind SVG Grid Background
// Remember to install mini-svg-data-uri
// Follow me on twitter for memes @jordienr
import { type Config } from "tailwindcss";
const {
default: flattenColorPalette,
} = require("tailwindcss/lib/util/flattenColorPalette");
const svgToDataUri = require("mini-svg-data-uri");
export default {
content: ["./src/**/*.{js,ts,jsx,tsx}"],
theme: {
},
plugins: [
function ({ matchUtilities, theme }: { matchUtilities: any; theme: any }) {
matchUtilities(
{
"bg-grid": (value: string) => ({
backgroundImage: `url("${svgToDataUri(
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32" fill="none" stroke="${value}"><path d="M0 .5H31.5V32"/></svg>`
)}")`,
}),
},
{ values: flattenColorPalette(theme("backgroundColor")), type: "color" }
);
},
],
} satisfies Config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment