PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / src / components / TableCaption / index.tsx

index.tsx in Tableberg – Simple Gutenberg Table Block 1.1.5, at src/components/TableCaption/index.tsx

45 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect } from "react";
2 import { RichText } from "@wordpress/block-editor";
3 import { __ } from "@wordpress/i18n";
4 import { useTableStore } from "../../store";
5
6 interface TableCaptionProps {
7 isSelected: boolean;
8 }
9
10 export function TableCaption({ isSelected }: TableCaptionProps) {
11 const caption = useTableStore(state => state.table.caption || "");
12 const updateTable = useTableStore(state => state.updateTable);
13 const showCaption = useTableStore(state => state.showCaption);
14 const setShowCaption = useTableStore(state => state.setShowCaption);
15
16 useEffect(() => {
17 if (caption.trim() !== "" && !showCaption) {
18 setShowCaption(true);
19 }
20 }, [caption, showCaption, setShowCaption]);
21
22 useEffect(() => {
23 if (!isSelected && caption.trim() === "" && showCaption) {
24 setShowCaption(false);
25 }
26 }, [isSelected, caption, setShowCaption, showCaption]);
27
28 if (!showCaption && caption.trim() === "") {
29 return null;
30 }
31
32 return (
33 <RichText
34 tagName="figcaption"
35 className="tableberg-table-caption wp-element-caption"
36 aria-label={__("Table caption text", "tableberg")}
37 placeholder={__("Add caption", "tableberg")}
38 value={caption}
39 onChange={(value: string) => {
40 updateTable({ caption: value });
41 }}
42 />
43 );
44 }
45