Skip to content

Commit

Permalink
fix: Livewire components without publishing (#9)
Browse files Browse the repository at this point in the history
* feat: Before testing the no-publishing method

* fix: Sidebar and navbar works without publishing

* docs: Moved the npm above publishing

* feat: Vite to build app.sass and sidebar.sass

* fix: Background image instead of color
  • Loading branch information
achyutkneupane authored Dec 28, 2023
1 parent a738763 commit 4016adb
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 59 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ You can install the package via composer:
composer require achyutn/laravel-dashboard
```

You can publish the views and config file with:
Install `sass` and `bootstrap` to your project:

```bash
php artisan vendor:publish --provider="AchyutN\Dashboard\DashboardServiceProvider"
npm install sass bootstrap
```

Install `sass` and `bootstrap` to your project:
You can publish the views and config file with:

```bash
npm install sass bootstrap
php artisan vendor:publish --provider="AchyutN\Dashboard\DashboardServiceProvider"
```

## Usage

You can simply customize the dashboard by editing the `config/dashboard.php` file.
You can simply customize the dashboard by editing the [config/dashboard.php](config/dashboard.php) file.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"rappasoft/laravel-livewire-tables": "^3.1.5|^2.15.0",
"spatie/laravel-medialibrary": "^11.0.0",
"laravel/framework": "^v10.38.0",
"laravel/ui": "^4.3.0"
"laravel/ui": "^4.3.0",
"ext-json": "*"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion config/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Background for the sidebar
* options => 'image' or 'color'
*/
'background' => 'color',
'background' => 'image',

/**
* background color for the sidebar
Expand Down
30 changes: 15 additions & 15 deletions src/DashboardServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace AchyutN\Dashboard;

use AchyutN\Dashboard\Livewire\Navbar;
use AchyutN\Dashboard\Livewire\Sidebar;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;

class DashboardServiceProvider extends ServiceProvider
{
Expand All @@ -13,6 +16,12 @@ class DashboardServiceProvider extends ServiceProvider
*/
public function boot()
{
/**
* Register Livewire components
*/
Livewire::component('sidebar', Sidebar::class);
Livewire::component('navbar', Navbar::class);

/**
* Load views from the package
*
Expand Down Expand Up @@ -47,24 +56,9 @@ public function boot()
$livewire_version = (int)substr($livewire_version, 1);

$viewPath = $livewire_version >= 3 ? 'components/' : '';
$compPath = $livewire_version >= 3 ? '' : 'Http/';

if($livewire_version >= 3) {
$this->publishes([
__DIR__.'/LiveWire/Sidebar.php' => app_path('Livewire/Components/Sidebar.php'),
__DIR__.'/LiveWire/Navbar.php' => app_path('Livewire/Components/Navbar.php'),
]);
} else {
$this->publishes([
__DIR__.'/LiveWire/Sidebarv2.php' => app_path('Http/Livewire/Components/Sidebar.php'),
__DIR__.'/LiveWire/Navbarv2.php' => app_path('Http/Livewire/Components/Navbar.php'),
]);
}

$this->publishes([
__DIR__.'/../config/dashboard.php' => config_path('dashboard.php'),
__DIR__.'/views/sidebar.blade.php' => resource_path('views/livewire/components/sidebar.blade.php'),
__DIR__.'/views/navbar.blade.php' => resource_path('views/livewire/components/navbar.blade.php'),
__DIR__.'/views/layout.blade.php' => resource_path('views/'.$viewPath.'layouts/app.blade.php'),

__DIR__.'/sass/_variables.scss' => resource_path('sass/_variables.scss'),
Expand All @@ -82,6 +76,12 @@ public function boot()
$bootstrap_js = "import 'bootstrap';\n" . $bootstrap_js;
file_put_contents(resource_path('js/bootstrap.js'), $bootstrap_js);
}

$vite = file_get_contents(base_path('vite.config.js'));
if(strpos($vite, "resources/sass/app.scss") === false) {
$vite = str_replace("input: ['resources/css/app.css', 'resources/js/app.js'],", "input: ['resources/sass/app.scss', 'resources/css/app.css', 'resources/js/app.js', 'resources/sass/sidebar.scss'],", $vite);
file_put_contents(base_path('vite.config.js'), $vite);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Livewire/Navbar.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Livewire\Components;
namespace AchyutN\Dashboard\Livewire;

use Livewire\Component;

Expand All @@ -13,6 +13,6 @@ public function mount($title)
}
public function render()
{
return view('livewire.components.navbar');
return app('view')->make('dashboard::navbar');
}
}
18 changes: 0 additions & 18 deletions src/Livewire/Navbarv2.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Livewire/Sidebar.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace App\Livewire\Components;
namespace AchyutN\Dashboard\Livewire;

use Livewire\Component;

class Sidebar extends Component
{
public function render()
{
return view('livewire.components.sidebar');
return app('view')->make('dashboard::sidebar');
}
}
13 changes: 0 additions & 13 deletions src/Livewire/Sidebarv2.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/views/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
<body>
<div id="app" class="vh-100 d-flex flex-row overflow-hidden">
@auth
@livewire('components.sidebar')
<livewire:sidebar />
@endauth
<main class="position-absolute body-comp top-0">
@auth
@livewire('components.navbar', ['title' => app()->view->getSections()['page_title'] ?? 'Undefined'])
<livewire:navbar :title="app()->view->getSections()['page_title'] ?? 'Undefined'" />
<div class="container-fluid w-100">
{{ $slot }}
</div>
Expand Down

0 comments on commit 4016adb

Please sign in to comment.