Skip to content

Commit

Permalink
add image and text block
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-bellenghi committed Sep 4, 2024
1 parent 5128652 commit da5d77d
Show file tree
Hide file tree
Showing 11 changed files with 456 additions and 10 deletions.
22 changes: 22 additions & 0 deletions packages/volto-blocks/locales/en/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ msgstr ""
msgid "Alignment"
msgstr ""

#. Default: "Box"
#: components/blocks/ImageAndTextBox/schema
msgid "Box"
msgstr ""

#. Default: "Boxes"
#: components/blocks/ImageAndTextBox/schema
msgid "Boxes"
msgstr ""

#. Default: "Link Title"
#: components/blocks/extenders/cta
msgid "Link title"
Expand All @@ -28,6 +38,8 @@ msgstr ""

#. Default: "Text"
#: components/blocks/Accordion/EditItem
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -41,6 +53,8 @@ msgstr ""
#: components/blocks/Accordion/Edit
#: components/blocks/Accordion/EditItem
#: components/blocks/Accordion/schema
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -52,6 +66,11 @@ msgstr ""
msgid "Title"
msgstr ""

#. Default: "Add column"
#: components/blocks/ImageAndTextBox/schema
msgid "addColumn"
msgstr ""

#. Default: "Columns"
#: components/blocks/Accordion/schema
msgid "redturtle__volto-blocks__accordion_columns_title"
Expand Down Expand Up @@ -108,11 +127,13 @@ msgid "redturtle__volto-blocks__text6_title"
msgstr ""

#. Default: "Image"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_image_title"
msgstr ""

#. Default: "Images"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_images_title"
msgstr ""
Expand All @@ -128,6 +149,7 @@ msgid "redturtle__volto-blocks__text7_img_column_width_title"
msgstr ""

#. Default: "Text 7"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_title"
msgstr ""
22 changes: 22 additions & 0 deletions packages/volto-blocks/locales/it/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ msgstr ""
msgid "Alignment"
msgstr ""

#. Default: "Box"
#: components/blocks/ImageAndTextBox/schema
msgid "Box"
msgstr ""

#. Default: "Boxes"
#: components/blocks/ImageAndTextBox/schema
msgid "Boxes"
msgstr ""

#. Default: "Link Title"
#: components/blocks/extenders/cta
msgid "Link title"
Expand All @@ -28,6 +38,8 @@ msgstr ""

#. Default: "Text"
#: components/blocks/Accordion/EditItem
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -41,6 +53,8 @@ msgstr "Testo"
#: components/blocks/Accordion/Edit
#: components/blocks/Accordion/EditItem
#: components/blocks/Accordion/schema
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -52,6 +66,11 @@ msgstr "Testo"
msgid "Title"
msgstr "Titolo"

#. Default: "Add column"
#: components/blocks/ImageAndTextBox/schema
msgid "addColumn"
msgstr ""

#. Default: "Columns"
#: components/blocks/Accordion/schema
msgid "redturtle__volto-blocks__accordion_columns_title"
Expand Down Expand Up @@ -108,11 +127,13 @@ msgid "redturtle__volto-blocks__text6_title"
msgstr ""

#. Default: "Image"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_image_title"
msgstr "Immagine"

#. Default: "Images"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_images_title"
msgstr ""
Expand All @@ -128,6 +149,7 @@ msgid "redturtle__volto-blocks__text7_img_column_width_title"
msgstr ""

#. Default: "Text 7"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_title"
msgstr ""
24 changes: 23 additions & 1 deletion packages/volto-blocks/locales/volto.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
"POT-Creation-Date: 2024-08-20T08:35:27.767Z\n"
"POT-Creation-Date: 2024-09-04T09:08:41.235Z\n"
"Last-Translator: Plone i18n <[email protected]>\n"
"Language-Team: Plone i18n <[email protected]>\n"
"Content-Type: text/plain; charset=utf-8\n"
Expand All @@ -18,6 +18,16 @@ msgstr ""
msgid "Alignment"
msgstr ""

#. Default: "Box"
#: components/blocks/ImageAndTextBox/schema
msgid "Box"
msgstr ""

#. Default: "Boxes"
#: components/blocks/ImageAndTextBox/schema
msgid "Boxes"
msgstr ""

#. Default: "Link Title"
#: components/blocks/extenders/cta
msgid "Link title"
Expand All @@ -30,6 +40,8 @@ msgstr ""

#. Default: "Text"
#: components/blocks/Accordion/EditItem
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -43,6 +55,8 @@ msgstr ""
#: components/blocks/Accordion/Edit
#: components/blocks/Accordion/EditItem
#: components/blocks/Accordion/schema
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -54,6 +68,11 @@ msgstr ""
msgid "Title"
msgstr ""

