Skip to content

Commit

Permalink
Add contents building blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinkipruto committed Sep 19, 2023
1 parent b1d24de commit ee1c6bd
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 0 deletions.
81 changes: 81 additions & 0 deletions apps/codeforafrica/src/payload/blocks/ExternalEmbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import blockFields from "../fields/blockFields";

const ExternalEmbed = {
slug: "external-embed",
fields: [
blockFields({
name: "embedBlockFields",
fields: [
{
type: "row",
fields: [
{
name: "embedType",
type: "radio",
defaultValue: "url",
options: [
{
label: {
en: "URL",
fr: "URL",
pt: "URL",
},
value: "url",
},
{
label: {
en: "Code",
fr: "Code",
pt: "Código",
},
value: "code",
},
],
},
],
},
{
name: "url",
label: {
en: "URL",
fr: "URL",
pt: "URL",
},
type: "text",
required: true,
admin: {
condition: (_, siblingData) => siblingData?.embedType === "url",
},
},
{
name: "caption",
label: {
en: "Caption",
fr: "Légende",
pt: "Rubrica",
},
type: "text",
localized: true,
admin: {
condition: (_, siblingData) => siblingData?.embedType === "url",
},
},
{
name: "code",
label: {
en: "Code",
fr: "Code",
pt: "Código",
},
type: "code",
required: true,
admin: {
condition: (_, siblingData) => siblingData?.embedType === "code",
},
},
],
}),
],
};

export default ExternalEmbed;
23 changes: 23 additions & 0 deletions apps/codeforafrica/src/payload/blocks/MediaBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import blockFields from "../fields/blockFields";

const MediaBlock = {
slug: "mediaBlock",
fields: [
blockFields({
name: "mediaBlockFields",
fields: [
{
name: "image",
type: "upload",
relationTo: "media",
required: true,
filterOptions: {
mimeType: { contains: "image" },
},
},
],
}),
],
};

export default MediaBlock;
32 changes: 32 additions & 0 deletions apps/codeforafrica/src/payload/blocks/RichText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import blockFields from "../fields/blockFields";
import richText from "../fields/richText";

const RichText = {
slug: "richText",
fields: [
blockFields({
name: "richTextBlockFields",
fields: [
richText({
name: "content",
admin: {
elements: [
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"link",
"ol",
"ul",
"indent",
],
},
}),
],
}),
],
};

export default RichText;
21 changes: 21 additions & 0 deletions apps/codeforafrica/src/payload/fields/blockFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { deepmerge } from "@mui/utils";

const blockFields = ({ name, fields, overrides }) =>
deepmerge(
{
name,
label: false,
type: "group",
admin: {
hideGutter: true,
style: {
margin: 0,
padding: 0,
},
},
fields,
},
overrides,
);

export default blockFields;
18 changes: 18 additions & 0 deletions apps/codeforafrica/src/payload/fields/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { deepmerge } from "@mui/utils";

import ExternalEmbed from "../blocks/ExternalEmbed";
import MediaBlock from "../blocks/MediaBlock";
import RichText from "../blocks/RichText";

const content = (overrides) =>
deepmerge(
{
name: "content",
type: "blocks",
blocks: [RichText, MediaBlock, ExternalEmbed],
localized: true,
},
overrides,
);

export default content;

0 comments on commit ee1c6bd

Please sign in to comment.