Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
Add Laravel 7 support (#15)
Browse files Browse the repository at this point in the history
* Add support for Laravel 7

This requires using laravel/ui to extend preset functionality

* Remove disclaimer

* Update stubs

* Update HomeController.stub

* Update readme

* Fix copy line

* Fix stubs

* Update screenshots
  • Loading branch information
zaknesler authored May 1, 2020
1 parent 9779e7f commit 462431e
Show file tree
Hide file tree
Showing 25 changed files with 572 additions and 492 deletions.
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"name": "zaknesler/tailwind-preset",
"description": "A Tailwind CSS preset for Laravel.",
"keywords": ["laravel", "laravel preset", "preset", "tailwind", "tailwindcss"],
"keywords": ["laravel", "preset", "tailwind", "tailwindcss"],
"license": "MIT",
"authors": [
{
"name": "Zak Nesler",
"email": "contact@zaknesler.com"
"email": "zak@nesler.dev"
}
],
"minimum-stability": "stable",
"require": {
"laravel/framework": "^5.5|^6.0"
"php": "^7.2",
"laravel/ui": "^2.0",
"illuminate/filesystem": "^7.0",
"illuminate/support": "^7.0"
},
"autoload": {
"psr-4": {
Expand Down
83 changes: 41 additions & 42 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,77 @@
## Tailwind CSS Laravel Front-end Preset

[![Latest Stable Version](https://poser.pugx.org/zaknesler/tailwind-preset/v/stable)](https://packagist.org/packages/zaknesler/tailwind-preset)
[![Total Downloads](https://poser.pugx.org/zaknesler/tailwind-preset/downloads)](https://packagist.org/packages/zaknesler/tailwind-preset)
[![License](https://poser.pugx.org/zaknesler/tailwind-preset/license)](https://packagist.org/packages/zaknesler/tailwind-preset)
[![Latest Stable Version](https://poser.pugx.org/zaknesler/tailwind-preset/v/stable)](https://packagist.org/packages/zaknesler/tailwind-preset) [![Total Downloads](https://poser.pugx.org/zaknesler/tailwind-preset/downloads)](https://packagist.org/packages/zaknesler/tailwind-preset) [![License](https://poser.pugx.org/zaknesler/tailwind-preset/license)](https://packagist.org/packages/zaknesler/tailwind-preset)

This is a Laravel front-end preset for [Tailwind CSS](https://tailwindcss.com). This preset replaces the default Bootstrap scaffolding, including the example Vue.js component. It also compiles the assets using [Laravel Mix](https://github.com/jeffreyway/laravel-mix) for convenience and [PurgeCSS](https://github.com/fullhuman/purgecss) to generate the smallest files possible.
A Laravel 7+ front-end preset for [Tailwind CSS](https://tailwindcss.com). This preset comes bundled with Vue.js and an example component, as well as a responsive navigation menu.

> **Deprecation Notice** – As of Laravel 6, all front-end presets have been extracted into the [laravel/ui](https://github.com/laravel/ui) repository. In soon time, a Tailwind preset by the maintainers of Laravel will be created. I will maintain development of this package until a Tailwind preset is created, after which this repository will be archived.
This preset uses Laravel Mix to compile and minify assets. Tailwind 1.4 includes PurgeCSS by default, and this preset is configured to purge the proper files.

> The reason I am confident in doing this is because I would think that an *official* Tailwind CSS preset would include a well-thought, elegant design. If, however, I am not a fan of the design, I would have no problem with continuing to maintain this package.
> This preset is built for Laravel 7 and up. For Laravel 5 or 6, please use [version 5.0](https://github.com/zaknesler/tailwind-preset/tree/a35309799e93fe384d16ead531add16b98b634e1).
**[Live Demo](https://preset.zaknesler.com)** · [Example Repository](https://github.com/zaknesler/tw-preset-demo)

<details>
<summary>View screenshots</summary>

![welcome.blade.php](https://user-images.githubusercontent.com/7189795/59567082-dfddce80-9036-11e9-952d-a535f21478e1.png)

![login.blade.php](https://user-images.githubusercontent.com/7189795/59567081-dfddce80-9036-11e9-8401-257eeb78a07c.png)
<img alt="Welcome page" src="https://user-images.githubusercontent.com/7189795/80769741-37d0d700-8b1c-11ea-9b16-e76fd8cde9f4.png">

![home.blade.php](https://user-images.githubusercontent.com/7189795/59567080-dfddce80-9036-11e9-81be-20044b2b6cd4.png)
<img alt="Login page" src="https://user-images.githubusercontent.com/7189795/80769744-399a9a80-8b1c-11ea-9caf-00783b9acc80.png">

<img alt="Home page" src="https://user-images.githubusercontent.com/7189795/80769745-3acbc780-8b1c-11ea-9010-25d38f9a3288.png">

</details>

### Warning
Laravel presets are meant to be used with a fresh installation of Laravel. Installing this preset will **overwrite** your existing views and assets. Please install with caution.
Laravel presets are meant to be installed onto a fresh instance of Laravel. This preset will **overwrite** your existing views, assets, and Home controller. Please use with caution.

### Installation
To install this preset, you must first require the composer dependency in your application. Laravel will automatically register the service provider for you.

```
composer require zaknesler/tailwind-preset
```
1. Require the composer dependency. Laravel will automatically register the package.

Now, install either the `tailwind` or the `tailwind-auth` preset. The `tailwind-auth` preset includes the authentication scaffolding normally generated when `php artisan make:auth` is executed.
```bash
composer require zaknesler/tailwind-preset --dev
```

```
php artisan preset tailwind
2. Install the preset:

// or
```bash
php artisan ui tailwind --auth
php artisan preset tailwind-auth
```
# Without authentication scaffolding
php artisan ui tailwind
```

> **Note:** If you install the `tailwind-auth` preset on a version of Laravel that is older than 5.7, you may delete the `views/auth/verify.blade.php` file, as it will not be used.

Install the NPM packages using your favorite package manager.
3. Install the npm dependencies using your preferred package manager:

```
yarn // npm install
```
```bash
# Using Yarn
yarn
Now you can compile the assets using any of the Laravel build scripts (dev, prod, watch).
# Using npm
npm install
```

```
yarn dev // npm run dev
```
4. Compile assets:

Ensure that your database is properly configured and migrated, and you're done!
```bash
# Using Yarn
yarn dev
### Localization
# Using npm
npm run dev
```

All of the text in the views that this preset provides are configured to be easily translatable. When you install the `tailwind-auth` preset, the file `en.json` will be copied into your application's `resources/lang` directory.
### Customization

This file includes all of the text found in this package. To update the default English text, simply update the values of any of the key-value pairs. To translate into a different language, duplicate `en.json` and rename it to `{locale}.json`; you can then translate the values into the destination language. For more about localization, please refer to the [Laravel documentation](https://laravel.com/docs/6.x/localization).
Tailwind is built to be fully customizable. The `tailwind.config.js` file that this preset provides includes a handful of customization options to help get you started, including adding [Inter](https://fonts.google.com/specimen/Inter) to the default font stack, as well as a `theme` color palette, as well as configuration for the [Tailwind custom-forms](https://tailwindcss-custom-forms.netlify.app/) plugin.

### EditorConfig
The `theme` color palette, by default, simply destructures Tailwind's blue color palette, but can be easily swapped out for your own color keys. For more information, visit the [Tailwind color customization page](https://tailwindcss.com/docs/customizing-colors).
To ensure proper guide highlighting in your text editor, it is recommended that you add the following to the end of the `.editorconfig` file:
I have tried to design this preset to use as many Tailwind features as possible. This includes using a plugin, overriding default theme values, configuration destructuring, and using PurgeCSS. To get the most out of Tailwind, it is recommended that you take a deep dive into Tailwind's [incredible documentation](https://tailwindcss.com/docs/installation), and more importantly... get your hands dirty with it!

### Localization

```
[{tailwind.config.js,webpack.mix.js}]
indent_style = space
indent_size = 2
```
This preset includes text that is already configured to be easily translated. An `en.json` file will be copied into your application's `resources/lang` directory when you install the authentication scaffolding. This file includes keys for all of the on-screen text found in this preset.
Alternatively, you may reindent both files to use an indent size of four, which is the default in a Laravel project.
To translate these values, duplicate the `en.json` file and rename it to `{language}.json`, and begin translating the values for each `"key": "value"` pair. For more about localization, please refer to the [Laravel documentation](https://laravel.com/docs/6.x/localization).
74 changes: 42 additions & 32 deletions src/Tailwind.php → src/TailwindPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
namespace ZakNesler\TailwindPreset;

use Illuminate\Support\Str;
use Laravel\Ui\Presets\Preset;
use Illuminate\Container\Container;
use Illuminate\Support\Facades\File;
use Illuminate\Foundation\Console\Presets\Preset;
use Illuminate\Filesystem\Filesystem;

class Tailwind extends Preset
class TailwindPreset extends Preset
{
/**
* Setup basic assets.
*
* @return void
*/
private static function setup()
protected static function setup()
{
static::ensureResourceDirectoriesExist();
static::updatePackages();
Expand Down Expand Up @@ -45,15 +45,15 @@ public static function install()
*
* @return void
*/
public static function installWithAuth()
public static function installAuth()
{
static::setup();
static::installAuthRoutes();

static::makeViewDirectories([
'auth/passwords',
'errors',
'layouts/partials',
static::createResourceDirectories([
'views/auth/passwords',
'views/errors',
'views/layouts/partials',
]);

static::installViews('auth', [
Expand All @@ -73,8 +73,13 @@ public static function installWithAuth()
'welcome.stub',
]);

copy(
base_path('vendor/laravel/ui/stubs/migrations/2014_10_12_100000_create_password_resets_table.php'),
base_path('database/migrations/2014_10_12_100000_create_password_resets_table.php')
);

file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());
File::copy(__DIR__.'/stubs/en.stub', resource_path('lang/en.json'));
copy(__DIR__.'/stubs/en.stub', resource_path('lang/en.json'));
}

/**
Expand All @@ -91,40 +96,43 @@ protected static function updatePackageArray(array $packages)
'axios' => '^0.19',
'cross-env' => '^6.0',
'laravel-mix' => '^5.0',
'laravel-mix-purgecss' => '^4.2',
'tailwindcss' => '^1.1',
'tailwindcss' => '^1.4',
'vue' => '^2.6',
'vue-template-compiler' => '^2.6',
];
}

/**
* Create view directories.
* Create directories if they do not already exist.
*
* @param array $directories
* @param array $dirs
* @return void
*/
protected static function makeViewDirectories($directories)
protected static function createResourceDirectories($dirs)
{
foreach ($directories as $directory) {
if (! is_dir($directory = resource_path('views/'.$directory))) {
File::makeDirectory($directory, 0755, true);
$filesystem = new Filesystem;

foreach ($dirs as $dir) {
if (! is_dir($dir = resource_path($dir))) {
$filesystem->makeDirectory($dir, 0755, true);
}
}
}

/**
* Copy the view stubs over to the application and rename them.
*
* @param string $baseDirectory
* @param string $baseDir
* @param array $views
* @return void
*/
protected static function installViews($baseDirectory, $views)
protected static function installViews($baseDir, $views)
{
$filesystem = new Filesystem;

foreach ($views as $view) {
File::copy(
__DIR__.'/stubs/views/'.$baseDirectory.'/'.$view,
$filesystem->copy(
__DIR__.'/stubs/views/'.$baseDir.'/'.$view,
resource_path('views/'.str_replace('stub', 'blade.php', $view))
);
}
Expand Down Expand Up @@ -169,10 +177,12 @@ protected static function compileControllerStub()
*/
protected static function ensureResourceDirectoriesExist()
{
$filesystem = new Filesystem;

collect(['css', 'js/components'])
->each(function ($directory) {
if (! is_dir(resource_path($directory))) {
File::makeDirectory(resource_path($directory), 0755, true);
->each(function ($dir) use ($filesystem) {
if (! is_dir(resource_path($dir))) {
$filesystem->makeDirectory(resource_path($dir), 0755, true);
}
});
}
Expand All @@ -184,13 +194,13 @@ protected static function ensureResourceDirectoriesExist()
*/
protected static function installScripts()
{
File::delete(base_path('webpack.mix.js'));
(new Filesystem)->delete(base_path('webpack.mix.js'));

File::copy(__DIR__.'/stubs/tailwind.stub', base_path('tailwind.config.js'));
File::copy(__DIR__.'/stubs/webpack.stub', base_path('webpack.mix.js'));
copy(__DIR__.'/stubs/tailwind.stub', base_path('tailwind.config.js'));
copy(__DIR__.'/stubs/webpack.stub', base_path('webpack.mix.js'));

File::copy(__DIR__.'/stubs/js/app.stub', resource_path('js/app.js'));
File::copy(__DIR__.'/stubs/js/bootstrap.stub', resource_path('js/bootstrap.js'));
copy(__DIR__.'/stubs/js/app.stub', resource_path('js/app.js'));
copy(__DIR__.'/stubs/js/bootstrap.stub', resource_path('js/bootstrap.js'));
}

/**
Expand All @@ -200,7 +210,7 @@ protected static function installScripts()
*/
protected static function installStyles()
{
File::copy(__DIR__.'/stubs/css/tailwind.stub', resource_path('css/tailwind.css'));
copy(__DIR__.'/stubs/css/tailwind.stub', resource_path('css/tailwind.css'));
}

/**
Expand All @@ -210,7 +220,7 @@ protected static function installStyles()
*/
protected static function updateExampleComponent()
{
File::copy(
copy(
__DIR__.'/stubs/js/components/ExampleComponent.stub',
resource_path('js/components/ExampleComponent.vue')
);
Expand Down
31 changes: 11 additions & 20 deletions src/TailwindServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace ZakNesler\TailwindPreset;

use Laravel\Ui\UiCommand;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\PresetCommand;

class TailwindServiceProvider extends ServiceProvider
{
Expand All @@ -14,28 +14,19 @@ class TailwindServiceProvider extends ServiceProvider
*/
public function boot()
{
PresetCommand::macro('tailwind', function ($command) {
Tailwind::install();
UiCommand::macro('tailwind', function ($command) {
if ($command->option('auth')) {
TailwindPreset::installAuth();
$command->callSilent('ui:controllers');

$this->installMessage($command);
});
$command->info('Tailwind authentication scaffolding installed successfully.');
} else {
TailwindPreset::install();

PresetCommand::macro('tailwind-auth', function ($command) {
Tailwind::installWithAuth();
$command->info('Tailwind scaffolding installed successfully.');
}

$this->installMessage($command);
$command->comment('Please run "yarn && yarn dev" or "npm install && npm run dev" to compile your fresh scaffolding.');
});
}

/**
* Print message after successful installation.
*
* @param \Illuminate\Console\Command $command
* @return void
*/
protected function installMessage($command)
{
$command->info('Tailwind scaffolding installed successfully.');
$command->comment('Please run "yarn && yarn dev" or "npm install && npm run dev" to compile your fresh scaffolding.');
}
}
2 changes: 1 addition & 1 deletion src/stubs/controllers/HomeController.stub
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HomeController extends Controller
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
Expand Down
10 changes: 2 additions & 8 deletions src/stubs/css/tailwind.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@
@tailwind base;
@tailwind components;

@variants focus {
.shadow-transition {
transition: box-shadow 100ms ease-in-out;
}
}

.btn {
@apply px-6 py-3 bg-brand-500 font-semibold text-white rounded-lg border-none appearance-none;
@apply px-6 py-3 bg-brand-500 font-semibold text-white rounded-lg border-none appearance-none transition duration-100 transition-shadow;
}

.btn:hover {
@apply bg-brand-600;
}

.btn:focus {
@apply outline-none shadow-outline shadow-transition;
@apply outline-none shadow-outline;
}

@tailwind utilities;
Loading

0 comments on commit 462431e

Please sign in to comment.