Skip to content

Commit 0f919f6

Browse files
committed
1 parent e454ee8 commit 0f919f6

36 files changed

+1275
-1
lines changed

README.md

Lines changed: 408 additions & 1 deletion
Large diffs are not rendered by default.

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "php-templates/bootstrap5",
3+
"license": "MIT",
4+
"description": "Php Templates bootstrap5 components",
5+
"keywords": ["php", "templates"],
6+
"homepage": "https://github.com/php-templates/bootstrap5",
7+
"authors": [
8+
{
9+
"name": "Florin Botea",
10+
"homepage": "https://github.com/florin-botea",
11+
"role": "Developer"
12+
}
13+
],
14+
"autoload": {
15+
"psr-4": {
16+
"PhpTemplates\\": "src/"
17+
}
18+
},
19+
"require": {
20+
"php-templates/php-templates": "^1.0"
21+
}
22+
}

composer.lock

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Bootstrap.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace PhpTemplates;
4+
5+
use PhpTemplates\Template;
6+
7+
class Bootstrap
8+
{
9+
private $components;
10+
11+
public function mount(Template $template, $options = [])
12+
{
13+
$prefix = isset($options['prefix']) ? $options['prefix'] : 'b-';
14+
$cfg = $template->subconfig('bootstrap', __DIR__ . '/bootstrap/');
15+
foreach ($this->getCached() as $alias => $rfilepath) {
16+
// echo $prefix.$alias . ' => ' . $rfilepath . PHP_EOL;
17+
18+
$template->setAlias($prefix.$alias, $rfilepath);
19+
}
20+
}
21+
22+
private function getCached()
23+
{
24+
$cache = __DIR__ . '/cache.json';
25+
if (!file_exists($file) || !json_decode(file_get_contents($file)) || 1) {
26+
$json = [];
27+
// components
28+
$files = $this->recursiveScanDir(__DIR__ . '/bootstrap/components/');
29+
foreach ($files as $file) {
30+
$rfilepath = explode(DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR, str_replace('.t.php', '', $file))[1];
31+
$alias = explode(DIRECTORY_SEPARATOR, $rfilepath); $alias = end($alias);
32+
$json[$alias] = 'bootstrap:' . $rfilepath;
33+
}
34+
// forms
35+
$files = $this->recursiveScanDir(__DIR__ . '/bootstrap/forms/');
36+
foreach ($files as $file) {
37+
$rfilepath = explode(DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR, str_replace('.t.php', '', $file))[1];
38+
$alias = explode(DIRECTORY_SEPARATOR, $rfilepath); $alias = end($alias);
39+
$json[$alias] = 'bootstrap:' . $rfilepath;
40+
}
41+
42+
file_put_contents($cache, json_encode($json));
43+
}
44+
45+
return json_decode(file_get_contents($cache), true);
46+
}
47+
48+
private function recursiveScanDir(string $path, array &$payload = [])
49+
{
50+
$files = array_diff(scandir($path), array('.', '..'));
51+
foreach($files as $file){
52+
$file = rtrim($path, DIRECTORY_SEPARATOR) . '/' . $file;
53+
if (is_file($file)) {
54+
if (strpos($file, '.t.php')) {
55+
$payload[] = $file;
56+
}
57+
} else {
58+
$this->recursiveScanDir($file, $payload);
59+
}
60+
}
61+
62+
return $payload;
63+
}
64+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@php
2+
$id = $id ?? 'accordion-' . md5(json_encode($items));
3+
@endphp
4+
<div class="accordion" :id="$id" :class="$open ? 'open' : ''" :class="$class">
5+
<div class="accordion-item" p-foreach="$items as $k => $val">
6+
<h2 class="accordion-header" :id="'ah-'.$k">
7+
<button class="accordion-button" type="button" data-bs-toggle="collapse" :data-bs-target="'#ac-'.$k" :aria-expanded="(!$value && $loop->isFirst()) || $k == $value ? 'true' : 'false'" :aria-controls="$k">
8+
{{ $val }}
9+
</button>
10+
</h2>
11+
<div :id="'ac-'.$k" class="accordion-collapse collapse" :class="(!$value && $loop->isFirst()) || $k == $value ? 'show' : ''" :aria-labelledby="'ah-'.$k" p-raw="$toggle ? 'data-bs-parent=\"#'.$id.'\"' : ''">
12+
<div class="accordion-body">
13+
@php $this->slots($k) && reset($this->slots($k))([]); @endphp
14+
</div>
15+
</div>
16+
</div>
17+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<div class="alert" role="alert" :class="['alert-'.$type, !empty($dismiss) ? 'alert-dismissible fade show' : '']">
2+
<div class="d-flex">
3+
<div class="d-flex align-items-center pe-1" p-if="!isset($icon) || $icon">
4+
<slot name="icon">
5+
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-exclamation-triangle-fill flex-shrink-0 me-2" viewBox="0 0 16 16" role="img" aria-label="Warning:">
6+
<path p-if="in_array($type, ['warning', 'danger'])" d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
7+
<path p-elseif="in_array($type, ['success'])" d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
8+
<path p-elseif="in_array($type, ['info', 'primary', 'secondary', 'light', 'dark'])" d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm.93-9.412-1 4.705c-.07.34.029.533.304.533.194 0 .487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703 0-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381 2.29-.287zM8 5.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2z"/>
9+
</svg>
10+
</slot>
11+
</div>
12+
<div class="flex-fill">
13+
<slot name="title">
14+
<h4 p-if="$title" class="alert-heading">{{ $title }}</h4>
15+
</slot>
16+
<slot></slot>
17+
</div>
18+
</div>
19+
<button p-if="!empty($dismiss)" type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
20+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<span :class="'badge '.$class.' bg-'.$v">
2+
<slot></slot>
3+
</span>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<nav aria-label="breadcrumb" :class="$class">
2+
<ol class="breadcrumb">
3+
<tpl p-foreach="$items as $item">
4+
<li p-if="!$loop->isLast()" class="breadcrumb-item"><a :href="$item['value']">{{ $item['label'] }}</a></li>
5+
<li p-else class="breadcrumb-item active" aria-current="page">{{ $item['label'] }}</li>
6+
</tpl>
7+
</ol>
8+
</nav>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@php
2+
$_attrs = $_context->except(['href','v','class','size','disabled']);
3+
@endphp
4+
<a p-if="$href" :class="['btn btn-'.$v, $class, $size ? 'btn-'.$size : '', $disabled ? 'disabled' : '']" :href="$href" role="button" p-bind="$disabled ? ['aria-disabled' => 'true', 'tabindex' => '-1'] : []" p-bind="$_attrs">
5+
<slot></slot>
6+
</a>
7+
<button p-else :class="['btn btn-'.$v, $class, $size ? 'btn-'.$size : '']" p-bind="$_attrs" p-disabled="$disabled">
8+
<slot></slot>
9+
</button>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@php
2+
$_attrs = $_context->except(['$img','alt','header','footer']);
3+
@endphp
4+
5+
<div class="card" p-bind="$_attrs">
6+
<img p-if="$img" :src="$img" class="card-img-top" :alt="$alt">
7+
<div p-if="$header || $this->slots('header')" class="card-header">
8+
<slot name="header">{{ $header }}</slot>
9+
</div>
10+
<slot name="above"></slot>
11+
<div class="card-body">
12+
<slot></slot>
13+
</div>
14+
<slot name="below"></slot>
15+
<div p-if="$footer || $this->slots('footer')" class="card-footer">
16+
<slot name="footer">{{ $footer }}</slot>
17+
</div>
18+
</div>

0 commit comments

Comments
 (0)