承接 harlew-com/laravel-sleek 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

harlew-com/laravel-sleek

最新稳定版本:v0.0.2

Composer 安装命令:

composer require harlew-com/laravel-sleek

包简介

React-style component syntax for Laravel Blade

README 文档

README

React-style component syntax for Laravel Blade templates.

Overview

Laravel Sleek transforms PascalCase component tags into Laravel's native x-component syntax, allowing you to write Blade components with a React-like syntax.

<!-- Write this -->
<Button type="primary" />
<Form.Input name="email" />

<!-- Get this -->
<x-button type="primary" />
<x-form.input name="email" />

Installation

Install via Composer:

composer require harlew-com/laravel-sleek

The package will automatically register itself via Laravel's package discovery.

Configuration (Optional)

Publish the configuration file:

php artisan vendor:publish --tag=sleek-config

This creates config/sleek.php where you can:

  • Enable/disable the compiler
  • Add custom HTML tags to ignore
return [
    'enabled' => true,

    'ignore_tags' => [
        // Standard HTML tags are already included
        // Add custom tags here if needed
    ],
];

Usage

Basic Components

Write PascalCase component names that automatically transform to kebab-case:

<Button />              → <x-button />
<UserProfile />         → <x-user-profile />
<NavigationMenu />      → <x-navigation-menu />

Nested Components (Dot Notation)

Use dot notation for namespaced components:

<Form.Input />          → <x-form.input />
<Layout.Header />       → <x-layout.header />
<Card.Title />          → <x-card.title />

Alternative: Subfolder Components Without Dot Notation

If you prefer subfolders without dot notation (e.g., <FormInput /> instead of <Form.Input />), register component aliases in your AppServiceProvider:

use Illuminate\Support\Facades\Blade;

public function boot()
{
    Blade::component('components.forms.input', 'FormInput');
}

Then use:

<FormInput />           → Uses components/forms/input.blade.php

With Attributes

All attributes are preserved:

<Button type="submit" class="btn-primary" @click="submit">
    Submit Form
</Button>

<!-- Transforms to -->
<x-button type="submit" class="btn-primary" @click="submit">
    Submit Form
</x-button>

Self-Closing Tags

Both syntaxes work:

<Avatar src="/user.jpg" />
<Avatar src="/user.jpg"/>

How It Works

Laravel Sleek registers a Blade precompiler that runs before standard Blade compilation. It:

  1. Identifies PascalCase HTML tags
  2. Converts them to kebab-case with x- prefix
  3. Preserves all attributes and content
  4. Ignores standard HTML tags

The transformation happens at compile time, so there's no runtime performance impact.

Requirements

  • PHP 8.1 or higher
  • Laravel 10.0 or 11.0

License

The MIT License (MIT). Please see License File for more information.

Credits

Support

For issues, questions, or contributions, please visit the GitHub repository.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-29