|
1 | | -<div class="flex gap-[2%] w-full max-w-[21rem] h-4 rounded-pill overflow-hidden"> |
2 | | - @for (item of likertValues; track $index) { |
3 | | - <button |
4 | | - type="button" |
5 | | - class="btn-bare flex-1 transition-colors" |
6 | | - [class]="selectable() ? 'cursor-pointer hover:brightness-75' : ''" |
7 | | - [style.background-color]="getSectionColor($index)" |
8 | | - [pTooltip]="tooltipTexts()[$index]" |
9 | | - tooltipPosition="top" |
10 | | - (click)="onSectionClick($index)" |
11 | | - ></button> |
12 | | - } |
13 | | -</div> |
| 1 | +@if (selectable()) { |
| 2 | + <div class="inline-flex flex-col gap-1"> |
| 3 | + <div |
| 4 | + class="flex items-center gap-1" |
| 5 | + role="radiogroup" |
| 6 | + [attr.aria-label]="groupLabel()" |
| 7 | + (mouseleave)="onHoverLeave()" |
| 8 | + (focusout)="onHoverLeave()" |
| 9 | + > |
| 10 | + @for (star of stars(); track star.value) { |
| 11 | + <button |
| 12 | + #starButton |
| 13 | + type="button" |
| 14 | + role="radio" |
| 15 | + class="p-0.5 rounded-sm border-0 bg-transparent cursor-pointer outline-none focus-visible:ring-3 focus-visible:ring-primary" |
| 16 | + [attr.aria-checked]="star.selected" |
| 17 | + [attr.aria-label]="star.label" |
| 18 | + [attr.tabindex]="star.tabbable ? 0 : -1" |
| 19 | + (click)="onStarClick(star.value)" |
| 20 | + (keydown)="onKeydown($event)" |
| 21 | + (mouseenter)="onStarHover(star.value)" |
| 22 | + (focus)="onStarHover(star.value)" |
| 23 | + > |
| 24 | + <fa-icon |
| 25 | + class="text-lg transition-colors" |
| 26 | + [class]="star.filled ? star.colourClass : emptyStarColourClass" |
| 27 | + [icon]="['fas', 'star']" |
| 28 | + /> |
| 29 | + </button> |
| 30 | + } |
| 31 | + </div> |
| 32 | + <!-- Height is reserved so previewing or picking a rating does not shift the surrounding layout. --> |
| 33 | + <span class="min-h-5 text-sm text-text-secondary">{{ selectedLabel() }}</span> |
| 34 | + </div> |
| 35 | +} @else { |
| 36 | + <div class="inline-flex items-center gap-1" role="img" [attr.aria-label]="readonlyLabel()"> |
| 37 | + @for (star of stars(); track star.value) { |
| 38 | + <fa-icon class="text-base" [class]="star.filled ? star.colourClass : emptyStarColourClass" [icon]="['fas', 'star']" /> |
| 39 | + } |
| 40 | + @if (selectedLabel() !== '') { |
| 41 | + <span class="ml-1.5 text-sm text-text-secondary">{{ selectedLabel() }}</span> |
| 42 | + } |
| 43 | + </div> |
| 44 | +} |
0 commit comments