定制 williams/bladestyler 二次开发

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

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

williams/bladestyler

Composer 安装命令:

composer require williams/bladestyler

包简介

Adds functionality for maintaining consistent styling when using utility-first CSS frameworks, such as Tailwind, in Laravel Blade files.

README 文档

README

BladeStyler is a Laravel extension designed to help maintain consistent styling within views and components, particularly suited for utility-first CSS frameworks like Tailwind.

Installation & Setup

BladeStyler is installed using Composer. To install BladeStyler, run the following command in your Laravel project directory:

composer require williams/bladestyler

Directives

BladeStyler introduces five new blade directives:

  • @bs_set - for defining reusable style class combinations.

  • @bs_class - for applying class tags with the specified styles.

  • @bs_merge - for merging style classes into blade component attributes.

  • @bs_string - for printing the style classes as a string without any attribute handling.

  • @bs_clear - for clearing definitions previously created with the @bs_set directive.

Defining Styles

Use @bs_set to define aliases for class style combinations:

@bs_set([
    'alert' => 'p-2 border',
    'success' => 'text-green-800 border-green-800 bg-green-200',
    'error' => 'text-red-800 border-red-800 bg-red-200'
])

Applying styles

You can apply these styles to HTML elements using the @bs_class directive:

<div @bs_class('alert success')>Alert Message</div>

This will produce the following output:

<div class="p-2 border text-green-800 border-green-800 bg-green-200">Alert Message</div>

Merging Attributes

BladeStyler offers a short, elegant solution for merging style classes into a Blade component's attribute bag with the @bs_merge directive:

//components/button.blade.php

@props(['kind'=>'primary']) // Set default button as 'primary'

@bs_set([
    'primary' => 'text-white bg-blue-500 hover:bg-blue-800 rounded',
    'md' => 'p-2' 
])

<button @bs_merge($kind)>{{slot}}</button>

Using the component:

<x-button kind="primary md" type="submit">Submit</x-button>

This will produce:

<button class="text-white bg-blue-500 hover:bg-blue-800 rounded p-2" type="submit">Submit</button>

Obtaining classes as a string

If the class list is required without class tags, use @bs_string:

<div class="@bs_string('alert success')">Alert Message</div>

Clearing style definitions

@bs_clear can be used to remove all or a specific definition:

@bs_set([
    'alert' => 'p-2 border',
    'success' => 'text-green-800 border-green-800 bg-green-200',
    'error' => 'text-red-800 border-red-800 bg-red-200'
])

{{--Remove a single definition--}}
@bs_clear('success') 
@bs_string('alert success') {-- Output: p-2 border success --}

{{-- remove all definitions --}}
@bs_clear 
@bs_string('alert success') {-- Output: alert success --}

Additional Features

Conditional Styling

The @bs_class, @bs_merge and @bs_string all support conditional styling, similar to Laravel's @class directive:

<div @bs_class([
    'alert',
    'success' => !$isError, 
    'error' => $isError
])>Alert Message</div>

Class Passthrough

If a class is not registered using the @bs_set directive, it will be passed through directly to the generated HTML. This allows additional utility classes to be applied as required:

<div @bs_class('alert mb-2')>Alert Message</div>

This will produce:

<div class="p-2 border mb-2">Alert Message</div>

williams/bladestyler 适用场景与选型建议

williams/bladestyler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 williams/bladestyler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 williams/bladestyler 我们能提供哪些服务?
定制开发 / 二次开发

基于 williams/bladestyler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-09-06