Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Us 57560 Background image and box with sub boxes #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 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,9 @@ msgstr ""

#. Default: "Text"
#: components/blocks/Accordion/EditItem
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/EditItem
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -41,6 +54,9 @@ msgstr ""
#: components/blocks/Accordion/Edit
#: components/blocks/Accordion/EditItem
#: components/blocks/Accordion/schema
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/EditItem
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -52,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 @@ -131,3 +152,13 @@ msgstr ""
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_title"
msgstr ""

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

#. Default: "Image and Text Boxes"
#: components/blocks/ImageAndTextBox/schema
msgid "redturtle__volto-blocks_imageandtext_title"
msgstr ""
31 changes: 31 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,9 @@ msgstr ""

#. Default: "Text"
#: components/blocks/Accordion/EditItem
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/EditItem
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -41,6 +54,9 @@ msgstr "Testo"
#: components/blocks/Accordion/Edit
#: components/blocks/Accordion/EditItem
#: components/blocks/Accordion/schema
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/EditItem
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -52,6 +68,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 @@ -131,3 +152,13 @@ msgstr ""
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_title"
msgstr ""

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

#. Default: "Image and Text Boxes"
#: components/blocks/ImageAndTextBox/schema
msgid "redturtle__volto-blocks_imageandtext_title"
msgstr ""
33 changes: 32 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-04T14:09:42.065Z\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,9 @@ msgstr ""

#. Default: "Text"
#: components/blocks/Accordion/EditItem
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/EditItem
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -43,6 +56,9 @@ msgstr ""
#: components/blocks/Accordion/Edit
#: components/blocks/Accordion/EditItem
#: components/blocks/Accordion/schema
#: components/blocks/ImageAndTextBox/Edit
#: components/blocks/ImageAndTextBox/EditItem
#: components/blocks/ImageAndTextBox/schema
#: components/blocks/Testimonials/Edit
#: components/blocks/Testimonials/schema
#: components/blocks/Text1/Edit
Expand All @@ -54,6 +70,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 @@ -133,3 +154,13 @@ msgstr ""
#: components/blocks/Text7/schema
msgid "redturtle__volto-blocks__text7_title"
msgstr ""

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

#. Default: "Image and Text Boxes"
#: components/blocks/ImageAndTextBox/schema
msgid "redturtle__volto-blocks_imageandtext_title"
msgstr ""
174 changes: 174 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,174 @@
import type { BlockEditProps } from '@plone/types';
import { Icon, SidebarPortal, UniversalLink } from '@plone/volto/components';
import { BlockDataForm } from '@plone/volto/components/manage/Form';
import cx from 'classnames';
import { defineMessages, useIntl } from 'react-intl';
import placeholder from './placeholder.png';

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}
>
{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=""
/>
) : (
<Image
className={cx('block-imageandtextbox-image', styles.image)}
// TODO serialize image brain in the backend
src={placeholder}
loading="lazy"
alt=""
/>
)}
<Container className={cx(styles['block-imageandtextbox-container'])}>
<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)}
onFocusPreviousBlock={onFocusPreviousBlock}
onFocusNextBlock={onFocusNextBlock}
/>
<TextEditorWidget
{...props}
fieldName="text"
selected={selected && selectedField === 'text'}
setSelected={setSelectedField}
focusPrevField={() => {
setSelectedField('title');
}}
placeholder={intl.formatMessage(messages.text)}
onFocusPreviousBlock={onFocusPreviousBlock}
onFocusNextBlock={onFocusNextBlock}
/>
<div className={cx('block-imageandtextbox-boxes', styles.boxes)}>
{data.boxes?.length > 0 &&
data.boxes.map((item) => (
<EditItem
data={item}
focusOn={selectedField}
setFocusOn={setSelectedField}
onChange={(id, field, value) => {
onChangeBlock(block, {
...data,
boxes: data.boxes.map((i) =>
i['@id'] === id ? { ...i, [field]: value } : i,
),
});
}}
// @ts-expect-error TODO fix type in @plone/types
selected={selected}
/>
))}
</div>
{data.linkHref?.[0] && (
<div className={cx(styles['block-imageandtextbox-cta'])}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
>
{data.linkTitle}
</UniversalLink>
</div>
)}
</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',
},
});
Loading
Loading