From 386eb229cd01fe96ecbbfa0ce11f99c47cda7eab Mon Sep 17 00:00:00 2001 From: Giulia Ghisini Date: Thu, 5 Oct 2023 11:10:30 +0200 Subject: [PATCH] fix: icons in Callout block --- .../ItaliaTheme/Blocks/Callout/Edit.jsx | 71 ++++++++++-------- .../ItaliaTheme/Blocks/Callout/Sidebar.jsx | 72 ++++++++++++++----- .../ItaliaTheme/Blocks/Callout/View.jsx | 13 ++-- .../ItaliaTheme/Widgets/_iconWidget.scss | 4 ++ src/theme/_cms-ui.scss | 8 +++ 5 files changed, 117 insertions(+), 51 deletions(-) diff --git a/src/components/ItaliaTheme/Blocks/Callout/Edit.jsx b/src/components/ItaliaTheme/Blocks/Callout/Edit.jsx index dd30860b8..a18c72fd4 100644 --- a/src/components/ItaliaTheme/Blocks/Callout/Edit.jsx +++ b/src/components/ItaliaTheme/Blocks/Callout/Edit.jsx @@ -35,21 +35,26 @@ const Edit = ({ block, onSelectBlock, onAddBlock, - index, selected, - onFocusPreviousBlock, - onFocusNextBlock, + ...otherProps }) => { const intl = useIntl(); const [selectedField, setSelectedField] = useState('title'); useEffect(() => { - if (selected) { + if (selected && !selectedField) { setSelectedField('title'); } else { setSelectedField(null); } }, [selected]); + + useEffect(() => { + if (!selected && selectedField) { + onSelectBlock(block); + } + }, [selectedField]); + /** * Change handler * @method onChange @@ -74,48 +79,58 @@ const Edit = ({ color={data.color?.replace('callout_', '')} > - - + {data.icon && } setSelectedField('title')} - onSelectBlock={(block) => setSelectedField('title')} - onChangeBlock={(block, data) => { - onChange({ ...data, title: data.plaintext }, 'title'); - }} selected={selectedField === 'title'} placeholder={intl.formatMessage(messages.title)} - showToolbar={false} - index={index} + onChangeBlock={(block, data) => { + onChange({ ...data, title: data.value }, 'title'); + }} + setSelected={() => setSelectedField('title')} + focusNextField={() => { + setSelectedField('text'); + }} wrapClass={`title-edit-wrapper ${ data.title?.blocks?.[0]?.text?.length > 0 ? 'has-text' : '' }`} - // onAddBlock={() => { - // setSelectedField('text'); - // }} - // onFocusNextBlock={() => { - // setSelectedField('text'); - // }} - // onFocusPreviousBlock={onFocusPreviousBlock} /> setSelectedField('text')} - onSelectBlock={(block) => setSelectedField('text')} + value={data.text_simple} onChangeBlock={(block, data) => { - onChange({ ...data, title: data.value }, 'text'); + onChange({ ...data, text_simple: data.value }, 'text_simple'); + }} + selected={selectedField === 'text_simple'} + placeholder={intl.formatMessage(messages.text)} + setSelected={() => { + setSelectedField('text_simple'); }} + focusPrevField={() => { + setSelectedField('title'); + }} + /> + { - // setSelectedField('title'); - // }} + onChangeBlock={(block, data) => { + onChange({ ...data, text: data.value }, 'text'); + }} + setSelected={() => setSelectedField('text')} + focusPrevField={() => { + setSelectedField('title'); + }} /> diff --git a/src/components/ItaliaTheme/Blocks/Callout/Sidebar.jsx b/src/components/ItaliaTheme/Blocks/Callout/Sidebar.jsx index da755c1bd..3f41c6f97 100644 --- a/src/components/ItaliaTheme/Blocks/Callout/Sidebar.jsx +++ b/src/components/ItaliaTheme/Blocks/Callout/Sidebar.jsx @@ -3,11 +3,11 @@ import PropTypes from 'prop-types'; import { Segment } from 'semantic-ui-react'; import { FormattedMessage, injectIntl } from 'react-intl'; import { /*TextWidget,*/ SelectWidget } from '@plone/volto/components'; - +import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable'; import { defineMessages, useIntl } from 'react-intl'; -import IconWidget from 'design-comuni-plone-theme/components/ItaliaTheme/manage/Widgets/IconWidget'; -import { defaultIconWidgetOptions } from 'design-comuni-plone-theme/helpers/index'; import { ColorListWidget } from 'design-comuni-plone-theme/components/ItaliaTheme'; +import { Icon } from 'design-comuni-plone-theme/components/ItaliaTheme'; +import { FormFieldWrapper } from '@plone/volto/components'; const messages = defineMessages({ color: { id: 'color', defaultMessage: 'Colore' }, @@ -37,10 +37,15 @@ const messages = defineMessages({ id: 'callout_style_highlight', defaultMessage: 'In evidenza', }, + icon: { + id: 'icon', + defaultMessage: 'Icona', + }, }); -const Sidebar = ({ data, block, onChangeBlock }) => { +const Sidebar = ({ data, block, onChangeBlock, reactSelect }) => { const intl = useIntl(); + const { Option } = reactSelect.components; const colors = [ { name: 'callout_default', @@ -59,7 +64,12 @@ const Sidebar = ({ data, block, onChangeBlock }) => { useEffect(() => { if (!data.style) { - onChangeBlock(block, { ...data, style: styles[0][0] }); + //default nuovo blocco + onChangeBlock(block, { + ...data, + style: styles[0][0], + icon: 'it-info-circle', + }); } }, []); @@ -96,18 +106,46 @@ const Sidebar = ({ data, block, onChangeBlock }) => { colors={colors} /> - { - onChangeBlock(block, { - ...data, - [name]: value, - }); - }} - /> +
+ { + onChangeBlock(block, { ...data, [id]: value }); + }} + choices={[ + ['it-info-circle', 'Info'], + ['it-check-circle', 'Check'], + ['it-help-circle', 'Help'], + ['it-close-circle', 'Close'], + ]} + customOptionStyling={(props) => { + return ( + + ); + }} + /> + +

+ {data.icon ? ( + + ) : ( + <> + )} +

+
+
{/* { + const title = ; + return (
- - {data.title} - {data.title} + {data.icon && } + {title} + {title} - Maecenas vulputate ante dictum vestibulum volutpat. Lorem ipsum dolor - sit amet, consectetur adipiscing elit. Aenean non augue non purus - vestibulum varius. +
diff --git a/src/theme/ItaliaTheme/Widgets/_iconWidget.scss b/src/theme/ItaliaTheme/Widgets/_iconWidget.scss index 94c3c516f..2101505ca 100644 --- a/src/theme/ItaliaTheme/Widgets/_iconWidget.scss +++ b/src/theme/ItaliaTheme/Widgets/_iconWidget.scss @@ -3,6 +3,10 @@ font-size: 40px; } + .show-icon-italia { + height: 2rem; + } + .icon-container { width: 15px; } diff --git a/src/theme/_cms-ui.scss b/src/theme/_cms-ui.scss index 583ecb701..43c77ad52 100644 --- a/src/theme/_cms-ui.scss +++ b/src/theme/_cms-ui.scss @@ -398,6 +398,14 @@ body.cms-ui { } } + .field-wrapper-icon { + .icon-container.italia-icon { + svg.icon { + height: 1.5em; + } + } + } + /*.DraftEditor-root { font-family: $font-family-serif; h1,