-
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.
Merge branch 'release' into SLB-308-cta-block-gutenberg
- Loading branch information
Showing
11 changed files
with
253 additions
and
7 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
packages/drupal/gutenberg_blocks/src/blocks/image-teaser.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,119 @@ | ||
import { | ||
// @ts-ignore | ||
__experimentalLinkControl as LinkControl, | ||
InnerBlocks, | ||
InspectorControls, | ||
RichText, | ||
} from 'wordpress__block-editor'; | ||
import { registerBlockType } from 'wordpress__blocks'; | ||
import { PanelBody } from 'wordpress__components'; | ||
import { dispatch } from 'wordpress__data'; | ||
|
||
import { DrupalMediaEntity } from '../utils/drupal-media'; | ||
|
||
// @ts-ignore | ||
const { t: __ } = Drupal; | ||
// @ts-ignore | ||
const { setPlainTextAttribute } = silverbackGutenbergUtils; | ||
|
||
registerBlockType('custom/image-teaser', { | ||
title: __('Image Teaser'), | ||
parent: ['custom/image-teasers'], | ||
icon: 'cover-image', | ||
category: 'layout', | ||
attributes: { | ||
mediaEntityIds: { | ||
type: 'array', | ||
}, | ||
title: { | ||
type: 'string', | ||
}, | ||
ctaUrl: { | ||
type: 'string', | ||
}, | ||
ctaText: { | ||
type: 'string', | ||
}, | ||
}, | ||
edit: (props) => { | ||
return ( | ||
<> | ||
<InspectorControls> | ||
<PanelBody title={__('CTA Link')}> | ||
<LinkControl | ||
placeholder={__('Link')} | ||
value={{ | ||
url: props.attributes.ctaUrl, | ||
}} | ||
settings={{}} | ||
onChange={(link: { url: string; opensInNewTab: boolean }) => { | ||
props.setAttributes({ | ||
ctaUrl: link.url, | ||
}); | ||
}} | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
<div> | ||
<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); | ||
}} | ||
/> | ||
</div> | ||
|
||
<div> | ||
<div> | ||
<RichText | ||
className={'font-bold text-2xl mt-3'} | ||
identifier="title" | ||
tagName="div" | ||
value={props.attributes.title as string} | ||
allowedFormats={[]} | ||
// @ts-ignore | ||
disableLineBreaks={true} | ||
placeholder={__('Title')} | ||
keepPlaceholderOnFocus={true} | ||
onChange={(title) => { | ||
setPlainTextAttribute(props, 'title', title); | ||
}} | ||
/> | ||
</div> | ||
<div> | ||
<RichText | ||
identifier="ctaText" | ||
tagName="div" | ||
multiline={false} | ||
value={props.attributes.ctaText as string} | ||
allowedFormats={[]} | ||
// @ts-ignore | ||
disableLineBreaks={true} | ||
placeholder={__('CTA text')} | ||
keepPlaceholderOnFocus={true} | ||
style={{ | ||
cursor: 'text', | ||
}} | ||
onChange={(ctaText) => { | ||
setPlainTextAttribute(props, 'ctaText', ctaText); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}, | ||
save: () => <InnerBlocks.Content />, | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/drupal/gutenberg_blocks/src/blocks/image-teasers.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,24 @@ | ||
import { InnerBlocks } from 'wordpress__block-editor'; | ||
import { registerBlockType } from 'wordpress__blocks'; | ||
|
||
// @ts-ignore | ||
const { t: __ } = Drupal; | ||
|
||
registerBlockType('custom/image-teasers', { | ||
title: __('Image Teasers'), | ||
icon: 'format-image', | ||
category: 'layout', | ||
attributes: {}, | ||
edit: () => { | ||
return ( | ||
<> | ||
<InnerBlocks | ||
templateLock={false} | ||
allowedBlocks={['custom/image-teaser']} | ||
template={[['custom/image-teaser']]} | ||
/> | ||
</> | ||
); | ||
}, | ||
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
11 changes: 11 additions & 0 deletions
11
packages/schema/src/fragments/PageContent/BlockImageTeasers.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,11 @@ | ||
fragment BlockImageTeasers on BlockImageTeasers { | ||
teasers { | ||
image { | ||
source(width: 1536, sizes: [[768, 768], [1536, 1536]]) | ||
alt | ||
} | ||
title | ||
ctaText | ||
ctaUrl | ||
} | ||
} |
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
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