helsingborg-stad / blade-component-library
基于 blade 引擎的组件库。
- dev-master
- 0.15.0
- 0.14.0
- 0.13.0
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.6
- 0.8.5
- 0.5.11
- 0.5.10
- 0.5.9
- 0.5.8
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5
- 0.4
- 0.3.9
- 0.3.8
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
- 0.0.2
- 0.0.1
- dev-fix/3.0/labelledby-attribute
- dev-fix/options-required
- dev-fix/date-translation
- dev-fix/table-sort
- dev-develop
- dev-feature/collection
- dev-feature/date-badge
- dev-collec
- dev-img-place
- dev-feature/grid-comp-2
- dev-fix/table-sort-hover
- dev-hotfix/if-endpoints
- dev-wip/dynamic-top-nav
- dev-wip/nav-dynamic-children
- dev-wip/footer-component
- dev-wip/side-bar-dynamic-children
- dev-wip/card-component-rework
- dev-feature/splitbutton-bug-fix
- dev-feature/json-attribute
- dev-wip/redesign
- dev-wip/notification
- dev-feature/react-init
- dev-wip/calendar
- dev-feature/card-doc-button-fix
- dev-wip/button-component-rework
- dev-feature/card-button-usage-refactor
- dev-feature/button-group-fix
- dev-feature/button-controller-cleanup
- dev-feature/button-fix
- dev-wip/button-fix
- dev-feature/form
- dev-feature/icon-button-hover-color
- dev-feature/code-prism
- dev-hotfix/icons-testimonials
- dev-feature/Testimonials-layout
- dev-feature/Testimonials
- dev-feature/icon-generator-fix
- dev-feature/Dropdown-mobile
- dev-feature/docs
- dev-feature/Cards-accordion
- dev-feature/unique-id
- dev-feature/tabindex
- dev-feature/base-class-generator
- dev-wip/text-button
- dev-feature/FW2-78-button-group
- dev-feature/FW2-79-split-button
- dev-feature/id
- dev-feature/Gallery-ie-compability
- dev-feature/Card-focus-traversing
- dev-feature/Card-dropdown
- dev-feature/toggle-only-outline
- dev-wip/toggle-only-outline
- dev-FW2-82-cards
- dev-wip/FW2-79-split-button
- dev-feature/FW2-80-drop
- dev-wip/FW2-80-drop
- dev-wip/FW2-77-button-toggle
- dev-wip/FW2-78-button-group
- dev-feature/refactor-init
- dev-feature/Fw2-76_Gallery
- dev-feature/FW2-72-notice-icon-size
- dev-feature/FW2-85-improve-customization
- dev-fix-button
- dev-feature/FW2-69-Button
- dev-feature/FW2-72-Notice
- dev-wip/FW2-72-Notice
- dev-feature/FW2-68-Image
- dev-feature/html
- dev-feature/data
- dev-feature/view-composers
This package is auto-updated.
Last update: 2024-02-11 15:27:51 UTC
README
这是一个包含加载函数和视图库及其控制器的库。它使得在多个产品中快速准确地开发静态用户界面成为可能。该包旨在独立使用或与 WordPress 作为 CMS 引擎一起使用。
重要提示:这是一个视图包!不会添加任何 CSS 或 JavaScript 代码。我们将(将,尚未完成)有一个单独的包以样式指南格式提供这些功能。
入门
推荐使用 composer。添加以下要求以启用一系列新功能。
composer reqire helsingborg-stad/blade-component-library
已知问题
- 组件/指令必须使用 @endcomponent 标签调用。不带结束标签的指令将不起作用。
示例用法(注册组件)
<?php namespace Municipio\Theme; class RegisterUtility { public function __construct() { \BladeComponentLibrary\Register::addViewPath( MUNICIPIO_PATH . 'views/utility', true //true = prepend, false = append, default = prepend ); \BladeComponentLibrary\Register::addControllerPath( MUNICIPIO_PATH . 'library/Controller/Utility/', true //true = prepend, false = append, default = prepend ); \BladeComponentLibrary\Register::add( 'button', [ 'isPrimary' => true, 'isDisabled' => false, 'isOutlined' => true, 'label' => "Button text", 'href' => "https://google.se", 'target' => "_self" ], 'button.blade.php' // You can leave this out, it will automatically be generated from slug. ); \BladeComponentLibrary\Register::add( 'date', [ 'hasTime' => false, 'hasDate' => true, 'isHumanReadable' => true ], 'date-time.blade.php' ); } }
示例用法(渲染组件)
注册的组件可以像在 Laravel 中一样作为组件或指令使用。它们增加了在渲染前加载控制器的功能,以确保内容格式化和定义。
作为指令渲染
@button(['text' => "Button text", 'href' => "https://helsingborg.se"]);
作为组件渲染
@component('button') Button text @slot('href') https://helsingborg.se @endslot @endcomponent
实现替换视图和控制器
该包旨在用主题或插件自己的视图覆盖。只需添加以下新路径。您有 prepend 或 append 现有搜索数组的选项。路径将按顺序搜索。
use BladeComponentLibrary/Register as Register; //Adds a new view search path Register::addViewPath( MUNICIPIO_PATH . 'views/utility', false //Prepend = true ); //Adds a new controller search path Register::addControllerPath( MUNICIPIO_PATH . 'library/Controller/Utility/', false //Prepend = true );
数据流
基础控制器组件 此控制器处理所有组件的数据流。有多种方式向组件输入数据。
-
组件的默认配置。这些设置在每个组件文件夹中的配置 json 中进行。控制器中使用的所有变量都应在此处声明。这是为了避免未声明的变量警告。
-
通过填充指令(在视图文件中)。这应该是指示状态的数据,如 isDisabled => true 等。这是用户定制的主体位置。
-
通过连接到每个组件的控制器中的数据操作。这些数据可以以任何形式存在,但应侧重于将其他输入转换为视图数据。此文件可以包含纯文本类。
示例
if($isDisabled) { $this->classList[] = 'disabled'; }
- 如果组件库在 WordPress 内运行,则有一个额外的过滤器可用于在外部操纵数据,作为输出前的最后一步。
过滤器(通用):BladeComponentLibrary/Component/Data - 接收 $data
过滤器(特定组件):BladeComponentLibrary/Component/ComponentName/Data - 接收 $data
过滤器类(通用):BladeComponentLibrary/Component/Class - 接收 $class
过滤器类(组件特定):BladeComponentLibrary/Component/ComponentName/Class - 接收 $class
类过滤器从 $data 对象中提取类变量。
添加内置组件
添加组件最有效和推荐的方式是通过向此包提交一个 PR。这将使所有人都可以使用。一个内部组件需要三个不同的文件。
- 视图
- 控制器
- 配置
视图
视图应尽可能简单,在大多数情况下仅包含几个 if 语句。对于更复杂的解决方案,请考虑使用指令组件作为较大组件的子组件。
示例
<a class="{{ $class }}" target="{{ $target }}" href="{{ $href or '#' }}">{{ $slot or $text }}</a>
控制器
控制器应处理与组件相关的所有逻辑。此文件的主要目的是将任何逻辑从视图中移除。
示例
namespace BladeComponentLibrary\Component\Button; class Button extends \BladeComponentLibrary\Component\BaseController { public function init() { $this->data['foo'] = "bar"; } }
配置
组件 slugs 的简单配置(用作指令和组件名称)。默认参数和视图名称(默认为 slug 名称)。配置应以有效的 JSON 格式编写。此文件必须包含“slug”、“default”(默认参数)和“view”键。
示例
{ "slug":"button", "default":{ "isPrimary":true, "isDisabled":false, "isOutlined":true, "label":"Button text", "href":"https:\/\/google.se", "target":"_self" }, "view":"button.blade.php" }
WordPress 兼容性
如果在此库之前包含 WordPress 核心,则每个组件将分别注册相应的 WordPress 过滤器。我们只需查找名为 apply_filters 的内置函数。过滤器将以其相应文件夹的位置命名。
例如;位于 "./src/Component/Card" 的 Card 组件将在渲染前应用 "BladeComponentLibrary/Component/Card/Data" 过滤器。slug 的最后一部分 "Data" 可以更改为 "Class",以仅过滤数据对象的 "classes" 子数组。
还会为数据对象中的每个键创建特定的过滤器。例如,如果数据对象包含键 'foo',则将创建如下过滤器:BladeComponentLibrary/Component/Card/Foo。这不会包含键 "data",因为它已被上述过滤器保留。
还会为数据对象调用一个通用过滤器,称为 "BladeComponentLibrary/Component/Data"。这有保留数据命名空间的副作用。因此,您不能创建名为 Data 的组件。
视图变量
所有组件视图都将分配一些基本参数。以下列出了这些参数。添加到 $data 数组中的其他一切都将自动添加为以键值命名的 $var。
变量 | 描述 |
---|---|
$class | 包装组件的类数组。 |
$compiledClass | 包装组件的类字符串。 |
$baseClass | 分配的第一个类字符串。 |
$attribute | 属性字符串 |
构建于
- Laravel Blade 5.*
依赖项
- PHP 7.0
版本
https://github.com/helsingborg-stad/blade-component-library/releases
作者
- Sebastian Thulin
- 约翰·西尔弗格伦德
- 扬纳坦·汉森
- 尼古拉斯·拉姆斯特德
- 埃里克·罗森博格
- 亚历山大·博曼·斯库格
许可
本项目遵循MIT许可协议 - 请参阅LICENSE文件以获取详细信息