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/slug

Slug Field

payload-extra-fields/slug
FreeItem

Copy of original payload slug field to allow code customization.

Install it

npx shadcn@latest add https://payload.veiag.dev/r/slug.json

Source

registry/fields/slug/index.tsxpayload.veiag.dev/r/slug.json
1'use client'
2
3import React, { useCallback, useState } from 'react'
4import { Button, useForm, useField, FieldLabel, TextInput } from '@payloadcms/ui'
5import './style.scss'
6import { SlugFieldProps } from './field'
7import { slugify } from './slugify'
8
9/**
10 * @experimental This component is experimental and may change or be removed in the future. Use at your own risk.
11 */
12export const SlugField: React.FC<SlugFieldProps> = ({
13 field,
14 fieldToUse,
15 path,
16 readOnly: readOnlyFromProps,
17}) => {
18 const { label } = field
19
20 const { setValue, value } = useField<string>({ path: path || field.name })
21
22 const { getDataByPath } = useForm()
23
24 const [isLocked, setIsLocked] = useState(true)
25
26 const handleGenerate = useCallback(
27 (e: React.MouseEvent<Element>) => {
28 e.preventDefault()
29
30 const targetFieldValue = getDataByPath(fieldToUse || 'title')
31
32 if (targetFieldValue) {
33 const formattedSlug = slugify(targetFieldValue as string)
34
35 if (value !== formattedSlug) {
36 setValue(formattedSlug)
37 }
38 } else {
39 if (value !== '') {
40 setValue('')
41 }
42 }
43 },
44 [setValue, value, fieldToUse, getDataByPath],
45 )
46
47 const toggleLock = useCallback((e: React.MouseEvent<Element>) => {
48 e.preventDefault()
49 setIsLocked((prev) => !prev)
50 }, [])
51
52 return (
53 <div className="field-type slug-field-component">
54 <div className="label-wrapper">
55 <FieldLabel htmlFor={`field-${path}`} label={label} />
56 {!isLocked && (
57 <Button buttonStyle="none" className="lock-button" onClick={handleGenerate}>
58 Generate
59 </Button>
60 )}
61 <Button buttonStyle="none" className="lock-button" onClick={toggleLock}>
62 {isLocked ? 'Unlock' : 'Lock'}
63 </Button>
64 </div>
65 <TextInput
66 onChange={setValue}
67 path={path || field.name}
68 readOnly={Boolean(readOnlyFromProps || isLocked)}
69 value={value}
70 />
71 </div>
72 )
73}

Files it writes

  • registry/fields/slug/field.ts
  • registry/fields/slug/index.tsx
  • registry/fields/slug/countVersions.ts
  • registry/fields/slug/generateSlug.ts
  • registry/fields/slug/slugify.ts
  • registry/fields/slug/style.scss

Facts

Registry
payload-extra-fields
Type
registry:item
Access
Free
Files written
6
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
Custom Array Row Labelarray-row-labelpayload-extra-fieldsOtherFreeno deps · 3 files
Color Pickercolor-pickerpayload-extra-fieldsOtherFreeno deps · 4 files
Lucide Icon Pickerlucide-icon-pickerpayload-extra-fieldsOtherFree4 deps · 5 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