Skip to content

Commit c8574de

Browse files
committed
fix theme toggle icons and add section for creating custom themes
1 parent a68917d commit c8574de

File tree

3 files changed

+154
-28
lines changed

3 files changed

+154
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ local_settings.py
6161
db.sqlite3
6262
db.sqlite3-journal
6363
core/
64+
app/
6465
manage.py
6566

6667
# Flask stuff:

README.md

Lines changed: 151 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,32 @@
1212

1313
## Overview
1414

15-
Welcome to `drf-restwind`, a modern re-imagining of the Django REST Framework. This project utilizes TailwindCSS and DaisyUI to provide flexible and customizable UI solutions with minimal coding effort.
15+
Welcome to `drf-restwind`, a modern re-imagining of the Django REST Framework.
16+
This project utilizes TailwindCSS and DaisyUI to provide flexible and
17+
customizable UI solutions with minimal coding effort.
1618

1719
## Key Features
1820

19-
- **Modern UI**: Crafted with TailwindCSS and DaisyUI for an appealing and contemporary design.
20-
- **Diverse Themes**: Offers a selection of visually appealing themes to choose from.
21-
- **Responsive Design**: Adapts seamlessly to various screen sizes for optimal user experience.
21+
- **Modern UI**: Crafted with TailwindCSS and DaisyUI for an appealing and
22+
contemporary design.
23+
- **Diverse Themes**: Offers a selection of visually appealing themes to choose
24+
from.
25+
- **Responsive Design**: Adapts seamlessly to various screen sizes for optimal
26+
user experience.
2227
- **Accessibility**: Built with accessibility as a priority.
2328
- **Code Highlighting**: Integrates Highlight.js for enhanced code visibility.
24-
- **CI/CD Automation**: Utilizes GitHub Actions for automated deployment and integration, ensuring reliability and consistency.
25-
- **Efficient Dependency Management**: Employs Poetry for meticulous project dependency management.
26-
- **Consistent Code Formatting**: Uses Black for automatic code formatting, enhancing code readability.
27-
- **Thorough Code Linting**: Implements Ruff to proactively identify and resolve potential code issues, boosting code quality and maintainability.
28-
- **Comprehensive Testing**: Leverages Django’s testing framework for effective test management.
29-
- **Essential Configuration Files**: Includes necessary files such as `.gitignore` and `pyproject.toml` for streamlined project setup.
29+
- **CI/CD Automation**: Utilizes GitHub Actions for automated deployment and
30+
integration, ensuring reliability and consistency.
31+
- **Efficient Dependency Management**: Employs Poetry for meticulous project
32+
dependency management.
33+
- **Consistent Code Formatting**: Uses Black for automatic code formatting,
34+
enhancing code readability.
35+
- **Thorough Code Linting**: Implements Ruff to proactively identify and resolve
36+
potential code issues, boosting code quality and maintainability.
37+
- **Comprehensive Testing**: Leverages Django’s testing framework for effective
38+
test management.
39+
- **Essential Configuration Files**: Includes necessary files such as
40+
`.gitignore` and `pyproject.toml` for streamlined project setup.
3041

3142
## Screenshots
3243

@@ -66,7 +77,8 @@ To customize `drf-restwind`, follow these steps:
6677

6778
1. **Add Required Templates**:
6879

69-
In your app's templates directory, create a folder named `rest_framework` and add a file called `api.html`:
80+
In your app's templates directory, create a folder named `rest_framework` and
81+
add a file called `api.html`:
7082

7183
```bash
7284
mkdir app/templates/rest_framework
@@ -100,7 +112,8 @@ Now you can proceed with the following customization guides.
100112

101113
### Changing the Theme
102114

103-
To modify the theme, update your `api.html`:
115+
You can view all available themes on [daisyUI](https://daisyui.com/) website. To
116+
modify the theme, update your `api.html`:
104117

105118
```html
106119
{% extends 'rest_framework/base.html' %}
@@ -113,11 +126,15 @@ To modify the theme, update your `api.html`:
113126

114127
<!-- Set the highlight_theme accordingly -->
115128
{% block highlight_theme %}
116-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/base16/github-dark.min.css">
129+
<link
130+
rel="stylesheet"
131+
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/base16/github-dark.min.css"
132+
>
117133
{% endblock %}
118134
```
119135

120-
If you want to update code highlight theme for API documentation (written in `Markdown` in `View`'s `docstring`):
136+
If you want to update code highlight theme for API documentation (written in
137+
`Markdown` in `View`'s `docstring`):
121138

122139
- Install `markdown` and `pygments`:
123140

@@ -145,13 +162,115 @@ If you want to update code highlight theme for API documentation (written in `Ma
145162

