mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## Description This PR ensures that the default prettier config is used for examples and templates. This config is compatible with `prettier@3` as well (upgrading prettier is bigger change that can be a future PR). ## Changes - Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will be needed upgrading to prettier@3) - Added `examples/.prettierrc.json` with default config (this will change every example) - Added `packages/create-next-app/templates/.prettierrc.json` with default config (this will change every template) ## Related - Fixes #54402 - Closes #54409
80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
"use client";
|
|
|
|
import React, { Fragment } from "react";
|
|
import { Page } from "../../payload-types";
|
|
import { toKebabCase } from "../../utilities/toKebabCase";
|
|
import { BackgroundColor } from "../BackgroundColor";
|
|
import { VerticalPaddingOptions } from "../VerticalPadding";
|
|
import { CallToActionBlock } from "./CallToAction";
|
|
import { ContentBlock } from "./Content";
|
|
import { MediaBlock } from "./MediaBlock";
|
|
|
|
const blockComponents = {
|
|
cta: CallToActionBlock,
|
|
content: ContentBlock,
|
|
mediaBlock: MediaBlock,
|
|
};
|
|
|
|
const Blocks: React.FC<{
|
|
blocks: Page["layout"];
|
|
}> = (props) => {
|
|
const { blocks } = props;
|
|
|
|
const hasBlocks = blocks && Array.isArray(blocks) && blocks.length > 0;
|
|
|
|
if (hasBlocks) {
|
|
return (
|
|
<Fragment>
|
|
{blocks.map((block, index) => {
|
|
const { blockName, blockType } = block;
|
|
|
|
if (blockType && blockType in blockComponents) {
|
|
const Block = blockComponents[blockType];
|
|
const backgroundColor = block[`${blockType}BackgroundColor`];
|
|
const prevBlock = blocks[index - 1];
|
|
const nextBlock = blocks[index + 1];
|
|
|
|
const prevBlockBackground =
|
|
prevBlock?.[`${prevBlock.blockType}BackgroundColor`];
|
|
const nextBlockBackground =
|
|
nextBlock?.[`${nextBlock.blockType}BackgroundColor`];
|
|
|
|
let paddingTop: VerticalPaddingOptions = "large";
|
|
let paddingBottom: VerticalPaddingOptions = "large";
|
|
|
|
if (backgroundColor === prevBlockBackground) {
|
|
paddingTop = "medium";
|
|
}
|
|
|
|
if (backgroundColor === nextBlockBackground) {
|
|
paddingBottom = "medium";
|
|
}
|
|
|
|
if (Block) {
|
|
return (
|
|
<BackgroundColor
|
|
key={index}
|
|
paddingTop={paddingTop}
|
|
paddingBottom={paddingBottom}
|
|
color={backgroundColor}
|
|
>
|
|
<Block
|
|
// @ts-ignore
|
|
id={toKebabCase(blockName)}
|
|
{...block}
|
|
/>
|
|
</BackgroundColor>
|
|
);
|
|
}
|
|
}
|
|
return null;
|
|
})}
|
|
</Fragment>
|
|
);
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
export default Blocks;
|