149 lines
4.2 KiB
TypeScript
149 lines
4.2 KiB
TypeScript
import type { Block } from 'payload'
|
|
import { anchorField } from '@/fields/anchorField'
|
|
|
|
export const FDDataTableBlock: Block = {
|
|
slug: 'fdDataTable',
|
|
imageURL: '/block-thumbnails/fd-data-table.png',
|
|
imageAltText: 'FD Datatabell',
|
|
interfaceName: 'FDDataTableBlock',
|
|
labels: {
|
|
singular: 'FD Datatabell',
|
|
plural: 'FD Datatabeller',
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'heading',
|
|
type: 'text',
|
|
localized: true,
|
|
label: 'Rubrik (valfri)',
|
|
},
|
|
{
|
|
name: 'description',
|
|
type: 'textarea',
|
|
localized: true,
|
|
label: 'Beskrivning (valfri)',
|
|
},
|
|
|
|
// ── Data source ──────────────────────────────────────────
|
|
{
|
|
name: 'dataSource',
|
|
type: 'select',
|
|
label: 'Datakälla',
|
|
defaultValue: 'upload',
|
|
options: [
|
|
{ label: 'Ladda upp fil (CSV eller Excel)', value: 'upload' },
|
|
{ label: 'Ange data manuellt', value: 'manual' },
|
|
],
|
|
admin: {
|
|
description: 'Välj om du vill ladda upp en fil eller ange tabelldata manuellt.',
|
|
},
|
|
},
|
|
|
|
// ── File upload (CSV or Excel) ────────────────────────────
|
|
{
|
|
name: 'file',
|
|
type: 'upload',
|
|
relationTo: 'media',
|
|
label: 'CSV- eller Excel-fil',
|
|
admin: {
|
|
condition: (_, siblingData) => siblingData?.dataSource === 'upload',
|
|
description: 'Ladda upp en .csv, .xlsx eller .xls fil. Den första raden används som kolumnrubriker.',
|
|
},
|
|
},
|
|
|
|
// ── Manual data entry ─────────────────────────────────────
|
|
{
|
|
name: 'headers',
|
|
type: 'array',
|
|
label: 'Kolumnrubriker',
|
|
maxRows: 20,
|
|
admin: {
|
|
condition: (_, siblingData) => siblingData?.dataSource === 'manual',
|
|
description: 'Lägg till en rad per kolumn.',
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'text',
|
|
type: 'text',
|
|
localized: true,
|
|
required: true,
|
|
label: 'Rubrik',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'rows',
|
|
type: 'array',
|
|
label: 'Rader',
|
|
admin: {
|
|
condition: (_, siblingData) => siblingData?.dataSource === 'manual',
|
|
description: 'Varje rad är en kommaseparerad sträng av cellvärden, i samma ordning som kolumnrubrikerna.',
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'cells',
|
|
type: 'text',
|
|
localized: true,
|
|
required: true,
|
|
label: 'Cellvärden (kommaseparerade)',
|
|
admin: {
|
|
description: 'T.ex: "Stockholm, 10 Gbit, 99.9%, 2 400 kr/mån"',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
|
|
// ── Style options ─────────────────────────────────────────
|
|
{
|
|
name: 'sectionBackground',
|
|
type: 'select',
|
|
label: 'Sektionsbakgrund',
|
|
defaultValue: 'white',
|
|
options: [
|
|
{ label: 'Vit', value: 'white' },
|
|
{ label: 'Navy', value: 'navy' },
|
|
{ label: 'Grå', value: 'gray' },
|
|
],
|
|
},
|
|
{
|
|
name: 'headerStyle',
|
|
type: 'select',
|
|
label: 'Rubrikradsstil',
|
|
defaultValue: 'navy',
|
|
options: [
|
|
{ label: 'Navy (vit text)', value: 'navy' },
|
|
{ label: 'Gul (navy text)', value: 'yellow' },
|
|
{ label: 'Mint (navy text)', value: 'mint' },
|
|
{ label: 'Grå (navy text)', value: 'gray' },
|
|
],
|
|
},
|
|
{
|
|
name: 'stripeRows',
|
|
type: 'checkbox',
|
|
label: 'Växlande radfärger',
|
|
defaultValue: true,
|
|
admin: {
|
|
description: 'Aktivera för att annenhålla rader med subtil bakgrundsfärg.',
|
|
},
|
|
},
|
|
{
|
|
name: 'bordered',
|
|
type: 'checkbox',
|
|
label: 'Visa cellinramning',
|
|
defaultValue: false,
|
|
admin: {
|
|
description: 'Lägg till linjer mellan alla celler.',
|
|
},
|
|
},
|
|
{
|
|
name: 'firstColumnBold',
|
|
type: 'checkbox',
|
|
label: 'Fet första kolumn',
|
|
defaultValue: false,
|
|
admin: {
|
|
description: 'Gör den första kolumnen fet — användbart för namnkolumner.',
|
|
},
|
|
},
|
|
anchorField,
|
|
],
|
|
} |