-
Notifications
You must be signed in to change notification settings - Fork 40
/
linkGroup.ts
70 lines (64 loc) · 1.48 KB
/
linkGroup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { ArrayField } from 'payload/dist/fields/config/types'
import type { Field } from 'payload/types'
import deepMerge from '../utilities/deepMerge'
import type { LinkAppearances } from './link'
import link from './link'
type LinkGroupType = (options?: {
overrides?: Partial<ArrayField>
appearances?: LinkAppearances[] | false
additions?: {
npmCta?: boolean
}
}) => Field
const additionalFields: Field[] = [
{
name: 'type',
type: 'select',
defaultValue: 'link',
options: [
{ value: 'link', label: 'Link' },
{ value: 'npmCta', label: 'NPM CTA' },
],
},
{
name: 'npmCta',
type: 'group',
fields: [
{
name: 'label',
type: 'text',
required: true,
},
],
admin: {
condition: (_, { type }) => Boolean(type === 'npmCta'),
},
},
]
const linkGroup: LinkGroupType = ({ overrides = {}, appearances, additions } = {}) => {
const generatedLinkGroup: Field = {
name: 'links',
type: 'array',
fields: [
...(additions?.npmCta
? [
...additionalFields,
link({
overrides: {
admin: {
condition: (_, { type }) => Boolean(type === 'link'),
},
},
appearances,
}),
]
: [
link({
appearances,
}),
]),
],
}
return deepMerge(generatedLinkGroup, overrides)
}
export default linkGroup