Created
February 18, 2025 18:42
-
-
Save frankdugan3/8f46f6d6aeb7bfcb95c6b9fc041e0b2a to your computer and use it in GitHub Desktop.
Phoenix Tailwind v4
This file contains hidden or 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
/* default is to use prefers-color-scheme */ | |
/* if you want dark mode via class: */ | |
@variant dark (&:where(.dark, .dark *)); | |
@variant phx-click-loading (.phx-click-loading&, .phx-click-loading &); | |
@variant phx-submit-loading (.phx-submit-loading&, .phx-submit-loading &); | |
@variant phx-change-loading (.phx-change-loading&, .phx-change-loading &); | |
@plugin "./heroicons.tailwind.plugin.js"; | |
@import "tailwindcss" source("../.."); |
This file contains hidden or 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
config :tailwind, | |
version: "4.0.7", | |
default: [ | |
args: ~w( | |
--input=css/app.css | |
--output=../priv/static/assets/app.css | |
), | |
cd: Path.expand("../assets", __DIR__) | |
] |
This file contains hidden or 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
watchers: [ | |
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]}, | |
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]} | |
] |
This file contains hidden or 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
const fs = require("fs"); | |
const path = require("path"); | |
module.exports = function ({ matchComponents, theme }) { | |
let iconsDir = path.join(process.cwd(), "../deps/heroicons/optimized"); | |
let values = {}; | |
let icons = [ | |
["", "/24/outline"], | |
["-solid", "/24/solid"], | |
["-mini", "/20/solid"], | |
["-micro", "/16/solid"], | |
]; | |
icons.forEach(([suffix, dir]) => { | |
fs.readdirSync(path.join(iconsDir, dir)).forEach((file) => { | |
let name = path.basename(file, ".svg") + suffix; | |
values[name] = { name, fullPath: path.join(iconsDir, dir, file) }; | |
}); | |
}); | |
matchComponents( | |
{ | |
hero: ({ name, fullPath }) => { | |
let content = fs | |
.readFileSync(fullPath) | |
.toString() | |
.replace(/\r?\n|\r/g, ""); | |
let size = theme("spacing.6"); | |
if (name.endsWith("-mini")) { | |
size = theme("spacing.5"); | |
} else if (name.endsWith("-micro")) { | |
size = theme("spacing.4"); | |
} | |
return { | |
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`, | |
"-webkit-mask": `var(--hero-${name})`, | |
mask: `var(--hero-${name})`, | |
"mask-repeat": "no-repeat", | |
"background-color": "currentColor", | |
"vertical-align": "middle", | |
display: "inline-block", | |
width: size, | |
height: size, | |
}; | |
}, | |
}, | |
{ values }, | |
); | |
}; |
This file contains hidden or 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
defp deps do | |
[ | |
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev}, | |
{:heroicons, | |
github: "tailwindlabs/heroicons", | |
tag: "v2.2.0", | |
sparse: "optimized", | |
app: false, | |
compile: false, | |
depth: 1}, | |
] | |
end | |
defp aliases do | |
[ | |
"assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"], | |
"assets.build": ["tailwind default", "esbuild default"], | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment