Skip to content

Commit 5861eb0

Browse files
MaijjayMaija Y
and
Maija Y
authored
Expandable content -block (#1305)
* Initial flip card block * Improvements for flip card * Added templateLock * Initial expandable content -block * Initial Revealable content -block * Changed icon to button * Little changes * Little changes to revealable content block * Changes to flipcard desing * Changes to style of expandable content -block * Changes to style of revealable content -block * Small changes to style of the flip card block * Small changes * Changes to margin * Seperated Inner card to back and front cards * Small changes to Revealable content -block * Little fixes --------- Co-authored-by: Maija Y <[email protected]>
1 parent 7dfc3a9 commit 5861eb0

34 files changed

+1096
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
import { BlockEditProps } from "@wordpress/blocks"
3+
import React from "react"
4+
import { useTranslation } from "react-i18next"
5+
6+
import BlockPlaceholderWrapper from "../BlockPlaceholderWrapper"
7+
8+
const ALLOWED_NESTED_BLOCKS = ["core/expandable-content-inner-block"]
9+
const ExpandableContentEditor: React.FC<
10+
React.PropsWithChildren<BlockEditProps<Record<string, never>>>
11+
> = ({ clientId }) => {
12+
const { t } = useTranslation()
13+
return (
14+
<BlockPlaceholderWrapper
15+
id={clientId}
16+
title={t("expandable-content-placeholder")}
17+
explanation={t("expandable-content-explanation")}
18+
>
19+
<div>
20+
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} />
21+
</div>
22+
</BlockPlaceholderWrapper>
23+
)
24+
}
25+
26+
export default ExpandableContentEditor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint-disable i18next/no-literal-string */
2+
import { css } from "@emotion/css"
3+
import { InnerBlocks } from "@wordpress/block-editor"
4+
import { BlockEditProps } from "@wordpress/blocks"
5+
import React from "react"
6+
import { useTranslation } from "react-i18next"
7+
8+
import BlockPlaceholderWrapper from "../../BlockPlaceholderWrapper"
9+
10+
import { ExpandableContentConfigurationProps } from "."
11+
12+
import TextField from "@/shared-module/common/components/InputFields/TextField"
13+
14+
const ALLOWED_NESTED_BLOCKS = ["core/heading", "core/paragraph", "core/image", "core/list"]
15+
const ExpandableContentInnerBlockEditor: React.FC<
16+
React.PropsWithChildren<BlockEditProps<ExpandableContentConfigurationProps>>
17+
> = ({ clientId, attributes, setAttributes }) => {
18+
const { t } = useTranslation()
19+
return (
20+
<BlockPlaceholderWrapper
21+
id={clientId}
22+
title={"Expandable content"}
23+
explanation={"Expandable content"}
24+
>
25+
<TextField
26+
placeholder={t("label-title")}
27+
value={attributes.name}
28+
onChangeByValue={(value) => setAttributes({ name: value })}
29+
className={css`
30+
margin-bottom: 1rem !important;
31+
`}
32+
/>
33+
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} />
34+
</BlockPlaceholderWrapper>
35+
)
36+
}
37+
38+
export default ExpandableContentInnerBlockEditor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
import React from "react"
3+
4+
const ExpandableContentInnerBlockSave: React.FC<unknown> = () => {
5+
return (
6+
<div>
7+
<InnerBlocks.Content />
8+
</div>
9+
)
10+
}
11+
12+
export default ExpandableContentInnerBlockSave
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable i18next/no-literal-string */
2+
import { BlockConfiguration } from "@wordpress/blocks"
3+
4+
import { MOOCFI_CATEGORY_SLUG } from "../../../utils/Gutenberg/modifyGutenbergCategories"
5+
6+
import ExpandableContentEditor from "./ExpandableContentInnerBlockEditor"
7+
import ExpandableContentSave from "./ExpandableContentInnerBlockSave"
8+
9+
export interface ExpandableContentConfigurationProps {
10+
name: string
11+
}
12+
const ExpandableContentInnerBlockConfiguration: BlockConfiguration<ExpandableContentConfigurationProps> =
13+
{
14+
title: "Expandable Content",
15+
description: "One or more heading that has expandable/collapsible content",
16+
category: MOOCFI_CATEGORY_SLUG,
17+
attributes: { name: { type: "string", default: "" } },
18+
parent: ["moocfi/expandable-content"],
19+
edit: ExpandableContentEditor,
20+
save: ExpandableContentSave,
21+
}
22+
23+
export default ExpandableContentInnerBlockConfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
import React from "react"
3+
4+
const ExpendableContentSave: React.FC<unknown> = () => {
5+
return (
6+
<div>
7+
<InnerBlocks.Content />
8+
</div>
9+
)
10+
}
11+
12+
export default ExpendableContentSave
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { BlockConfiguration } from "@wordpress/blocks"
2+
3+
import { MOOCFI_CATEGORY_SLUG } from "../../utils/Gutenberg/modifyGutenbergCategories"
4+
5+
import ExpandableContentEditor from "./ExpandableContentEditor"
6+
import ExpandableContentSave from "./ExpandableContentSave"
7+
8+
// eslint-disable-next-line i18next/no-literal-string
9+
const ExpandableContent = "ExpandableContent"
10+
11+
const ExpandableContentConfiguration: BlockConfiguration = {
12+
title: ExpandableContent,
13+
description: ExpandableContent,
14+
category: MOOCFI_CATEGORY_SLUG,
15+
attributes: {},
16+
edit: ExpandableContentEditor,
17+
save: ExpandableContentSave,
18+
}
19+
20+
export default ExpandableContentConfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
import { BlockEditProps } from "@wordpress/blocks"
3+
import React from "react"
4+
import { useTranslation } from "react-i18next"
5+
6+
import BlockPlaceholderWrapper from "../../BlockPlaceholderWrapper"
7+
8+
const ALLOWED_NESTED_BLOCKS = ["core/image", "core/paragraph", "core/heading", "core/list"]
9+
10+
const BackFlipCardEditor: React.FC<BlockEditProps<Record<string, never>>> = ({ clientId }) => {
11+
const { t } = useTranslation()
12+
13+
return (
14+
<BlockPlaceholderWrapper
15+
id={clientId}
16+
title={t("back-card")}
17+
explanation={t("back-card-explanation")}
18+
>
19+
<div>
20+
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} templateLock={false} />
21+
</div>
22+
</BlockPlaceholderWrapper>
23+
)
24+
}
25+
export default BackFlipCardEditor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
3+
const BackFlipCardSave: React.FC = () => {
4+
return (
5+
<div>
6+
<InnerBlocks.Content />
7+
</div>
8+
)
9+
}
10+
11+
export default BackFlipCardSave
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable i18next/no-literal-string */
2+
import { BlockConfiguration } from "@wordpress/blocks"
3+
4+
import BackFlipCardEditor from "./BackFlipCardEditor"
5+
import InnerCardSave from "./BackFlipCardSave"
6+
7+
import { MOOCFI_CATEGORY_SLUG } from "@/utils/Gutenberg/modifyGutenbergCategories"
8+
9+
const BackFlipCardConfiguration: BlockConfiguration = {
10+
title: "Back Flip Card",
11+
description: "Back side for the flip card block",
12+
category: MOOCFI_CATEGORY_SLUG,
13+
parent: ["moocfi/flip-card"],
14+
attributes: {},
15+
edit: BackFlipCardEditor,
16+
save: InnerCardSave,
17+
}
18+
19+
export default BackFlipCardConfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { InnerBlocks, InspectorControls } from "@wordpress/block-editor"
2+
import { BlockEditProps, TemplateArray } from "@wordpress/blocks"
3+
import React from "react"
4+
import { useTranslation } from "react-i18next"
5+
6+
import BlockPlaceholderWrapper from "../BlockPlaceholderWrapper"
7+
8+
import { FlipCardAttributes } from "."
9+
10+
import FlipBoxSizeCustomizer from "@/components/blocks/FlipCardSizeCustomizer"
11+
12+
const ALLOWED_NESTED_BLOCKS = ["moocfi/front-card"]
13+
const INNER_BLOCKS_TEMPLATE: TemplateArray = [
14+
["moocfi/front-card", {}],
15+
["moocfi/back-card", {}],
16+
]
17+
18+
const FlipCardEditor: React.FC<React.PropsWithChildren<BlockEditProps<FlipCardAttributes>>> = ({
19+
clientId,
20+
attributes,
21+
setAttributes,
22+
}) => {
23+
const { t } = useTranslation()
24+
25+
return (
26+
<BlockPlaceholderWrapper
27+
id={clientId}
28+
title={t("flip-card-placeholder")}
29+
explanation={t("flip-card-placeholder-explanation")}
30+
>
31+
<InspectorControls key="flip-card-settings">
32+
<FlipBoxSizeCustomizer attributes={attributes} setAttributes={setAttributes} />
33+
</InspectorControls>
34+
<div>
35+
<InnerBlocks
36+
allowedBlocks={ALLOWED_NESTED_BLOCKS}
37+
template={INNER_BLOCKS_TEMPLATE}
38+
templateLock="all"
39+
/>
40+
</div>
41+
</BlockPlaceholderWrapper>
42+
)
43+
}
44+
export default FlipCardEditor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
3+
const FlipCardSave: React.FC = () => {
4+
return (
5+
<div>
6+
<InnerBlocks.Content />
7+
</div>
8+
)
9+
}
10+
11+
export default FlipCardSave
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
import { BlockEditProps } from "@wordpress/blocks"
3+
import React from "react"
4+
import { useTranslation } from "react-i18next"
5+
6+
import BlockPlaceholderWrapper from "../../BlockPlaceholderWrapper"
7+
8+
const ALLOWED_NESTED_BLOCKS = ["core/image", "core/paragraph", "core/heading", "core/list"]
9+
10+
const FrontFlipCardEditor: React.FC<BlockEditProps<Record<string, never>>> = ({ clientId }) => {
11+
const { t } = useTranslation()
12+
13+
return (
14+
<BlockPlaceholderWrapper
15+
id={clientId}
16+
title={t("front-card")}
17+
explanation={t("front-card-explanation")}
18+
>
19+
<div>
20+
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} templateLock={false} />
21+
</div>
22+
</BlockPlaceholderWrapper>
23+
)
24+
}
25+
export default FrontFlipCardEditor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
3+
const FrontFlipCardSave: React.FC = () => {
4+
return (
5+
<div>
6+
<InnerBlocks.Content />
7+
</div>
8+
)
9+
}
10+
11+
export default FrontFlipCardSave
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable i18next/no-literal-string */
2+
import { BlockConfiguration } from "@wordpress/blocks"
3+
4+
import FrontFlipCardEditor from "./FrontFlipCardEditor"
5+
import FrontFlipCardSave from "./FrontFlipCardSave"
6+
7+
import { MOOCFI_CATEGORY_SLUG } from "@/utils/Gutenberg/modifyGutenbergCategories"
8+
9+
const FrontFlipCardConfiguration: BlockConfiguration = {
10+
title: "Inner Card",
11+
description: "Front side for the flip card block",
12+
category: MOOCFI_CATEGORY_SLUG,
13+
parent: ["moocfi/flip-card"],
14+
attributes: {},
15+
edit: FrontFlipCardEditor,
16+
save: FrontFlipCardSave,
17+
}
18+
19+
export default FrontFlipCardConfiguration
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable i18next/no-literal-string */
2+
import { BlockConfiguration } from "@wordpress/blocks"
3+
4+
import FlipCardEditor from "./FlipCardEditor"
5+
import FlipCardSave from "./FlipCardSave"
6+
7+
import { MOOCFI_CATEGORY_SLUG } from "@/utils/Gutenberg/modifyGutenbergCategories"
8+
9+
export interface FlipCardAttributes {
10+
size: string
11+
}
12+
const FlipCardConfiguration: BlockConfiguration<FlipCardAttributes> = {
13+
title: "Flip Card",
14+
description: "A two sided flip card that can be flipped by clicking the card",
15+
category: MOOCFI_CATEGORY_SLUG,
16+
attributes: {
17+
size: {
18+
type: "string",
19+
default: "xl",
20+
},
21+
},
22+
edit: FlipCardEditor,
23+
save: FlipCardSave,
24+
}
25+
26+
export default FlipCardConfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
import { BlockEditProps } from "@wordpress/blocks"
3+
import { t } from "i18next"
4+
import React from "react"
5+
6+
import BlockPlaceholderWrapper from "../BlockPlaceholderWrapper"
7+
8+
import { ConditionAttributes } from "."
9+
10+
const ALLOWED_NESTED_BLOCKS = [
11+
"core/heading",
12+
"core/paragraph",
13+
"core/image",
14+
"core/list",
15+
"moocfi/revealable-hidden-content",
16+
]
17+
18+
const ConditionalBlockEditor: React.FC<
19+
React.PropsWithChildren<BlockEditProps<ConditionAttributes>>
20+
> = ({ clientId }) => {
21+
return (
22+
<BlockPlaceholderWrapper
23+
id={clientId}
24+
title={t("revealable-content-placeholder")}
25+
explanation={t("revealable-content-explanation")}
26+
>
27+
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} />
28+
</BlockPlaceholderWrapper>
29+
)
30+
}
31+
32+
export default ConditionalBlockEditor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { InnerBlocks } from "@wordpress/block-editor"
2+
3+
const RevealableContentSave: React.FC = () => {
4+
return (
5+
<div>
6+
<InnerBlocks.Content />
7+
</div>
8+
)
9+
}
10+
11+
export default RevealableContentSave

0 commit comments

Comments
 (0)