Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve tailwind config to also catch dynamic classes #3143

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/tailwind_actix/end2end/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";

test("should see the welcome message", async ({ page }) => {
test("homepage has title 'Leptos + Tailwindcss'", async ({ page }) => {
await page.goto("http://localhost:3000/");

await expect(page.locator("h2")).toHaveText("Welcome to Leptos with Tailwind");
await expect(page).toHaveTitle("Leptos + Tailwindcss");
});
37 changes: 21 additions & 16 deletions examples/tailwind_actix/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@ pub fn App() -> impl IntoView {

#[component]
fn Home() -> impl IntoView {
let (count, set_count) = signal(0);
let (value, set_value) = signal(0);

// thanks to https://tailwindcomponents.com/component/blue-buttons-example for the showcase layout
view! {
<main class="my-0 mx-auto max-w-3xl text-center">
<h2 class="p-6 text-4xl">"Welcome to Leptos with Tailwind"</h2>
<p class="px-10 pb-10 text-left">"Tailwind will scan your Rust files for Tailwind class names and compile them into a CSS file."</p>
<button
class="bg-amber-600 hover:bg-sky-700 px-5 py-3 text-white rounded-lg"
on:click=move |_| set_count.update(|count| *count += 1)
>
"Something's here | "
{move || if count.get() == 0 {
"Click me!".to_string()
} else {
count.get().to_string()
}}
" | Some more text"
</button>
<Title text="Leptos + Tailwindcss"/>
<main>
<div class="bg-gradient-to-tl from-blue-800 to-blue-500 text-white font-mono flex flex-col min-h-screen">
<div class="flex flex-row-reverse flex-wrap m-auto">
<button on:click=move |_| set_value.update(|value| *value += 1) class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-700 border-blue-800 text-white">
"+"
</button>
<button class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-800 border-blue-900 text-white">
{value}
</button>
<button
on:click=move |_| set_value.update(|value| *value -= 1)
class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-700 border-blue-800 text-white"
class:invisible=move || {value.get() < 1}
>
"-"
</button>
</div>
</div>
</main>
}
}
5 changes: 4 additions & 1 deletion examples/tailwind_actix/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: {
content: {
files: ["*.html", "./src/**/*.rs"],
transform: {
rs: (content) => content.replace(/(?:^|\s)class:/g, ' '),
},
},
theme: {
extend: {},
Expand Down
6 changes: 2 additions & 4 deletions examples/tailwind_axum/end2end/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { test, expect } from "@playwright/test";

test("homepage has title and links to intro page", async ({ page }) => {
test("homepage has title 'Leptos + Tailwindcss'", async ({ page }) => {
await page.goto("http://localhost:3000/");

await expect(page).toHaveTitle("Welcome to Leptos");

await expect(page.locator("h1")).toHaveText("Welcome to Leptos!");
await expect(page).toHaveTitle("Leptos + Tailwindcss");
});
6 changes: 5 additions & 1 deletion examples/tailwind_axum/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ fn Home() -> impl IntoView {
<button class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-800 border-blue-900 text-white">
{value}
</button>
<button on:click=move |_| set_value.update(|value| *value -= 1) class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-700 border-blue-800 text-white">
<button
on:click=move |_| set_value.update(|value| *value -= 1)
class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-700 border-blue-800 text-white"
class:invisible=move || {value.get() < 1}
>
"-"
</button>
</div>
Expand Down
8 changes: 6 additions & 2 deletions examples/tailwind_axum/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["*.html", "./src/**/*.rs",],
content: {
files: ["*.html", "./src/**/*.rs"],
transform: {
rs: (content) => content.replace(/(?:^|\s)class:/g, ' '),
},
},
theme: {
extend: {},
},
plugins: [],
}

6 changes: 2 additions & 4 deletions examples/tailwind_csr/end2end/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { test, expect } from "@playwright/test";

test("homepage has title and links to intro page", async ({ page }) => {
test("homepage has title 'Leptos + Tailwindcss'", async ({ page }) => {
await page.goto("http://localhost:8080/");

await expect(page).toHaveTitle("Leptos • Counter with Tailwind");

await expect(page.locator("h2")).toHaveText("Welcome to Leptos with Tailwind");
await expect(page).toHaveTitle("Leptos + Tailwindcss");
});
39 changes: 22 additions & 17 deletions examples/tailwind_csr/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@ pub fn App() -> impl IntoView {

#[component]
fn Home() -> impl IntoView {
let (count, set_count) = signal(0);
let (value, set_value) = signal(0);

// thanks to https://tailwindcomponents.com/component/blue-buttons-example for the showcase layout
view! {
<div class="my-0 mx-auto max-w-3xl text-center">
<h2 class="p-6 text-4xl">"Welcome to Leptos with Tailwind"</h2>
<p class="px-10 pb-10 text-left">"Tailwind will scan your Rust files for Tailwind class names and compile them into a CSS file."</p>
<button
class="bg-amber-600 hover:bg-sky-700 px-5 py-3 text-white rounded-lg"
on:click=move |_| set_count.update(|count| *count += 1)
>
"Something's here | "
{move || if count.get() == 0 {
"Click me!".to_string()
} else {
count.get().to_string()
}}
" | Some more text"
</button>
</div>
<Title text="Leptos + Tailwindcss"/>
<main>
<div class="bg-gradient-to-tl from-blue-800 to-blue-500 text-white font-mono flex flex-col min-h-screen">
<div class="flex flex-row-reverse flex-wrap m-auto">
<button on:click=move |_| set_value.update(|value| *value += 1) class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-700 border-blue-800 text-white">
"+"
</button>
<button class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-800 border-blue-900 text-white">
{value}
</button>
<button
on:click=move |_| set_value.update(|value| *value -= 1)
class="rounded px-3 py-2 m-1 border-b-4 border-l-2 shadow-lg bg-blue-700 border-blue-800 text-white"
class:invisible=move || {value.get() < 1}
>
"-"
</button>
</div>
</div>
</main>
}
}
5 changes: 4 additions & 1 deletion examples/tailwind_csr/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: {
content: {
files: ["*.html", "./src/**/*.rs"],
transform: {
rs: (content) => content.replace(/(?:^|\s)class:/g, ' '),
},
},
theme: {
extend: {},
Expand Down