BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/payload-extra-fields/array-row-label

Custom Array Row Label

payload-extra-fields/array-row-label
FreeItem

A custom array row label component for PayloadCMS.

Install it

npx shadcn@latest add https://payload.veiag.dev/r/array-row-label.json

Source

registry/components/array-row-label/index.tsxpayload.veiag.dev/r/array-row-label.json
1'use client'
2import { useRowLabel } from '@payloadcms/ui'
3import { ArrayRowLabelArgs } from './types'
4import { useMemo } from 'react'
5
6/**
7 * Helper function to get nested value from an object using dot notation
8 * e.g. getNestedValue(obj, 'nested.fieldName')
9 */
10const getNestedValue = (obj: unknown, path: string): unknown => {
11 return path.split('.').reduce((acc, part) => {
12 if (acc && typeof acc === 'object' && acc !== null && part in acc) {
13 return (acc as Record<string, unknown>)[part]
14 }
15 return undefined
16 }, obj)
17}
18
19/**
20 * Helper function to check if all field variables in a template are empty
21 */
22const hasEmptyFieldValues = (template: string, data: unknown): boolean => {
23 const fieldMatches = template.match(/{{\s*([\w.]+)\s*}}/g)
24
25 if (!fieldMatches) {
26 return false
27 }
28
29 // Check if all field variables (excluding 'index') are empty
30 return fieldMatches.every((match) => {
31 const fieldPath = match.replace(/{{\s*|\s*}}/g, '')
32
33 // Skip 'index' as it's always populated
34 if (fieldPath === 'index') {
35 return false
36 }
37
38 const value = getNestedValue(data, fieldPath)
39 return !value || (typeof value === 'string' && value.trim() === '')
40 })
41}
42
43/**
44 * Helper function to process template strings with variable replacement
45 */
46const processTemplate = (template: string, data: unknown, rowNumber?: number): string => {
47 let result = template.replace(/{{\s*index\s*}}/g, String(rowNumber || 0))
48
49 result = result.replace(/{{\s*([\w.]+)\s*}}/g, (_, fieldPath) => {
50 const value = getNestedValue(data, fieldPath)
51 if (typeof value === 'string' || typeof value === 'number') {
52 return String(value)
53 }
54 return ''
55 })
56
57 return result
58}
59
60const ArrayCustomLabel: React.FC<ArrayRowLabelArgs> = ({
61 fieldToUse,
62 template = false,
63 fallbackLabel = 'Item {{index}}',
64}) => {
65 // eslint-disable-next-line @typescript-eslint/no-explicit-any
66 const { data, rowNumber } = useRowLabel<any>()
67
68 const customLabel = useMemo(() => {
69 let labelValue = ''
70 let shouldUseFallback = false
71
72 if (!template) {
73 // Simple field mode
74 const value = getNestedValue(data, fieldToUse)
75 if (typeof value === 'string' || typeof value === 'number') {
76 labelValue = String(value).trim()
77 }
78 shouldUseFallback = !labelValue
79 } else {
80 // Template mode - check if all field values are empty
81 shouldUseFallback = hasEmptyFieldValues(fieldToUse, data)
82
83 if (!shouldUseFallback) {
84// … truncated

Files it writes

  • registry/components/array-row-label/utility.ts
  • registry/components/array-row-label/index.tsx
  • registry/components/array-row-label/types.ts

Facts

Registry
payload-extra-fields
Type
registry:item
Access
Free
Files written
3
Licence
MIT
First indexed
2026-08-04
Last confirmed
today

Go to the source

payload.veiag.dev VeiaG/payload-extra-fields on GitHub Raw registry item This item as JSON

More from payload-extra-fields

All 4 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Color Pickercolor-pickerpayload-extra-fieldsOtherFreeno deps · 4 files
Lucide Icon Pickerlucide-icon-pickerpayload-extra-fieldsOtherFree4 deps · 5 files
Slug Fieldslugpayload-extra-fieldsOtherFreeno deps · 6 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex