generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
5 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
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,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); |
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
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,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); |
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