|
| 1 | +import { Slot, component$ } from '@builder.io/qwik'; |
| 2 | +import { SfProgressSize } from '../../shared/SfProgress'; |
| 3 | +import { SfProgressCircularProps } from './types'; |
| 4 | + |
| 5 | +const sizeClasses = { |
| 6 | + [SfProgressSize.xs]: 'h-4 w-4 ring-2', |
| 7 | + [SfProgressSize.sm]: 'h-5 w-5 ring-2', |
| 8 | + [SfProgressSize.base]: 'h-6 w-6 ring-2', |
| 9 | + [SfProgressSize.lg]: 'h-8 w-8 ring-2', |
| 10 | + [SfProgressSize.xl]: 'h-10 w-10 ring-2', |
| 11 | + [SfProgressSize['2xl']]: 'h-14 w-14 ring-[3px]', |
| 12 | + [SfProgressSize['3xl']]: 'h-24 w-24 ring-4', |
| 13 | + [SfProgressSize['4xl']]: 'h-48 w-48 ring-8', |
| 14 | +}; |
| 15 | + |
| 16 | +const strokeSizeClass = { |
| 17 | + [SfProgressSize.xs]: 'stroke-[10px]', |
| 18 | + [SfProgressSize.sm]: 'stroke-[8px]', |
| 19 | + [SfProgressSize.base]: 'stroke-[6px]', |
| 20 | + [SfProgressSize.lg]: 'stroke-[4px]', |
| 21 | + [SfProgressSize.xl]: 'stroke-[3px]', |
| 22 | + [SfProgressSize['2xl']]: 'stroke-[3px]', |
| 23 | + [SfProgressSize['3xl']]: 'stroke-2', |
| 24 | + [SfProgressSize['4xl']]: 'stroke-2', |
| 25 | +}; |
| 26 | + |
| 27 | +export const SfProgressCircular = component$<SfProgressCircularProps>( |
| 28 | + ({ |
| 29 | + value = 0, |
| 30 | + size = SfProgressSize.base, |
| 31 | + ariaLabel = 'Progress element', |
| 32 | + class: _class, |
| 33 | + ...attributes |
| 34 | + }) => { |
| 35 | + const strokeDasharray = `${(value / 100) * 151}, 150`; |
| 36 | + return ( |
| 37 | + <svg |
| 38 | + role="progressbar" |
| 39 | + aria-valuemin={0} |
| 40 | + aria-valuemax={100} |
| 41 | + aria-valuenow={value} |
| 42 | + aria-label={ariaLabel} |
| 43 | + class={`inline-block ring-inset ring-neutral-300 text-primary-700 rounded-full transition-[stroke-dasharray] ease-in-out duration-500 text-sm |
| 44 | + ${sizeClasses[size]} |
| 45 | + ${_class}`} |
| 46 | + viewBox="25 25 50 50" |
| 47 | + strokeDasharray={strokeDasharray} |
| 48 | + data-testid="progress" |
| 49 | + {...attributes} |
| 50 | + > |
| 51 | + <circle |
| 52 | + className={`origin-bottom-right -rotate-90 stroke-current fill-none ${strokeSizeClass[size]}`} |
| 53 | + cx="50" |
| 54 | + cy="50" |
| 55 | + r="24" |
| 56 | + /> |
| 57 | + <Slot /> |
| 58 | + </svg> |
| 59 | + ); |
| 60 | + } |
| 61 | +); |
0 commit comments