Skip to content

Commit fcc3b75

Browse files
committed
♻️ refactor: remove all @apply and use inline styling
1 parent c96ef95 commit fcc3b75

File tree

9 files changed

+63
-158
lines changed

9 files changed

+63
-158
lines changed
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{% extends 'base.html' %}
22

3-
43
{% block body %}
5-
<div class="container">
6-
<h1 class="heading-1">Django React Boilerplate Example App</h1>
7-
<p class="paragraph">
4+
<div class="max-w-5xl mx-auto px-4">
5+
<h1 class="text-5xl mb-2">Django React Boilerplate Example App</h1>
6+
<p class="mb-2">
87
Below is an example of a React app included in the Django template.<br/>
9-
Check <code class="inline-code">backend/templates/common/index.html</code> and <code class="inline-code">frontend/js/index.js</code> to understand how they're linked:
8+
Check <code class="px-1.5 py-0.5 text-sm font-mono text-pink-600 bg-gray-100 rounded">backend/templates/common/index.html</code> and <code class="px-1.5 py-0.5 text-sm font-mono text-pink-600 bg-gray-100 rounded">frontend/js/index.js</code> to understand how they're linked:
109
</p>
1110
</div>
12-
<div class="container" id="react-app"></div>
11+
<div class="max-w-5xl mx-auto px-4" id="react-app"></div>
1312
{% endblock %}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends 'base.html' %}
22

33
{% block body %}
4-
<div class="container">
4+
<div class="max-w-5xl mx-auto px-4">
55
<h1>Temporary User Lockout</h1>
66
<p>
77
You have been locked out due to too many failed attempts. You have reached the failure limit of {{ failure_limit }} attempts.
@@ -11,4 +11,4 @@ <h1>Temporary User Lockout</h1>
1111
</p>
1212
<p>Please try again after the cool off period.</p>
1313
</div>
14-
{% endblock %}
14+
{% endblock %}

frontend/css/style.css

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1 @@
11
@import "tailwindcss";
2-
3-
/* Django background */
4-
#django-background {
5-
@apply text-[#092e20] text-[11pt] bg-no-repeat bg-[auto_200px] bg-center h-[300px] bg-[url('../assets/images/django-logo-positive.png')];
6-
}
7-
8-
/* Logo wrapper */
9-
#django-logo-wrapper {
10-
@apply text-[#092e20] mb-4;
11-
}
12-
13-
#django-logo-wrapper > img {
14-
@apply w-[100px];
15-
}
16-
17-
/* Page container */
18-
.container {
19-
@apply max-w-5xl mx-auto px-4;
20-
}
21-
22-
/* Inline code */
23-
.inline-code {
24-
@apply px-1.5 py-0.5 text-sm font-mono text-pink-600 bg-gray-100 rounded;
25-
}
26-
/* Headings */
27-
.heading-1 {
28-
@apply text-5xl mb-2;
29-
}
30-
31-
.heading-2 {
32-
@apply text-4xl mb-2;
33-
}
34-
35-
/* Paragraphs */
36-
.paragraph {
37-
@apply mb-2;
38-
}
39-
40-
/* Button */
41-
.btn {
42-
@apply px-2 py-1 border border-black text-black rounded-md
43-
hover:bg-black hover:text-white transition duration-200 cursor-pointer;
44-
}
45-
46-
/* TopNav */
47-
/* Container */
48-
.nav {
49-
@apply mx-auto max-w-6xl mt-4 mb-6 rounded-xl bg-zinc-900/80 backdrop-blur ring-1 ring-white/10;
50-
}
51-
52-
/* Brand */
53-
.nav-brand {
54-
@apply text-white font-semibold tracking-tight mr-2;
55-
}
56-
57-
/* Links */
58-
.nav-link {
59-
@apply px-3 py-2 rounded-lg text-sm font-medium text-zinc-300 transition;
60-
}
61-
.nav-link:hover {
62-
@apply text-white bg-white/5;
63-
}
64-
.nav-link:focus-visible {
65-
@apply outline-none ring-2 ring-white/40;
66-
}
67-
.nav-link--active {
68-
@apply text-white bg-white/10;
69-
}

frontend/css/users.css

Lines changed: 0 additions & 52 deletions
This file was deleted.