146163
<!-- Set the highlight_theme accordingly -->
147164
{% block highlight_theme %}
148-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/base16/github-dark.min.css">
165+
<link
166+
rel="stylesheet"
167+
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/base16/github-dark.min.css"
168+
>
149169

150170
<!-- Include styles -->
151171
<link rel="stylesheet" href="{% static 'app/css/highlight.css' %}">
152172
{% endblock %}
153173
```
154174

175+
### Creating your own theme
176+
177+
Can not find what you are looking for? Create your own theme:
178+
179+
1. Go to daisyUI [theme generator](https://daisyui.com/theme-generator/).
180+
2. Select a theme or Click the `Random` button to generate a random theme.
181+
3. Customize the defaults.
182+
4. After customization click the `CSS` button to copy CSS variables.
183+
5. Follow the steps:
184+
- Create `static` folder in your `app`:
185+
186+
```console
187+
mkdir -p app/static/app
188+
cd app/static/app
189+
```
190+
191+
- Install dependencies:
192+
193+
```console
194+
npm install tailwindcss '@tailwindcss/cli'
195+
npm install -D daisyui
196+
```
197+
198+
- Create your `css` folder and `styles`:
199+
200+
```console
201+
mkdir css
202+
touch css/app.css
203+
```
204+
205+
- Open your `app.css` and add the following lines:
206+
207+
```css
208+
@import "tailwindcss";
209+
210+
@plugin "daisyui";
211+
212+
/* Add your customized theme here */
213+
@plugin "daisyui/theme" {
214+
name: "lemon";
215+
default: false;
216+
prefersdark: false;
217+
color-scheme: "light";
218+
--color-base-100: oklch(98% 0.031 120.757);
219+
--color-base-200: oklch(96% 0.067 122.328);
220+
--color-base-300: oklch(93% 0.127 124.321);
221+
--color-base-content: oklch(40% 0.101 131.063);
222+
--color-primary: oklch(0% 0 0);
223+
--color-primary-content: oklch(100% 0 0);
224+
--color-secondary: oklch(62% 0.265 303.9);
225+
--color-secondary-content: oklch(97% 0.014 308.299);
226+
--color-accent: oklch(55% 0.013 58.071);
227+
--color-accent-content: oklch(98% 0.001 106.423);
228+
--color-neutral: oklch(40% 0.101 131.063);
229+
--color-neutral-content: oklch(98% 0.031 120.757);
230+
--color-info: oklch(78% 0.154 211.53);
231+
--color-info-content: oklch(30% 0.056 229.695);
232+
--color-success: oklch(84% 0.238 128.85);
233+
--color-success-content: oklch(27% 0.072 132.109);
234+
--color-warning: oklch(75% 0.183 55.934);
235+
--color-warning-content: oklch(26% 0.079 36.259);
236+
--color-error: oklch(71% 0.202 349.761);
237+
--color-error-content: oklch(28% 0.109 3.907);
238+
--radius-selector: 2rem;
239+
--radius-field: 0rem;
240+
--radius-box: 2rem;
241+
--size-selector: 0.25rem;
242+
--size-field: 0.25rem;
243+
--border: 1.5px;
244+
--depth: 1;
245+
--noise: 0;
246+
}
247+
```
248+
249+
- Generate your `styles`:
250+
251+
```console
252+
npx @tailwindcss/cli -i css/app.css -o css/styles.css
253+
```
254+
255+
- Include your `styles.css` in your templates:
256+
257+
```html
258+
{% extends 'rest_framework/base.html' %}{% load static %}
259+
260+
<!-- Add your styles -->
261+
{% block styles %}
262+
{{ block.super }}
263+
<link rel="stylesheet" href="{% static 'app/css/styles.css' %}">
264+
{% endblock %}
265+
266+
<!-- Your custom theme -->
267+
{% block theme %}lemon{% endblock %}
268+
```
269+
270+
- Run your app to view the result.
271+
272+
Now, you have a theme that matches your brand.
273+
155274
### Removing theme selector
156275

157276
To remove the theme selector, update your `api.html`:
@@ -190,7 +309,6 @@ To remove theme toggle, update your `api.html`:
190309
{% extends 'rest_framework/base.html' %}
191310

192311
{% block searchbar_right %}{% endblock %}
193-
194312
{% block sidebar_styles %}lg:h-[calc(100dvh-1rem)] lg:max-h-[calc(100dvh-1rem)]{% endblock %}
195313
{% block content_styles %}lg:h-[calc(100dvh-1rem)] lg:max-h-[calc(100dvh-1rem)]{% endblock %}
196314
```
@@ -206,6 +324,7 @@ To change the brand name and add custom links, modify your `api.html`:
206324

