v0.0.2
Demos (demo panel, opens in a new tab)

Horizontal form

A form layout with labels on the left and fields on the right, for settings and detail screens.

Form layout zubazar/ui · free (MIT)

Basic usage

Basic usage: view
BLADE

Split each row into two columns with grid sm:grid-cols-[10rem_1fr] and match the label's for to the field's name.

blade
<form class="space-y-4">
    <div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
        <label for="customer_name" class="text-sm font-medium text-body">Customer name</label>
        <zb:input name="customer_name" value="Ayşe Yılmaz" />
    </div>
    <div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
        <label for="customer_email" class="text-sm font-medium text-body">Email</label>
        <zb:input name="customer_email" type="email" value="ayse.yilmaz@example.com" />
    </div>
</form>
PropValues
sm:grid-cols-[10rem_1fr]Width of the label column
for / nameLinks the label to the field

In a card

In a card: view
BLADE

Leave the first cell of the button row empty (<span></span>); the buttons line up with the fields.

blade
<zb:card title="Product details">
    <form class="space-y-4">
        <div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
            <label for="product_name" class="text-sm font-medium text-body">Product name</label>
            <zb:input name="product_name" value="Wireless headphones" />
        </div>
        <div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
            <label for="product_sku" class="text-sm font-medium text-body">SKU</label>
            <zb:input name="product_sku" value="WHP-02" />
        </div>
        <div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
            <label for="product_category" class="text-sm font-medium text-body">Category</label>
            <zb:select name="product_category" :options="['1' => 'Electronics', '2' => 'Accessories']" />
        </div>
        <div class="grid gap-2 sm:grid-cols-[10rem_1fr]">
            <span></span>
            <div class="flex gap-2"><zb:button type="submit">Save</zb:button><zb:button variant="white">Cancel</zb:button></div>
        </div>
    </form>
</zb:card>

Multi-line fields and options

Multi-line fields and options: view
BLADE

For tall fields align the row to the top with items-start and give the label sm:pt-2.5.

blade
<zb:card title="Order settings">
    <div class="space-y-4">
        <div class="grid items-start gap-2 sm:grid-cols-[10rem_1fr]">
            <label for="setting_note" class="text-sm font-medium text-body sm:pt-2.5">Invoice note</label>
            <zb:textarea name="setting_note" rows="3" />
        </div>
        <div class="grid items-start gap-2 sm:grid-cols-[10rem_1fr]">
            <span class="text-sm font-medium text-body">Notifications</span>
            <div class="flex flex-col gap-3">
                <zb:switch name="setting_sms" label="Send SMS" checked />
                <zb:switch name="setting_email" label="Send email" />
            </div>
        </div>
    </div>
</zb:card>
PropValues
items-startAligns the row to the top
sm:pt-2.5Moves the label down to the field's first line

Required field, hint and error

Required field, hint and error: view
BLADE

In this layout add the required star to the label yourself; the hint and the error show below the field, in the right column.

blade
<div class="space-y-4">
    <div class="grid items-start gap-2 sm:grid-cols-[10rem_1fr]">
        <label for="code" class="text-sm font-medium text-body sm:pt-2.5">SKU <span class="text-danger-line">*</span></label>
        <zb:input name="code" value="WHP-01" required />
    </div>
    <div class="grid items-start gap-2 sm:grid-cols-[10rem_1fr]">
        <label for="capacity" class="text-sm font-medium text-body sm:pt-2.5">Daily capacity</label>
        <zb:input name="capacity" type="number" value="40" hint="Maximum number of orders that can ship in a day." />
    </div>
</div>
PropValues
requiredPassed to the field; add the asterisk to the label by hand
hintBelow the field, in the right column

Developer notes

Events, hooks and details
  • On small screens the labels move above the fields.
  • Use the fields without label; zb:input takes its id from name when none is given, and shows the star only with its own label.
Zubazar UI · ZubazarDesigned for people.