Skip to content

Commit 59e1743

Browse files
committed
Update tailwind to version 4.0.0
1 parent 77ce927 commit 59e1743

File tree

15 files changed

+72
-118
lines changed

15 files changed

+72
-118
lines changed

guides/mix_tasks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ And then `assets/` which should look similar to this:
419419

420420
```console
421421
├── css
422-
│   └── app.css
422+
│   ├── app.css
423+
│   └── tailwind_heroicons.js
423424
├── js
424425
│   └── app.js
425-
├── tailwind.config.js
426426
└── vendor
427427
└── topbar.js
428428
```

installer/lib/phx_new/single.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ defmodule Phx.New.Single do
7070
template(:css, [
7171
{:eex, :web,
7272
"phx_assets/app.css": "assets/css/app.css",
73-
"phx_assets/tailwind.config.js": "assets/tailwind.config.js"}
73+
"phx_assets/tailwind_heroicons.js": "assets/css/tailwind_heroicons.js"}
7474
])
7575

7676
template(:js, [

installer/templates/phx_assets/app.css

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
@import "tailwindcss/base";
2-
@import "tailwindcss/components";
3-
@import "tailwindcss/utilities";
1+
/* See the Tailwind configuration guide for advanced usage
2+
https://tailwindcss.com/docs/configuration */
3+
4+
@import "tailwindcss";
5+
@plugin "@tailwindcss/forms";
6+
@plugin "./tailwind_heroicons.js";
7+
@variant phx-click-loading ([".phx-click-loading&", ".phx-click-loading &"]);
8+
@variant phx-submit-loading ([".phx-submit-loading&", ".phx-submit-loading &"]);
9+
@variant phx-change-loading ([".phx-change-loading&", ".phx-change-loading &"]);
10+
@theme {
11+
--color-brand: "#FD4F00",
12+
};
413

514
/*
615
* Make LiveView wrapper divs transparent for layout.

installer/templates/phx_assets/tailwind.config.js

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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(__dirname, "../..<%= if @in_umbrella, do: "/../.." %>/deps/heroicons/optimized")
7+
let values = {}
8+
let icons = [
9+
["", "/24/outline"],
10+
["-solid", "/24/solid"],
11+
["-mini", "/20/solid"],
12+
["-micro", "/16/solid"]
13+
]
14+
icons.forEach(([suffix, dir]) => {
15+
fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
16+
let name = path.basename(file, ".svg") + suffix
17+
values[name] = {name, fullPath: path.join(iconsDir, dir, file)}
18+
})
19+
})
20+
matchComponents({
21+
"hero": ({name, fullPath}) => {
22+
let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
23+
content = encodeURIComponent(content)
24+
let size = theme("spacing.6")
25+
if (name.endsWith("-mini")) {
26+
size = theme("spacing.5")
27+
} else if (name.endsWith("-micro")) {
28+
size = theme("spacing.4")
29+
}
30+
return {
31+
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
32+
"-webkit-mask": `var(--hero-${name})`,
33+
"mask": `var(--hero-${name})`,
34+
"mask-repeat": "no-repeat",
35+
"background-color": "currentColor",
36+
"vertical-align": "middle",
37+
"display": "inline-block",
38+
"width": size,
39+
"height": size
40+
}
41+
}
42+
}, {values})
43+
})

installer/templates/phx_single/config/config.exs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ config :esbuild,
4545

4646
# Configure tailwind (the version is required)
4747
config :tailwind,
48-
version: "3.4.3",
48+
version: "4.0.3",
4949
<%= @app_name %>: [
5050
args: ~w(
51-
--config=tailwind.config.js
52-
--input=css/app.css
53-
--output=../priv/static/assets/app.css
51+
--input=assets/css/app.css
52+
--output=priv/static/assets/app.css
5453
),
55-
cd: Path.expand("..<%= if @in_umbrella, do: "/apps/#{@app_name}" %>/assets", __DIR__),
54+
cd: Path.expand("..<%= if @in_umbrella, do: "/apps/#{@app_name}" %>", __DIR__),
5655
]<% end %>
5756

5857
# Configures Elixir's Logger

installer/templates/phx_single/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule <%= @app_module %>.MixProject do
4747
{:floki, ">= 0.30.0", only: :test},<% end %><%= if @dashboard do %>
4848
{:phoenix_live_dashboard, "~> 0.8.3"},<% end %><%= if @javascript do %>
4949
{:esbuild, "~> 0.8", runtime: Mix.env() == :dev},<% end %><%= if @css do %>
50-
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
50+
{:tailwind, "~> 0.3", runtime: Mix.env() == :dev},
5151
{:heroicons,
5252
github: "tailwindlabs/heroicons",
5353
tag: "v2.1.1",

installer/templates/phx_umbrella/apps/app_name_web/config/config.exs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ config :esbuild,
2929

3030
# Configure tailwind (the version is required)
3131
config :tailwind,
32-
version: "3.4.3",
32+
version: "4.0.3",
3333
<%= @web_app_name %>: [
3434
args: ~w(
35-
--config=tailwind.config.js
36-
--input=css/app.css
37-
--output=../priv/static/assets/app.css
35+
--input=assets/css/app.css
36+
--output=priv/static/assets/app.css
3837
),
39-
cd: Path.expand("../apps/<%= @web_app_name %>/assets", __DIR__)
38+
cd: Path.expand("../apps/<%= @web_app_name %>", __DIR__)
4039
]<% end %>

installer/templates/phx_umbrella/apps/app_name_web/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule <%= @web_namespace %>.MixProject do
4545
{:floki, ">= 0.30.0", only: :test},<% end %><%= if @dashboard do %>
4646
{:phoenix_live_dashboard, "~> 0.8.3"},<% end %><%= if @javascript do %>
4747
{:esbuild, "~> 0.8", runtime: Mix.env() == :dev},<% end %><%= if @css do %>
48-
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
48+
{:tailwind, "~> 0.3", runtime: Mix.env() == :dev},
4949
{:heroicons,
5050
github: "tailwindlabs/heroicons",
5151
tag: "v2.1.1",

installer/templates/phx_web/components/core_components.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
520520
width, height, and background color classes.
521521
522522
Icons are extracted from the `deps/heroicons` directory and bundled within
523-
your compiled app.css by the plugin in your `assets/tailwind.config.js`.
523+
your compiled app.css by the plugin in `assets/css/tailwind_heroicons.js`.
524524
525525
## Examples
526526

0 commit comments

Comments
 (0)