Skip to content
This repository was archived by the owner on Dec 11, 2021. It is now read-only.

Commit 84ae492

Browse files
committed
Build Dark mode Blade
1 parent bab0af6 commit 84ae492

13 files changed

+547
-5
lines changed

Diff for: src/LaravelPresetDark.php

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
namespace TailwindComponents\LaravelPreset;
4+
5+
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Str;
7+
use Illuminate\Container\Container;
8+
use Illuminate\Filesystem\Filesystem;
9+
use Laravel\Ui\Presets\Preset;
10+
use Symfony\Component\Finder\SplFileInfo;
11+
12+
class LaravelPresetDark extends Preset
13+
{
14+
public static function install()
15+
{
16+
static::updatePackages();
17+
static::updateStyles();
18+
static::updateBootstrapping();
19+
static::updatePagination();
20+
static::removeNodeModules();
21+
}
22+
23+
public static function installAuth()
24+
{
25+
static::scaffoldController();
26+
static::scaffoldAuth();
27+
}
28+
29+
protected static function updatePackageArray(array $packages)
30+
{
31+
return array_merge([
32+
'vue' => '^2.6.11',
33+
'vue-template-compiler' => '^2.6.11',
34+
'laravel-mix' => '^5.0.1',
35+
'tailwindcss' => '^1.4',
36+
'@tailwindcss/custom-forms' => '^0.2',
37+
], Arr::except($packages, [
38+
'bootstrap',
39+
'bootstrap-sass',
40+
'popper.js',
41+
'laravel-mix',
42+
'jquery',
43+
]));
44+
}
45+
46+
protected static function updateStyles()
47+
{
48+
tap(new Filesystem, function ($filesystem) {
49+
$filesystem->deleteDirectory(resource_path('sass'));
50+
$filesystem->delete(public_path('js/app.js'));
51+
$filesystem->delete(public_path('css/app.css'));
52+
53+
if (! $filesystem->isDirectory($directory = resource_path('css'))) {
54+
$filesystem->makeDirectory($directory, 0755, true);
55+
}
56+
});
57+
58+
copy(__DIR__.'/stubs/resources/css/app.css', resource_path('css/app.css'));
59+
}
60+
61+
protected static function updateBootstrapping()
62+
{
63+
copy(__DIR__.'/stubs/tailwind.config.js', base_path('tailwind.config.js'));
64+
65+
copy(__DIR__.'/stubs/webpack.mix.js', base_path('webpack.mix.js'));
66+
67+
copy(__DIR__.'/stubs/resources/js/app.js', resource_path('js/app.js'));
68+
69+
copy(__DIR__.'/stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
70+
71+
(new Filesystem)->copyDirectory(__DIR__.'/stubs/resources/js/components', resource_path('js/components'));
72+
}
73+
74+
protected static function updatePagination()
75+
{
76+
(new Filesystem)->delete(resource_path('views/vendor/paginate'));
77+
78+
(new Filesystem)->copyDirectory(__DIR__.'/stubs/resources/dark/views/vendor/pagination', resource_path('views/vendor/pagination'));
79+
}
80+
81+
protected static function scaffoldController()
82+
{
83+
if (! is_dir($directory = app_path('Http/Controllers/Auth'))) {
84+
mkdir($directory, 0755, true);
85+
}
86+
87+
$filesystem = new Filesystem;
88+
89+
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/Auth')))
90+
->each(function (SplFileInfo $file) use ($filesystem) {
91+
$filesystem->copy(
92+
$file->getPathname(),
93+
app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename()))
94+
);
95+
});
96+
}
97+
98+
protected static function scaffoldAuth()
99+
{
100+
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());
101+
102+
file_put_contents(
103+
base_path('routes/web.php'),
104+
"Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n",
105+
FILE_APPEND
106+
);
107+
108+
tap(new Filesystem, function ($filesystem) {
109+
$filesystem->copyDirectory(__DIR__.'/stubs/resources/dark/views', resource_path('views'));
110+
111+
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/migrations')))
112+
->each(function (SplFileInfo $file) use ($filesystem) {
113+
$filesystem->copy(
114+
$file->getPathname(),
115+
database_path('migrations/'.$file->getFilename())
116+
);
117+
});
118+
});
119+
}
120+
121+
protected static function compileControllerStub()
122+
{
123+
return str_replace(
124+
'{{namespace}}',
125+
Container::getInstance()->getNamespace(),
126+
file_get_contents(__DIR__.'/stubs/controllers/HomeController.stub')
127+
);
128+
}
129+
}

