master
parent
d1fbf455cf
commit
4bf0c9c678
@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import type { MetadataFieldType } from '../../lib';
|
||||
import FieldTypeIcon from './FieldTypeIcon.svelte';
|
||||
|
||||
let {
|
||||
onSelect,
|
||||
label = 'Añadir',
|
||||
iconOnly = false,
|
||||
}: {
|
||||
onSelect: (type: MetadataFieldType) => void;
|
||||
label?: string;
|
||||
iconOnly?: boolean;
|
||||
} = $props();
|
||||
|
||||
const typeLabels: Record<MetadataFieldType, string> = {
|
||||
string: 'Texto', number: 'Número', boolean: 'Bool', ling: 'i18n',
|
||||
date: 'Fecha', datetime: 'DateTime', url: 'URL', currency: 'Moneda',
|
||||
image: 'Imagen', video: 'Vídeo', audio: 'Audio', pdf: 'PDF',
|
||||
file: 'Fichero', html: 'HTML', group: 'Grupo',
|
||||
};
|
||||
|
||||
const typeGroups: { label: string; types: MetadataFieldType[] }[] = [
|
||||
{ label: 'Texto', types: ['string', 'ling', 'html', 'url'] },
|
||||
{ label: 'Número', types: ['number', 'currency'] },
|
||||
{ label: 'Fecha', types: ['date', 'datetime'] },
|
||||
{ label: 'Lógico', types: ['boolean'] },
|
||||
{ label: 'Media', types: ['image', 'video', 'audio', 'pdf', 'file'] },
|
||||
{ label: 'Grupo', types: ['group'] },
|
||||
];
|
||||
</script>
|
||||
|
||||
<div class="dropdown dropdown-end">
|
||||
<button tabindex="0" type="button"
|
||||
class={iconOnly ? 'btn btn-ghost btn-xs btn-square' : 'btn btn-sm btn-ghost gap-1'}
|
||||
title="Añadir campo">
|
||||
<svg class="h-4 w-4" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M8 3v10M3 8h10"/>
|
||||
</svg>
|
||||
{#if !iconOnly}<span class="text-xs">{label}</span>{/if}
|
||||
</button>
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<div tabindex="0" class="dropdown-content z-10 card card-compact bg-base-100 border border-base-200 shadow-lg p-3 w-124">
|
||||
<div class="flex flex-col gap-2">
|
||||
{#each typeGroups as group}
|
||||
<div class="flex flex-wrap items-center gap-1">
|
||||
<span class="text-base-content/30 text-xs w-10 shrink-0">{group.label}</span>
|
||||
{#each group.types as type}
|
||||
<button type="button"
|
||||
onclick={() => onSelect(type)}
|
||||
class="btn btn-ghost btn-xs gap-1 px-1.5"
|
||||
title={typeLabels[type]}>
|
||||
<FieldTypeIcon {type} size={14} />
|
||||
<span class="text-xs">{typeLabels[type]}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Reference in new issue