f/basic-mdx-components #9
@@ -5,6 +5,7 @@ import { Hero } from "./blocks/hero";
|
|||||||
import { Testimonial } from "./blocks/testimonial";
|
import { Testimonial } from "./blocks/testimonial";
|
||||||
import { tinaField } from "tinacms/dist/react";
|
import { tinaField } from "tinacms/dist/react";
|
||||||
import { Carousel } from "./blocks/carousel";
|
import { Carousel } from "./blocks/carousel";
|
||||||
|
import { ReactElement } from "react";
|
||||||
|
|
||||||
export const Blocks = (props: Omit<Page, "id" | "_sys" | "_values">) => {
|
export const Blocks = (props: Omit<Page, "id" | "_sys" | "_values">) => {
|
||||||
return (
|
return (
|
||||||
@@ -22,7 +23,15 @@ export const Blocks = (props: Omit<Page, "id" | "_sys" | "_values">) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Block = (block: PageBlocks) => {
|
interface PageBlockProps<T = PageBlocks> {
|
||||||
|
data: T
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PageBlockFunction<T = PageBlocks> = ({
|
||||||
|
data
|
||||||
|
}: PageBlockProps<T>) => ReactElement;
|
||||||
|
|
||||||
|
const Block = (block: PageBlocks): ReactElement<PageBlockProps, PageBlockFunction> => {
|
||||||
switch (block.__typename) {
|
switch (block.__typename) {
|
||||||
case "PageBlocksContent":
|
case "PageBlocksContent":
|
||||||
return <Content data={ block } />;
|
return <Content data={ block } />;
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Section } from "../util/section";
|
import { Section } from "../util/section";
|
||||||
import { PageBlocksCarousel } from "../../tina/__generated__/types";
|
import { PageBlocks, PageBlocksCarousel, PageBlocksMutation } from "../../tina/__generated__/types";
|
||||||
import { Anchoring, anchoringSchema } from "../util/anchoring";
|
import { Anchoring, anchoringSchema } from "../util/anchoring";
|
||||||
import { Template } from "tinacms";
|
import { Template } from "tinacms";
|
||||||
|
import { PageBlockFunction } from "../blocks-renderer";
|
||||||
|
|
||||||
export const Carousel = ({ data }: { data: PageBlocksCarousel }) => {
|
/**
|
||||||
|
* Section carousel used for the main page but can be used everywhere
|
||||||
|
* @param {PageBlocksCarousel} data The data from the carousel
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
export const Carousel: PageBlockFunction<PageBlocksCarousel> = ({ data }) => {
|
||||||
return (
|
return (
|
||||||
<Section>
|
<Section>
|
||||||
<div className="carousel flex w-[100%] items-end justify-center" style={ { backgroundImage: `url(${ data?.images?.[0] })` } }>
|
<div className="carousel flex w-[100%] items-end justify-center" style={ { backgroundImage: `url(${ data?.images?.[0] })` } }>
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ import { Container } from "../util/container";
|
|||||||
import { Section } from "../util/section";
|
import { Section } from "../util/section";
|
||||||
import { TinaMarkdown } from "tinacms/dist/rich-text";
|
import { TinaMarkdown } from "tinacms/dist/rich-text";
|
||||||
import type { Template, TinaTemplate } from "tinacms";
|
import type { Template, TinaTemplate } from "tinacms";
|
||||||
import { PageBlocksContent } from "../../tina/__generated__/types";
|
import { PageBlocksCarousel, PageBlocksContent } from "../../tina/__generated__/types";
|
||||||
import { tinaField } from "tinacms/dist/react";
|
import { tinaField } from "tinacms/dist/react";
|
||||||
|
import { PageBlockFunction } from "../blocks-renderer";
|
||||||
|
|
||||||
export const Content = ({ data }: { data: PageBlocksContent }) => {
|
export const Content: PageBlockFunction<PageBlocksContent> = ({ data }) => {
|
||||||
return (
|
return (
|
||||||
<Section color={ data.color }>
|
<Section color={ data.color }>
|
||||||
<Container
|
<Container
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from "../../tina/__generated__/types";
|
} from "../../tina/__generated__/types";
|
||||||
import { tinaField } from "tinacms/dist/react";
|
import { tinaField } from "tinacms/dist/react";
|
||||||
import { Template } from "tinacms";
|
import { Template } from "tinacms";
|
||||||
|
import { PageBlockFunction } from "../blocks-renderer";
|
||||||
|
|
||||||
export const Feature = ({
|
export const Feature = ({
|
||||||
featuresColor,
|
featuresColor,
|
||||||
@@ -49,7 +50,7 @@ export const Feature = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Features = ({ data }: { data: PageBlocksFeatures }) => {
|
export const Features: PageBlockFunction<PageBlocksFeatures> = ({ data }) => {
|
||||||
return (
|
return (
|
||||||
<Section color={ data.color }>
|
<Section color={ data.color }>
|
||||||
<Container
|
<Container
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import { Actions } from "../util/actions";
|
|||||||
import { Container } from "../util/container";
|
import { Container } from "../util/container";
|
||||||
import { Section } from "../util/section";
|
import { Section } from "../util/section";
|
||||||
import { TinaMarkdown } from "tinacms/dist/rich-text";
|
import { TinaMarkdown } from "tinacms/dist/rich-text";
|
||||||
import type { Template, TinaTemplate } from "tinacms";
|
import type { Template } from "tinacms";
|
||||||
import { PageBlocksHero } from "../../tina/__generated__/types";
|
import { PageBlocksHero } from "../../tina/__generated__/types";
|
||||||
import { tinaField } from "tinacms/dist/react";
|
import { tinaField } from "tinacms/dist/react";
|
||||||
|
import { PageBlockFunction } from "../blocks-renderer";
|
||||||
|
|
||||||
export const Hero = ({ data }: { data: PageBlocksHero }) => {
|
export const Hero: PageBlockFunction<PageBlocksHero> = ({ data }) => {
|
||||||
const headlineColorClasses = {
|
const headlineColorClasses = {
|
||||||
blue: "from-blue-400 to-blue-600",
|
blue: "from-blue-400 to-blue-600",
|
||||||
teal: "from-teal-400 to-teal-600",
|
teal: "from-teal-400 to-teal-600",
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import { Section } from "../util/section";
|
|||||||
import type { Template } from "tinacms";
|
import type { Template } from "tinacms";
|
||||||
import { PageBlocksTestimonial } from "../../tina/__generated__/types";
|
import { PageBlocksTestimonial } from "../../tina/__generated__/types";
|
||||||
import { tinaField } from "tinacms/dist/react";
|
import { tinaField } from "tinacms/dist/react";
|
||||||
|
import { PageBlockFunction } from "../blocks-renderer";
|
||||||
|
|
||||||
export const Testimonial = ({ data }: { data: PageBlocksTestimonial }) => {
|
export const Testimonial: PageBlockFunction<PageBlocksTestimonial> = ({ data }) => {
|
||||||
return (
|
return (
|
||||||
<Section color={ data.color }>
|
<Section color={ data.color }>
|
||||||
<Container size="large">
|
<Container size="large">
|
||||||
|
|||||||
@@ -112,20 +112,6 @@ const components: Components<{
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const Post = (props: PostType) => {
|
export const Post = (props: PostType) => {
|
||||||
const titleColorClasses = {
|
|
||||||
blue: "from-blue-400 to-blue-600 dark:from-blue-300 dark:to-blue-500",
|
|
||||||
teal: "from-teal-400 to-teal-600 dark:from-teal-300 dark:to-teal-500",
|
|
||||||
green: "from-green-400 to-green-600",
|
|
||||||
red: "from-red-400 to-red-600",
|
|
||||||
pink: "from-pink-300 to-pink-500",
|
|
||||||
purple:
|
|
||||||
"from-purple-400 to-purple-600 dark:from-purple-300 dark:to-purple-500",
|
|
||||||
orange:
|
|
||||||
"from-orange-300 to-orange-600 dark:from-orange-200 dark:to-orange-500",
|
|
||||||
yellow:
|
|
||||||
"from-yellow-400 to-yellow-500 dark:from-yellow-300 dark:to-yellow-500"
|
|
||||||
};
|
|
||||||
|
|
||||||
const date = new Date(props.date);
|
const date = new Date(props.date);
|
||||||
let formattedDate = "";
|
let formattedDate = "";
|
||||||
if (!isNaN(date.getTime())) {
|
if (!isNaN(date.getTime())) {
|
||||||
|
|||||||
@@ -8,7 +8,12 @@ interface AnchoringProps {
|
|||||||
linkTo?: string // Default: #main-page
|
linkTo?: string // Default: #main-page
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Anchoring = (props: AnchoringProps) => {
|
/**
|
||||||
|
* Made to be used with the carousel
|
||||||
|
* @param {AnchoringProps} props Props for the anchoring.
|
||||||
|
* @return {ReactElement} The function component
|
||||||
|
*/
|
||||||
|
export const Anchoring: React.FC<AnchoringProps> = (props) => {
|
||||||
const [opacity, setOpacity] = useState(1);
|
const [opacity, setOpacity] = useState(1);
|
||||||
const anchoringRef = useRef<HTMLDivElement>(null);
|
const anchoringRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,5 @@
|
|||||||
"twitter": "/",
|
"twitter": "/",
|
||||||
"instagram": "/"
|
"instagram": "/"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"theme": {
|
|
||||||
"color": "blue",
|
|
||||||
"font": "sans",
|
|
||||||
"darkMode": "system"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ excerpt: >
|
|||||||
vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla
|
vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla
|
||||||
facilities morbi tempus.
|
facilities morbi tempus.
|
||||||
author: content/authors/pedro.md
|
author: content/authors/pedro.md
|
||||||
date: "2021-07-03T20:30:00.000Z"
|
date: 2021-07-03T20:30:00.000Z
|
||||||
---
|
---
|
||||||
|
|
||||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus.
|
<DateTime format="iso" /> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus.
|
||||||
|
|||||||
@@ -214,11 +214,9 @@ const config = defineConfig({
|
|||||||
},
|
},
|
||||||
templates: [
|
templates: [
|
||||||
heroBlockSchema,
|
heroBlockSchema,
|
||||||
// @ts-ignore
|
|
||||||
featureBlockSchema,
|
featureBlockSchema,
|
||||||
contentBlockSchema,
|
contentBlockSchema,
|
||||||
testimonialBlockSchema,
|
testimonialBlockSchema,
|
||||||
// @ts-ignore
|
|
||||||
carouselBlockSchema
|
carouselBlockSchema
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user