View on GitLab

Custom Elements

Given the multiple kind of components provided by Larastrap, it is possible to define your owns. Once, with a few lines in the configuration, and ready to be used across all of your application.

Custom Elements can be defined in the customs array in config/larastrap.php , in the form

<?php

return [
    'customs' => [
        'my-element-name' => [
            'extends' => 'a-larastrap-kind-of-element',
            'params' => [
                'first_parameter' => 'value',
                'second_parameter' => 'value',
            ]
        ]
    ]
];

or, for a more practical example

<?php

return [
    'customs' => [
        'mybutton' => [
            'extends' => 'button',
            'params' => [
                'color' => 'warning',
            ]
        ]
    ]
];

Given this configuration, every time you use x-larastrap::mybutton tag, you obtain a x-larastrap::button whose default color is warning

<x-larastrap::mybutton label="A Button" />
<button id="button-9dd9ba90d0ee8f8ba43b414886564052" class="btn btn-warning">A Button</button>

Dynamic Load

You can also dynamically define your custom elements with the addCustomElement() provided by LarastrapStack service provider. This has to be used before Blade rendering, for example in the parent Controller or in a Laravel Service Provider.

app()->make('LarastrapStack')->addCustomElement('jerkbutton', [
    'extends' => 'button',
    'params' => [
        'color' => 'secondary',
        'postlabel' => ' (Click Here!)',
    ],
]);
<x-larastrap::jerkbutton label="A Button" />
<button id="button-b54636c09a08bf353f9774c1ae2abae5" class="btn btn-secondary">A Button (Click Here!)</button>