التنبيهات
progress
شريط تقدم يعرض نسبة إنجاز مهمة.
<div class="flex w-full max-w-sm flex-col gap-4">
<x-ui.progress :value="0" />
<x-ui.progress :value="33" />
<x-ui.progress :value="66" />
<x-ui.progress :value="100" />
</div>
التثبيت
php artisan ui:add progress
1. ثبّت الاعتماديات
- composer:
gehrisandro/tailwind-merge-laravel
2.
انسخ الكود إلى
resources/views/components/ui/
resources/views/components/ui/progress.blade.php
@props([
'value' => 0,
'max' => 100,
])
@php
// Guard the divisor: a max of 0 from a caller's arithmetic would blow up.
$ceiling = max(1, (int) $max);
$current = max(0, min($ceiling, (float) $value));
// Rounded so the style attribute does not carry 33.333333333333336%.
$remaining = round(100 - ($current / $ceiling) * 100, 2);
$classes = \TailwindMerge\Laravel\Facades\TailwindMerge::merge(
// rtl:-scale-x-100 mirrors the track so the fill grows from the
// right; the inline translateX below stays the same either way.
'relative h-2 w-full overflow-hidden rounded-full bg-primary/20 rtl:-scale-x-100',
$attributes->get('class'),
);
@endphp
<div role="progressbar" aria-valuenow="{{ $current }}" aria-valuemin="0"
aria-valuemax="{{ $ceiling }}"
{{ $attributes->except('class')->merge(['class' => $classes]) }}>
{{-- The fill is positioned by transform, not width, so it animates on the
compositor. A dynamic width has to be an inline style either way:
w-[{{ '$percent' }}%] never reaches Tailwind's class scanner. --}}
<div class="h-full w-full flex-1 bg-primary transition-transform duration-300 ease-out"
style="transform: translateX(-{{ $remaining }}%)"></div>
</div>
الاستخدام
<x-ui.progress :value="66" />
{{-- max rescales the bar: 30 out of 120 renders as 25% --}}
<x-ui.progress :value="30" :max="120" />
بلا JavaScript. مرّر value (وmax، افتراضيًا 100)؛ يُحدَّد موضع التعبئة بـ transform مضمّن لأن Tailwind لا يستطيع تجميع صنف عرض ديناميكي.
الخصائص
كل خاصية مع قيمتها الافتراضية. مرّر أيًّا منها كسمة، واستخدم : لربط قيمة PHP.
@props([
'value' => 0,
'max' => 100,
])