beartropy/ui
Beartropy UI is a small Laravel UI package providing ready-made components and helpers to speed up building admin and front-end screens. Drop in common layouts, forms, and UI utilities to get a consistent look fast with minimal setup.
<x-bt-toggle />
Toggle → extends BeartropyComponenttoggle.blade.phpresources/views/presets/toggle.php (25 color variants)resources/views/presets/sizes.php (toggle-specific keys: trackHeight, trackWidth, thumb, thumbTranslate, thumbTop, thumbLeft, font)support/field-help.blade.php for error and help text below togglechecked state, x-model on hidden input, autosave logic with triggerAutosave()| Prop | PHP Type | Default | Blade Attribute |
|---|---|---|---|
| name | ?string |
null |
name="setting" |
| label | ?string |
null |
label="Dark mode" |
| labelPosition | ?string |
'right' |
label-position="left" |
| color | ?string |
null |
color="blue" or magic: blue |
| size | ?string |
null |
size="lg" or magic: lg |
| customError | mixed |
null |
:custom-error="$error" |
| disabled | bool |
false |
:disabled="true" |
| hint | ?string |
null |
hint="Hint text" |
| help | ?string |
null |
help="Help text" |
| autosave | bool |
false |
:autosave="true" |
| autosaveMethod | string |
'savePreference' |
autosave-method="customSave" |
| autosaveKey | ?string |
null |
autosave-key="dark_mode" |
| autosaveDebounce | int |
300 |
:autosave-debounce="500" |
HTML attributes (id, checked, wire:model, etc.) are NOT constructor props — they pass through $attributes to the native <input>.
beartropy via config)primary, beartropy, red, blue, green, yellow, purple, pink, gray, orange, amber, lime, emerald, teal, cyan, sky, indigo, violet, rose, fuchsia, slate, stone, zinc, neutral
md)xs, sm, md, lg, xl
| Slot | Description |
|---|---|
| default | Label content override (takes precedence over label prop). Supports rich HTML. |
| Position | Layout | CSS |
|---|---|---|
top |
Vertical, label above | flex flex-col gap-1 |
bottom |
Vertical, label below | flex flex-col gap-1 |
left |
Horizontal, label left | inline-flex items-center gap-2 |
right (default) |
Horizontal, label right | inline-flex items-center gap-2 |
colors → {color} → {
checked, bg, border, border_error,
thumb, hover, focus, focus_error,
active, disabled,
label, label_error
}
checked — peer-checked:bg-{color}-600 (track fill on check)bg — unchecked track: bg-neutral-300 dark:bg-gray-700thumb — bg-white (always white)border_error — ring-2 ring-red-500disabled — opacity-60 cursor-not-allowed{
autosave: bool,
method: string,
key: string|null,
debounceMs: int,
saving: false,
saved: false,
error: false,
checked: bool | $wire.entangle(wireModel).live,
triggerAutosave() { ... }
}
When wire:model is present, checked is entangled via $wire.entangle(). Otherwise, it reads from the checked HTML attribute.
When autosave is true and [@change](https://github.com/change) fires:
saving: true, clears previous timeoutdebounceMs milliseconds$wire.call(method, boolValue, key) on the Livewire componentsaving: false, saved: truesaving: false, error: trueVisual indicators (only rendered when $autosave is true):
animate-spin) while savingautosaveKey defaults to $wireModelValue if not explicitly provided.
$errors bag for field name or wire:model valuecustomError propborder_error), label turns red (label_error), focus ring switches to red (focus_error)field-help component below the toggle<div> wraps Alpine state + autosave border transitions<div> contains label + toggle + autosave indicators<input type="checkbox"> is peer sr-only (visually hidden but accessible)rounded-full <span> with color presetsrounded-full <span> with peer-checked:translate-x-{N} animation{{-- Basic --}}
<x-bt-toggle label="Enable feature" />
{{-- With name --}}
<x-bt-toggle name="dark_mode" label="Dark mode" />
{{-- Pre-checked --}}
<x-bt-toggle label="On by default" checked />
{{-- Colored --}}
<x-bt-toggle blue label="Blue toggle" />
{{-- Sized --}}
<x-bt-toggle lg label="Large toggle" />
{{-- Label positions --}}
<x-bt-toggle label="Left label" label-position="left" />
<x-bt-toggle label="Top label" label-position="top" />
{{-- Rich label via slot --}}
<x-bt-toggle name="tos">
I accept the <a href="/terms">Terms</a>
</x-bt-toggle>
{{-- Disabled --}}
<x-bt-toggle label="Locked" :disabled="true" checked />
{{-- With help text --}}
<x-bt-toggle label="Notifications" help="Email and push notifications." />
{{-- Custom error --}}
<x-bt-toggle label="Accept" :custom-error="'Required'" />
{{-- Livewire --}}
<x-bt-toggle wire:model="enabled" label="Enabled" />
{{-- Livewire live --}}
<x-bt-toggle wire:model.live="darkMode" label="Dark mode" />
{{-- Autosave --}}
<x-bt-toggle label="Setting" :autosave="true" wire:model="setting" />
{{-- Autosave with custom method --}}
<x-bt-toggle
label="Notifications"
:autosave="true"
autosave-method="savePreference"
autosave-key="notifications"
:autosave-debounce="500"
wire:model="notifications"
/>
'toggle' => [
'color' => env('BEARTROPY_UI_TOGGLE_COLOR', 'beartropy'),
'size' => env('BEARTROPY_UI_TOGGLE_SIZE', 'md'),
],
x-data, x-model, [@change](https://github.com/change)<input type="checkbox"> is sr-only — the visible toggle is styled <span> elementsid auto-generates as beartropy-toggle-{uniqid} if not providedhelp and hint are aliases; help takes precedence in the field-help componentlabel prop (checked via trim($slot) !== '')autosaveKey falls back to $wireModelValue when not explicitly set — this is resolved after $getWireModelState() in the Blade templateprimary preset maps to beartropy colors — identical to beartropy preset$autosave is true:class bindings even when autosave is false (border is transparent)How can I help you explore Laravel packages today?