Started doing an Image component for inline text

This commit is contained in:
2023-09-03 19:45:19 +02:00
parent bfeeb71312
commit 4f5d822e11
5 changed files with 42 additions and 27 deletions

View File

@@ -10,11 +10,9 @@ import inlineComponents, { richTextTemplates } from "../inline/inline-definition
export const Content: PageBlockFunction<PageBlocksContent> = ({ data }) => { export const Content: PageBlockFunction<PageBlocksContent> = ({ data }) => {
return ( return (
<Section color={ data.color }> <Section>
<Container <Container
className={ `prose prose-lg ${ className={ "prose prose-lg" }
data.color === "primary" ? "prose-primary" : "dark:prose-dark"
}` }
data-tina-field={ tinaField(data, "body") } data-tina-field={ tinaField(data, "body") }
size="large" size="large"
width="medium" width="medium"
@@ -42,16 +40,6 @@ export const contentBlockSchema: Template = {
name: "body", name: "body",
templates: richTextTemplates, templates: richTextTemplates,
isBody: true isBody: true
},
{
type: "string",
label: "Color",
name: "color",
options: [
{ label: "Default", value: "default" },
{ label: "Tint", value: "tint" },
{ label: "Primary", value: "primary" }
]
} }
] ]
}; };

View File

@@ -1,14 +1,29 @@
import { TinaMarkdown, TinaMarkdownContent } from "tinacms/dist/rich-text"; import { TinaMarkdownContent } from "tinacms/dist/rich-text";
import { Template } from "tinacms";
import { anchoringSchema } from "../util/anchoring";
import { RichTextTemplate } from "@tinacms/schema-tools"; import { RichTextTemplate } from "@tinacms/schema-tools";
enum imageSize {
small = "small",
medium = "medium",
large = "large"
}
enum imageDecorations {
default = "default",
noStyle = "no-style"
}
enum imagePosition {
left = "left",
middle = "middle",
right = "right"
}
export interface ImageProps { export interface ImageProps {
children: TinaMarkdownContent; children: TinaMarkdownContent;
size: "small" | "medium" | "large"; size: imageSize;
imageUrl: string, imageUrl: string,
decorations: string, decorations: imageDecorations,
position: "left" | "middle" | "right" position: imagePosition
} }
const Image = (props: ImageProps) => ( const Image = (props: ImageProps) => (
@@ -17,21 +32,27 @@ const Image = (props: ImageProps) => (
</div>); </div>);
export const imageSchema: RichTextTemplate = { export const imageSchema: RichTextTemplate = {
name: "image", name: "Image",
label: "Image", label: "Image",
inline: true, inline: true,
ui: {
defaultItem: {
size: Object.values(imageSize)[0],
decorations: Object.values(imageDecorations)[0]
}
},
fields: [ fields: [
{ {
name: "size", name: "size",
label: "Size", label: "Size",
type: "string", type: "string",
options: ["small", "medium", "large"] options: Object.values(imageSize)
}, },
{ {
name: "position", name: "position",
label: "Position", label: "Position",
type: "string", type: "string",
options: ["left", "middle", "right"] options: Object.values(imagePosition)
}, },
{ {
name: "imageUrl", name: "imageUrl",
@@ -41,7 +62,8 @@ export const imageSchema: RichTextTemplate = {
{ {
name: "decorations", name: "decorations",
label: "Decorations", label: "Decorations",
type: "string" type: "string",
options: Object.values(imageDecorations)
} }
] }; ] };

View File

@@ -9,8 +9,9 @@ blocks:
text: Découvrez-en plus ! text: Découvrez-en plus !
linkTo: main-page linkTo: main-page
_template: carousel _template: carousel
- body: | - body: >
aezaeaezae<DateTime format="iso" />dzds aezaeaezae<DateTime format="iso" />dzd <Image size="small" position="left"
imageUrl="/uploads/etoile.jpg" decorations="default" />
_template: content _template: content
- headline: Welcome to the Tina Starter - headline: Welcome to the Tina Starter
text: > text: >
@@ -85,6 +86,10 @@ url: home

BIN
public/uploads/etoile.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

File diff suppressed because one or more lines are too long