frontend/js/components/TopNav.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ import { NavLink } from "react-router";
33
const TopNav = () => {
44
return (
55
<header className="sticky top-0 z-50">
6-
<nav aria-label="Primary" className="nav">
6+
<nav
7+
aria-label="Primary"
8+
className="mx-auto mt-4 mb-6 max-w-6xl rounded-xl bg-zinc-900/80 backdrop-blur ring-1 ring-white/10"
9+
>
710
<div className="flex items-center gap-2 px-4 py-2">
8-
<a className="nav-brand" href="/">
11+
<a className="mr-2 font-semibold tracking-tight text-white" href="/">
912
django-react-boilerplate
1013
</a>
1114

1215
<NavLink
1316
className={({ isActive }) =>
14-
isActive ? "nav-link nav-link--active" : "nav-link"
17+
[
18+
"px-3 py-2 rounded-lg text-sm font-medium text-zinc-300 transition",
19+
"hover:text-white hover:bg-white/5",
20+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/40",
21+
isActive ? "text-white bg-white/10" : "",
22+
].join(" ")
1523
}
1624
end
1725
to="/"
@@ -21,7 +29,12 @@ const TopNav = () => {
2129

2230
<NavLink
2331
className={({ isActive }) =>
24-
isActive ? "nav-link nav-link--active" : "nav-link"
32+
[
33+
"px-3 py-2 rounded-lg text-sm font-medium text-zinc-300 transition",
34+
"hover:text-white hover:bg-white/5",
35+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/40",
36+
isActive ? "text-white bg-white/10" : "",
37+
].join(" ")
2538
}
2639
to="/users"
2740
>

frontend/js/pages/Home.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,26 @@ const Home = () => {
1919
return (
2020
<>
2121
<TopNav />
22-
<h2 className="heading-2">Static assets</h2>
23-
<div id="django-background">
22+
<h2 className="text-4xl mb-2">Static assets</h2>
23+
<div className="text-[#092e20] text-[11pt] bg-no-repeat bg-[auto_200px] bg-center h-[300px] bg-[url('../assets/images/django-logo-positive.png')]">
2424
If you are seeing the green Django logo on a white background and this
2525
text color is #092e20, frontend static files serving is working:
2626
</div>
27-
<div id="django-logo-wrapper">
27+
<div className="text-[#092e20] mb-4">
2828
<div>
2929
Below this text, you should see an img tag with the white Django logo
3030
on a green background:
3131
</div>
32-
<img alt="Django Negative Logo" src={DjangoImgSrc} />
32+
<img
33+
alt="Django Negative Logo"
34+
className="w-[100px]"
35+
src={DjangoImgSrc}
36+
/>
3337
</div>
34-
<h2 className="heading-2">Rest API</h2>
35-
<p className="paragraph">{restCheck?.message}</p>
38+
<h2 className="text-4xl mb-2">Rest API</h2>
39+
<p className="mb-2">{restCheck?.message}</p>
3640
<button
37-
className="btn"
41+
className="px-2 py-1 border border-black text-black rounded-md hover:bg-black hover:text-white transition duration-200 cursor-pointer"
3842
type="button"
3943
onClick={() => setShowBugComponent(true)}
4044
>

frontend/js/pages/Users.tsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,67 @@ import { Link, useLoaderData } from "react-router";
22

33
import { PaginatedUserList } from "../api";
44
import { TopNav } from "../components";
5-
import "../../css/users.css";
5+
import { makeLink } from "../utils";
66

77
const Users = () => {
88
const data = useLoaderData<PaginatedUserList>();
99

10-
const makeLink = (href: string | null | undefined) => {
11-
if (!href) return null;
12-
const u = new URL(href, window.location.origin);
13-
return `?${u.searchParams.toString()}`;
14-
};
15-
1610
const prev = makeLink(data.previous);
1711
const next = makeLink(data.next);
1812

1913
return (
2014
<>
2115
<TopNav />
22-
<section className="users-wrap">
23-
<h1 className="users-title">Users</h1>
16+
<section className="mx-auto max-w-3xl px-4">
17+
<h1 className="mt-4 mb-3 font-semibold text-slate-950">Users</h1>
2418

25-
<ul className="users-list">
19+
<ul className="bg-white rounded-xl border border-zinc-300">
2620
{data.results.map((u) => (
27-
<li key={u.id} className="users-item">
21+
<li
22+
key={u.id}
23+
className="px-4 py-3 text-sm text-slate-900 border-t border-zinc-200 first:border-t-0 hover:bg-slate-50"
24+
>
2825
{u.email}
2926
</li>
3027
))}
3128
</ul>
3229

33-
<div className="users-pager">
34-
<span className="users-count">
30+
<div className="mt-3 flex items-center justify-between text-sm">
31+
<span className="text-slate-600">
3532
{data.results.length} on this page • {data.count} total
3633
</span>
3734

3835
<div className="flex items-center gap-2">
39-
{/* Anchor elements do not natively support 'aria-disabled', which can cause accessibility issues. To improve accessibility, use 'tabIndex={-1}' with 'aria-disabled', or render a instead of when disabled. */}
4036
{!prev ? (
4137
<span
4238
aria-disabled="true"
43-
className="users-btn users-btn--primary users-btn--disabled"
39+
className="inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm text-white bg-emerald-600 border border-transparent opacity-45 pointer-events-none"
4440
tabIndex={-1}
4541
>
4642
← Previous
4743
</span>
4844
) : (
49-
<Link className="users-btn users-btn--primary" to={prev}>
45+
<Link
46+
className="inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm text-white bg-emerald-600 hover:bg-emerald-700 border border-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/45"
47+
to={prev}
48+
>
5049
← Previous
5150
</Link>
5251
)}
52+
5353
{!next ? (
5454
<span
5555
aria-disabled="true"
56-
className="users-btn users-btn--primary users-btn--disabled"
56+
className="inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm text-white bg-emerald-600 border border-transparent opacity-45 pointer-events-none"
5757
tabIndex={-1}
5858
>
5959
Next →
6060
</span>
6161
) : (
62-
<Link className="users-btn users-btn--primary" to={next}>
62+
<Link
63+
className="inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm text-white bg-emerald-600 hover:bg-emerald-700 border border-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/45"
64+
to={next}
65+
>
6366
Next →
6467
</Link>
6568
)}

frontend/js/utils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { makeLink } from "./navigation";
12
import Urls from "./urls";
23

3-
export { Urls };
4+
export { Urls, makeLink };

frontend/js/utils/navigation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const makeLink = (href: string | null | undefined) => {
2+
if (!href) return null;
3+
const u = new URL(href, window.location.origin);
4+
return `?${u.searchParams.toString()}`;
5+
};

0 commit comments

Comments
 (0)