charcoal/ui
Composer 安装命令:
composer require charcoal/ui
包简介
UI tools (Dashboard, Layout, Form and Menu)
README 文档
README
The UI package provides abstract tools for creating user interface elements.
Installation
composer require charcoal/ui
For Charcoal projects, the service provider can be registered from your configuration file:
{
"service_providers": {
"charcoal/ui/service-provider/ui": {}
}
}
Example
use Charcoal\Config\GenericMetadata; use Charcoal\Ui\Form\FormBuilder; use Charcoal\Ui\Form\FormFactory; $metadata = new GenericMetadata([ 'properties' => [ 'first_name' => [ 'type' => 'string', ], 'last_name' => [ 'type' => 'string', ], 'email' => [ 'type' => 'email', ], ], ]); $formData = [ 'first_name' => 'Mathieu', 'last_name' => 'Ducharme', 'email' => 'mat@locomotive.ca', ]; $formConfig = [ 'type' => 'charcoal/ui/form/generic' 'template_ident' => 'foo/bar/form', 'template_data' => [], 'label' => 'Example Form', 'groups' => [ 'info' => [ 'layout' => [ 'structure' => [ 'columns' => [ [ 1, 1 ], [ 1 ], ], ], ], 'properties' => [ 'first_name', 'last_name', 'email', ], ], ], ]; $formBuilder = new FormBuilder([ 'form_factory' => new FormFactory(), 'view' => $container['view'], ]); $form = $formBuilder->build($formConfig); $form->setMetadata($metadata); $form->setFormData($formData); echo $form->render();
API
Base UI Item
All UI classes implements the same basic class: \Charcoal\Ui\UiItemInterface. This interface defines a basic set of properties that are shared across (almost) all ui item types.
Base UI Item config
| Key | Type | Default | Description |
|---|---|---|---|
| type | string |
||
| title | string[1] |
||
| subtitle | string[1] |
||
| description | string[1] |
||
| notes | string[1] |
||
| template_ident | string |
'' |
The default view template. |
Notes:
- [1] Indicates a multilingual string (
TranslationString).
View Integration
The UiItemInterface is a Viewable item; that means it also implements the \Charcoal\View\ViewableInterface. The AbstractUiItem fully implements this interface by using \Charcoal\View\ViewableTrait.
Viewable objects can set a View object with setView($view) have a template_ident (which can be set with setTemplateIdent($id)). See the charcoal/view module for details.
The easiest way to use a View is by setting a ViewInterface object as view service on a DI container / Service Provider.
Dashboard
Dashboards define a layout of widgets.
layoutis aLayoutInterfaceobject that can be created with aLayoutBuilder.widgetsis a collection of anyUiItemInterfaceobjects.- Any PHP class can actually be a "widget", but base widgets are provided as convenience.
Dashboard config
| Key | Type | Default | Description |
|---|---|---|---|
| type | string |
||
| layout | LayoutConfig |
||
| widgets | array |
Dashboard dependencies
loggerviewwidget_factory
Dashboard API
setLayout()layout()setWidgets(array $widgets)widgets()addWidget()numWidgets()hasWidget()
Layout
Layouts define a grid (column-based) structure.
Layout config
| Key | Type | Default | Description |
|---|---|---|---|
| structure | array |
||
| structure.columns | array |
Example layout JSON config
"layout": { "structure": [ { "columns": [ 2, 1 ] }, { "columns": [ 1 ] }, { "columns": [ 1 ] } ] }
Layout API
setStructure(array $layouts)structure()numRows()rowIndex($position = null)rowData($position = null)rowNumColumns($position = null)rowNumCells($position = null)rowFirstCellIndex($position = null)cellRowIndex($position = null)numCellsTotal()cellSpan($position = null)cellSpanBy12($position = null)cellStartsRow($position = null)cellEndsRow($position = null)start()end()
Layout Aware objects
The UI package has three basic objects that use a layout: dashboards, forms and form groups.
Those classes implement the Layout requirement by implementing the \Charcoal\Ui\Layout\LayoutAwareInterface with the use of its corresponding LayoutAwareTrait.
Form
Forms define a layout of form groups, form options, data and metadata.
- Forms have groups, which have inputs.
- Groups can be layouted with a
layoutobject. - Form can be pre-populated with form data.
- Metadata ca
Form config
| Key | Type | Default | Description |
|---|---|---|---|
| type | string |
||
| action | string |
'' |
URL where the form will be submitted. |
| method | string |
'post' |
HTTP method to submit ("post" or "get"). |
| layout | LayoutConfig |
||
| groups | FormGroupConfig[] |
||
| form_data | array |
||
| metadata | array |
Form dependencies
viewgroup_factory
Form API
setAction($action)action()setMethod($method)method()setGroups(array $groups)groups()addGroup($groupIdent, $groupData)numGroups()hasGroups()setFormData(array $formData)formData()addFormData()
Form Group
Form group config
| Key | Type | Default | Description |
|---|---|---|---|
| form | |||
| template_ident | string |
||
| template_controller | string |
||
| priority | int |
||
| layout | LayoutConfig |
||
| properties | array |
Form group API
setForm($form)setInputs(array $groups)inputs()addInput($inputIdent, $inputData)numInputs()hasInputs()
Form Input
formlabelproperty_identtemplate_identtemplate_dataread_onlyrequireddisabledmultipleinput_idinput_name
Menu
Menu Item
Menu items define a menu level (ident, label and url) and its children (array of Menu Item).
Menu item config
identicon_identlabelurlchildren
Menu item API
setIdent($ident)ident()setLabel($label)label()setUrl($url)url()setChildren($children)children()numChildren()hasChildren()
Creational Helpers
Most UI elements are very dynamic. The types of object to create is often read from a string in a configuration object. Therefore, factories are the preferred way of instanciating new UI items.
Ui items have also many inter-connected dependencies. Builders should therefore be used for object creation / instanciation. They use a factory internally, and have a build($opts) methods that allow to retrieve class name from a dynamic source, do initialization, dpendencies management and more. Builders require Pimple for a DI container.
Factories
\Charcoal\Ui\Dashboard\DashboardFactory\Charcoal\Ui\Layout\LayoutFactory\Charcoal\Ui\Form\FormFactory\Charcoal\Ui\FormGroup\FormGroupFactory\Charcoal\Ui\FormInput\FormInputFactory\Charcoal\Ui\Menu\MenuFactory\Charcoal\Ui\MenuItem\MenuItemFactory
Builders
\Charcoal\Ui\Dashboard\DashboardBuilder\Charcoal\Ui\Layout\LayoutBuilder\Charcoal\Ui\Form\FormBuilder\Charcoal\Ui\FormGroup\FormGroupBuilder\Charcoal\Ui\FormInput\FormInputBuilder\Charcoal\Ui\Menu\MenuBuilder\Charcoal\Ui\MenuItem\MenuItemBuilder
Service Providers
Service providers are provided in the Charcoal\Ui\ServiceProvider namespace for for convenience. They are the recommended way of using the UI package, as they register all the creational utilities to a container, taking care of dependencies.
\Charcoal\Ui\ServiceProvider\DashboardServiceProviderdashboard/factorydashboard/builder
\Charcoal\Ui\ServiceProvider\FormServiceProviderform/factoryform/builderform/group/factoryform/input/factoryform/input/builder
\Charcoal\Ui\ServiceProvider\LayoutServiceProviderlayout/factorylayout/builder
\Charcoal\Ui\ServiceProvider\MenuServiceProvidermenu/factorymenu/buildermenu/item/factorymenu/item/builder
\Charcoal\Ui\ServiceProvider\UiServiceProvider- Register all the other service providers (dashboard, form, layout and menu).
Resources
charcoal/ui 适用场景与选型建议
charcoal/ui 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「menu」 「ui」 「form」 「control」 「layout」 「dashboard」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 charcoal/ui 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 charcoal/ui 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 charcoal/ui 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony extension to get active class base on current bundle/controller/action
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Provide a way to secure accesses to all routes of an symfony application.
A Laravel Filament Forms slug field.
A jQuery augmented PHP library for creating and validating HTML forms
Yii2 prettyPhoto image galary widget uses Lightbox view control jquery.prettyphoto.js
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-08