Một framework React-based để xây dựng WordPress admin dashboards với interface hiện đại và dễ sử dụng.
Dashboard Framework cung cấp một hệ thống component-based để tạo WordPress admin interfaces với React, TypeScript và modern UI patterns.
graph TD
A[Dashboard Framework] --> B[Elements]
A --> C[Factories]
A --> D[Interfaces]
A --> E[Option Framework]
B --> F[Page]
B --> G[Section]
B --> H[Field]
H --> I[TextField]
H --> J[TextareaField]
H --> K[SelectField]
H --> L[ImageField]
H --> M[IconField]
H --> N[ColorField]
H --> O[CheckboxField]
H --> P[RadioField]
H --> Q[SwitchField]
H --> R[SliderField]
H --> S[TypographyField]
H --> T[BackgroundField]
H --> U[SpacingField]
C --> V[FieldFactory]
D --> W[PageInterface]
D --> X[SectionInterface]
D --> Y[FieldInterface]
E --> Z[OptionFramework]
src/
├── Elements/
│ ├── Page.php # Page element
│ ├── Section.php # Section element
│ ├── Field.php # Abstract field class
│ └── Fields/ # Concrete field implementations
│ ├── TextField.php # Text input field
│ ├── TextareaField.php # Textarea field
│ ├── SelectField.php # Select dropdown field
│ ├── ImageField.php # Image upload field
│ ├── IconField.php # Icon picker field
│ ├── ColorField.php # Color picker field
│ ├── CheckboxField.php # Checkbox field
│ ├── RadioField.php # Radio button field
│ ├── SwitchField.php # Toggle switch field
│ ├── SliderField.php # Range slider field
│ ├── TypographyField.php # Typography settings field
│ ├── BackgroundField.php # Background settings field
│ └── SpacingField.php # Spacing controls field
├── Factories/
│ └── FieldFactory.php # Factory for creating field instances
├── Interfaces/
│ ├── PageInterface.php # Page interface
│ ├── SectionInterface.php # Section interface
│ └── FieldInterface.php # Field interface
└── OptionFramework.php # Main option framework class
Đại diện cho một trang trong dashboard.
Properties:
$id- Unique identifier$title- Page title$sections- Array of sections$icon- Page icon
Methods:
getId()- Get page IDgetTitle()- Get page titlegetSubtitle()- Get page subtitlegetDescription()- Get page descriptiongetPriority()- Get page prioritygetIcon()- Get page icongetSections()- Get page sectionsaddSection($section)- Add section to page
Interfaces:
PageInterfaceJsonSerializableArrayAccess
Đại diện cho một section trong page.
Properties:
$id- Unique identifier$title- Section title$fields- Array of fields
Methods:
getId()- Get section IDgetTitle()- Get section titlegetSubtitle()- Get section subtitlegetDescription()- Get section descriptiongetPriority()- Get section prioritygetFields()- Get section fieldsaddField($field)- Add field to section
Interfaces:
SectionInterfaceJsonSerializableArrayAccess
Abstract class cho tất cả field types.
Properties:
$id- Field ID$title- Field title$type- Field type$args- Field arguments
Methods:
getId()- Get field IDgetType()- Get field typegetTitle()- Get field titlegetSubtitle()- Get field subtitlegetDescription()- Get field descriptiongetDefault()- Get default valuehasOptions()- Check if field has optionsgetOptions()- Get field optionshasMin()- Check if field has min valuegetMin()- Get min valuehasMax()- Check if field has max valuegetMax()- Get max valuehasStep()- Check if field has step valuegetStep()- Get step valueisWordPressNative()- Check if field is WordPress nativegetOptionName()- Get WordPress option namehasSubFields()- Check if field has sub-fieldsgetSubFields()- Get sub-fieldsgetArgs()- Get all field arguments
Interfaces:
FieldInterfaceJsonSerializableArrayAccess
Text input field.
$field = FieldFactory::create('site_title', 'Site Title', 'text', [
'subtitle' => 'Main site title',
'description' => 'Enter your site title',
'default' => 'Bookix - Book Store',
]);Multi-line text input field.
$field = FieldFactory::create('site_description', 'Site Description', 'textarea', [
'subtitle' => 'Site description',
'description' => 'Enter your site description',
'default' => 'Your premier destination for books and literature',
]);Dropdown selection field.
$field = FieldFactory::create('header_style', 'Header Style', 'select', [
'subtitle' => 'Header layout style',
'description' => 'Choose header layout style',
'default' => 'style1',
'options' => [
'style1' => 'Style 1 - Classic',
'style2' => 'Style 2 - Modern',
'style3' => 'Style 3 - Minimal',
'style4' => 'Style 4 - Creative',
],
]);Image upload field.
$field = FieldFactory::create('site_logo', 'Site Logo', 'image', [
'subtitle' => 'Upload logo',
'description' => 'Upload your site logo',
]);Icon picker field.
$field = FieldFactory::create('menu_icon', 'Menu Icon', 'icon', [
'subtitle' => 'Choose menu icon',
'description' => 'Select an icon for the menu',
]);Color picker field.
$field = FieldFactory::create('primary_color', 'Primary Color', 'color', [
'subtitle' => 'Main primary color',
'description' => 'Main primary color for the theme',
'default' => '#2c3e50',
]);Checkbox field.
$field = FieldFactory::create('enable_feature', 'Enable Feature', 'checkbox', [
'subtitle' => 'Enable this feature',
'description' => 'Check to enable this feature',
'default' => true,
]);Radio button field.
$field = FieldFactory::create('logo_position', 'Logo Position', 'radio', [
'subtitle' => 'Logo position in header',
'description' => 'Choose logo position in header',
'default' => 'left',
'options' => [
'left' => 'Left',
'center' => 'Center',
'right' => 'Right',
],
]);Toggle switch field.
$field = FieldFactory::create('enable_sticky_header', 'Enable Sticky Header', 'switch', [
'subtitle' => 'Sticky header option',
'description' => 'Enable sticky header on scroll',
'default' => true,
]);Range slider field.
$field = FieldFactory::create('container_width', 'Container Width', 'slider', [
'subtitle' => 'Container width in pixels',
'description' => 'Set the maximum width of the main container',
'default' => 1200,
'min' => 800,
'max' => 1400,
'step' => 10,
]);Typography settings field.
$field = FieldFactory::create('body_typography', 'Body Typography', 'typography', [
'subtitle' => 'Body text typography',
'description' => 'Configure typography for body text',
'default' => [
'font-family' => 'Open Sans, sans-serif',
'font-size' => '16px',
'font-weight' => '400',
'font-style' => 'normal',
'line-height' => '1.6',
'letter-spacing' => '0px',
'text-align' => 'left',
'text-transform' => 'none',
'color' => '#333333',
],
]);Background settings field.
$field = FieldFactory::create('body_background', 'Body Background', 'background', [
'subtitle' => 'Body background settings',
'description' => 'Configure background for body element',
'default' => [
'background-color' => '#ffffff',
'background-image' => '',
'background-repeat' => 'no-repeat',
'background-position' => 'center center',
'background-size' => 'cover',
],
]);Spacing controls field.
$field = FieldFactory::create('content_padding', 'Content Padding', 'spacing', [
'subtitle' => 'Content area padding',
'description' => 'Set padding for main content area',
'default' => [
'top' => '40px',
'right' => '20px',
'bottom' => '40px',
'left' => '20px',
'units' => 'px',
],
]);Factory class để tạo field instances.
Methods:
create($id, $title, $type, $args)- Create field instancecreateTextField($id, $title, $args)- Create text fieldcreateTextareaField($id, $title, $args)- Create textarea fieldcreateSelectField($id, $title, $args)- Create select fieldcreateImageField($id, $title, $args)- Create image fieldcreateIconField($id, $title, $args)- Create icon fieldcreateColorField($id, $title, $args)- Create color fieldcreateCheckboxField($id, $title, $args)- Create checkbox fieldcreateRadioField($id, $title, $args)- Create radio fieldcreateSwitchField($id, $title, $args)- Create switch fieldcreateSliderField($id, $title, $args)- Create slider fieldcreateTypographyField($id, $title, $args)- Create typography fieldcreateBackgroundField($id, $title, $args)- Create background fieldcreateSpacingField($id, $title, $args)- Create spacing field
Supported Types:
text,input→ TextFieldtextarea→ TextareaFieldselect,dropdown,option→ SelectFieldimage→ ImageFieldicon→ IconFieldcolor,color_picker→ ColorFieldcheckbox→ CheckboxFieldradio→ RadioFieldswitch,button_set→ SwitchFieldslider→ SliderFieldtypography→ TypographyFieldbackground→ BackgroundFieldspacing,dimensions→ SpacingField
use Jankx\Dashboard\Elements\Page;
use Jankx\Dashboard\Elements\Section;
use Jankx\Dashboard\Factories\FieldFactory;
// Create page
$page = new Page('General Settings', [], 'dashicons-admin-generic');
// Create section
$section = new Section('Site Information');
// Create fields
$siteTitleField = FieldFactory::create('site_title', 'Site Title', 'text', [
'subtitle' => 'Main site title',
'description' => 'Enter your site title',
'default' => 'Bookix - Book Store',
]);
$siteLogoField = FieldFactory::create('site_logo', 'Site Logo', 'image', [
'subtitle' => 'Upload logo',
'description' => 'Upload your site logo',
]);
// Add fields to section
$section->addField($siteTitleField);
$section->addField($siteLogoField);
// Add section to page
$page->addSection($section);// Create typography field
$typographyField = FieldFactory::create('body_typography', 'Body Typography', 'typography', [
'subtitle' => 'Body text typography',
'description' => 'Configure typography for body text',
'default' => [
'font-family' => 'Open Sans, sans-serif',
'font-size' => '16px',
'font-weight' => '400',
'line-height' => '1.6',
'color' => '#333333',
],
]);
// Create background field
$backgroundField = FieldFactory::create('body_background', 'Body Background', 'background', [
'subtitle' => 'Body background settings',
'description' => 'Configure background for body element',
'default' => [
'background-color' => '#ffffff',
'background-image' => '',
'background-repeat' => 'no-repeat',
'background-position' => 'center center',
'background-size' => 'cover',
],
]);
// Create spacing field
$spacingField = FieldFactory::create('content_padding', 'Content Padding', 'spacing', [
'subtitle' => 'Content area padding',
'description' => 'Set padding for main content area',
'default' => [
'top' => '40px',
'right' => '20px',
'bottom' => '40px',
'left' => '20px',
'units' => 'px',
],
]);// Create WordPress native field
$blogNameField = FieldFactory::create('blogname', 'Site Title', 'text', [
'subtitle' => 'WordPress site title',
'description' => 'This field is connected to WordPress option',
'wordpress_native' => true,
'option_name' => 'blogname',
]);Tất cả elements đều hỗ trợ ArrayAccess interface:
// Access as array
$pageTitle = $page['title'];
$sectionTitle = $section['title'];
$fieldId = $field['id'];
// Set as array
$page['title'] = 'New Title';
$section['title'] = 'New Section';
$field['title'] = 'New Field';Tất cả elements đều hỗ trợ JSON serialization:
// Serialize to JSON
$pageJson = json_encode($page);
$sectionJson = json_encode($section);
$fieldJson = json_encode($field);- Lazy Loading - Components chỉ load khi cần
- Memory Efficient - Tối ưu memory usage
- Caching - Cache component instances
- Minimal Dependencies - Ít dependencies
- Graceful Degradation - Fallback khi component không load được
- Validation - Validate input data
- Exception Handling - Catch và handle exceptions
- Create Field Class:
class NewField extends Field
{
protected $type = 'new_field';
public function render()
{
// Custom rendering logic
}
}- Add to FieldFactory:
// Trong FieldFactory::create()
case 'new_field':
return static::createNewField($id, $title, $args);
protected static function createNewField($id, $title, $args)
{
return new NewField($id, $title, $args);
}// Test field creation
$field = FieldFactory::create('test', 'Test Field', 'text', []);
assert($field instanceof TextField);
// Test field properties
assert($field->getId() === 'test');
assert($field->getTitle() === 'Test Field');
assert($field->getType() === 'text');MIT License - Xem file LICENSE để biết thêm chi tiết.