Skip to content

Commit

Permalink
Add Stretch style widget WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiggr committed Aug 20, 2021
1 parent f52eccb commit a54f047
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
61 changes: 61 additions & 0 deletions src/Blocks/StretchBlock.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import { Icon } from '@plone/volto/components';
import { Button } from 'semantic-ui-react';
import imageFitSVG from '@plone/volto/icons/image-fit.svg';
import imageFullSVG from '@plone/volto/icons/image-full.svg';

const messages = defineMessages({
fit: {
id: 'Fit',
defaultMessage: 'Fit',
},
stretch: {
id: 'Stretch',
defaultMessage: 'Stretch',
},
});

const StretchBlock = ({ stretch, onChangeBlock, data, intl, block }) => {
/**
* Stretch block handler
* @method onStretchBlock
* @param {string} stretch Stretchment option
* @returns {undefined}
*/
function onStretchBlock(stretch) {
onChangeBlock(block, {
...data,
stretch,
});
}

return (
<div>
<Button.Group>
<Button
icon
basic
aria-label={intl.formatMessage(messages.fit)}
onClick={() => onStretchBlock('fit')}
active={data.stretch === 'fit' || !data.stretch}
>
<Icon name={imageFitSVG} size="24px" />
</Button>
</Button.Group>
<Button.Group>
<Button
icon
basic
aria-label={intl.formatMessage(messages.stretch)}
onClick={() => onStretchBlock('stretch')}
active={data.stretch === 'stretch'}
>
<Icon name={imageFullSVG} size="24px" />
</Button>
</Button.Group>
</div>
);
};

export default injectIntl(StretchBlock);
6 changes: 5 additions & 1 deletion src/StyleWrapper/StyleWrapperView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ const StyleWrapperView = (props) => {
isDropCap,
isScreenHeight,
hidden = false,
stretch,
} = styleData;

const containerType = data['@type'];
const backgroundImage = styleData.backgroundImage;

Expand All @@ -102,7 +104,8 @@ const StyleWrapperView = (props) => {
customClass ||
isDropCap ||
hidden ||
customId;
customId ||
stretch;

const attrs = {
style: inlineStyles,
Expand All @@ -112,6 +115,7 @@ const StyleWrapperView = (props) => {
'styled-with-bg': styleData.backgroundColor || backgroundImage,
'screen-height': isScreenHeight,
'full-width': align === 'full',
stretch: stretch === 'stretch',
large: size === 'l',
medium: size === 'm',
small: size === 's',
Expand Down
8 changes: 6 additions & 2 deletions src/StyleWrapper/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const StyleSchema = () => ({
{
id: 'standard',
title: 'Standard',
fields: ['textAlign', 'fontSize', 'align', 'size', 'isDropCap'],
fields: ['textAlign', 'fontSize', 'align', "stretch", 'size', 'isDropCap'],
},
{
id: 'decorations',
Expand All @@ -33,7 +33,7 @@ export const StyleSchema = () => ({
{
id: 'layout',
title: 'Layout',
fields: ['margin', 'padding', 'size', 'align'], // todo: width, conflicts with size
fields: ['margin', 'padding', 'size', 'align', 'stretch'], // todo: width, conflicts with size
},
{
id: 'advanced',
Expand All @@ -54,6 +54,10 @@ export const StyleSchema = () => ({
title: 'Align',
widget: 'style_align',
},
stretch: {
title: 'Stretch',
widget: 'style_stretch',
},
fontSize: {
title: 'Font size',
description: 'Relative to normal size of text in the block',
Expand Down
30 changes: 30 additions & 0 deletions src/Widgets/Stretch.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* StretchWidget component.
* To benefit from styling integration, use with a field named 'Stretch'
* @module components/manage/Widgets/StretchWidget
*/

import React from 'react';
import { injectIntl } from 'react-intl';

import { FormFieldWrapper } from '@plone/volto/components';
import StretchBlock from '../Blocks/StretchBlock';

const StretchWidget = (props) => {
const { id, onChange, value } = props;

return (
<FormFieldWrapper {...props} className="align-widget">
<div className="align-tools">
<StretchBlock
stretch={value}
onChangeBlock={(block, { stretch }) => onChange(id, stretch)}
data={{ stretch: value }}
block={id}
/>
</div>
</FormFieldWrapper>
);
};

export default injectIntl(StretchWidget);
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
} from './BlockStyleWrapper';
import StyleSelectWidget from './Widgets/StyleSelect';
import AlignWidget from './Widgets/Align';
import StretchWidget from './Widgets/Stretch';

import TextAlignWidget from './Widgets/TextAlign';
import SliderWidget from './Widgets/Slider';
import SizeWidget from './Widgets/Size';
Expand Down Expand Up @@ -64,6 +66,7 @@ const applyConfig = (config) => {

config.widgets.widget.style_select = StyleSelectWidget;
config.widgets.widget.style_align = AlignWidget; // avoid conflict for now
config.widgets.widget.style_stretch = StretchWidget; // Make stretch widget
config.widgets.widget.style_text_align = TextAlignWidget; // avoid conflict for now
config.widgets.widget.style_size = SizeWidget; // avoid conflict for now
config.widgets.widget.style_simple_color = SimpleColorPicker;
Expand Down

0 comments on commit a54f047

Please sign in to comment.