View on GitLab

Typography

Larastrap provides a generic utility component called x-larastrap::t , able to be rendered as any preferred HTML tag type.

a simple span
<x-larastrap::t node="span">a simple span</x-larastrap::t>
<span id="basenode-eccbc87e4b5ce2fe28308fd9f2a7baf3" class="">a simple span</span>

Of course this is not meant to be directly used in templates - as it would be tedious and unconvenient to write so much code just to open and close a span - but is considered a base to define your own Custom Elements, so to define the typography style of your whole application and keep it consistent through the centralized configuration.

On this website, references to Larastrap components , parameters and examples of values are defined once in the global configuration as Custom Elements.

[
    'customs' => [
        'element' => [
            'extends' => 't',
            'params' => [
                'classes' => ['text-danger'],
                'node' => 'strong',
            ]
        ],

        'value' => [
            'extends' => 't',
            'params' => [
                'node' => 'code',
            ]
        ],

        'parameter' => [
            'extends' => 't',
            'params' => [
                'node' => 'strong',
            ]
        ]
    ]
]
<p>
    On this website, references to <x-larastrap::element>Larastrap components</x-larastrap::element>, <x-larastrap::parameter>parameters</x-larastrap::parameter> and <x-larastrap::value>examples of values</x-larastrap::value> are defined once in the global configuration as Custom Elements.
</p>
<p>
  On this website, references to <strong id="basenode-3cc57317e892542eb270979a5671e79c" class="text-danger">Larastrap components</strong> , <strong id="basenode-1679091c5a880faf6fb5e6087eb1b2dc" class="">parameters</strong> and <code id="basenode-8f14e45fceea167a5a36dedd4bea2543" class="">examples of values</code> are defined once in the global configuration as Custom Elements.
</p>

x-larastrap::t can be used to handle, among the other, classic Bootstrap Alerts and Badges: get a look to the page of Custom Elements Examples.

content

When you just want a shortcut for a static label, you can use the content parameter to define once a string to be placed into the node.

OK
NO GOOD
[
    'customs' => [
        'badge_ok' => [
            'extends' => 't',
            'params' => [
                'node' => 'span',
                'classes' => ['badge', 'text-bg-success'],
                'content' => 'OK',
            ],
        ],
        'badge_ko' => [
            'extends' => 't',
            'params' => [
                'node' => 'span',
                'classes' => ['badge', 'text-bg-danger'],
                'content' => 'NO GOOD',
            ],
        ],
    ],
]
<x-larastrap::badge_ok />
<br>
<x-larastrap::badge_ko />
<span id="basenode-a838fe9e70d1cede27888f4c1f298644" class="badge text-bg-success">OK</span><br>
<span id="basenode-8b9f856ea0b6fed30e34be3cb2f2ac55" class="badge text-bg-danger">NO GOOD</span>

obj / name

x-larastrap::t is a Container, and an obj can be assigned (or inherited), but it also sports a few other parameters that permits you to display the value from a named attribute of the object (eventually: an Eloquent model) directly within the textual node

  • name - same as in Inputs, define the name of the attribute to access
  • prelabel / postlabel - same as in Buttons, permit to prepend or append an arbitrary text
xwelch@example.org
@php
$user = App\Models\User::inRandomOrder()->first();
@endphp

<x-larastrap::t :obj="$user" name="email" />
<span id="basenode-f1f7e8442528f8cdb8f07ea715f4be76" class="">xwelch@example.org</span>

In this case, also, it is possible to define your own Custom Elements to always display the same attribute with the same style, decorations, addictional graphics and more.

Edwina Hettinger

hermina.streich@example.net

Gerard McGlynn

xwelch@example.org

Jules Wunsch

daniel.arlie@example.net

[
    'customs' => [
        'ctitle' => [
            'extends' => 't',
            'params' => [
                'node' => 'h5',
                'classes' => ['card-title'],
                'name' => 'name',
            ]
        ],
        'cmail' => [
            'extends' => 't',
            'params' => [
                'node' => 'p',
                'classes' => ['card-text'],
                'name' => 'email',
                'prelabel' => '<i class="bi bi-envelope"></i> '
            ]
        ],
    ]
]
@php
$users = App\Models\User::inRandomOrder()->take(3)->get();
@endphp

