shawe / laravel-bs5-components
Laravel Bootstrap Blade组件。这是一个基于https://github.com/bastinald/laravel-bootstrap-components的分支,增加了更多需要的组件。所有荣誉归Kevin Dion。
Requires
- laravel/framework: ^11.0
This package is auto-updated.
Last update: 2024-09-11 18:54:38 UTC
README
此包包含一组有用的Bootstrap Laravel Blade组件。它促进了DRY原则,并允许您保持HTML的整洁。组件包括警报、徽章、按钮、表单输入(带自动错误反馈)、下拉菜单、导航、分页(响应式)等。组件内置了Laravel Livewire集成,因此您可以使用Livewire或无Livewire来使用它们。
文档
要求
- Bootstrap 5必须首先通过webpack安装
- 必须安装Font Awesome才能使用图标
安装
使用Composer要求该包
composer require shawe/laravel-bs5-components
组件
手风琴
一个Bootstrap手风琴
<x-bs::accordion id="accordionExample"> <x-bs::accordion-item id="accordionExample" target="collapseOne" :header="__('Section 1')" active> <p>Section 1 content...</p> </x-bs::accordion-item> <x-bs::accordion-item id="accordionExample" target="collapseTwo" :label="__('Section 2')"> <p>Section 2 content...</p> </x-bs::accordion-item> </x-bs::accordion>
可用的属性 & 插槽
body
: 手风琴主体内容,也可以放置在slot
中
手风琴项
一个Bootstrap手风琴项
<x-bs::accordion-item id="accordionExample" target="collapseOne" :header="__('Section 1')" active> <p>Section 1 content...</p> </x-bs::accordion-item>
可用的属性 & 插槽
header
: 手风琴头部文本body
: 手风琴主体内容,也可以放置在slot
中active
: 将手风琴项设置为活动状态
警报
一个Bootstrap警报
<x-bs::alert :label="__('It was successful!')" color="info" dismissible />
可用的属性 & 插槽
icon
: 在标签之前显示的Font Awesome图标,例如cog
、envelope
label
: 要显示的标签,也可以放置在slot
中color
: Bootstrap颜色,例如primary
、danger
、success
dismissible
: 将警报设置为可取消
徽章
一个Bootstrap徽章
<x-bs::badge :label="__('Pending')" color="warning" />
可用的属性 & 插槽
icon
: 在标签之前显示的Font Awesome图标,例如cog
、envelope
label
: 要显示的标签,也可以放置在slot
中color
: Bootstrap颜色,例如primary
、danger
、success
面包屑
一个Bootstrap面包屑
<x-bs::breadcrumb> <li class="breadcrumb-item"> <x-bs::link :label="__('Home')" route="home" /> </li> <li class="breadcrumb-item"> <x-bs::link :label="__('Library')" route="library" /> </li> <li class="breadcrumb-item"> <x-bs::link class="active" :label="__('Data')" /> </li> </x-bs::breadcrumb>
按钮
一个Bootstrap按钮
<x-bs::button :label="__('Login')" color="primary" size="lg" route="login" />
可用的属性 & 插槽
icon
: 在标签之前显示的Font Awesome图标,例如cog
、envelope
label
: 要显示的标签,也可以放置在slot
中color
: Bootstrap颜色,例如primary
、danger
、success
size
: Bootstrap按钮大小,例如sm
、lg
type
: 按钮类型,例如button
、submit
route
: 将href
设置为路由url
: 将href
设置为URLhref
: 设置href
dismiss
:data-bs-dismiss
的值,例如alert
、modal
toggle
:data-bs-toggle
的值,例如collapse
、dropdown
click
: 点击时的Livewire操作confirm
: 点击时提示用户确认
卡片
一个Bootstrap卡片
<x-bs::card> <x-slot name="header"> <h5>Card Title</h5> </x-slot> <x-slot name="body"> <p>Card body content...</p> </x-slot> <x-slot name="footer"> <button class="btn btn-primary">Card footer button</button> </x-slot> </x-bs::card>
可用的属性 & 插槽
header
: 卡片头部内容body
: 卡片主体内容,也可以放置在slot
中footer
: 卡片底部内容
轮播
一个Bootstrap轮播
@php($images = [ [ 'src' => 'https://via.placeholder.com/800x400?text=First+slide', 'alt' => 'First slide', 'caption' => 'First slide caption', ], [ 'src' => 'https://via.placeholder.com/800x400?text=Second+slide', 'alt' => 'Second slide', 'caption' => 'Second slide caption', ], [ 'src' => 'https://via.placeholder.com/800x400?text=Third+slide', 'alt' => 'Third slide', 'caption' => 'Third slide caption', ], ]) <x-bs::carousel :images="$images" />
可用的属性 & 插槽
images
: 图片数组indicators
: 显示轮播指示器controls
: 显示轮播控件id
: 轮播id
检查
一个Bootstrap复选框输入
<x-bs::check :label="__('Agree')" :checkLabel="__('I agree to the TOS')" :help="__('Please accept the TOS.')" switch model="agree" />
可用的属性 & 插槽
label
: 在输入上方显示的标签checkLabel
: 在输入旁边显示的标签help
: 在输入下方显示的帮助标签switch
: 将输入样式设置为开关model
: Livewire模型属性键lazy
: 在更改时绑定Livewire数据
关闭
一个Bootstrap关闭按钮
<x-bs::close dismiss="modal" />
可用的属性 & 插槽
color
: Bootstrap关闭颜色,例如white
dismiss
:data-bs-dismiss
的值,例如alert
、modal
颜色
一个Bootstrap颜色选择器输入
<x-bs::color :label="__('Favorite Color')" :prepend="__('I like')" :append="_('the most.')" :help="__('Please pick a color.')" model="favorite_color" />
可用的属性 & 插槽
label
: 在输入上方显示的标签icon
:在输入框前显示的 Font Awesome 图标,例如cog
、envelope
prepend
:在输入框前显示的附加组件,可以通过命名插槽使用append
:在输入框后显示的附加组件,可以通过命名插槽使用size
:Bootstrap 输入框大小,例如sm
、lg
help
: 在输入下方显示的帮助标签model
: Livewire模型属性键lazy
: 在更改时绑定Livewire数据
数据列表
Bootstrap 数据列表输入框
<x-bs::datalist :label="__('City Name')" :options="['Toronto', 'Montreal', 'Las Vegas']" :prepend="__('I live in')" :append="_('right now.')" :help="__('Please enter your city.')" model="city_name" />
可用的属性 & 插槽
label
: 在输入上方显示的标签options
:输入框选项数组,例如['Red', 'Blue']
icon
:在输入框前显示的 Font Awesome 图标,例如cog
、envelope
prepend
:在输入框前显示的附加组件,可以通过命名插槽使用append
:在输入框后显示的附加组件,可以通过命名插槽使用size
:Bootstrap 输入框大小,例如sm
、lg
help
: 在输入下方显示的帮助标签model
: Livewire模型属性键debounce
:在 keyup 事件上绑定 Livewire 数据的时间(毫秒),例如500
lazy
: 在更改时绑定Livewire数据
描述
描述列表
<x-bs::desc :term="__('ID')" :details="$user->id" />
可用的属性 & 插槽
tern
:描述列表的术语details
:描述列表的详细信息,也可以放置在slot
中date
:用于代替详细信息的日期(用于与 Laravel Timezone 一起使用)
下拉菜单
Bootstrap 下拉菜单
<x-bs::dropdown :label="__('Filter')" color="danger"> <x-bs::dropdown-item :label="__('By Name')" click="$set('filter', 'name')" /> <x-bs::dropdown-item :label="__('By Age')" click="$set('filter', 'age')" /> </x-bs::dropdown>
可用的属性 & 插槽
icon
: 在标签之前显示的Font Awesome图标,例如cog
、envelope
label
:要显示的下拉菜单标签,可以通过命名插槽使用items
:下拉菜单项,也可以放置在slot
中color
: Bootstrap颜色,例如primary
、danger
、success
size
: Bootstrap按钮大小,例如sm
、lg
下拉菜单项
Bootstrap 下拉菜单项
<x-bs::dropdown-item :label="__('Login')" route="login" />
可用的属性 & 插槽
icon
: 在标签之前显示的Font Awesome图标,例如cog
、envelope
label
: 要显示的标签,也可以放置在slot
中route
: 将href
设置为路由url
: 将href
设置为URLhref
: 设置href
表单
Bootstrap 表单
<x-bs::form submit="login"> <x-bs::input :label="__('Email')" type="email" model="email"/> <x-bs::input :label="__('Password')" type="password" model="password"/> <x-bs::button :label="__('Login')" type="submit"/> </x-bs::form>
可用的属性 & 插槽
submit
:提交时 Livewire 的操作
图标
Font Awesome 图标
<x-bs::icon name="cog" />
可用的属性 & 插槽
name
:Font Awesome 图标名称,例如cog
、rocket
style
:Font Awesome 图标样式,例如solid
、regular
、brands
size
:Font Awesome 图标大小,例如sm
、lg
、3x
、5x
color
: Bootstrap颜色,例如primary
、danger
、success
spin
:使图标使用旋转动画pulse
:使图标使用脉冲动画
图片
图片
<x-bs::image asset="images/logo.png" height="24" rounded />
可用的属性 & 插槽
asset
:将src
设置为资产src
:设置src
fluid
:将图片设置为流体宽度thumbnail
:将图片设置为缩略图样式rounded
:将图片设置为圆角样式
输入
Bootstrap 文本输入框
<x-bs::input :label="__('Email Address')" type="email" :help="__('Please enter your email.')" model="email_address"> <x-slot name="prepend"> <i class="fa fa-envelope"></i> </x-slot> </x-bs::input>
可用的属性 & 插槽
label
: 在输入上方显示的标签type
:输入框类型,例如text
、email
icon
:在输入框前显示的 Font Awesome 图标,例如cog
、envelope
prepend
:在输入框前显示的附加组件,可以通过命名插槽使用append
:在输入框后显示的附加组件,可以通过命名插槽使用size
:Bootstrap 输入框大小,例如sm
、lg
help
: 在输入下方显示的帮助标签model
: Livewire模型属性键debounce
:在 keyup 事件上绑定 Livewire 数据的时间(毫秒),例如500
lazy
: 在更改时绑定Livewire数据
链接
超链接
<x-bs::link :label="__('Users')" route="users" />
可用的属性 & 插槽
icon
: 在标签之前显示的Font Awesome图标,例如cog
、envelope
label
: 要显示的标签,也可以放置在slot
中route
: 将href
设置为路由url
: 将href
设置为URLhref
: 设置href
模态框
Bootstrap 模态框
<x-bs::modal id="profile.update"> <x-slot name="title"> <h5 class="modal-title">Modal title</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </slot> <x-slot name="body"> <p>Modal body text goes here.</p> </slot> <x-slot name="footer" class="text-body-secondary"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </slot> </x-bs::modal>
可用的属性 & 插槽
title
:模态框标题内容body
:模态框主体内容footer
:模态框底部内容class
:模态框类,例如modal-lg
、modal-dialog-centered
导航下拉菜单
Bootstrap 导航下拉菜单
<x-bs::nav-dropdown :label="Auth::user()->name"> <x-bs::dropdown-item :label="__('Update Profile')" click="$emit('showModal', 'profile.update')" /> <x-bs::dropdown-item :label="__('Logout')" click="logout" /> </x-bs::nav-dropdown>
可用的属性 & 插槽
icon
: 在标签之前显示的Font Awesome图标,例如cog
、envelope
label
:要显示的下拉菜单标签,可以通过命名插槽使用items
:下拉菜单项,也可以放置在slot
中
导航链接
Bootstrap 导航链接
<x-bs::nav-link :label="__('Users')" route="users" />
可用的属性 & 插槽
icon
: 在标签之前显示的Font Awesome图标,例如cog
、envelope
label
: 要显示的标签,也可以放置在slot
中route
: 将href
设置为路由url
: 将href
设置为URLhref
: 设置href
分页
响应式 Bootstrap 分页链接
<x-bs::pagination :links="App\Models\User::paginate()" justify="center" />
可用的属性 & 插槽
links
:分页的 Laravel 模型justify
:Bootstrap 对齐方式,例如start
、end
进度条
Bootstrap 进度条
<x-bs::progress :label="__('25% Complete')" percent="25" color="success" height="10" animated striped />
可用的属性 & 插槽
label
:进度条内部显示的标签percent
:进度条的百分比color
: Bootstrap颜色,例如primary
、danger
、success
height
:进度条的高度(像素)animated
:动画进度条striped
:进度条使用条纹样式
单选按钮
Bootstrap 单选框输入
<x-bs::radio :label="__('Gender')" :options="['Male', 'Female']" :help="__('Please select your gender.')" switch model="gender" />
可用的属性 & 插槽
label
: 在输入上方显示的标签options
:输入框选项数组,例如['Red', 'Blue']
help
: 在输入下方显示的帮助标签switch
:将输入设置为开关样式model
: Livewire模型属性键lazy
: 在更改时绑定Livewire数据
选择框
Bootstrap 选择框输入
@php($countries = ['Australia', 'Canada', 'USA']) <x-bs::select :label="__('Your Country')" :placeholder="__('Select Country')" :options="$countries" :prepend="__('I live in')" :append="_('right now.')" :help="__('Please select your country.')" model="your_country" />
可用的属性 & 插槽
label
: 在输入上方显示的标签placeholder
:用于空第一个选项的占位符options
:输入框选项数组,例如['Red', 'Blue']
icon
:在输入框前显示的 Font Awesome 图标,例如cog
、envelope
prepend
:在输入框前显示的附加组件,可以通过命名插槽使用append
:在输入框后显示的附加组件,可以通过命名插槽使用size
:Bootstrap 输入框大小,例如sm
、lg
help
: 在输入下方显示的帮助标签model
: Livewire模型属性键lazy
: 在更改时绑定Livewire数据
文本区域
Bootstrap 文本区域输入
<x-bs::textarea :label="__('Biography')" rows="5" :help="__('Please tell us about yourself.')" model="biography" />
可用的属性 & 插槽
label
: 在输入上方显示的标签icon
:在输入框前显示的 Font Awesome 图标,例如cog
、envelope
prepend
:在输入框前显示的附加组件,可以通过命名插槽使用append
:在输入框后显示的附加组件,可以通过命名插槽使用size
:Bootstrap 输入框大小,例如sm
、lg
help
: 在输入下方显示的帮助标签model
: Livewire模型属性键debounce
:在 keyup 事件上绑定 Livewire 数据的时间(毫秒),例如500
lazy
: 在更改时绑定Livewire数据
特质
WithModel
这个特性使得对表单数据模型进行操作变得简单。不再需要为每个表单输入创建 Livewire 组件属性。所有表单数据都将放置在 $model
属性数组中。
获取模型数据
以集合的形式获取模型数据
$collection = $this->model();
设置模型数据
设置单个值
$this->setModel('name', 'Kevin');
使用 Eloquent 模型数据设置值
$this->setModel(User::first());
使用数组设置值
$this->setModel([ 'name' => 'Kevin', 'email' => 'kevin@example.com', ]);
处理数组
添加一个空数组项
$this->addModelItem('locations');
通过键移除数组项
$this->removeModelItem('locations', 3);
按键和方向排序数组项
$this->orderModelItem('locations', 3, 'up');
方向应该是 up
或 down
。
绑定模型数据
组件通过 model
属性与这个特性一起工作
<x-bs::input :label="__('Name')" model="name"/> <x-bs::input :label="__('Email')" type="email" model="email"/>
验证模型数据
使用 validateModel
方法来验证模型数据
$this->validateModel([ 'name' => ['required'], 'email' => ['required', 'email'], ]);
这个方法与 Livewire 的 validate
方法类似,所以如果你愿意,可以在单独的 rules
方法中指定你的规则。
发布资源
自定义视图
通过发布包视图使用你自己的组件视图
php artisan vendor:publish --tag=laravel-bs5-components:views
现在编辑 resources/views/vendor/bs
内的文件。该包将使用这些文件来渲染组件。
自定义图标
通过发布包配置来使用您自己的字体图标
php artisan vendor:publish --tag=laravel-bs5-components:config
现在编辑 config/laravel-bs5-components.php
内的 icon_class_prefix
值。该包将使用这个类来渲染图标。