Diff for: src/LightViews.php renamed to src/LaravelPresetLight.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Laravel\Ui\Presets\Preset;
1010
use Symfony\Component\Finder\SplFileInfo;
1111

12-
class LightViews extends Preset
12+
class LaravelPresetLight extends Preset
1313
{
1414
public static function install()
1515
{

Diff for: src/LaravelPresetServiceProvider.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,26 @@ class LaravelPresetServiceProvider extends ServiceProvider
1111
public function boot()
1212
{
1313
UiCommand::macro('tailwindcss', function ($command) {
14-
LightViews::install();
14+
LaravelPresetLight::install();
1515

1616
$command->info('Tailwind CSS scaffolding installed successfully.');
1717

1818
if ($command->option('auth')) {
19-
LightViews::installAuth();
19+
LaravelPresetLight::installAuth();
20+
21+
$command->info('Tailwind CSS auth scaffolding installed successfully.');
22+
}
23+
24+
$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
25+
});
26+
27+
UiCommand::macro('tailwindcss:dark', function ($command) {
28+
LaravelPresetDark::install();
29+
30+
$command->info('Tailwind CSS scaffolding installed successfully.');
31+
32+
if ($command->option('auth')) {
33+
LaravelPresetDark::installAuth();
2034

2135
$command->info('Tailwind CSS auth scaffolding installed successfully.');
2236
}

Diff for: src/stubs/resources/dark/views/auth/#.blade.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="flex items-center justify-center mt-16 mx-6">
5+
<div class="p-6 max-w-sm w-full bg-gray-800 shadow rounded-md">
6+
<h3 class="text-white text-xl text-center">{{ __('Login') }}</h3>
7+
8+
<form class="mt-4" method="POST" action="{{ route('login') }}">
9+
@csrf
10+
11+
<label class="block">
12+
<span class="text-white text-sm">{{ __('E-Mail Address') }}</span>
13+
<input type="email" id="email" name="email" class="form-input mt-1 block w-full rounded-md bg-gray-800 border-gray-700 text-white" value="{{ old('email') }}" required autocomplete="email" autofocus>
14+
15+
@error('email')
16+
<span class="text-sm text-red-500" role="alert">
17+
<strong>{{ $message }}</strong>
18+
</span>
19+
@enderror
20+
</label>
21+
22+
<label class="block mt-3">
23+
<span class="text-white text-sm">{{ __('Password') }}</span>
24+
<input id="password" type="password" class="form-input mt-1 block w-full rounded-md bg-gray-800 border-gray-700 text-white" name="password" required autocomplete="current-password">
25+
26+
@error('password')
27+
<span class="text-sm text-red-500" role="alert">
28+
<strong>{{ $message }}</strong>
29+
</span>
30+
@enderror
31+
</label>
32+
33+
<div class="flex justify-between items-center mt-4">
34+
<div>
35+
<label class="inline-flex items-center">
36+
<input type="checkbox" class="form-checkbox text-blue-500 bg-gray-800 border-gray-600" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
37+
<span class="mx-2 text-gray-200 text-sm">{{ __('Remember Me') }}</span>
38+
</label>
39+
</div>
40+
41+
<div>
42+
@if (Route::has('password.request'))
43+
<a class="block text-sm text-blue-500 hover:underline" href="{{ route('password.request') }}">
44+
{{ __('Forgot Your Password?') }}
45+
</a>
46+
@endif
47+
</div>
48+
</div>
49+
50+
<div class="mt-6">
51+
<button type="submit" class="w-full py-2 px-4 text-center bg-blue-600 rounded-md text-white text-sm hover:bg-blue-500 focus:outline-none">
52+
{{ __('Login') }}
53+
</button>
54+
</div>
55+
</form>
56+
</div>
57+
</div>
58+
@endsection
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="flex items-center justify-center mt-16 mx-6">
5+
<div class="p-6 max-w-sm w-full bg-gray-800 shadow rounded-md">
6+
<h3 class="text-white text-xl text-center">{{ __('Confirm Password') }}</h3>
7+
8+
<p class="text-gray-400 mt-3">{{ __('Please confirm your password before continuing.') }}</p>
9+
10+
<form class="mt-4" method="POST" action="{{ route('password.confirm') }}">
11+
@csrf
12+
13+
<label class="block mt-3">
14+
<span class="text-white text-sm">{{ __('Password') }}</span>
15+
<input id="password" type="password" class="form-input mt-1 block w-full rounded-md bg-gray-800 border-gray-700 text-white" name="password" required autocomplete="current-password">
16+
17+
@error('password')
18+
<span class="text-sm text-red-500" role="alert">
19+
<strong>{{ $message }}</strong>
20+
</span>
21+
@enderror
22+
</label>
23+
24+
<div class="mt-6">
25+
<button type="submit" class="w-full py-2 px-4 text-center bg-blue-600 rounded-md text-white text-sm hover:bg-blue-500 focus:outline-none">
26+
{{ __('Confirm Password') }}
27+
</button>
28+
</div>
29+
</form>
30+
</div>
31+
</div>
32+
@endsection
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="flex items-center justify-center mt-16 mx-6">
5+
<div class="p-6 max-w-sm w-full bg-gray-800 shadow rounded-md">
6+
<h3 class="text-white text-xl text-center">{{ __('Reset Password') }}</h3>
7+
8+
@if (session('status'))
9+
<div class="w-full bg-blue-500 text-white mt-2" role="alert">
10+
<div class="container mx-auto py-4 px-6">
11+
<div class="flex">
12+
<svg viewBox="0 0 40 40" class="h-6 w-6 fill-current">
13+
<path d="M20 3.33331C10.8 3.33331 3.33337 10.8 3.33337 20C3.33337 29.2 10.8 36.6666 20 36.6666C29.2 36.6666 36.6667 29.2 36.6667 20C36.6667 10.8 29.2 3.33331 20 3.33331ZM21.6667 28.3333H18.3334V25H21.6667V28.3333ZM21.6667 21.6666H18.3334V11.6666H21.6667V21.6666Z"></path>
14+
</svg>
15+
16+
<p class="mx-3">{{ session('status') }}</p>
17+
</div>
18+
</div>
19+
</div>
20+
@endif
21+
22+
<form class="mt-4" method="POST" action="{{ route('password.email') }}">
23+
@csrf
24+
25+
<label class="block">
26+
<span class="text-white text-sm">{{ __('E-Mail Address') }}</span>
27+
<input id="email" type="email" class="form-input mt-1 block w-full rounded-md bg-gray-800 border-gray-700 text-white" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
28+
</label>
29+
30+
<div class="mt-6">
31+
<button type="submit" class="w-full py-2 px-4 text-center bg-blue-600 rounded-md text-white text-sm hover:bg-blue-500 focus:outline-none">
32+
{{ __('Send Password Reset Link') }}
33+
</button>
34+
</div>
35+
</form>
36+
</div>
37+
</div>
38+
@endsection
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="flex items-center justify-center mt-16 mx-6">
5+
<div class="p-6 max-w-sm w-full bg-gray-800 shadow rounded-md">
6+
<h3 class="text-white text-xl text-center">{{ __('Reset Password') }}</h3>
7+
8+
<form class="mt-4" method="POST" action="{{ route('password.update') }}">
9+
@csrf
10+
11+
<input type="hidden" name="token" value="{{ $token }}">
12+
13+
<label class="block">
14+
<span class="text-white text-sm">{{ __('E-Mail Address') }}</span>
15+
<input id="email" type="email" class="form-input mt-1 block w-full rounded-md bg-gray-800 border-gray-700 text-white" name="email" value="{{ $email ?? old('email') }}" required autocomplete="email" autofocus>
16+
17+
@error('email')
18+
<span class="text-sm text-red-500" role="alert">
19+
<strong>{{ $message }}</strong>
20+
</span>
21+
@enderror
22+
</label>
23+
24+
<label class="block mt-3">
25+
<span class="text-white text-sm">{{ __('Password') }}</span>
26+
<input id="password" type="password" class="form-input mt-1 block w-full rounded-md bg-gray-800 border-gray-700 text-white" name="password" required autocomplete="new-password">
27+
28+
@error('password')
29+
<span class="text-sm text-red-500" role="alert">
30+
<strong>{{ $message }}</strong>
31+
</span>
32+
@enderror
33+
</label>
34+
35+
<label class="block mt-3">
36+
<span class="text-white text-sm">{{ __('Confirm Password') }}</span>
37+
<input id="password-confirm" type="password" class="form-input mt-1 block w-full rounded-md bg-gray-800 border-gray-700 text-white" name="password_confirmation" required autocomplete="new-password">
38+
</label>
39+
40+
<div class="mt-6">
41+
<button class="w-full py-2 px-4 text-center bg-blue-600 rounded-md text-white text-sm hover:bg-blue-500 focus:outline-none">
42+
{{ __('Reset Password') }}
43+
</button>
44+
</div>
45+
</form>
46+
</div>
47+
</div>
48+
@endsection

0 commit comments

Comments
 (0)