<div class="card-group">
    @foreach($users as $user)
        <x-larastrap::enclose :obj="$user">
            <div class="card">
                <div class="card-body">
                    <x-larastrap::ctitle />
                    <x-larastrap::cmail />
                </div>
            </div>
        </x-larastrap::enclose>
    @endforeach
</div>
<div class="card-group">
  <div class="card">
    <div class="card-body">
      <h5 id="basenode-bd1a3c7597e3165c90eca342d67d581b" class="card-title">
        Edwina Hettinger
      </h5>
      <p id="basenode-425ff3cd93f1a06825707d8ca8dfb540" class="card-text">
        hermina.streich@example.net
      </p>
    </div>
  </div>
  <div class="card">
    <div class="card-body">
      <h5 id="basenode-9e840fe15e47df948a9d81d6b09b4bb8" class="card-title">
        Gerard McGlynn
      </h5>
      <p id="basenode-59992dd5fb9c17c6c3518149c1d287ba" class="card-text">
        xwelch@example.org
      </p>
    </div>
  </div>
  <div class="card">
    <div class="card-body">
      <h5 id="basenode-13cb4b3d0d25a2dd552f36e0a08b6ce8" class="card-title">
        Jules Wunsch
      </h5>
      <p id="basenode-664b215efd647450fdc808dc68b86437" class="card-text">
        daniel.arlie@example.net
      </p>
    </div>
  </div>
</div>

inner prepend / append

As x-larastrap::t is a Container, it supports prependNodes /appendNodes parameters to attach items before and after the element itself. But the Typography node also has innerPrependNodes /innerAppendNodes parameters to be able to prepend and append items inside the element, and be able to define once complex layouts.

The above example of users' card can be squeezed into a single Larastrap Custom Element containing multiple informations.

Edwina Hettinger

hermina.streich@example.net

Jules Wunsch

daniel.arlie@example.net

[
    'customs' => [
        'easy-user-card' => [
            'extends' => 't',
            'params' => [
                'node' => 'div',
                'classes' => ['card'],
                'innerAppendNodes' => [
                    [
                        'extends' => 't',
                        'params' => [
                            'node' => 'div',
                            'classes' => ['card-body'],
                            'innerAppendNodes' => [
                                [
                                    'extends' => 't',
                                    'params' => [
                                        'node' => 'h5',
                                        'classes' => ['card-title'],
                                        'name' => 'name',
                                    ],
                                ],
                                [
                                    'extends' => 't',
                                    'params' => [
                                        'node' => 'p',
                                        'classes' => ['card-text'],
                                        'name' => 'email',
                                        'prelabel' => '<i class="bi bi-envelope"></i> '
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
]
@php
$users = App\Models\User::inRandomOrder()->take(2)->get();
@endphp

<div class="card-group">
    @foreach($users as $user)
        <x-larastrap::easy-user-card :obj="$user" />
    @endforeach
</div>
<div class="card-group">
  <div id="basenode-4c0f5c074509a9759079a7dfec830f21" class="card">
    <div id="basenode-2d52c154c1a952375355dfd8e8543166" class="card-body">
      <h5 id="basenode-57e2ea5227fd793695a472bbb0c95cb1" class="card-title">
        Edwina Hettinger
      </h5>
      <p id="basenode-6c24385b95994f7950a433cae5d87509" class="card-text">
        hermina.streich@example.net
      </p>
    </div>
  </div>
  <div id="basenode-e5d155164340273133541f961f5e4d6e" class="card">
    <div id="basenode-068d60d702507f3f4bd57f4f45c8d08f" class="card-body">
      <h5 id="basenode-f05c012b7e8e7484e27fe0d2660b4246" class="card-title">
        Jules Wunsch
      </h5>
      <p id="basenode-07b8b1cca072bbb57fcb3b009b48efbe" class="card-text">
        daniel.arlie@example.net
      </p>
    </div>
  </div>
</div>