Laravel Blade Emerald
Emmet like Abbreviation to generate and wrap Laravel Blade Component with markup
π
Features
- Generate HTML in a Blade file via package provided component:
- Emmet style syntax to produce nested markup
- Wrap around any content / other component with markup
- Make any Blade Component accept abbreviation to wrap itself with markup ( doesn't work for Anonymous Components )
πΈ
Compatibility
Package Version | Laravel version | PHP version | Compatible |
---|---|---|---|
^1.0 | 9.* | 8.0 - 8.1 | |
^1.0 | 8.* | 7.3 - 8.0 | |
7.* | 7.3 - 7.4 | |
π₯
Installation
composer require aqua/blade-emerald
π
Usage
, This component can be used like
as an alias. The component support one prop named make
which accept the abbreviation
π·οΈ
Generate static nested markup
<x-markup make="div.card[style='color:green;'] > div.card-body#box" />
produced html
<div class="card" style="color:green;"> <div class="card-body" id="box">div> div>
π·οΈ
Wrap some content
<x-markup make="div.col>div.alert.alert-success[role=alert]">
<strong>Success !strong> give it a click if you like.
x-markup>
produced html
<div class="col"> <div class="alert alert-success" role="alert"> <strong>Success !strong> give it a click if you like. div> div>
π·οΈ
Accept abbreviation in your Blade Component
this feature doesn't support Anonymous Components
- use
Aqua\Emerald\Traits\Markup
trait in your Component Class
class YourComponent extends Component {
use Markup;
...
- the
Markup
trait assumes the prop name to bewrap
, so lets add this as a class property & instantiate
public function __construct(public $wrap) {...} // using php 8.0 constructor property promotion
read more about constructor property promotion
- accept abbreviation
<x-your-component wrap=".card.bg-dark.pt-2 > .card-body.text-danger" />
produced html
Laravel... The PHP Framework for Web Artisans
<div class="card bg-dark pt-2"> <div class="card-body text-danger"> <p>Laravel... The PHP Framework for Web Artisansp> div> div>
- accept abbreviation using prop of your choise to customize the prop name that receives the abbreviation create a static property
$wrapby
and set its value to your prop name
class YourComponent extends Component {
use Markup;
protected static $wrapby = 'markup'; π
public function __construct(public $markup, ...) {
π
}
...
<x-your-component markup=".card.bg-dark.pt-2 > .card-body.text-danger" />
π
π§°
Useful Examples
Bootstrap grid
Hello world!
"><x-markup make="div.container > div.row > div.col-md-6">
<p>Hello world!p>
x-markup>
Breadcrumb
<x-markup make="nav[aria-label=breadcrumb]>ol.breadcrumb">
<li class="breadcrumb-item"><a href="#">Homea>li>
<li class="breadcrumb-item active" aria-current="page">Libraryli>
x-markup>
Bootstrap card with links
With supporting text below as a natural lead-in to additional content.
<x-markup make="div.card.text-center">
<x-markup make="div.card-header>ul.nav.nav-pills.card-header-pills">
<x-markup make="li.nav-item>a.nav-link.active[href=#]">Activex-markup>
<x-markup make="li.nav-item>a.nav-link[href=#]">Linkx-markup>
<x-markup make="li.nav-item>a.nav-link.disabled[href=# tabindex=-1 aria-disabled=true]">Disabledx-markup>
x-markup>
<div class="card-body">
<p class="card-text">With supporting text below as a natural lead-in to additional content.p>
div> x-markup>
Bootstrap form-group
<x-markup make="div.form-group>div.mb-3">
<label for="email" class="form-label">Email addresslabel>
<input type="email" class="form-control" id="email" aria-describedby="emailHelp" />
<x-markup make="div>div.#emailHelp.form-text>span.text-danger.validation-msg" />
x-markup>
Self closing tag
"><x-markup make="img#profile[src=/avatar.jpg width=80]" />
Alpine x-for
<ul x-data="{ colors: [{ id: 1, label: 'Green' }, ...] }">
<x-markup make="template[x-for=color in colors] [:key=color.id] > li[x-text=color.label]" />
ul>
equivalent to
<ul x-data="{ colors: ...}">
<template x-for="color in colors" :key="color.id">
<li x-text="color.label">li>
template>
ul>
π
Abbreviation Guide
checkout spatie/html-element to get more idea.
Syntax | Example | Description |
---|---|---|
#id |
p#foo |
ID attribute |
.class |
p.foo |
Class attribute |
> |
div.row>div.col |
Nesting with child |
[style='color:green;'] |
div[style='color:green;'] |
Single attribute |
[title=Hello world][data-foo=bar] |
Multiple attributes |
π
Changelog
Please see CHANGELOG for more information on what has changed recently.
π
Credits
This package is actually a wrapper around spatie/html-element, all the hard work has been done by Team Spatie so they deserve all the credits. All I did is make it work with Laravel Blade Components.
π«
License
The MIT License (MIT). Please see License File for more information.