Skip to content

Commit a00c2fc

Browse files
committed
refactor(payload): extract reusable button, link and gradient fields
1 parent 28c31c9 commit a00c2fc

16 files changed

Lines changed: 137 additions & 473 deletions

src/blocks/ActionHeroBlock.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { buttonField } from "@/fields/buttonField"
12
import { colorField } from "@mvriu5/payload-color-picker"
23
import type { Block } from "payload"
34

@@ -58,28 +59,6 @@ export const ActionHeroBlock: Block = {
5859
required: false,
5960
fields: [{ name: "text", type: "text", required: true, localized: true }],
6061
},
61-
{
62-
name: "buttons",
63-
label: "Buttons",
64-
type: "array",
65-
required: false,
66-
maxRows: 3,
67-
fields: [
68-
{ name: "label", type: "text", required: true, localized: true },
69-
{ name: "url", type: "text", required: true },
70-
{
71-
name: "variant",
72-
type: "select",
73-
required: false,
74-
defaultValue: "normal",
75-
options: [
76-
{ label: "None", value: "none" },
77-
{ label: "Normal", value: "normal" },
78-
{ label: "Outlined", value: "outlined" },
79-
{ label: "Filled", value: "filled" },
80-
],
81-
},
82-
],
83-
},
62+
buttonField(3),
8463
],
8564
}

src/blocks/BentoBlock.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { linkField } from "@/fields/linkField"
12
import { sectionFields } from "@/fields/sectionFields"
23
import type { Block, Field } from "payload"
34

@@ -17,22 +18,7 @@ function cardContentFields(name: string, label: string): Field {
1718
type: "textarea",
1819
localized: true,
1920
},
20-
{
21-
name: "link",
22-
label: "Link",
23-
type: "group",
24-
fields: [
25-
{
26-
name: "label",
27-
type: "text",
28-
localized: true,
29-
},
30-
{
31-
name: "url",
32-
type: "text",
33-
},
34-
],
35-
},
21+
linkField(),
3622
],
3723
}
3824
}

src/blocks/CTAImageBlock.ts

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { buttonField } from "@/fields/buttonField"
12
import type { Block } from "payload"
23

34
export const CTAImageBlock: Block = {
@@ -27,50 +28,7 @@ export const CTAImageBlock: Block = {
2728
},
2829
],
2930
},
30-
{
31-
name: "buttons",
32-
label: "Buttons",
33-
type: "array",
34-
required: false,
35-
maxRows: 3,
36-
fields: [
37-
{
38-
name: "label",
39-
type: "text",
40-
required: true,
41-
localized: true,
42-
},
43-
{
44-
name: "url",
45-
type: "text",
46-
required: true,
47-
},
48-
{
49-
name: "variant",
50-
type: "select",
51-
required: false,
52-
defaultValue: "normal",
53-
options: [
54-
{
55-
label: "None",
56-
value: "none",
57-
},
58-
{
59-
label: "Normal",
60-
value: "normal",
61-
},
62-
{
63-
label: "Outlined",
64-
value: "outlined",
65-
},
66-
{
67-
label: "Filled",
68-
value: "filled",
69-
},
70-
],
71-
},
72-
],
73-
},
31+
buttonField(3),
7432
{
7533
name: "image",
7634
label: "Image",

src/blocks/CardRowBlock.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { linkField } from "@/fields/linkField"
12
import { sectionFields } from "@/fields/sectionFields"
23
import type { Block } from "payload"
34

@@ -27,23 +28,7 @@ export const CardRowBlock: Block = {
2728
required: false,
2829
localized: true,
2930
},
30-
{
31-
name: "link",
32-
type: "group",
33-
fields: [
34-
{
35-
name: "label",
36-
type: "text",
37-
required: false,
38-
localized: true,
39-
},
40-
{
41-
name: "url",
42-
type: "text",
43-
required: false,
44-
},
45-
],
46-
},
31+
linkField(),
4732
{
4833
name: "image",
4934
type: "upload",

src/blocks/CtaBlock.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { linkField } from "@/fields/linkField"
12
import type { Block } from "payload"
23

34
export const CtaBlock: Block = {
@@ -19,24 +20,6 @@ export const CtaBlock: Block = {
1920
required: true,
2021
localized: true,
2122
},
22-
{
23-
name: "ctaLink",
24-
label: "CTA Link",
25-
type: "group",
26-
required: true,
27-
fields: [
28-
{
29-
name: "label",
30-
type: "text",
31-
required: true,
32-
localized: true,
33-
},
34-
{
35-
name: "url",
36-
type: "text",
37-
required: true,
38-
},
39-
],
40-
},
23+
linkField({ name: "ctaLink", label: "CTA Link", required: true }),
4124
],
4225
}

src/blocks/HeroBlock.ts

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { buttonField } from "@/fields/buttonField"
12
import { colorField } from "@mvriu5/payload-color-picker"
23
import type { Block } from "payload"
34

@@ -83,49 +84,6 @@ export const HeroBlock: Block = {
8384
},
8485
],
8586
},
86-
{
87-
name: "buttons",
88-
label: "Buttons",
89-
type: "array",
90-
required: false,
91-
maxRows: 3,
92-
fields: [
93-
{
94-
name: "label",
95-
type: "text",
96-
required: true,
97-
localized: true,
98-
},
99-
{
100-
name: "url",
101-
type: "text",
102-
required: true,
103-
},
104-
{
105-
name: "variant",
106-
type: "select",
107-
required: false,
108-
defaultValue: "normal",
109-
options: [
110-
{
111-
label: "None",
112-
value: "none",
113-
},
114-
{
115-
label: "Normal",
116-
value: "normal",
117-
},
118-
{
119-
label: "Outlined",
120-
value: "outlined",
121-
},
122-
{
123-
label: "Filled",
124-
value: "filled",
125-
},
126-
],
127-
},
128-
],
129-
},
87+
buttonField(3),
13088
],
13189
}

