Skip to content

Commit

Permalink
Adding more content to theme
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed Aug 17, 2024
1 parent a6d06dd commit 3ae3778
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 29 deletions.
3 changes: 3 additions & 0 deletions collections/themes.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
{
"name" : "Anchor",
"cover" : "https://cdn.devdojo.com/images/august2024/theme-anchor.jpeg",
"download" : "",
"slug" : "anchor",
"description": "Anchor is the default theme available. This theme is clean with a sidebar app layout design.",
"repo" : "https://github.com/thedevdojo/wave"
},
{
"name" : "Blank",
"cover" : "https://cdn.devdojo.com/images/august2024/theme-blank.jpeg",
"download" : "https://github.com/thedevdojo/blank/archive/refs/heads/main.zip",
"slug" : "blank",
"description": "This is a minimal blank theme that can be used to easily modify. It also contains a sidebar app layout.",
"repo" : "https://github.com/thedevdojo/wave"
},
{
"name" : "Cove",
"cover" : "https://cdn.devdojo.com/images/august2024/theme-cove.jpeg",
"download" : "https://github.com/thedevdojo/cove/archive/refs/heads/main.zip",
"slug" : "cove",
"description": "This blue colored theme is a good template for showcasing your SaaS. Top bar app layout",
"repo" : "https://github.com/thedevdojo/wave"
Expand Down
107 changes: 92 additions & 15 deletions content/docs/features/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,119 @@ title: Themes
description: Learn how to use themes
prevTitle: 'Admin'
prevURL: '/docs/features/admin'
nextTitle: null
nextURL: null
nextTitle: 'Volt Pages'
nextURL: '/docs/features/volt'
---

# Themes

Wave has Theme support, which means that when you start a new project you may choose between a few themes to get your application up and running. This also means that you can choose to create different versions of your theme and swap between these different versions by activating and de-activating specific versions.
Wave allows you to customize the look and feel of your application through a flexible and easy-to-use theme system.

- [Themes](#themes)
- [Theme Views](#theme-views)
- [Theme Assets](#theme-assets)
- [Compiling Assets \& HMR](#compiling-assets--hmr)
- [Building Assets](#building-assets)
- [How Does It Work](#how-does-it-work)
- [Selecting Themes](#selecting-themes)
- [Download Themes](#download-themes)
- [Installing Themes](#installing-themes)
- [Activate Theme](#activate-theme)
- [Digging Deeper](#digging-deeper)


In this section you will learn where the themes are located and how to activate a specific theme.

## Theme Location
## Theme Views

All the views that you need for your application will live inside your `resources/themes/{theme}` folder. When you install Wave, the default theme `anchor` is activated. Therefore all you theme files will be located at `resources/themes/anchor`.

The active theme location is registered in the `theme` view namespace, so as an example if you wanted to reference a `home.blade.php` file inside the active theme you can return a view like so:

```php
return view('theme::home');
```

That will return the view located at `resources/themes/anchor/home.blade.php`.

## Theme Assets

Every theme will have it's own assets located at the following locations:

1. `resources/themes/{theme}/assets/css/app.css`
2. `resources/themes/{theme}/assets/js/app.js`

When you run your asset watchers and builder using `npm` it will look at these files.

### Compiling Assets & HMR

Every theme is located inside of the `resources/themes` folder. When you install Wave there will be 1 theme available, which is the anchor theme. In each theme you will find a `theme.json` file which contains the name of the theme as well as the specific version, like so:
You can use the common `npm run dev` command to compile your assets and serve them up from your current theme. Running `npm run dev` also supports Hot Module Reloading so when you make a change to any theme file, your assets will automatically be compiled and the browser will refresh.

### Building Assets

When you want to build your assets for production you will run `npm run build`. Wave utilizes the same commands that a default Laravel application supports. You may want to learn more about how to customize and modify your asset builder by visiting the <a href="https://laravel.com/docs/vite" target="_blank">Laravel Vite</a> documentation.

### How Does It Work

You may want to know how the asset bundler works in case you need to debug an issue or implement some additional functionality. When you **Activate** a theme, a new file called `theme.json` will be stored in the root of your directory containing something like the following:

```json
{
"name": "Anchor",
"version": "1.0"
"name": "anchor"
}
```

### Creating a Theme
This file stores the currently active theme inside of the `theme.json` file. This will be used inside our `vite.config.js`, file like so:

```js
const themeFilePath = path.resolve(__dirname, 'theme.json');
const activeTheme = fs.existsSync(themeFilePath) ? JSON.parse(fs.readFileSync(themeFilePath, 'utf8')).name : 'anchor';
console.log(`Active theme: ${activeTheme}`);

export default defineConfig({
plugins: [
laravel({
input: [
`resources/themes/${activeTheme}/assets/css/app.css`,
`resources/themes/${activeTheme}/assets/js/app.js`,
'resources/css/filament/admin/theme.css',
],
refresh: [
`resources/themes/${activeTheme}/**/*`,
],
}),
],
});
```

### Downloading a Theme
As you can see the `vite` config will read this file to find the currently active theme and then it will compile those assets.

## Theme Assets
## Selecting Themes

When you want to select a new theme to use, you will need to download and install the specific theme and then you'll need to login to the admin section and activate that theme.

To compile a theme's assets you can navigate into the theme folder and run `npm install`, after you install the node dependencies you can run `npm run watch` to start your asset watcher and develop your theme. When you are ready to compile and minify your assets for production you will want to run `npm run production`.
### Download Themes

## Activating Themes
Visit the <a href="{ url('/themes') }" target="_blank">Themes Page</a> from this website and you'll see a list of available themes to download. Be sure to return to this page often as we'll be releasing many more themes down the road. After you download the theme you'll need to install it (movie the contents).

If you are logged in as an admin user and you visit visit the <a href="/admin/themes" target="_blank">`/admin/themes`</a> section of your application you’ll see the current themes available in your app.
### Installing Themes

![themes](https://cdn.devdojo.com/images/may2021/themes.png)
Installing themes are really simple. After you <a href="{ url('/themes') }" target="_blank">download the theme</a> you want to use make sure to extract the theme and move the contents of that folder to the `resources/themes` directory. So, for example if you download the `blank` theme, you should have a new theme folder located at `resources/themes/blank` and all the contents of that theme should be inside that folder.

> You will want to rename the folder to be the name of the theme. As an example if you download the blank theme and it has a folder name of `blank-main`, you'll want to rename it to be `blank`.
### Activate Theme

Now that you have the theme installed, you'll need to head to the admin to activate it. Be sure to login as your admin user and visit <a href="/admin/themes" target="_blank">`/admin/themes`</a> and you’ll see the current themes available in your app.

<img src="https://cdn.devdojo.com/images/august2024/activate-theme.png" class="w-full" alt="Wave Activate Theme" />

To activate a Theme you can simply click the Activate button for the current theme you would like to activate, and that will be the current active theme.

> Important: After activating a theme you will need to make sure that you stop your asset watcher `npm run dev` and re-run it after the new theme has been activated. This is because we need the asset watcher to look in the correct directory.
## Digging Deeper

Visit the Creating Themes guide to learn more about how simple it can be to create your own theme. Additionally if you want to source dive you can check out the DevDojo Themes package here.

For more information on customizing and modifying themes, you may want to check out the <a href="https://devdojo.com/wave/videos" target="_blank">Wave Videos</a> to learn more about how you can customize and build new themes for your application.
Next, we'll talk about Volt pages. Because as you can see that each theme also has a `pages` directory. Any file that you place in that directory will automatically be mapped to a route. Let's talk more about that next.
125 changes: 125 additions & 0 deletions content/docs/features/volt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
title: Vole Pages
description: Learn how to use volt pages in your themes
prevTitle: 'Themes'
prevURL: '/docs/features/themes'
nextTitle: null
nextURL: null
---

# Volt Pages

When you create/install a new theme, the `pages` directory. Let's discuss more about how this works below:

- [Volt Pages](#volt-pages)
- [Pages Directory and Folio](#pages-directory-and-folio)
- [Single File Volt Pages](#single-file-volt-pages)


### Pages Directory and Folio

We are utilizing <a href="https://laravel.com/docs/folio" target="_blank">Laravel Folio</a> to make it easy to create new routes and pages in your app. When you add a new file to the `pages` directory. For example, if we add a file called `about.blade.php` our application will now have a new route at `/about` which is mapped to that file. Here is a list of how files can map to URL's.

| **File** | **Route** |
|----------------------------------|-----------------------------|
| `pages/index.blade.php` | `/` (Homepage) |
| `pages/about.blade.php` | `/about` |
| `pages/about/index.blade.php` | `/about` |
| `pages/blog/index.blade.php` | `/blog` |
| `pages/blog/show.blade.php` | `/blog/show` |
| `pages/blog/[post].blade.php` | `/blog/{post}` (Dynamic) |
| `pages/contact.blade.php` | `/contact` |
| `pages/services/web.blade.php` | `/services/web` |
| `pages/[category]/index.blade.php`| `/{category}` (Dynamic) |
| `pages/[category]/[id].blade.php`| `/{category}/{id}` (Dynamic)|

You will want to learn more about how Folio works by checking out the official <a href="https://laravel.com/docs/folio" target="_blank">documentation here</a>.

### Single File Volt Pages

We are utilizing Laravel Livewire in every theme. This means that you can add Volt functionality to any page you create inside the `resources/themes/{theme}/pages` directory.

Here's a simple version `todos` Volt single-file component:

```php
<?php

use function Laravel\Folio\{middleware, name};
use Livewire\Volt\Component;
use Livewire\Attributes\Rule;
use Livewire\Attributes\Computed;
name('todos');

new class extends Component
{
public $todos;

#[Rule('required')]
public $todo;

public function mount()
{
$this->todos = [
['todo' => 'Install Wave Application', 'completed' => true,],
['todo' => 'Read the documentation', 'completed' => false,],
['todo' => 'Learn how to use folio and volt', 'completed' => false,],
['todo' => 'Add the todos single-file volt component', 'completed' => false,],
['todo' => 'See how simple Wave will make your life', 'completed' => false,]
];
}

public function add()
{
$this->validate();

$this->todos[] = [
'todo' => $this->todo,
'completed' => false,
];

$this->reset('todo');
}

#[Computed]
public function remaining()
{
return collect($this->todos)->where('completed', false)->count();
}
}
?>

<x-layouts.marketing>
@volt('todos')
<div class="flex justify-center items-center px-16 py-20 w-full h-full text-gray-300 bg-gray-100">
<div class="p-10 bg-white rounded">
<h2 class="text-base font-semibold leading-7 text-gray-900">My Todo</h2>
<p class="mt-1 text-sm leading-6 text-gray-500">You have {{ $this->remaining }} things on your todo list.</p>

<div class="mt-4 space-y-3">
@foreach($todos as $todo)
<div class="flex relative items-start">
<div class="flex items-center h-6">
<input id="todo-{{ $loop->index }}" wire:model.live="todos.{{ $loop->index }}.completed" type="checkbox" value="1" class="w-4 h-4 text-indigo-600 rounded border-gray-300 focus:ring-indigo-600">
</div>
<div class="ml-3 text-sm leading-6">
<label for="todo-{{ $loop->index }}" class="font-medium text-gray-900">{{ $todo['todo'] }}</label>
</div>
</div>
@endforeach
</div>

<form wire:submit="add" class="mt-6">
<input type="text" wire:model="todo" placeholder="My new todo..." class="block py-1.5 w-full text-gray-900 rounded-md border-0 ring-1 ring-inset ring-gray-300 shadow-sm placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
</form>
</div>
</div>
@endvolt
</x-layouts.marketing>
```

If you add this file to `resources/themes/anchor/todos.blade.php` you'll be able to visit the todos page at your app URL `/todos`, and see a page that looks like this:

<img src="https://cdn.devdojo.com/images/august2024/todos-component.png" class="w-full" alt="Single-file Todos Component" />

Be sure to learn more about Volt page by visiting the <a href="https://livewire.laravel.com/docs/volt" target="_blank">full documentation here</a>.

Loading

0 comments on commit 3ae3778

Please sign in to comment.