定制 chat-agency/laravel-backend-component 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chat-agency/laravel-backend-component

最新稳定版本:v0.13.1

Composer 安装命令:

composer require chat-agency/laravel-backend-component

包简介

Use Laravel component using php classes

README 文档

README

Tests PHPStan Laravel Pint

A package that simplifies the creation of dynamic, class-based Laravel components.

This package allows you to build complex, reusable UI components in PHP, making your backend and frontend integration seamless.

View the full documentation

Install the package via Composer:

composer require chat-agency/laravel-backend-component

To use the package’s Tailwind themes, configure Tailwind to scan the package's Blade files. The method differs slightly between Tailwind versions:

Tailwind CSS v3:

Add the package's view path to the content array in your tailwind.config.js file:

// tailwind.config.js
export default {
    content: [
        './vendor/chat-agency/laravel-backend-component/resources/views/**/*.blade.php', // <- Add this line
        // other paths
    ],
    // ...
};

Tailwind CSS v4:

In your main CSS file (e.g., resources/css/app.css), use the @source at-rule to include the package's view path:

@import 'tailwindcss';

/* Add the path for the package's views */
@source '../../vendor/chat-agency/laravel-backend-component/resources/views/**/*.blade.php';

Basic use

Use the MainBackendComponent class to construct your component. Pass the component name/path as the first parameter:

use ChatAgency\BackendComponents\MainBackendComponent;

$button = new MainBackendComponent('inline.button');

Alternatively, builders and an enum are available to streamline instance creation:

use ChatAgency\BackendComponents\Builders\ComponentBuilder;
use ChatAgency\BackendComponents\Enums\ComponentEnum;

$button = ComponentBuilder::make(ComponentEnum::BUTTON);

Since the main component class implements Laravel’s Htmlable interface, you can output the component using simple Blade syntax—no escaping needed:

{{-- This will render the button's HTML --}}
{{ $button }}

Components can be composed with other components:

use ChatAgency\BackendComponents\Builders\ComponentBuilder;
use ChatAgency\BackendComponents\Enums\ComponentEnum;

$divWithButton = $button = ComponentBuilder::make(ComponentEnum::DIV)
    ->setContent(
        ComponentBuilder::make(ComponentEnum::BUTTON)
            ->seContent('Click me!')
    );

Theming

The package supports theming, primarily designed for use with Tailwind CSS classes. All themes are stored inside resources/views/_themes/tailwind by default, ensuring they are automatically discovered by Tailwind's scanner.

You can apply a theme using the setTheme method:

use ChatAgency\BackendComponents\Builders\ComponentBuilder;
use ChatAgency\BackendComponents\Enums\ComponentEnum;

$button = ComponentBuilder::make(ComponentEnum::BUTTON)
    ->setTheme('theme_file', 'theme_name');

Tests

Run tests using Composer:

composer test

If you're submitting a pull request, use the qa command—it runs phpstan, pint, and tests. These are the same checks performed in GitHub Actions

composer qa 

License

This package is licensed under the MIT License.

统计信息

  • 总下载量: 252
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-13