src/blocks/OffsetCardsBlock.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { linkField } from "@/fields/linkField"
12
import { sectionFields } from "@/fields/sectionFields"
23
import type { Block } from "payload"
34

@@ -94,24 +95,7 @@ export const OffsetCardsBlock: Block = {
9495
hasMany: true,
9596
localized: true,
9697
},
97-
{
98-
name: "link",
99-
label: "Link",
100-
type: "group",
101-
fields: [
102-
{
103-
name: "label",
104-
type: "text",
105-
required: false,
106-
localized: true,
107-
},
108-
{
109-
name: "url",
110-
type: "text",
111-
required: false,
112-
},
113-
],
114-
},
98+
linkField(),
11599
],
116100
},
117101
],

src/blocks/ScrollCardBlock.ts

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { gradientFields } from "@/fields/gradientFields"
2+
import { linkField } from "@/fields/linkField"
13
import type { Block } from "payload"
24

35
export const ScrollCardBlock: Block = {
@@ -60,72 +62,7 @@ export const ScrollCardBlock: Block = {
6062
},
6163
],
6264
},
63-
{
64-
name: "gradient",
65-
label: "Gradient",
66-
type: "select",
67-
required: false,
68-
defaultValue: "blue",
69-
options: [
70-
{
71-
label: "Blue",
72-
value: "blue",
73-
},
74-
{
75-
label: "Yellow",
76-
value: "yellow",
77-
},
78-
{
79-
label: "Pink",
80-
value: "pink",
81-
},
82-
{
83-
label: "Aqua",
84-
value: "aqua",
85-
},
86-
{
87-
label: "Brand",
88-
value: "brand",
89-
},
90-
{
91-
label: "Lime",
92-
value: "lime",
93-
},
94-
{
95-
label: "Magenta",
96-
value: "magenta",
97-
},
98-
{
99-
label: "Neutral",
100-
value: "neutral",
101-
},
102-
],
103-
},
104-
{
105-
name: "gradientDirection",
106-
label: "Gradient Direction",
107-
type: "select",
108-
required: false,
109-
defaultValue: "topLeft",
110-
options: [
111-
{
112-
label: "Top left",
113-
value: "topLeft",
114-
},
115-
{
116-
label: "Top right",
117-
value: "topRight",
118-
},
119-
{
120-
label: "Bottom left",
121-
value: "bottomLeft",
122-
},
123-
{
124-
label: "Bottom right",
125-
value: "bottomRight",
126-
},
127-
],
128-
},
65+
...gradientFields(),
12966
{
13067
name: "bulletPoints",
13168
label: "Bullet Points",
@@ -141,24 +78,7 @@ export const ScrollCardBlock: Block = {
14178
relationTo: "media",
14279
required: false,
14380
},
144-
{
145-
name: "link",
146-
label: "Link",
147-
type: "group",
148-
fields: [
149-
{
150-
name: "label",
151-
type: "text",
152-
required: false,
153-
localized: true,
154-
},
155-
{
156-
name: "url",
157-
type: "text",
158-
required: false,
159-
},
160-
],
161-
},
81+
linkField(),
16282
],
16383
},
16484
],

0 commit comments

Comments
 (0)