#. Default: "Add column"
#: components/blocks/ImageAndTextBox/schema
msgid "addColumn"
msgstr ""

#. Default: "Columns"
#: components/blocks/Accordion/schema
msgid "redturtle__volto-blocks__accordion_columns_title"
Expand Down Expand Up @@ -110,11 +129,13 @@ msgid "redturtle__volto-blocks__text6_title"
msgstr ""

#. Default: "Image"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_image_title"
msgstr ""

#. Default: "Images"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_images_title"
msgstr ""
Expand All @@ -130,6 +151,7 @@ msgid "redturtle__volto-blocks__text7_img_column_width_title"
msgstr ""

#. Default: "Text 7"
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_title"
msgstr ""
137 changes: 137 additions & 0 deletions packages/volto-blocks/src/components/blocks/ImageAndTextBox/Edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { Icon, SidebarPortal } from '@plone/volto/components';
import { BlockDataForm } from '@plone/volto/components/manage/Form';
import cx from 'classnames';
import { defineMessages, useIntl } from 'react-intl';

import type { BlockEditProps } from '@plone/types';

import type { ImageAndTextBoxData } from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/schema';
import styles from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/styles.module.css';
import {
TextEditorWidget,
useHandleDetachedBlockFocus,
} from '@redturtle/volto-rt-slate';

import config from '@plone/registry';
// import EditItem from './EditItem';

type ImageAndTextBoxEditProps = Omit<BlockEditProps, 'data'> & {
data: ImageAndTextBoxData;
};

export default function Edit(props: ImageAndTextBoxEditProps) {
const {
data,
selected,
block,
onChangeBlock,
blocksConfig,
blocksErrors,
onFocusPreviousBlock,
onFocusNextBlock,
} = props;
const intl = useIntl();

const { selectedField, setSelectedField } = useHandleDetachedBlockFocus(
props,
'title',
);

const schema = blocksConfig[data['@type']].blockSchema({
data,
intl,
});

if (__SERVER__) {
return <div />;
}

const Container = config.getComponent('Container').component || 'div';
const Image = config.getComponent('Image').component;

return (
<>
<section
className={cx('block-imageandtextbox', styles.imageandtextbox)}
aria-label={data.title}
>
<Container
className={cx(
'block-imageandtextbox-container',
styles['block-imageandtextbox-container'],
)}
>
{data.image ? (
<Image
className={cx('block-imageandtextbox-image', styles.image)}
// TODO serialize image brain in the backend
src={`${data.image}/@@images/image/large`}
loading="lazy"
alt=""
/>
) : (
<div className="image-add">Upload image</div>
)}
<div className={cx('box-wrapper', styles['box-wrapper'])}>
<TextEditorWidget
{...props}
className={cx('block-imageandtextbox-title', styles.title)}
as="h2"
data={data}
fieldName="title"
selected={selected && selectedField === 'title'}
setSelected={setSelectedField}
focusNextField={() => {
setSelectedField('text');
}}
showToolbar={false}
placeholder={intl.formatMessage(messages.title)}
/>
<TextEditorWidget
{...props}
fieldName="text"
selected={selected && selectedField === 'text'}
setSelected={setSelectedField}
focusPrevField={() => {
setSelectedField('title');
}}
placeholder={intl.formatMessage(messages.text)}
/>
{/* {data.boxes ? <EditItem /> : ''} */}
</div>
</Container>
</section>
{/* @ts-expect-error TODO */}
<SidebarPortal selected={selected}>
{schema && (
<BlockDataForm
icon={<Icon size="24px" name={'blockIcon'} />}
schema={schema}
title={schema.title}
onChangeField={(id: string, value: unknown) => {
onChangeBlock(block, {
...data,
[id]: value,
});
}}
onChangeBlock={onChangeBlock}
formData={data}
block={block}
errors={blocksErrors}
/>
)}
</SidebarPortal>
</>
);
}

const messages = defineMessages({
title: {
id: 'Title',
defaultMessage: 'Title',
},
text: {
id: 'Text',
defaultMessage: 'Text',
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import cx from 'classnames';
import { defineMessages, useIntl } from 'react-intl';

import type { ArrayElement } from '@plone/types';

import type { ImageAndTextBoxData } from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/schema';
import styles from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/styles.module.css';

type Props = {
data: ArrayElement<ImageAndTextBoxData['boxes']>;
focusOn: string;
setFocusOn: Function;
onChange: (id: string, field: string, value: unknown) => void;
selected: boolean;
};

export default function EditItem({
data,
focusOn,
setFocusOn,
onChange,
selected,
}: Props) {
const intl = useIntl();

if (__SERVER__) {
return <div />;
}

return <div className={cx('block-imageandtextbox', styles.item)}>BOX</div>;
}

const messages = defineMessages({});
Loading

0 comments on commit da5d77d

Please sign in to comment.