-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maija Y
committed
Sep 2, 2024
1 parent
1e1b97d
commit 5b52ea1
Showing
10 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
services/cms/src/blocks/ExpandableContent/ExpandableContentEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable i18next/no-literal-string */ | ||
import { InnerBlocks } from "@wordpress/block-editor" | ||
import { BlockEditProps } from "@wordpress/blocks" | ||
import React from "react" | ||
// import { useTranslation } from "react-i18next" | ||
|
||
import BlockPlaceholderWrapper from "../BlockPlaceholderWrapper" | ||
|
||
const ALLOWED_NESTED_BLOCKS = ["core/expandable-content-inner-block"] | ||
const ExpandableContentEditor: React.FC< | ||
React.PropsWithChildren<BlockEditProps<Record<string, never>>> | ||
> = ({ clientId }) => { | ||
// const { t } = useTranslation() | ||
return ( | ||
<BlockPlaceholderWrapper | ||
id={clientId} | ||
title={"Expandable content"} | ||
explanation={"Expandable content"} | ||
> | ||
<div> | ||
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} /> | ||
</div> | ||
</BlockPlaceholderWrapper> | ||
) | ||
} | ||
|
||
export default ExpandableContentEditor |
39 changes: 39 additions & 0 deletions
39
...locks/ExpandableContent/ExpandableContentInnerBlock/ExpandableContentInnerBlockEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable i18next/no-literal-string */ | ||
import { css } from "@emotion/css" | ||
import { InnerBlocks } from "@wordpress/block-editor" | ||
import { BlockEditProps } from "@wordpress/blocks" | ||
import React from "react" | ||
// import { useTranslation } from "react-i18next" | ||
|
||
import BlockPlaceholderWrapper from "../../BlockPlaceholderWrapper" | ||
|
||
import { ExpandableContentConfigurationProps } from "." | ||
|
||
import TextField from "@/shared-module/common/components/InputFields/TextField" | ||
|
||
const ALLOWED_NESTED_BLOCKS = [""] | ||
const ExpandableContentInnerBlockEditor: React.FC< | ||
React.PropsWithChildren<BlockEditProps<ExpandableContentConfigurationProps>> | ||
> = ({ clientId, attributes, setAttributes }) => { | ||
// const { t } = useTranslation() | ||
return ( | ||
<BlockPlaceholderWrapper | ||
id={clientId} | ||
title={"Expandable content"} | ||
explanation={"Expandable content"} | ||
> | ||
<TextField | ||
label="header" | ||
placeholder="header" | ||
value={attributes.name} | ||
onChangeByValue={(value) => setAttributes({ name: value })} | ||
className={css` | ||
margin-bottom: 1rem !important; | ||
`} | ||
/> | ||
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} /> | ||
</BlockPlaceholderWrapper> | ||
) | ||
} | ||
|
||
export default ExpandableContentInnerBlockEditor |
12 changes: 12 additions & 0 deletions
12
.../blocks/ExpandableContent/ExpandableContentInnerBlock/ExpandableContentInnerBlockSave.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { InnerBlocks } from "@wordpress/block-editor" | ||
import React from "react" | ||
|
||
const ExpandableContentInnerBlockSave: React.FC<unknown> = () => { | ||
return ( | ||
<div> | ||
<InnerBlocks.Content /> | ||
</div> | ||
) | ||
} | ||
|
||
export default ExpandableContentInnerBlockSave |
26 changes: 26 additions & 0 deletions
26
services/cms/src/blocks/ExpandableContent/ExpandableContentInnerBlock/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable i18next/no-literal-string */ | ||
import { BlockConfiguration } from "@wordpress/blocks" | ||
|
||
import { MOOCFI_CATEGORY_SLUG } from "../../../utils/Gutenberg/modifyGutenbergCategories" | ||
|
||
import ExpandableContentEditor from "./ExpandableContentInnerBlockEditor" | ||
import ExpandableContentSave from "./ExpandableContentInnerBlockSave" | ||
|
||
// eslint-disable-next-line i18next/no-literal-string | ||
const ExpandableContent = "ExpandableContent" | ||
|
||
export interface ExpandableContentConfigurationProps { | ||
name: string | ||
} | ||
const ExpandableContentInnerBlockConfiguration: BlockConfiguration<ExpandableContentConfigurationProps> = | ||
{ | ||
title: ExpandableContent, | ||
description: ExpandableContent, | ||
category: MOOCFI_CATEGORY_SLUG, | ||
attributes: { name: { type: "string", default: "" } }, | ||
parent: ["moocfi/expandable-content"], | ||
edit: ExpandableContentEditor, | ||
save: ExpandableContentSave, | ||
} | ||
|
||
export default ExpandableContentInnerBlockConfiguration |
12 changes: 12 additions & 0 deletions
12
services/cms/src/blocks/ExpandableContent/ExpandableContentSave.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { InnerBlocks } from "@wordpress/block-editor" | ||
import React from "react" | ||
|
||
const ExpendableContentSave: React.FC<unknown> = () => { | ||
return ( | ||
<div> | ||
<InnerBlocks.Content /> | ||
</div> | ||
) | ||
} | ||
|
||
export default ExpendableContentSave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { BlockConfiguration } from "@wordpress/blocks" | ||
|
||
import { MOOCFI_CATEGORY_SLUG } from "../../utils/Gutenberg/modifyGutenbergCategories" | ||
|
||
import ExpandableContentEditor from "./ExpandableContentEditor" | ||
import ExpandableContentSave from "./ExpandableContentSave" | ||
|
||
// eslint-disable-next-line i18next/no-literal-string | ||
const ExpandableContent = "ExpandableContent" | ||
|
||
const ExpandableContentConfiguration: BlockConfiguration = { | ||
title: ExpandableContent, | ||
description: ExpandableContent, | ||
category: MOOCFI_CATEGORY_SLUG, | ||
attributes: {}, | ||
edit: ExpandableContentEditor, | ||
save: ExpandableContentSave, | ||
} | ||
|
||
export default ExpandableContentConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...l/src/components/ContentRenderer/moocfi/ExpandableContentBlock/ExpandableContentBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { css } from "@emotion/css" | ||
import React from "react" | ||
|
||
import { BlockRendererProps } from "../.." | ||
import InnerBlocks from "../../util/InnerBlocks" | ||
|
||
import withErrorBoundary from "@/shared-module/common/utils/withErrorBoundary" | ||
|
||
interface ExpandableContentBlockProps { | ||
name: string | ||
} | ||
|
||
const ExpandableContentBlock: React.FC< | ||
React.PropsWithChildren<BlockRendererProps<ExpandableContentBlockProps>> | ||
> = (props) => { | ||
return ( | ||
<div | ||
className={css` | ||
display: flex; | ||
flex-direction: column; | ||
border-bottom: 2px solid gray; | ||
margin: 0; | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
h6 { | ||
margin-top: 0; | ||
} | ||
`} | ||
> | ||
{<InnerBlocks parentBlockProps={props} />} | ||
</div> | ||
) | ||
} | ||
|
||
export default withErrorBoundary(ExpandableContentBlock) |
67 changes: 67 additions & 0 deletions
67
.../components/ContentRenderer/moocfi/ExpandableContentBlock/ExpandableContentInnerBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { css } from "@emotion/css" | ||
import { MinusCircle, PlusCircle } from "@vectopus/atlas-icons-react" | ||
import React, { useState } from "react" | ||
|
||
import { BlockRendererProps } from "../.." | ||
import InnerBlocks from "../../util/InnerBlocks" | ||
|
||
import Button from "@/shared-module/common/components/Button" | ||
import withErrorBoundary from "@/shared-module/common/utils/withErrorBoundary" | ||
|
||
interface ExpandableContentInnerBlockProps { | ||
name: string | ||
} | ||
|
||
const ExpandableContentInnerBlock: React.FC< | ||
React.PropsWithChildren<BlockRendererProps<ExpandableContentInnerBlockProps>> | ||
> = (props) => { | ||
const heading = props.data.attributes.name | ||
|
||
const [x, setX] = useState(0) | ||
return ( | ||
<div | ||
className={css` | ||
display: flex; | ||
flex-direction: column; | ||
padding: 2rem; | ||
border: 2px solid gray; | ||
border-bottom: 0; | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
h6 { | ||
margin-top: 0; | ||
} | ||
border-left: ${x === 1 ? "4px solid black" : "2px solid gray"}; | ||
`} | ||
role="presentation" | ||
onKeyDown={() => (x === 0 ? setX(1) : setX(0))} | ||
onClick={() => (x === 0 ? setX(1) : setX(0))} | ||
> | ||
<div | ||
className={css` | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
width: 100%; | ||
`} | ||
> | ||
<div>{heading}</div> | ||
<Button variant={"icon"} size={"small"}> | ||
{x == 0 ? <PlusCircle /> : <MinusCircle />} | ||
</Button> | ||
</div> | ||
|
||
{x == 1 && <InnerBlocks parentBlockProps={props} />} | ||
</div> | ||
) | ||
} | ||
|
||
const exported = withErrorBoundary(ExpandableContentInnerBlock) | ||
// @ts-expect-error: Custom property | ||
exported.dontUseDefaultBlockMargin = true | ||
|
||
export default exported |