Skip to content

Commit 1d77541

Browse files
committed
Switch icons from inline SVG to CSS masks
CSP doesn't allow inline styles, which includes the url-masks that our app was using for icons. This removes the icons/asset pipeline in favor of the standard Tailwind plugin approach used by modern Phoenix apps. Closes #176
1 parent 180c4e8 commit 1d77541

File tree

105 files changed

+275
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+275
-274
lines changed

assets/css/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ select:-moz-focusring {
9292

9393
@import "tailwindcss";
9494
@plugin "@tailwindcss/forms";
95+
@plugin "../icons.plugin.js";
9596

9697
@custom-variant dark (&:where(.dark, .dark *));
9798

assets/icons.plugin.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const plugin = require("tailwindcss/plugin")
2+
const fs = require("fs");
3+
const path = require("path");
4+
5+
module.exports = plugin(function ({ matchComponents, theme }) {
6+
let iconsDir = path.join(process.cwd(), "icons");
7+
let values = {};
8+
let icons = [
9+
["", "outline"],
10+
["-solid", "solid"],
11+
["-special", "special"],
12+
];
13+
14+
icons.forEach(([suffix, dir]) => {
15+
let dirPath = path.join(iconsDir, dir);
16+
17+
fs.readdirSync(dirPath).forEach((file) => {
18+
if (!file.endsWith(".svg")) return;
19+
20+
let name = path.basename(file, ".svg") + suffix;
21+
values[name] = { name, fullPath: path.join(dirPath, file) };
22+
});
23+
});
24+
25+
matchComponents(
26+
{
27+
icon: ({ name, fullPath }) => {
28+
let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
29+
content = encodeURIComponent(content)
30+
31+
return {
32+
[`--icon-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
33+
"-webkit-mask": `var(--icon-${name})`,
34+
"mask": `var(--icon-${name})`,
35+
"background-color": "currentColor",
36+
"vertical-align": "middle",
37+
"display": "inline-block",
38+
"width": theme("spacing.6"),
39+
"height": theme("spacing.6"),
40+
};
41+
},
42+
},
43+
{ values },
44+
);
45+
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)