Skip to content

Commit 40c17a1

Browse files
committed
Update README.md
1 parent 3a66d0b commit 40c17a1

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

README.md

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,57 @@
11

22
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1" />](https://supportukrainenow.org)
33

4-
# A package that allows you to use livewire components the same way you would use blade components. Ie, giving it slots, atttributes etc
4+
# X-livewire
55

66
[![Latest Version on Packagist](https://img.shields.io/packagist/v/titonova/x-livewire.svg?style=flat-square)](https://packagist.org/packages/titonova/x-livewire)
77
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/titonova/x-livewire/run-tests?label=tests)](https://github.com/titonova/x-livewire/actions?query=workflow%3Arun-tests+branch%3Amain)
88
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/titonova/x-livewire/Fix%20PHP%20code%20style%20issues?label=code%20style)](https://github.com/titonova/x-livewire/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
99
[![Total Downloads](https://img.shields.io/packagist/dt/titonova/x-livewire.svg?style=flat-square)](https://packagist.org/packages/titonova/x-livewire)
1010

11-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
11+
This package allows you to render livewire components like a blade component, giving it attributes, slots etc.
1212

13-
## Support us
13+
Assuming you wanted to create a livewire component, `alert`, usually you would render the component by:
14+
`<livewire:alert/>`. However, there a few problems.
15+
1. You can't allow slots within the component. That is, this is invalid: `<livewire:alert>Alert</livewire:alert>`.
16+
2. You can't access the `$attributes` bag. Thus, can't access the `$attributes` variable directly.
17+
That is, if you do this: `<livewire:alert title="Alert!"/>`, you can't access the `$title` attribute by `$attributes->get('title')`. Instead, you'd have to make `$title` a public property in the component. Not to mention, other methods on `$attributes` are not accessible. Such as `->merge([])`, `->whereStartsWith()`, etc.
1418

15-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/x-livewire.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/x-livewire)
19+
The creator of livewire, Caleb Porzio has made it clear that [adding slots, attributes etc are not currently on the roadmap](https://github.com/livewire/livewire/issues/68#issuecomment-599012420).
1620

17-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
21+
That's why I created X-livewire.
1822

19-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
23+
With X-Livewire, you can do:
2024

25+
<x-livewire _="alert">
26+
My alert message
27+
</x-livewire>
28+
And, just like with Blade, you can:
29+
1. Access the `$attributes` variable:
30+
`{{ $attributes->get('title') }}`,
31+
2. Access the `$slot` variable:
32+
`{{ $slot }}`
2133
## Installation
2234

2335
You can install the package via composer:
2436

25-
```bash
26-
composer require titonova/x-livewire
27-
```
28-
29-
You can publish and run the migrations with:
30-
31-
```bash
32-
php artisan vendor:publish --tag="x-livewire-migrations"
33-
php artisan migrate
34-
```
35-
36-
You can publish the config file with:
37-
38-
```bash
39-
php artisan vendor:publish --tag="x-livewire-config"
40-
```
41-
42-
This is the contents of the published config file:
43-
44-
```php
45-
return [
46-
];
47-
```
48-
49-
Optionally, you can publish the views using
50-
51-
```bash
52-
php artisan vendor:publish --tag="x-livewire-views"
53-
```
37+
composer require titonova/x-livewire
5438

5539
## Usage
5640

57-
```php
58-
$xLivewire = new Titonova\XLivewire();
59-
echo $xLivewire->echoPhrase('Hello, Titonova!');
60-
```
61-
41+
1. After creating your livewire component, make it extend `XLivewireBaseComponent` rather than `Component`.
42+
ie: `class Alert extends XLivewireBaseComponent{`
43+
2. In the view file of the component, e.g `alert.blade.php` add `@setUpXLivewire` to the top of the file.
44+
3. When you want to render the component:
45+
```Blade
46+
<x-livewire _="alert" title="Warning">
47+
My alert message
48+
</x-livewire>
49+
```
50+
4. You can access the `$slot` and `$attributes` variables just like you would in a Blade component:
51+
```
52+
{{ $slot }}
53+
{{ $attributes->get('title') }}
54+
```
6255
## Testing
6356
6457
```bash

0 commit comments

Comments
 (0)