|
| 1 | +<script setup lang="ts"> |
| 2 | + import { createSelection } from '@vuetify/v0' |
| 3 | + import { computed } from 'vue' |
| 4 | +
|
| 5 | + const files = [ |
| 6 | + { id: 'readme', name: 'README.md', icon: '📄', size: '2.4 KB' }, |
| 7 | + { id: 'package', name: 'package.json', icon: '📦', size: '1.1 KB' }, |
| 8 | + { id: 'src', name: 'src/', icon: '📁', size: '—' }, |
| 9 | + { id: 'index', name: 'index.ts', icon: '📜', size: '340 B' }, |
| 10 | + { id: 'license', name: 'LICENSE', icon: '📄', size: '1.0 KB', disabled: true }, |
| 11 | + { id: 'tests', name: 'tests/', icon: '📁', size: '—' }, |
| 12 | + { id: 'config', name: 'tsconfig.json', icon: '⚙️', size: '520 B' }, |
| 13 | + { id: 'ci', name: '.github/', icon: '📂', size: '—' }, |
| 14 | + ] |
| 15 | +
|
| 16 | + const selection = createSelection({ multiple: true }) |
| 17 | + const tickets = selection.onboard(files.map(f => ({ |
| 18 | + id: f.id, |
| 19 | + value: f, |
| 20 | + disabled: f.disabled, |
| 21 | + }))) |
| 22 | +
|
| 23 | + const totalSize = computed(() => { |
| 24 | + const sizes = Array.from(selection.selectedValues.value) |
| 25 | + .map((v: any) => v.size) |
| 26 | + .filter((s: string) => s !== '—') |
| 27 | + return sizes.length > 0 ? sizes.join(' + ') : 'nothing' |
| 28 | + }) |
| 29 | +</script> |
| 30 | + |
| 31 | +<template> |
| 32 | + <div class="space-y-4"> |
| 33 | + <!-- Toolbar --> |
| 34 | + <div class="flex items-center justify-between"> |
| 35 | + <span class="text-sm font-medium text-on-surface"> |
| 36 | + {{ selection.selectedIds.size }} selected |
| 37 | + </span> |
| 38 | + <button |
| 39 | + class="text-xs px-2 py-1 rounded border border-divider text-on-surface-variant hover:bg-surface-tint transition-colors disabled:opacity-40" |
| 40 | + :disabled="selection.selectedIds.size === 0" |
| 41 | + @click="selection.reset()" |
| 42 | + > |
| 43 | + Clear |
| 44 | + </button> |
| 45 | + </div> |
| 46 | + |
| 47 | + <!-- File list --> |
| 48 | + <div class="border border-divider rounded-lg overflow-hidden divide-y divide-divider"> |
| 49 | + <button |
| 50 | + v-for="ticket in tickets" |
| 51 | + :key="ticket.id" |
| 52 | + class="w-full flex items-center gap-3 px-3 py-2.5 text-left transition-colors" |
| 53 | + :class="[ |
| 54 | + ticket.isSelected.value |
| 55 | + ? 'bg-primary/10' |
| 56 | + : 'hover:bg-surface-variant', |
| 57 | + ticket.disabled ? 'opacity-40 cursor-not-allowed' : 'cursor-pointer', |
| 58 | + ]" |
| 59 | + :disabled="!!ticket.disabled" |
| 60 | + @click="!ticket.disabled && ticket.toggle()" |
| 61 | + > |
| 62 | + <!-- Checkbox --> |
| 63 | + <div |
| 64 | + class="size-4 rounded border flex items-center justify-center transition-colors shrink-0" |
| 65 | + :class="ticket.isSelected.value |
| 66 | + ? 'bg-primary border-primary' |
| 67 | + : 'border-divider'" |
| 68 | + > |
| 69 | + <span |
| 70 | + v-if="ticket.isSelected.value" |
| 71 | + class="text-on-primary text-xs leading-none" |
| 72 | + >✓</span> |
| 73 | + </div> |
| 74 | + |
| 75 | + <!-- Icon --> |
| 76 | + <span class="shrink-0 text-base leading-none">{{ ticket.value.icon }}</span> |
| 77 | + |
| 78 | + <!-- Name --> |
| 79 | + <span |
| 80 | + class="flex-1 text-sm" |
| 81 | + :class="ticket.isSelected.value ? 'text-primary font-medium' : 'text-on-surface'" |
| 82 | + > |
| 83 | + {{ ticket.value.name }} |
| 84 | + </span> |
| 85 | + |
| 86 | + <!-- Size --> |
| 87 | + <span class="text-xs text-on-surface-variant">{{ ticket.value.size }}</span> |
| 88 | + </button> |
| 89 | + </div> |
| 90 | + |
| 91 | + <!-- Status --> |
| 92 | + <p class="text-xs text-on-surface-variant text-center"> |
| 93 | + Selected: {{ totalSize }} |
| 94 | + <span v-if="selection.selectedIds.size > 0"> |
| 95 | + · |
| 96 | + <button class="text-primary hover:underline" @click="selection.reset()"> |
| 97 | + Deselect all |
| 98 | + </button> |
| 99 | + </span> |
| 100 | + </p> |
| 101 | + </div> |
| 102 | +</template> |
0 commit comments