-
Notifications
You must be signed in to change notification settings - Fork 1
/
emptyBlock.tsx
66 lines (61 loc) · 2.2 KB
/
emptyBlock.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import classNames from "classnames";
import { CslpData } from "../../cslp/types/cslp.types";
import { visualBuilderStyles } from "../visualBuilder.style";
import visualBuilderPostMessage from "../utils/visualBuilderPostMessage";
import { observeParentAndFocusNewInstance } from "../utils/multipleElementAddButton";
import { ISchemaFieldMap } from "../utils/types/index.types";
import { VisualBuilderPostMessageEvents } from "../utils/types/postMessage.types";
import React from "preact/compat";
interface EmptyBlockProps {
details: {
fieldMetadata: CslpData;
fieldSchema: ISchemaFieldMap;
};
}
export function EmptyBlock(props: EmptyBlockProps): JSX.Element {
const { details } = props;
const blockParentName = details.fieldSchema.display_name;
async function sendAddInstanceEvent() {
await visualBuilderPostMessage?.send(
VisualBuilderPostMessageEvents.ADD_INSTANCE,
{
fieldMetadata: details.fieldMetadata,
index: 0,
}
);
observeParentAndFocusNewInstance({
parentCslp: details.fieldMetadata.cslpValue,
index: 0,
});
}
return (
<div
className={classNames(
"visual-builder__empty-block",
visualBuilderStyles()["visual-builder__empty-block"]
)}
>
<div
className={classNames(
"visual-builder__empty-block-title",
visualBuilderStyles()["visual-builder__empty-block-title"]
)}
>
There are no {blockParentName.toLowerCase()} on this page yet. Click the button below to add one.
</div>
<button
className={classNames(
"visual-builder__empty-block-add-button",
visualBuilderStyles()[
"visual-builder__empty-block-add-button"
]
)}
onClick={() => sendAddInstanceEvent()}
type="button"
>
<i className="fas fa-plus"></i>
{blockParentName}
</button>
</div>
);
}