-
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' of https://github.com/AmazeeLabs/silverback-te…
…mplate into feat/SLB-288
- Loading branch information
Showing
35 changed files
with
1,280 additions
and
384 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
51 changes: 51 additions & 0 deletions
51
.../gutenberg_blocks/src/Plugin/Validation/GutenbergValidator/AccordionItemTextValidator.php
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,51 @@ | ||
<?php | ||
|
||
namespace Drupal\gutenberg_blocks\Plugin\Validation\GutenbergValidator; | ||
|
||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\silverback_gutenberg\GutenbergValidation\GutenbergCardinalityValidatorInterface; | ||
use Drupal\silverback_gutenberg\GutenbergValidation\GutenbergCardinalityValidatorTrait; | ||
use Drupal\silverback_gutenberg\GutenbergValidation\GutenbergValidatorBase; | ||
|
||
/** | ||
* @GutenbergValidator( | ||
* id="accordion_item_text_validator", | ||
* label = @Translation("Accordion Item Text validator") | ||
* ) | ||
*/ | ||
class AccordionItemTextValidator extends GutenbergValidatorBase { | ||
use GutenbergCardinalityValidatorTrait; | ||
use StringTranslationTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function applies(array $block): bool { | ||
return $block['blockName'] === 'custom/accordion-item-text'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function validatedFields($block = []): array { | ||
return [ | ||
'title' => [ | ||
'field_label' => $this->t('Title'), | ||
'rules' => ['required'], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function validateContent($block = []): array { | ||
$expectedChildren = [ | ||
'validationType' => GutenbergCardinalityValidatorInterface::CARDINALITY_ANY, | ||
'min' => 1, | ||
'max' => GutenbergCardinalityValidatorInterface::CARDINALITY_UNLIMITED, | ||
]; | ||
return $this->validateCardinality($block, $expectedChildren); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...s/drupal/gutenberg_blocks/src/Plugin/Validation/GutenbergValidator/AccordionValidator.php
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,42 @@ | ||
<?php | ||
|
||
namespace Drupal\gutenberg_blocks\Plugin\Validation\GutenbergValidator; | ||
|
||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\silverback_gutenberg\GutenbergValidation\GutenbergCardinalityValidatorInterface; | ||
use Drupal\silverback_gutenberg\GutenbergValidation\GutenbergCardinalityValidatorTrait; | ||
use Drupal\silverback_gutenberg\GutenbergValidation\GutenbergValidatorBase; | ||
|
||
/** | ||
* @GutenbergValidator( | ||
* id="accordion_validator", | ||
* label = @Translation("Accordion validator") | ||
* ) | ||
*/ | ||
class AccordionValidator extends GutenbergValidatorBase { | ||
use GutenbergCardinalityValidatorTrait; | ||
use StringTranslationTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function applies(array $block): bool { | ||
return $block['blockName'] === 'custom/accordion'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function validateContent($block = []): array { | ||
$expectedChildren = [ | ||
[ | ||
'blockName' => 'custom/accordion-item-text', | ||
'blockLabel' => $this->t('Accordion'), | ||
'min' => 1, | ||
'max' => GutenbergCardinalityValidatorInterface::CARDINALITY_UNLIMITED, | ||
], | ||
]; | ||
return $this->validateCardinality($block, $expectedChildren); | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
packages/drupal/gutenberg_blocks/src/blocks/accordion-item-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,91 @@ | ||
import clsx from 'clsx'; | ||
import React, { Fragment } from 'react'; | ||
import { | ||
InnerBlocks, | ||
InspectorControls, | ||
RichText, | ||
} from 'wordpress__block-editor'; | ||
import { registerBlockType } from 'wordpress__blocks'; | ||
import { PanelBody, SelectControl } from 'wordpress__components'; | ||
import { compose, withState } from 'wordpress__compose'; | ||
|
||
// @ts-ignore | ||
const { t: __ } = Drupal; | ||
// @ts-ignore | ||
registerBlockType('custom/accordion-item-text', { | ||
title: 'Accordion Item Text', | ||
icon: 'text', | ||
category: 'layout', | ||
parent: ['custom/accordion'], | ||
attributes: { | ||
title: { | ||
type: 'string', | ||
}, | ||
icon: { | ||
type: 'string', | ||
}, | ||
}, | ||
// @ts-ignore | ||
edit: compose(withState())((props) => { | ||
const { attributes, setAttributes } = props; | ||
const icons = [ | ||
{ label: __('- Select an optional icon -'), value: '' }, | ||
{ label: __('Checkmark'), value: 'checkmark' }, | ||
{ label: __('Questionmark'), value: 'questionmark' }, | ||
{ label: __('Arrow'), value: 'arrow' }, | ||
]; | ||
setAttributes({ | ||
icon: attributes.icon === undefined ? '' : attributes.icon, | ||
}); | ||
|
||
return ( | ||
<Fragment> | ||
<InspectorControls> | ||
<PanelBody title={__('Block settings')}> | ||
<SelectControl | ||
value={attributes.icon} | ||
options={icons} | ||
onChange={(newValue) => { | ||
setAttributes({ | ||
icon: newValue, | ||
}); | ||
}} | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
<div className={'container-wrapper'}> | ||
<div className={'container-label'}>{__('Accordion Item Text')}</div> | ||
<div | ||
className={clsx( | ||
'custom-block-accordion-item-text', | ||
attributes.icon, | ||
)} | ||
> | ||
<RichText | ||
identifier="title" | ||
tagName="h3" | ||
value={attributes.title} | ||
allowedFormats={[]} | ||
// @ts-ignore | ||
disableLineBreaks={true} | ||
placeholder={__('Title')} | ||
keepPlaceholderOnFocus={true} | ||
onChange={(newValue) => { | ||
setAttributes({ title: newValue }); | ||
}} | ||
/> | ||
<InnerBlocks | ||
templateLock={false} | ||
allowedBlocks={['core/paragraph', 'core/list', 'core/heading']} | ||
template={[['core/paragraph', {}]]} | ||
/> | ||
</div> | ||
</div> | ||
</Fragment> | ||
); | ||
}), | ||
|
||
save: () => { | ||
return <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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { InnerBlocks } from 'wordpress__block-editor'; | ||
import { registerBlockType } from 'wordpress__blocks'; | ||
|
||
// @ts-ignore | ||
const { t: __ } = Drupal; | ||
|
||
registerBlockType('custom/accordion', { | ||
title: __('Accordion'), | ||
icon: 'menu', | ||
category: 'layout', | ||
attributes: {}, | ||
edit: () => { | ||
return ( | ||
<div className={'container-wrapper'}> | ||
<div className={'container-label'}>{__('Accordion')}</div> | ||
<InnerBlocks | ||
templateLock={false} | ||
allowedBlocks={['custom/accordion-item-text']} | ||
template={[['custom/accordion-item-text']]} | ||
/> | ||
</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
21 changes: 21 additions & 0 deletions
21
packages/drupal/gutenberg_blocks/src/blocks/horizontal-separator.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,21 @@ | ||
import { registerBlockType } from 'wordpress__blocks'; | ||
import { compose, withState } from 'wordpress__compose'; | ||
|
||
declare const Drupal: { t: (s: string) => string }; | ||
|
||
const { t: __ } = Drupal; | ||
|
||
// @ts-ignore | ||
registerBlockType(`custom/horizontal-separator`, { | ||
title: __('Horizontal separator'), | ||
icon: 'minus', | ||
category: 'text', | ||
attributes: {}, | ||
// @ts-ignore | ||
edit: compose(withState())(() => { | ||
return <hr />; | ||
}), | ||
save() { | ||
return null; | ||
}, | ||
}); |
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
Oops, something went wrong.