-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nkondrashov
committed
Feb 24, 2024
1 parent
038970b
commit c5171ed
Showing
6 changed files
with
713 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<p align="center"> | ||
<a href="https://github.com/yiisoft" target="_blank"> | ||
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px"> | ||
</a> | ||
<a href="https://htmx.org/" target="_blank" rel="external"> | ||
<img src="https://raw.githubusercontent.com/bigskysoftware/htmx/master/www/static/img/htmx_logo.1.png" height="100px"> | ||
</a> | ||
<h1 align="center">Yii3 Framework htmx simple extension</h1> | ||
<br> | ||
</p> | ||
|
||
This [Yii Framework] extension encapsulates basic functions [htmx] and makes using in Yii applications extremely easy. | ||
|
||
[Yii Framework]: http://www.yiiframework.com/ | ||
[</> htmx]: https://htmx.org/docs/ | ||
|
||
For license information check the [LICENSE](LICENSE.md)-file. | ||
|
||
Installation | ||
------------ | ||
|
||
1. The preferred way to install this extension is through [composer](http://getcomposer.org/download/). | ||
|
||
``` | ||
php composer.phar require --prefer-dist nkondrashov/yii3-htmx | ||
``` | ||
|
||
2. Add `HTMXMiddleware.php` to router. | ||
```php | ||
->middleware(HTMXMiddleware::class) | ||
``` | ||
|
||
3. Register asset in main layout or `AppAsset` | ||
```php | ||
$assetManager->register(HTMXAsset::class); | ||
``` | ||
|
||
Warning! | ||
------------ | ||
4. Add to `<body>` tag attribute `hx-headers='{"X-CSRF-Token":"<?=$csrf; ?>"}'` for success post requests. Like this: | ||
```html | ||
<body hx-headers='{"X-CSRF-Token":"<?=$csrf; ?>"}'> | ||
``` | ||
|
||
## Install assets | ||
|
||
Using the [npm-asset](https://www.npmjs.com/) package manager. | ||
|
||
Run the following command at the root directory of your application. | ||
|
||
```shell | ||
npm i [email protected] | ||
``` | ||
|
||
## General usage | ||
|
||
Examples | ||
------- | ||
|
||
Simple: | ||
```php | ||
<?php | ||
$tag = Yiisoft\Html\Html::button('[ X ]']); | ||
|
||
$htmx = HTMX::make($tag) | ||
->request(Yiisoft\Http\Method::DELETE, '/item/delete/' . $todo->id) | ||
->triggerCustomEventAfterRequest('someCustomEvent') | ||
->setSwap('none') | ||
->runOnClick(); | ||
|
||
if (!$todo->is_complete) { | ||
$htmx->addConfirm('Are you sure?'); | ||
} | ||
|
||
echo $htmx; | ||
?> | ||
``` | ||
|
||
```php | ||
<?= HTMX::make(Yiisoft\Html\Html::tag('div')) | ||
->request(Yiisoft\Http\Method::GET, '/item/index') | ||
->runOnCustomEvent('someCustomEvent', 'someCustomEvent2') | ||
->runOnLoad();?> | ||
``` | ||
|
||
More native: | ||
```php | ||
<?php | ||
$tag = Yiisoft\Html\Html::button('[ X ]']); | ||
|
||
$htmx = HTMX::make($tag) | ||
->request(Yiisoft\Http\Method::DELETE, '/item/delete/' . $todo->id) | ||
->triggerCustomEventAfterRequest('someCustomEvent') | ||
->addTriggers('click') | ||
->setSwap('none'); | ||
|
||
if (!$todo->is_complete) { | ||
$htmx->addConfirm('Are you sure?'); | ||
} | ||
|
||
echo $htmx; | ||
?> | ||
``` | ||
|
||
```php | ||
<?= HTMX::make(Yiisoft\Html\Html::tag('div')) | ||
->request(Yiisoft\Http\Method::GET, '/item/index') | ||
->addTriggers('load','someCustomEvent from:body', 'someCustomEvent2 from:body'); | ||
?> | ||
``` | ||
|
||
Max native: | ||
```php | ||
<?php | ||
$tag = Yiisoft\Html\Html::button('[ X ]']); | ||
|
||
$htmx = HTMX::make($tag) | ||
->setHx('delete', '/item/delete/' . $todo->id) | ||
->triggerCustomEventAfterRequest('someCustomEvent') | ||
->setHx('trigger', 'click') | ||
->setHx('swap', 'none'); | ||
|
||
if (!$todo->is_complete) { | ||
$htmx->setHx('conf', 'Are you sure?'); | ||
} | ||
|
||
echo $htmx; | ||
?> | ||
``` | ||
|
||
```php | ||
<?= HTMX::make(Yiisoft\Html\Html::tag('div')) | ||
->setHx('get', '/item/index') | ||
->setHx('trigger', 'load, someCustomEvent from:body, someCustomEvent2 from:body'); | ||
?> | ||
``` | ||
|
||
|
||
|
||
### Support the Yii3 project | ||
|
||
[](https://opencollective.com/yiisoft) | ||
|
||
### Follow Yii3 updates | ||
|
||
[](https://www.yiiframework.com/) | ||
[](https://twitter.com/yiiframework) | ||
[](https://t.me/yii3en) | ||
[](https://www.facebook.com/groups/yiitalk) | ||
[](https://yiiframework.com/go/slack) | ||
|
||
## License | ||
|
||
The Yii Framework htmx Extension is free software. It is released under the terms of the BSD License. | ||
Please see [`LICENSE`](./LICENSE.md) for more information. | ||
|
||
This package maintained by Me ¯\_(ツ)_/¯ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "nkondrashov/yii3-htmx", | ||
"type": "library", | ||
"description": "htmx extension for Yii Framework", | ||
"keywords": [ | ||
"yii", | ||
"htmx" | ||
], | ||
"require": { | ||
"php": "^8.1", | ||
"yiisoft/arrays": "^1.0|^2.0|^3.0", | ||
"yiisoft/assets": "^4.0", | ||
"yiisoft/files": "^2.0", | ||
"yiisoft/html": "^3.0", | ||
"yiisoft/json": "^1.0" | ||
}, | ||
"license": "BSD-3-Clause", | ||
"autoload": { | ||
"psr-4": { | ||
"Nkondrashov\\Yii3\\Htmx\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "nkondrashov" | ||
} | ||
], | ||
"minimum-stability": "stable" | ||
} |
Oops, something went wrong.