Skip to content

Commit fc8427b

Browse files
committed
Merge branch 'main' into 2130-Table_icon_issue
# Conflicts: # components/tina-markdown/markdown-component-mapping.tsx # pnpm-lock.yaml # styles.css # tina/tina-lock.json
2 parents 2182fd1 + af8201e commit fc8427b

File tree

16 files changed

+448
-663
lines changed

16 files changed

+448
-663
lines changed
Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import React from "react";
33
import { FaLightbulb } from "react-icons/fa6";
44
import { Template } from "tinacms";
55
import { TinaMarkdown } from "tinacms/dist/rich-text";
6-
import MarkdownComponentMapping from "../tina-markdown/markdown-component-mapping";
7-
import { ComponentWithFigure, withFigureEmbedTemplateFields } from "./componentWithFigure";
86
import { toolbarFields } from "@/tina/collection/shared/toolbarFields";
7+
import MarkdownComponentMapping from "../tina-markdown/markdown-component-mapping";
8+
import { Figure, inlineFigureDefaultItem, inlineFigureFields } from "./figure";
99

10-
type AsideVariant = "greybox" | "info" | "todo" | "china" | "codeauditor" | "highlight" | "warning" | "tips";
10+
type BoxVariant = "greybox" | "info" | "todo" | "china" | "codeauditor" | "highlight" | "warning" | "tips";
1111

1212
type VariantConfig = {
1313
containerClass: string;
1414
icon?: JSX.Element;
1515
textClass?: string;
1616
};
1717

