PHP code example of tilabs / manet
1. Go to this page and download the library: Download tilabs/manet library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tilabs / manet example snippets
use Tilabs\Manet\Facades\Manet;
// Simple class addition
$classes = Manet::classList()->add('p-4 rounded shadow');
// Output: "p-4 rounded shadow"
// Chaining add()
$classes = Manet::classList()
->add('text-blue-500')
->add('font-bold');
// Output: "text-blue-500 font-bold"
// Initial classes
$classes = Manet::classList('base-class another-base')
->add('extra-class');
// Output: "base-class another-base extra-class"
$classes = Manet::classList()->add(['p-4', 'bg-gray-100', 'rounded']);
// Output: "p-4 bg-gray-100 rounded"
$isActive = true;
$hasError = false;
$classes = Manet::classList('btn')
->add([
'btn-active' => $isActive,
'btn-primary' => $isActive && !$hasError,
'btn-danger' => $hasError,
'opacity-50' => !$isActive,
]);
// If $isActive = true, $hasError = false: "btn btn-active btn-primary"
// If $isActive = false, $hasError = true: "btn btn-danger opacity-50"
$isPrimary = true;
$isLarge = false;
$classes = Manet::classList('button')
->when($isPrimary, 'button-primary')
->when($isLarge, 'button-large', 'button-medium'); // Optional default if condition is false
// If $isPrimary = true, $isLarge = false: "button button-primary button-medium"
$userType = 'admin';
$classes = Manet::classList('user-profile')
->when($userType === 'admin', function ($classBuilder) {
return $classBuilder->add('bg-red-500 text-white p-2');
})
->when($userType === 'editor', function ($classBuilder) {
return $classBuilder->add('bg-yellow-300 p-1');
});
// If $userType = 'admin': "user-profile bg-red-500 text-white p-2"
$isDisabled = false;
$classes = Manet::classList('form-input')
->unless($isDisabled, 'focus:ring-2 focus:ring-blue-500');
// If $isDisabled = false: "form-input focus:ring-2 focus:ring-blue-500"
$isComplete = true;
$classes = Manet::classList('task-item')
->unless($isComplete, function ($classBuilder) {
return $classBuilder->add('border-l-4 border-orange-400');
});
// If $isComplete = true: "task-item"
// If $isComplete = false: "task-item border-l-4 border-orange-400"
bash
php artisan vendor:publish --tag=tilabs-manet-tests