207325
{% block title %}{% trans 'YOUR_BRAND' %}{% endblock %}
208326

327+
<!-- Branding -->
209328
{% block branding %}
210329
<li
211330
class="tooltip tooltip-right tooltip-primary"
@@ -221,15 +340,15 @@ To change the brand name and add custom links, modify your `api.html`:
221340
</li>
222341
{% endblock %}
223342

343+
<!-- Add your brand text -->
224344
{% block branding_text %}
225-
<!-- Add your brand -->
226-
<h1 class="hidden text-xl font-semibold text-primary lg:block">{% trans 'YOUR_BRAND' %}</h1>
345+
<h1 class="hidden text-xl font-semibold text-primary lg:block">
346+
{% trans 'YOUR_BRAND' %}
347+
</h1>
227348

228349
<!-- Or an empty div to center the search bar -->
229350
<div class="hidden lg:block"></div>
230-
{% endblock %}
231-
232-
{% block userlinks %}
351+
{% endblock %} {% block userlinks %}
233352
<li
234353
class="tooltip tooltip-right tooltip-secondary"
235354
data-tip="{% trans 'Home' %}"
@@ -238,7 +357,7 @@ To change the brand name and add custom links, modify your `api.html`:
238357
href="https://www.django-rest-framework.org/"
239358
class="btn btn-sm btn-square btn-ghost lg:btn-md"
240359
>
241-
<i data-lucide="house" class="size-4 lg:size-6"></i>
360+
<i data-lucide="house" class="size-4 lg:size-6"></i>
242361
<span class="sr-only">{% trans 'Home' %}</span>
243362
</a>
244363
</li>
@@ -260,7 +379,6 @@ To add menu items to profile menu, modify your `api.html`:
260379
</a>
261380
</li>
262381
{% endblock %}
263-
264382
```
265383

266384
### Generating CSS styles
@@ -279,12 +397,19 @@ npx @tailwindcss/cli -i ../static/rest_wind/css/app.css -o ../static/rest_wind/c
279397

280398
## Contributing
281399

282-
We encourage community contributions! Please check our [CONTRIBUTING](CONTRIBUTING.md) guide for detailed instructions on how to contribute effectively. Your input and support play an essential role in the ongoing enhancement of this project.
400+
We encourage community contributions! Please check our
401+
[CONTRIBUTING](CONTRIBUTING.md) guide for detailed instructions on how to
402+
contribute effectively. Your input and support play an essential role in the
403+
ongoing enhancement of this project.
283404

284405
## Support
285406

286-
If you have any questions or require assistance, feel free to open an issue or join our discussions in the [GitHub Discussions](https://github.com/youzarsiph/drf-restwind/discussions) section. We welcome community engagement and cherish your feedback!
407+
If you have any questions or require assistance, feel free to open an issue or
408+
join our discussions in the
409+
[GitHub Discussions](https://github.com/youzarsiph/drf-restwind/discussions)
410+
section. We welcome community engagement and cherish your feedback!
287411

288412
## Licensing
289413

290-
This project is licensed under the MIT License. You can find the full terms of the license in the [LICENSE](LICENSE) file.
414+
This project is licensed under the MIT License. You can find the full terms of
415+
the license in the [LICENSE](LICENSE) file.

rest_wind/templates/rest_framework/base.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ <h1 class="hidden text-xl font-semibold text-primary lg:block">
235235
class="theme-controller"
236236
value="{% block toggle_theme %}light{% endblock %}"
237237
/>
238-
<i data-lucide="sun-icon" class="swap-off size-4 lg:size-6"></i>
239-
<i data-lucide="moon-star-icon" class="swap-on size-4 lg:size-6"></i>
238+
<i data-lucide="sun" class="swap-off size-4 lg:size-6"></i>
239+
<i data-lucide="moon-star" class="swap-on size-4 lg:size-6"></i>
240240
</label>
241241
</li>
242242
</ul>

0 commit comments

Comments
 (0)