18-
const variantConfig: Record<AsideVariant, VariantConfig> = {
18+
const variantConfig: Record<BoxVariant, VariantConfig> = {
1919
greybox: {
2020
containerClass: "bg-gray-100",
2121
},
@@ -73,40 +73,44 @@ const variantConfig: Record<AsideVariant, VariantConfig> = {
7373
},
7474
};
7575

76-
export function AsideEmbed(props: any) {
77-
// Handle both cases: props.data (from asideEmbedComponent) or props directly (from IntroEmbed)
76+
export function BoxEmbed(props: any) {
77+
// Handle both cases: props.data (from BoxEmbedComponent) or props directly (from IntroEmbed)
7878
const data = props.data || props;
7979

8080
// Safety check: if data is undefined or null, return null
8181
if (!data) {
8282
return null;
8383
}
8484

85-
const variant: AsideVariant = data?.variant || "info";
85+
// Support both legacy 'variant' and new 'style' prop names
86+
const variant: BoxVariant = (data?.style || "info") as BoxVariant;
8687
const config = variantConfig[variant];
88+
const figure: string = data?.figure || "";
89+
const figurePrefix: any = data?.figurePrefix || "default";
8790

8891
return (
89-
<ComponentWithFigure data={data}>
92+
<>
9093
<div className={`p-4 rounded-sm my-4 ${config.containerClass}`}>
9194
<div className="flex items-start">
9295
{config.icon}
93-
<div className={`${config.textClass ?? ""}`}>
96+
<div className={`[&_p:last-child]:mb-0 ${config.textClass ?? ""}`}>
9497
<div>
9598
<TinaMarkdown content={data.body} components={MarkdownComponentMapping} />
9699
</div>
97100
</div>
98101
</div>
99102
</div>
100-
</ComponentWithFigure>
103+
<Figure prefix={figurePrefix} text={figure} />
104+
</>
101105
);
102106
}
103107

104-
export const asideEmbedTemplate: Template = withFigureEmbedTemplateFields({
105-
name: "asideEmbed",
106-
label: "Aside Box",
108+
export const boxEmbedTemplate: Template = {
109+
name: "boxEmbed",
110+
label: "Box",
107111
ui: {
108112
defaultItem: {
109-
variant: "info",
113+
style: "info",
110114
body: {
111115
type: "root",
112116
children: [
@@ -116,12 +120,13 @@ export const asideEmbedTemplate: Template = withFigureEmbedTemplateFields({
116120
},
117121
],
118122
},
123+
...inlineFigureDefaultItem,
119124
},
120125
},
121126
fields: [
122127
{
123-
name: "variant",
124-
label: "Variant",
128+
name: "style",
129+
label: "style",
125130
type: "string",
126131
options: [
127132
{ value: "greybox", label: "Greybox" },
@@ -140,9 +145,10 @@ export const asideEmbedTemplate: Template = withFigureEmbedTemplateFields({
140145
type: "rich-text",
141146
toolbarOverride: toolbarFields,
142147
},
148+
...(inlineFigureFields as any),
143149
],
144-
});
150+
};
145151

146-
export const asideEmbedComponent = {
147-
asideEmbed: (props: any) => <AsideEmbed data={props} />,
152+
export const boxEmbedComponent = {
153+
boxEmbed: (props: any) => <BoxEmbed data={props} />,
148154
};

components/embeds/componentWithFigure.tsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

components/embeds/emailEmbed.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use client'
1+
"use client";
2+
3+
import React, { useRef } from "react";
24
import { Template } from "tinacms";
35
import { TinaMarkdown } from "tinacms/dist/rich-text";
4-
import React, { useRef } from "react";
5-
import {
6-
ComponentWithFigure,
7-
withFigureEmbedTemplateFields,
8-
} from "./componentWithFigure";
9-
import MarkdownComponentMapping from "../tina-markdown/markdown-component-mapping";
106
import { useMarkHighlight } from "@/lib/useMarkHighlight";
7+
import MarkdownComponentMapping from "../tina-markdown/markdown-component-mapping";
8+
import { Figure, inlineFigureDefaultItem, inlineFigureFields } from "./figure";
119

1210
export function EmailEmbed({ data }: { data: any }) {
1311
const fields = [
@@ -21,17 +19,18 @@ export function EmailEmbed({ data }: { data: any }) {
2119
const contentRef = useRef<HTMLDivElement>(null);
2220
useMarkHighlight(contentRef, "ol li div");
2321

22+
const figure: string = data?.figure || "";
23+
const figurePrefix: any = data?.figurePrefix || "default";
24+
2425
return (
25-
<ComponentWithFigure data={data}>
26+
<>
2627
<div className="bg-gray-100 p-6 rounded-md mt-4">
2728
<div className="space-y-3">
2829
{fields.map(({ label, value }) => (
2930
<div key={label} className="flex items-start text-right">
3031
<div className="w-24 pt-2 pr-2">{label}:</div>
3132
<div className="flex-1">
32-
<div className="bg-white border px-3 py-2 rounded text-sm min-h-[40px] flex items-center">
33-
{value}
34-
</div>
33+
<div className="bg-white border px-3 py-2 rounded text-sm min-h-[40px] flex items-center">{value}</div>
3534
</div>
3635
</div>
3736
))}
@@ -47,11 +46,12 @@ export function EmailEmbed({ data }: { data: any }) {
4746
</div>
4847
)}
4948
</div>
50-
</ComponentWithFigure>
49+
<Figure prefix={figurePrefix} text={figure} className="mt-2" />
50+
</>
5151
);
5252
}
5353

54-
export const emailEmbedTemplate: Template = withFigureEmbedTemplateFields({
54+
export const emailEmbedTemplate: Template = {
5555
name: "emailEmbed",
5656
label: "Email",
5757
ui: {
@@ -75,6 +75,7 @@ export const emailEmbedTemplate: Template = withFigureEmbedTemplateFields({
7575
},
7676
],
7777
},
78+
...inlineFigureDefaultItem,
7879
},
7980
},
8081
fields: [
@@ -85,8 +86,9 @@ export const emailEmbedTemplate: Template = withFigureEmbedTemplateFields({
8586
{ name: "subject", label: "Subject", type: "string" },
8687
{ name: "shouldDisplayBody", label: "Display Body?", type: "boolean" },
8788
{ name: "body", label: "Body", type: "rich-text" },
89+
...(inlineFigureFields as any),
8890
],
89-
});
91+
};
9092

9193
export const emailEmbedComponent = {
9294
emailEmbed: (props: any) => <EmailEmbed data={props} />,
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from "react";
22
import { Template } from "tinacms";
33

4-
export function EndOfIntro() {
4+
export function EndIntro() {
55
return <></>;
66
}
77

8-
export const endOfIntroTemplate: Template = {
9-
name: "endOfIntro",
10-
label: "End Of Intro",
8+
export const endIntroTemplate: Template = {
9+
name: "endIntro",
10+
label: "End Intro",
1111
fields: [
1212
{
1313
type: "string",
@@ -27,6 +27,6 @@ export const endOfIntroTemplate: Template = {
2727
},
2828
};
2929

30-
export const endOfIntroComponent = {
31-
endOfIntro: () => <EndOfIntro />,
30+
export const endIntroComponent = {
31+
endIntro: () => <EndIntro />,
3232
};

components/embeds/figure.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from "react";
2+
3+
export type FigurePrefix = "none" | "bad" | "ok" | "good";
4+
5+
export function getPrefix(prefix?: FigurePrefix): string {
6+
switch (prefix) {
7+
case "bad":
8+
return "❌ Figure: ";
9+
case "ok":
10+
return "😐 Figure: ";
11+
case "good":
12+
return "✅ Figure: ";
13+
case "none":
14+
default:
15+
return "Figure: ";
16+
}
17+
}
18+
19+
export function Figure({ prefix = "none", text, className }: { prefix?: FigurePrefix; text?: string; className?: string }) {
20+
const trimmed = text?.trim();
21+
if (!trimmed) return null;
22+
const prefixText = getPrefix(prefix);
23+
return (
24+
<p className={`font-bold mt-1 ${className ?? ""}`.trim()}>
25+
{prefixText}
26+
{trimmed}
27+
</p>
28+
);
29+
}
30+
31+
export const inlineFigureFields = [
32+
{
33+
name: "figurePrefix",
34+
label: "Figure Prefix",
35+
type: "string",
36+
options: [
37+
{ value: "none", label: "Default" },
38+
{ value: "bad", label: "Bad Example" },
39+
{ value: "ok", label: "OK Example" },
40+
{ value: "good", label: "Good Example" },
41+
],
42+
},
43+
{ name: "figure", label: "Figure", type: "string" },
44+
] as const;
45+
46+
export const inlineFigureDefaultItem = {
47+
figurePrefix: "none",
48+
figure: "",
49+
};

components/embeds/figureEmbed.tsx

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)