-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SLB-289): introduce custom/image-with-text block
- Loading branch information
Showing
11 changed files
with
402 additions
and
37 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
79 changes: 79 additions & 0 deletions
79
packages/drupal/gutenberg_blocks/src/blocks/image-with-text.tsx
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,79 @@ | ||
import { InnerBlocks, InspectorControls } from 'wordpress__block-editor'; | ||
import { registerBlockType } from 'wordpress__blocks'; | ||
import { PanelBody, SelectControl } from 'wordpress__components'; | ||
import { dispatch } from 'wordpress__data'; | ||
|
||
import { DrupalMediaEntity } from '../utils/drupal-media'; | ||
|
||
// @ts-ignore | ||
const { t: __ } = Drupal; | ||
|
||
registerBlockType('custom/image-with-text', { | ||
title: __('Image with Text'), | ||
icon: 'cover-image', | ||
category: 'layout', | ||
attributes: { | ||
mediaEntityIds: { | ||
type: 'array', | ||
}, | ||
imagePosition: { | ||
type: 'string', | ||
default: 'left', | ||
}, | ||
}, | ||
edit: (props) => { | ||
const { setAttributes } = props; | ||
return ( | ||
<> | ||
<InspectorControls> | ||
<PanelBody title={__('Image position')}> | ||
<SelectControl | ||
value={props.attributes.imagePosition as string} | ||
options={[ | ||
{ label: __('Left'), value: 'left' }, | ||
{ label: __('Right'), value: 'right' }, | ||
]} | ||
onChange={(imagePosition: string) => { | ||
setAttributes({ | ||
imagePosition, | ||
}); | ||
}} | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
<div className={'container-wrapper'}> | ||
<div className={'container-label'}>{__('Image with Text')}</div> | ||
<DrupalMediaEntity | ||
classname={'w-full'} | ||
attributes={{ | ||
...(props.attributes as any), | ||
lockViewMode: true, | ||
viewMode: 'gutenberg_header', | ||
allowedTypes: ['image'], | ||
}} | ||
setAttributes={props.setAttributes} | ||
isMediaLibraryEnabled={true} | ||
onError={(error) => { | ||
// @ts-ignore | ||
error = typeof error === 'string' ? error : error[2]; | ||
dispatch('core/notices').createWarningNotice(error); | ||
}} | ||
/> | ||
<InnerBlocks | ||
templateLock={false} | ||
allowedBlocks={[ | ||
// Only markup blocks. | ||
'core/paragraph', | ||
'core/list', | ||
'core/table', | ||
'core/quote', | ||
'custom/heading', | ||
]} | ||
template={[['core/paragraph']]} | ||
/> | ||
</div> | ||
</> | ||
); | ||
}, | ||
save: () => <InnerBlocks.Content />, | ||
}); |
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
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
9 changes: 9 additions & 0 deletions
9
packages/schema/src/fragments/PageContent/BlockImageWithText.gql
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,9 @@ | ||
fragment BlockImageWithText on BlockImageWithText { | ||
image { | ||
source(width: 1536, sizes: [[768, 768], [1536, 1536]]) | ||
alt | ||
} | ||
textContent { | ||
markup | ||
} | ||
} |
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
Oops, something went wrong.