@brilo/base-blocks 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/blocks/column/column-group/edit.tsx +56 -0
- package/src/blocks/column/column-group/editor.scss +7 -0
- package/src/blocks/column/column-group/factory.tsx +29 -0
- package/src/blocks/column/column-group/index.ts +14 -0
- package/src/blocks/column/column-group/types.ts +8 -0
- package/src/blocks/column/column-item/constants.ts +1 -0
- package/src/blocks/column/column-item/edit.tsx +48 -0
- package/src/blocks/column/column-item/editor.scss +34 -0
- package/src/blocks/column/column-item/factory.tsx +25 -0
- package/src/blocks/column/column-item/index.ts +10 -0
- package/src/blocks/column/column-item/types.ts +7 -0
- package/src/blocks/compare/compare-group/constants.ts +1 -0
- package/src/blocks/compare/compare-group/edit.tsx +52 -0
- package/src/blocks/compare/compare-group/factory.tsx +29 -0
- package/src/blocks/compare/compare-group/icon.tsx +7 -0
- package/src/blocks/compare/compare-group/index.ts +13 -0
- package/src/blocks/compare/compare-group/types.ts +12 -0
- package/src/blocks/compare/compare-item/edit.tsx +38 -0
- package/src/blocks/compare/compare-item/editor.scss +15 -0
- package/src/blocks/compare/compare-item/factory.tsx +28 -0
- package/src/blocks/compare/compare-item/icon.tsx +9 -0
- package/src/blocks/compare/compare-item/index.ts +13 -0
- package/src/blocks/compare/compare-item/types.ts +9 -0
- package/src/blocks/compare/compare-option/constants.ts +7 -0
- package/src/blocks/compare/compare-option/edit.tsx +64 -0
- package/src/blocks/compare/compare-option/editor.scss +26 -0
- package/src/blocks/compare/compare-option/factory.tsx +35 -0
- package/src/blocks/compare/compare-option/icon.tsx +7 -0
- package/src/blocks/compare/compare-option/index.ts +8 -0
- package/src/blocks/compare/compare-option/types.ts +12 -0
- package/src/blocks/contact/contact-group/constants.ts +3 -0
- package/src/blocks/contact/contact-group/edit.tsx +57 -0
- package/src/blocks/contact/contact-group/editor.scss +20 -0
- package/src/blocks/contact/contact-group/factory.tsx +35 -0
- package/src/blocks/contact/contact-group/index.ts +12 -0
- package/src/blocks/contact/contact-group/types.ts +12 -0
- package/src/blocks/contact/contact-item/constants.ts +17 -0
- package/src/blocks/contact/contact-item/edit.tsx +93 -0
- package/src/blocks/contact/contact-item/editor.scss +38 -0
- package/src/blocks/contact/contact-item/factory.tsx +35 -0
- package/src/blocks/contact/contact-item/index.ts +23 -0
- package/src/blocks/contact/contact-item/types.ts +21 -0
- package/src/blocks/core/basic-button/constants.ts +17 -0
- package/src/blocks/core/basic-button/edit.tsx +107 -0
- package/src/blocks/core/basic-button/editor.scss +80 -0
- package/src/blocks/core/basic-button/factory.tsx +54 -0
- package/src/blocks/core/basic-button/index.ts +8 -0
- package/src/blocks/core/basic-button/types.ts +29 -0
- package/src/blocks/core/basic-heading/constants.ts +1 -0
- package/src/blocks/core/basic-heading/edit.tsx +76 -0
- package/src/blocks/core/basic-heading/editor.scss +8 -0
- package/src/blocks/core/basic-heading/factory.tsx +40 -0
- package/src/blocks/core/basic-heading/index.ts +8 -0
- package/src/blocks/core/basic-heading/types.ts +20 -0
- package/src/blocks/core/basic-overline/edit.tsx +28 -0
- package/src/blocks/core/basic-overline/editor.scss +14 -0
- package/src/blocks/core/basic-overline/factory.tsx +22 -0
- package/src/blocks/core/basic-overline/index.ts +8 -0
- package/src/blocks/core/basic-overline/types.ts +7 -0
- package/src/blocks/faq/faq-group/constants.ts +11 -0
- package/src/blocks/faq/faq-group/edit.tsx +55 -0
- package/src/blocks/faq/faq-group/editor.scss +11 -0
- package/src/blocks/faq/faq-group/factory.tsx +39 -0
- package/src/blocks/faq/faq-group/index.ts +11 -0
- package/src/blocks/faq/faq-group/types.ts +14 -0
- package/src/blocks/faq/faq-item/edit.tsx +50 -0
- package/src/blocks/faq/faq-item/editor.scss +57 -0
- package/src/blocks/faq/faq-item/factory.tsx +24 -0
- package/src/blocks/faq/faq-item/index.ts +9 -0
- package/src/blocks/faq/faq-item/types.ts +7 -0
- package/src/blocks/form/form-field/constants.ts +14 -0
- package/src/blocks/form/form-field/edit.tsx +178 -0
- package/src/blocks/form/form-field/editor.scss +71 -0
- package/src/blocks/form/form-field/factory.tsx +32 -0
- package/src/blocks/form/form-field/index.ts +10 -0
- package/src/blocks/form/form-field/types.ts +18 -0
- package/src/blocks/form/form-group/constants.ts +16 -0
- package/src/blocks/form/form-group/edit.tsx +190 -0
- package/src/blocks/form/form-group/editor.scss +41 -0
- package/src/blocks/form/form-group/factory.tsx +35 -0
- package/src/blocks/form/form-group/index.ts +18 -0
- package/src/blocks/form/form-group/types.ts +22 -0
- package/src/blocks/groups/banner-group/constants.ts +15 -0
- package/src/blocks/groups/banner-group/edit.tsx +122 -0
- package/src/blocks/groups/banner-group/editor.scss +18 -0
- package/src/blocks/groups/banner-group/factory.tsx +64 -0
- package/src/blocks/groups/banner-group/icon.tsx +13 -0
- package/src/blocks/groups/banner-group/index.ts +11 -0
- package/src/blocks/groups/banner-group/types.ts +30 -0
- package/src/blocks/groups/basic-header-group/constants.ts +9 -0
- package/src/blocks/groups/basic-header-group/edit.tsx +99 -0
- package/src/blocks/groups/basic-header-group/editor.scss +35 -0
- package/src/blocks/groups/basic-header-group/factory.tsx +46 -0
- package/src/blocks/groups/basic-header-group/icon.tsx +17 -0
- package/src/blocks/groups/basic-header-group/index.ts +9 -0
- package/src/blocks/groups/basic-header-group/types.ts +27 -0
- package/src/blocks/groups/button-group/constants.ts +7 -0
- package/src/blocks/groups/button-group/edit.tsx +52 -0
- package/src/blocks/groups/button-group/editor.scss +23 -0
- package/src/blocks/groups/button-group/factory.tsx +34 -0
- package/src/blocks/groups/button-group/index.ts +11 -0
- package/src/blocks/groups/button-group/types.ts +12 -0
- package/src/blocks/groups/text-and-media-group/constants.ts +43 -0
- package/src/blocks/groups/text-and-media-group/edit.tsx +241 -0
- package/src/blocks/groups/text-and-media-group/editor.scss +123 -0
- package/src/blocks/groups/text-and-media-group/factory.tsx +100 -0
- package/src/blocks/groups/text-and-media-group/icon.tsx +37 -0
- package/src/blocks/groups/text-and-media-group/index.ts +18 -0
- package/src/blocks/groups/text-and-media-group/types.ts +60 -0
- package/src/blocks/hero/hero-group/constants.ts +23 -0
- package/src/blocks/hero/hero-group/edit.tsx +85 -0
- package/src/blocks/hero/hero-group/editor.scss +0 -0
- package/src/blocks/hero/hero-group/factory.tsx +45 -0
- package/src/blocks/hero/hero-group/icon.tsx +28 -0
- package/src/blocks/hero/hero-group/index.ts +11 -0
- package/src/blocks/hero/hero-group/types.ts +22 -0
- package/src/blocks/hero/hero-item/constants.ts +15 -0
- package/src/blocks/hero/hero-item/edit.tsx +107 -0
- package/src/blocks/hero/hero-item/editor.scss +87 -0
- package/src/blocks/hero/hero-item/factory.tsx +49 -0
- package/src/blocks/hero/hero-item/index.ts +10 -0
- package/src/blocks/hero/hero-item/types.ts +38 -0
- package/src/blocks/map/map-group/constants.ts +20 -0
- package/src/blocks/map/map-group/edit.tsx +108 -0
- package/src/blocks/map/map-group/editor.scss +24 -0
- package/src/blocks/map/map-group/factory.tsx +51 -0
- package/src/blocks/map/map-group/index.ts +9 -0
- package/src/blocks/map/map-group/types.ts +16 -0
- package/src/blocks/newsletter/newsletter-form/constants.ts +5 -0
- package/src/blocks/newsletter/newsletter-form/edit.tsx +194 -0
- package/src/blocks/newsletter/newsletter-form/editor.scss +68 -0
- package/src/blocks/newsletter/newsletter-form/factory.tsx +59 -0
- package/src/blocks/newsletter/newsletter-form/index.ts +11 -0
- package/src/blocks/newsletter/newsletter-form/types.ts +45 -0
- package/src/blocks/post/post-slider-group/constants.ts +3 -0
- package/src/blocks/post/post-slider-group/edit.tsx +76 -0
- package/src/blocks/post/post-slider-group/factory.tsx +43 -0
- package/src/blocks/post/post-slider-group/icon.tsx +13 -0
- package/src/blocks/post/post-slider-group/index.ts +9 -0
- package/src/blocks/post/post-slider-group/types.ts +20 -0
- package/src/blocks/responsive-grid/responsive-grid-group/edit.tsx +95 -0
- package/src/blocks/responsive-grid/responsive-grid-group/factory.tsx +33 -0
- package/src/blocks/responsive-grid/responsive-grid-group/index.ts +13 -0
- package/src/blocks/responsive-grid/responsive-grid-group/types.ts +9 -0
- package/src/blocks/responsive-grid/responsive-grid-item/edit.tsx +19 -0
- package/src/blocks/responsive-grid/responsive-grid-item/factory.tsx +20 -0
- package/src/blocks/responsive-grid/responsive-grid-item/index.ts +9 -0
- package/src/blocks/responsive-grid/responsive-grid-item/types.ts +5 -0
- package/src/blocks/sections/base-section/attributes.ts +17 -0
- package/src/blocks/sections/base-section/constants.ts +18 -0
- package/src/blocks/sections/base-section/controls.tsx +70 -0
- package/src/blocks/sections/base-section/edit.tsx +34 -0
- package/src/blocks/sections/base-section/editor.scss +24 -0
- package/src/blocks/sections/base-section/factory.tsx +47 -0
- package/src/blocks/sections/base-section/icon.tsx +6 -0
- package/src/blocks/sections/base-section/index.ts +14 -0
- package/src/blocks/sections/base-section/types.ts +26 -0
- package/src/blocks/signpost/signpost-group/constants.ts +3 -0
- package/src/blocks/signpost/signpost-group/edit.tsx +75 -0
- package/src/blocks/signpost/signpost-group/editor.scss +0 -0
- package/src/blocks/signpost/signpost-group/factory.tsx +40 -0
- package/src/blocks/signpost/signpost-group/icon.tsx +19 -0
- package/src/blocks/signpost/signpost-group/index.ts +15 -0
- package/src/blocks/signpost/signpost-group/types.ts +9 -0
- package/src/blocks/signpost/signpost-item/constants.ts +4 -0
- package/src/blocks/signpost/signpost-item/edit.tsx +90 -0
- package/src/blocks/signpost/signpost-item/editor.scss +25 -0
- package/src/blocks/signpost/signpost-item/factory.tsx +29 -0
- package/src/blocks/signpost/signpost-item/icon.tsx +7 -0
- package/src/blocks/signpost/signpost-item/index.ts +10 -0
- package/src/blocks/signpost/signpost-item/types.ts +12 -0
- package/src/blocks/step/step-group/constants.ts +6 -0
- package/src/blocks/step/step-group/edit.tsx +64 -0
- package/src/blocks/step/step-group/editor.scss +19 -0
- package/src/blocks/step/step-group/factory.tsx +36 -0
- package/src/blocks/step/step-group/icon.tsx +27 -0
- package/src/blocks/step/step-group/index.ts +15 -0
- package/src/blocks/step/step-group/types.ts +13 -0
- package/src/blocks/step/step-item/constants.ts +6 -0
- package/src/blocks/step/step-item/edit.tsx +60 -0
- package/src/blocks/step/step-item/editor.scss +18 -0
- package/src/blocks/step/step-item/factory.tsx +27 -0
- package/src/blocks/step/step-item/index.ts +11 -0
- package/src/blocks/step/step-item/types.ts +12 -0
- package/src/blocks/testimonial/testimonial-group/constants.ts +27 -0
- package/src/blocks/testimonial/testimonial-group/edit.tsx +74 -0
- package/src/blocks/testimonial/testimonial-group/editor.scss +38 -0
- package/src/blocks/testimonial/testimonial-group/factory.tsx +44 -0
- package/src/blocks/testimonial/testimonial-group/icon.tsx +33 -0
- package/src/blocks/testimonial/testimonial-group/index.ts +15 -0
- package/src/blocks/testimonial/testimonial-group/types.ts +19 -0
- package/src/blocks/testimonial/testimonial-item/edit.tsx +48 -0
- package/src/blocks/testimonial/testimonial-item/editor.scss +20 -0
- package/src/blocks/testimonial/testimonial-item/factory.tsx +35 -0
- package/src/blocks/testimonial/testimonial-item/index.ts +9 -0
- package/src/blocks/testimonial/testimonial-item/types.ts +9 -0
- package/src/blocks/text-and-form/text-and-form-group/constants.ts +6 -0
- package/src/blocks/text-and-form/text-and-form-group/edit.tsx +59 -0
- package/src/blocks/text-and-form/text-and-form-group/editor.scss +21 -0
- package/src/blocks/text-and-form/text-and-form-group/factory.tsx +38 -0
- package/src/blocks/text-and-form/text-and-form-group/icon.tsx +23 -0
- package/src/blocks/text-and-form/text-and-form-group/index.ts +9 -0
- package/src/blocks/text-and-form/text-and-form-group/types.ts +23 -0
- package/src/blocks/text-and-form/text-and-form-text-column/constants.ts +10 -0
- package/src/blocks/text-and-form/text-and-form-text-column/edit.tsx +94 -0
- package/src/blocks/text-and-form/text-and-form-text-column/editor.scss +29 -0
- package/src/blocks/text-and-form/text-and-form-text-column/factory.tsx +41 -0
- package/src/blocks/text-and-form/text-and-form-text-column/index.ts +18 -0
- package/src/blocks/text-and-form/text-and-form-text-column/types.ts +23 -0
- package/src/blocks/usp/usp-group/constants.ts +54 -0
- package/src/blocks/usp/usp-group/edit.tsx +197 -0
- package/src/blocks/usp/usp-group/editor.scss +24 -0
- package/src/blocks/usp/usp-group/factory.tsx +113 -0
- package/src/blocks/usp/usp-group/icon.tsx +18 -0
- package/src/blocks/usp/usp-group/index.ts +15 -0
- package/src/blocks/usp/usp-group/types.ts +70 -0
- package/src/blocks/usp/usp-item/constants.ts +7 -0
- package/src/blocks/usp/usp-item/edit.tsx +65 -0
- package/src/blocks/usp/usp-item/editor.scss +17 -0
- package/src/blocks/usp/usp-item/factory.tsx +30 -0
- package/src/blocks/usp/usp-item/index.ts +11 -0
- package/src/blocks/usp/usp-item/types.ts +17 -0
- package/src/components/IconControl/IconControl.tsx +55 -0
- package/src/components/IconControl/editor.scss +53 -0
- package/src/components/IconControl/index.ts +2 -0
- package/src/components/IconControl/index.tsx +1 -0
- package/src/components/ImagePicker/ImagePicker.tsx +124 -0
- package/src/components/ImagePicker/editor.scss +79 -0
- package/src/components/ImagePicker/index.ts +2 -0
- package/src/components/ImagePicker/index.tsx +1 -0
- package/src/components/ItemIconControl/ItemIconControl.tsx +72 -0
- package/src/components/ItemIconControl/ItemIconModal.tsx +12 -0
- package/src/components/ItemIconControl/ItemIconPreview.tsx +93 -0
- package/src/components/ItemIconControl/editor.scss +52 -0
- package/src/components/ItemIconControl/index.ts +2 -0
- package/src/components/ItemIconControl/types.d.ts +30 -0
- package/src/constants.ts +20 -0
- package/src/editor.scss +34 -0
- package/src/globals.scss +237 -0
- package/src/hooks/useGroupBlock.ts +53 -0
- package/src/index.ts +122 -0
- package/src/types.ts +33 -0
- package/src/utils/createEditAdapter.ts +11 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {InspectorControls, RichText} from '@wordpress/block-editor'
|
|
2
|
+
import {
|
|
3
|
+
PanelBody,
|
|
4
|
+
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
5
|
+
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
6
|
+
ColorPalette,
|
|
7
|
+
ToggleControl,
|
|
8
|
+
BaseControl,
|
|
9
|
+
} from '@wordpress/components'
|
|
10
|
+
import {__} from '@wordpress/i18n'
|
|
11
|
+
import {ImagePickerBody, ImagePickerControl} from '~/components/ImagePicker'
|
|
12
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
13
|
+
import {DEFAULT_HEADING_STYLES, DEFAULT_VARIANTS} from './constants'
|
|
14
|
+
import {HEADING_LEVELS} from '~/constants'
|
|
15
|
+
import type {BannerGroupAttributes, BannerGroupOptions, HeadingLevels, HeadingStyles, Variants} from './types'
|
|
16
|
+
import clsx from 'clsx'
|
|
17
|
+
|
|
18
|
+
export function createBannerGroupEdit(options: BannerGroupOptions) {
|
|
19
|
+
const VARIANTS = options.variants ?? DEFAULT_VARIANTS
|
|
20
|
+
const HEADING_STYLES = options.headingStyles ?? DEFAULT_HEADING_STYLES
|
|
21
|
+
|
|
22
|
+
return function Edit({
|
|
23
|
+
attributes,
|
|
24
|
+
setAttributes,
|
|
25
|
+
}: {
|
|
26
|
+
attributes: BannerGroupAttributes
|
|
27
|
+
setAttributes: (a: Partial<BannerGroupAttributes>) => void
|
|
28
|
+
}) {
|
|
29
|
+
const {header, img, description, variant, hasBackgroundColor, backgroundColor, textColor} = attributes
|
|
30
|
+
|
|
31
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
32
|
+
blockClassName: [options.blockClassName ?? 'g-banner wp-block-section', `--variant-${variant}`],
|
|
33
|
+
containerClassName: options.containerClassName ?? 'g-banner__inner-blocks',
|
|
34
|
+
allowedBlocks: options.allowedBlocks,
|
|
35
|
+
template: options.template,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<InspectorControls>
|
|
41
|
+
<PanelBody title={__('Vzhled', 'brilo-blocks')}>
|
|
42
|
+
<ToggleGroupControl
|
|
43
|
+
label={__('Varianta', 'brilo-blocks')}
|
|
44
|
+
value={variant}
|
|
45
|
+
onChange={(value) => setAttributes({variant: value as Variants})}
|
|
46
|
+
isBlock
|
|
47
|
+
>
|
|
48
|
+
{VARIANTS.map((v) => (
|
|
49
|
+
<ToggleGroupControlOption key={v.value} value={v.value} label={v.label} />
|
|
50
|
+
))}
|
|
51
|
+
</ToggleGroupControl>
|
|
52
|
+
</PanelBody>
|
|
53
|
+
|
|
54
|
+
<PanelBody title={__('Nadpis', 'brilo-blocks')} initialOpen={false}>
|
|
55
|
+
<ToggleGroupControl
|
|
56
|
+
label={__('Úroveň nadpisu', 'brilo-blocks')}
|
|
57
|
+
value={String(header.heading.level)}
|
|
58
|
+
onChange={(value) =>
|
|
59
|
+
setAttributes({header: {...header, heading: {...header.heading, level: Number(value) as HeadingLevels}}})
|
|
60
|
+
}
|
|
61
|
+
isBlock
|
|
62
|
+
>
|
|
63
|
+
{HEADING_LEVELS.map((l) => (
|
|
64
|
+
<ToggleGroupControlOption key={l} value={String(l)} label={`H${l}`} />
|
|
65
|
+
))}
|
|
66
|
+
</ToggleGroupControl>
|
|
67
|
+
<ToggleGroupControl
|
|
68
|
+
label={__('Styl nadpisu', 'brilo-blocks')}
|
|
69
|
+
value={header.heading.style}
|
|
70
|
+
onChange={(value) => setAttributes({header: {...header, heading: {...header.heading, style: value as HeadingStyles}}})}
|
|
71
|
+
isBlock
|
|
72
|
+
>
|
|
73
|
+
{HEADING_STYLES.map((s) => (
|
|
74
|
+
<ToggleGroupControlOption key={s} value={s} label={s} />
|
|
75
|
+
))}
|
|
76
|
+
</ToggleGroupControl>
|
|
77
|
+
</PanelBody>
|
|
78
|
+
|
|
79
|
+
<PanelBody title={__('Obrázek v pozadí', 'brilo-blocks')}>
|
|
80
|
+
<ImagePickerControl value={img} onChange={(val) => setAttributes({img: val})} />
|
|
81
|
+
</PanelBody>
|
|
82
|
+
|
|
83
|
+
<PanelBody title={__('Vzhled', 'brilo-blocks')}>
|
|
84
|
+
<ToggleControl
|
|
85
|
+
label={__('Použít barvu pozadí', 'brilo-blocks')}
|
|
86
|
+
checked={hasBackgroundColor}
|
|
87
|
+
onChange={(value) => setAttributes({hasBackgroundColor: value})}
|
|
88
|
+
/>
|
|
89
|
+
{hasBackgroundColor && (
|
|
90
|
+
<BaseControl label={__('Barva pozadí', 'brilo-blocks')}>
|
|
91
|
+
<ColorPalette value={backgroundColor} onChange={(value) => setAttributes({backgroundColor: value})} enableAlpha={true} />
|
|
92
|
+
</BaseControl>
|
|
93
|
+
)}
|
|
94
|
+
<BaseControl label={__('Barva textu', 'brilo-blocks')}>
|
|
95
|
+
<ColorPalette value={textColor} onChange={(value) => setAttributes({textColor: value})} />
|
|
96
|
+
</BaseControl>
|
|
97
|
+
</PanelBody>
|
|
98
|
+
</InspectorControls>
|
|
99
|
+
<div {...blockProps}>
|
|
100
|
+
<div className="g-banner__content">
|
|
101
|
+
<RichText
|
|
102
|
+
tagName={`h${header.heading.level}` as HeadingStyles}
|
|
103
|
+
className={clsx('g-banner__heading', `--heading-style-${header.heading.style}`, 'u-text-editable')}
|
|
104
|
+
value={header.heading.title}
|
|
105
|
+
onChange={(value: string) => setAttributes({header: {...header, heading: {...header.heading, title: value}}})}
|
|
106
|
+
placeholder={__('Nadpis...', 'brilo-blocks')}
|
|
107
|
+
allowedFormats={['core/bold', 'core/italic']}
|
|
108
|
+
/>
|
|
109
|
+
<RichText
|
|
110
|
+
tagName="div"
|
|
111
|
+
className="g-banner__description u-text-editable"
|
|
112
|
+
value={description}
|
|
113
|
+
onChange={(value: string) => setAttributes({description: value})}
|
|
114
|
+
placeholder={__('Popis...', 'brilo-blocks')}
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
<div {...innerBlocksProps} />
|
|
118
|
+
</div>
|
|
119
|
+
</>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {InnerBlocks} from '@wordpress/block-editor'
|
|
2
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import type {OptionArray, StringArray} from '~/types'
|
|
5
|
+
import {DEFAULT_VARIANTS, DEFAULT_HEADING_STYLES} from './constants'
|
|
6
|
+
import {createBannerGroupEdit} from './edit'
|
|
7
|
+
import type {BannerGroupAttributes, BannerGroupOptions} from './types'
|
|
8
|
+
import {HEADING_LEVELS} from '~/constants'
|
|
9
|
+
import {icon as defaultIcon} from './icon'
|
|
10
|
+
|
|
11
|
+
export type {BannerGroupAttributes, BannerGroupOptions}
|
|
12
|
+
|
|
13
|
+
export function createBannerGroupBlock<
|
|
14
|
+
TVariants extends OptionArray = typeof DEFAULT_VARIANTS,
|
|
15
|
+
THeadingStyles extends StringArray = typeof DEFAULT_HEADING_STYLES,
|
|
16
|
+
>(
|
|
17
|
+
options: BannerGroupOptions<TVariants, THeadingStyles>,
|
|
18
|
+
): BlockConfiguration<BannerGroupAttributes<TVariants[number]['value'], THeadingStyles[number]>> {
|
|
19
|
+
const variants = options.variants ?? DEFAULT_VARIANTS
|
|
20
|
+
const headingStyles = options.headingStyles ?? DEFAULT_HEADING_STYLES
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
name: options.name,
|
|
24
|
+
title: options.title ?? __('Banner', 'brilo-blocks'),
|
|
25
|
+
description: options.description,
|
|
26
|
+
category: options.category ?? 'layout',
|
|
27
|
+
icon: options.icon ?? defaultIcon,
|
|
28
|
+
...(options.parent && {parent: options.parent}),
|
|
29
|
+
supports: {html: false, customClassName: false},
|
|
30
|
+
attributes: {
|
|
31
|
+
title: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
default: '',
|
|
34
|
+
},
|
|
35
|
+
header: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
default: {
|
|
38
|
+
heading: {title: '', level: HEADING_LEVELS[1], style: headingStyles[1] ?? headingStyles[0]},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
img: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
default: {
|
|
44
|
+
id: 0,
|
|
45
|
+
alt: '',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
description: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
default: '',
|
|
51
|
+
},
|
|
52
|
+
variant: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
default: variants[0].value,
|
|
55
|
+
enum: variants.map((v) => v.value),
|
|
56
|
+
},
|
|
57
|
+
hasBackgroundColor: {type: 'boolean', default: false},
|
|
58
|
+
backgroundColor: {type: 'string', default: ''},
|
|
59
|
+
textColor: {type: 'string', default: ''},
|
|
60
|
+
},
|
|
61
|
+
edit: createBannerGroupEdit(options as unknown as BannerGroupOptions),
|
|
62
|
+
save: () => <InnerBlocks.Content />,
|
|
63
|
+
} as unknown as BlockConfiguration<BannerGroupAttributes<TVariants[number]['value'], THeadingStyles[number]>>
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const icon = (
|
|
2
|
+
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<rect x="0.5" y="5.5" width="19" height="8" stroke="black" fill="none" />
|
|
4
|
+
<path d="M2 8H8V9H2V8Z" fill="black" />
|
|
5
|
+
<path d="M2 10H9V11H2V10Z" fill="black" />
|
|
6
|
+
<path
|
|
7
|
+
fill-rule="evenodd"
|
|
8
|
+
clip-rule="evenodd"
|
|
9
|
+
d="M11.5 8C10.6716 8 10 8.67157 10 9.5C10 10.3284 10.6716 11 11.5 11H16.5C17.3284 11 18 10.3284 18 9.5C18 8.67157 17.3284 8 16.5 8H11.5ZM16 9H12V10H16V9Z"
|
|
10
|
+
fill="#357AB5"
|
|
11
|
+
/>
|
|
12
|
+
</svg>
|
|
13
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {BannerGroupOptions} from '~/blocks/groups/banner-group/types'
|
|
2
|
+
|
|
3
|
+
export type {BannerGroupAttributes, BannerGroupOptions} from './factory'
|
|
4
|
+
export {createBannerGroupBlock} from './factory'
|
|
5
|
+
|
|
6
|
+
export const bannerGroupDefaults: BannerGroupOptions = {
|
|
7
|
+
name: 'brilo/banner-group',
|
|
8
|
+
parent: ['brilo/base-section'],
|
|
9
|
+
allowedBlocks: ['brilo/button-group'],
|
|
10
|
+
template: [['brilo/button-group', {}]],
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {BriloBlockType, Media, OptionArray, StringArray} from '~/types'
|
|
2
|
+
import {DEFAULT_HEADING_STYLES, DEFAULT_VARIANTS} from './constants'
|
|
3
|
+
import {HEADING_LEVELS} from '~/constants'
|
|
4
|
+
|
|
5
|
+
export type Variants = (typeof DEFAULT_VARIANTS)[number]['value']
|
|
6
|
+
export type HeadingLevels = (typeof HEADING_LEVELS)[number]
|
|
7
|
+
export type HeadingStyles = (typeof DEFAULT_HEADING_STYLES)[number]
|
|
8
|
+
|
|
9
|
+
export interface BannerGroupAttributes<TVariant extends string = Variants, THeadingStyle extends string = HeadingStyles>
|
|
10
|
+
extends Record<string, unknown> {
|
|
11
|
+
title: string
|
|
12
|
+
header: {
|
|
13
|
+
heading: {title: string; level: HeadingLevels; style: THeadingStyle}
|
|
14
|
+
}
|
|
15
|
+
img: Media
|
|
16
|
+
hasBackgroundColor: boolean
|
|
17
|
+
backgroundColor: string
|
|
18
|
+
textColor: string
|
|
19
|
+
description: string
|
|
20
|
+
variant: TVariant
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BannerGroupOptions<
|
|
24
|
+
TVariants extends OptionArray = typeof DEFAULT_VARIANTS,
|
|
25
|
+
THeadingStyles extends StringArray = typeof DEFAULT_HEADING_STYLES,
|
|
26
|
+
> extends BriloBlockType {
|
|
27
|
+
variants?: TVariants
|
|
28
|
+
headingStyles?: THeadingStyles
|
|
29
|
+
headingLevels?: HeadingLevels
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {__} from '@wordpress/i18n'
|
|
2
|
+
|
|
3
|
+
export {HEADING_LEVELS as DEFAULT_LEVELS, HEADING_STYLES as DEFAULT_STYLES} from '~/constants'
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_ALIGNMENTS = [
|
|
6
|
+
{value: 'left', label: __('Vlevo', 'brilo-blocks')},
|
|
7
|
+
{value: 'center', label: __('Středem', 'brilo-blocks')},
|
|
8
|
+
{value: 'right', label: __('Vpravo', 'brilo-blocks')},
|
|
9
|
+
] as const
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {InspectorControls, RichText, useBlockProps} from '@wordpress/block-editor'
|
|
2
|
+
import {
|
|
3
|
+
PanelBody,
|
|
4
|
+
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
5
|
+
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
6
|
+
} from '@wordpress/components'
|
|
7
|
+
import {__} from '@wordpress/i18n'
|
|
8
|
+
import clsx from 'clsx'
|
|
9
|
+
import {DEFAULT_ALIGNMENTS, DEFAULT_LEVELS, DEFAULT_STYLES} from './constants'
|
|
10
|
+
import type {BasicHeaderGroupAttributes, BasicHeaderGroupOptions, HeaderAlignment, HeadingStyle} from './types'
|
|
11
|
+
|
|
12
|
+
export function createBasicHeaderGroupEdit(options: BasicHeaderGroupOptions) {
|
|
13
|
+
const LEVELS = options.levels ?? DEFAULT_LEVELS
|
|
14
|
+
const STYLES = options.styles ?? DEFAULT_STYLES
|
|
15
|
+
const ALIGNMENTS = options.alignments ?? DEFAULT_ALIGNMENTS
|
|
16
|
+
|
|
17
|
+
return function Edit({
|
|
18
|
+
attributes,
|
|
19
|
+
setAttributes,
|
|
20
|
+
}: {
|
|
21
|
+
attributes: BasicHeaderGroupAttributes
|
|
22
|
+
setAttributes: (a: Partial<BasicHeaderGroupAttributes>) => void
|
|
23
|
+
}) {
|
|
24
|
+
const {heading, overline, content, textAlign} = attributes
|
|
25
|
+
const blockProps = useBlockProps({
|
|
26
|
+
className: clsx(options.blockClassName ?? 'g-header wp-block-section', `--textAlign-${textAlign}`),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<>
|
|
31
|
+
<InspectorControls>
|
|
32
|
+
<PanelBody title={__('Nadpis', 'brilo-blocks')}>
|
|
33
|
+
<ToggleGroupControl
|
|
34
|
+
label={__('Úroveň nadpisu', 'brilo-blocks')}
|
|
35
|
+
value={String(heading.level)}
|
|
36
|
+
onChange={(value) =>
|
|
37
|
+
setAttributes({
|
|
38
|
+
heading: {...heading, level: Number(value) as BasicHeaderGroupAttributes['heading']['level']},
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
isBlock
|
|
42
|
+
>
|
|
43
|
+
{LEVELS.map((l) => (
|
|
44
|
+
<ToggleGroupControlOption key={l} value={String(l)} label={`H${l}`} />
|
|
45
|
+
))}
|
|
46
|
+
</ToggleGroupControl>
|
|
47
|
+
<ToggleGroupControl
|
|
48
|
+
label={__('Styl nadpisu', 'brilo-blocks')}
|
|
49
|
+
value={heading.style}
|
|
50
|
+
onChange={(value) => setAttributes({heading: {...heading, style: value as HeadingStyle}})}
|
|
51
|
+
isBlock
|
|
52
|
+
>
|
|
53
|
+
{STYLES.map((s) => (
|
|
54
|
+
<ToggleGroupControlOption key={s} value={s} label={s.toUpperCase()} />
|
|
55
|
+
))}
|
|
56
|
+
</ToggleGroupControl>
|
|
57
|
+
<ToggleGroupControl
|
|
58
|
+
label={__('Zarovnání', 'brilo-blocks')}
|
|
59
|
+
value={textAlign}
|
|
60
|
+
onChange={(value) => setAttributes({textAlign: value as HeaderAlignment})}
|
|
61
|
+
isBlock
|
|
62
|
+
>
|
|
63
|
+
{ALIGNMENTS.map((a) => (
|
|
64
|
+
<ToggleGroupControlOption key={a.value} value={a.value} label={a.label} />
|
|
65
|
+
))}
|
|
66
|
+
</ToggleGroupControl>
|
|
67
|
+
</PanelBody>
|
|
68
|
+
</InspectorControls>
|
|
69
|
+
<div {...blockProps}>
|
|
70
|
+
<RichText
|
|
71
|
+
tagName="span"
|
|
72
|
+
className="g-header__overline u-text-editable"
|
|
73
|
+
value={overline.title}
|
|
74
|
+
onChange={(value) => setAttributes({overline: {title: value}})}
|
|
75
|
+
placeholder={__('Overline...', 'brilo-blocks')}
|
|
76
|
+
allowedFormats={[]}
|
|
77
|
+
/>
|
|
78
|
+
<RichText
|
|
79
|
+
tagName={`h${heading.level}` as 'h1' | 'h2' | 'h3' | 'h4'}
|
|
80
|
+
className={clsx('g-header__heading', `--heading-style-${heading.style}`, 'u-text-editable')}
|
|
81
|
+
value={heading.title}
|
|
82
|
+
onChange={(value) => setAttributes({heading: {...heading, title: value}})}
|
|
83
|
+
placeholder={__('Nadpis...', 'brilo-blocks')}
|
|
84
|
+
allowedFormats={['core/bold', 'core/italic']}
|
|
85
|
+
/>
|
|
86
|
+
<RichText
|
|
87
|
+
tagName="div"
|
|
88
|
+
multiline="p"
|
|
89
|
+
className="g-header__content u-text-editable"
|
|
90
|
+
value={content}
|
|
91
|
+
onChange={(value) => setAttributes({content: value})}
|
|
92
|
+
placeholder={__('Perex...', 'brilo-blocks')}
|
|
93
|
+
allowedFormats={['core/bold', 'core/italic', 'core/link']}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
</>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@layer base {
|
|
2
|
+
.g-header {
|
|
3
|
+
padding: 12px 16px;
|
|
4
|
+
|
|
5
|
+
&.--textAlign-left {
|
|
6
|
+
text-align: left;
|
|
7
|
+
}
|
|
8
|
+
&.--textAlign-center {
|
|
9
|
+
text-align: center;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.g-header__overline {
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
font-size: 11px;
|
|
16
|
+
font-weight: 600;
|
|
17
|
+
text-transform: uppercase;
|
|
18
|
+
letter-spacing: 1.5px;
|
|
19
|
+
color: #555;
|
|
20
|
+
background-color: #f0f0f0;
|
|
21
|
+
border-radius: 100px;
|
|
22
|
+
padding: 3px 10px;
|
|
23
|
+
margin-bottom: 8px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.g-header__heading {
|
|
27
|
+
margin: 0 0 10px;
|
|
28
|
+
font-weight: 700;
|
|
29
|
+
font-size: var(--heading-size, 24px);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.g-header__content {
|
|
33
|
+
margin-block: 4px;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
2
|
+
import {__} from '@wordpress/i18n'
|
|
3
|
+
import type {NumberArray, OptionArray, StringArray} from '~/types'
|
|
4
|
+
import {DEFAULT_ALIGNMENTS, DEFAULT_LEVELS, DEFAULT_STYLES} from './constants'
|
|
5
|
+
import {createBasicHeaderGroupEdit} from './edit'
|
|
6
|
+
import {icon as defaultIcon} from './icon'
|
|
7
|
+
import type {BasicHeaderGroupAttributes, BasicHeaderGroupOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export type {BasicHeaderGroupAttributes, BasicHeaderGroupOptions}
|
|
10
|
+
|
|
11
|
+
export function createBasicHeaderGroupBlock<
|
|
12
|
+
TLevels extends NumberArray = typeof DEFAULT_LEVELS,
|
|
13
|
+
TStyles extends StringArray = typeof DEFAULT_STYLES,
|
|
14
|
+
TAlignments extends OptionArray = typeof DEFAULT_ALIGNMENTS,
|
|
15
|
+
>(
|
|
16
|
+
options: BasicHeaderGroupOptions<TLevels, TStyles, TAlignments>,
|
|
17
|
+
): BlockConfiguration<BasicHeaderGroupAttributes<TLevels[number], TStyles[number], TAlignments[number]['value']>> {
|
|
18
|
+
const levels = options.levels ?? DEFAULT_LEVELS
|
|
19
|
+
const styles = options.styles ?? DEFAULT_STYLES
|
|
20
|
+
const alignments = options.alignments ?? DEFAULT_ALIGNMENTS
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
name: options.name,
|
|
24
|
+
title: options.title ?? __('Hlavička základní', 'brilo-blocks'),
|
|
25
|
+
description: options.description,
|
|
26
|
+
category: options.category ?? 'layout',
|
|
27
|
+
...(options.parent && {parent: options.parent}),
|
|
28
|
+
icon: options.icon ?? defaultIcon,
|
|
29
|
+
supports: {html: false, customClassName: false},
|
|
30
|
+
attributes: {
|
|
31
|
+
heading: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
default: {title: '', level: levels[1] ?? levels[0], style: styles[1] ?? styles[0]},
|
|
34
|
+
},
|
|
35
|
+
overline: {type: 'object', default: {title: ''}},
|
|
36
|
+
content: {type: 'string', default: ''},
|
|
37
|
+
textAlign: {
|
|
38
|
+
type: 'string',
|
|
39
|
+
default: alignments[1]?.value ?? alignments[0].value,
|
|
40
|
+
enum: alignments.map((a) => a.value),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
edit: createBasicHeaderGroupEdit(options as unknown as BasicHeaderGroupOptions),
|
|
44
|
+
save: () => null,
|
|
45
|
+
} as unknown as BlockConfiguration<BasicHeaderGroupAttributes<TLevels[number], TStyles[number], TAlignments[number]['value']>>
|
|
46
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const icon = (
|
|
2
|
+
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<title>Basic Header Group</title>
|
|
4
|
+
<rect x="12" y="4" width="3" height="2" rx="1" fill="black" />
|
|
5
|
+
<rect x="5" y="4" width="6" height="2" rx="1" fill="black" />
|
|
6
|
+
<rect x="1" y="8" width="6" height="1" fill="black" />
|
|
7
|
+
<rect x="9" y="8" width="10" height="1" fill="black" />
|
|
8
|
+
<rect x="3" y="10" width="9" height="1" fill="black" />
|
|
9
|
+
<rect x="14" y="10" width="3" height="1" fill="black" />
|
|
10
|
+
<path
|
|
11
|
+
fillRule="evenodd"
|
|
12
|
+
clipRule="evenodd"
|
|
13
|
+
d="M7.5 13C6.67157 13 6 13.6716 6 14.5C6 15.3284 6.67157 16 7.5 16H12.5C13.3284 16 14 15.3284 14 14.5C14 13.6716 13.3284 13 12.5 13H7.5ZM12 14H8V15H12V14Z"
|
|
14
|
+
fill="#357AB5"
|
|
15
|
+
/>
|
|
16
|
+
</svg>
|
|
17
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type {BasicHeaderGroupAttributes, BasicHeaderGroupOptions} from './types'
|
|
2
|
+
export {createBasicHeaderGroupBlock} from './factory'
|
|
3
|
+
|
|
4
|
+
import type {BasicHeaderGroupOptions} from './types'
|
|
5
|
+
|
|
6
|
+
export const basicHeaderGroupDefaults: BasicHeaderGroupOptions = {
|
|
7
|
+
name: 'brilo/basic-header-group',
|
|
8
|
+
parent: ['brilo/base-section'],
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {BriloBlockType, NumberArray, OptionArray, StringArray} from '~/types'
|
|
2
|
+
import type {DEFAULT_ALIGNMENTS, DEFAULT_LEVELS, DEFAULT_STYLES} from './constants'
|
|
3
|
+
|
|
4
|
+
export type HeaderAlignment = (typeof DEFAULT_ALIGNMENTS)[number]['value']
|
|
5
|
+
export type HeadingLevel = (typeof DEFAULT_LEVELS)[number]
|
|
6
|
+
export type HeadingStyle = (typeof DEFAULT_STYLES)[number]
|
|
7
|
+
|
|
8
|
+
export interface BasicHeaderGroupAttributes<
|
|
9
|
+
TLevel extends number = HeadingLevel,
|
|
10
|
+
TStyle extends string = HeadingStyle,
|
|
11
|
+
TAlignment extends string = HeaderAlignment,
|
|
12
|
+
> extends Record<string, unknown> {
|
|
13
|
+
heading: {title: string; level: TLevel; style: TStyle}
|
|
14
|
+
overline: {title: string}
|
|
15
|
+
content: string
|
|
16
|
+
textAlign: TAlignment
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface BasicHeaderGroupOptions<
|
|
20
|
+
TLevels extends NumberArray = typeof DEFAULT_LEVELS,
|
|
21
|
+
TStyles extends StringArray = typeof DEFAULT_STYLES,
|
|
22
|
+
TAlignments extends OptionArray = typeof DEFAULT_ALIGNMENTS,
|
|
23
|
+
> extends BriloBlockType {
|
|
24
|
+
levels?: TLevels
|
|
25
|
+
styles?: TStyles
|
|
26
|
+
alignments?: TAlignments
|
|
27
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {__} from '@wordpress/i18n'
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_ALIGNMENTS = [
|
|
4
|
+
{value: 'left', label: __('Vlevo', 'brilo-blocks'), icon: 'align-left'},
|
|
5
|
+
{value: 'center', label: __('Na střed', 'brilo-blocks'), icon: 'align-center'},
|
|
6
|
+
{value: 'right', label: __('Vpravo', 'brilo-blocks'), icon: 'align-right'},
|
|
7
|
+
] as const
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {InspectorControls} from '@wordpress/block-editor'
|
|
2
|
+
import {
|
|
3
|
+
PanelBody,
|
|
4
|
+
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
5
|
+
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
6
|
+
} from '@wordpress/components'
|
|
7
|
+
import {__} from '@wordpress/i18n'
|
|
8
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
9
|
+
import {DEFAULT_ALIGNMENTS} from './constants'
|
|
10
|
+
import type {ButtonGroupAlignment, ButtonGroupAttributes, ButtonGroupOptions} from './types'
|
|
11
|
+
|
|
12
|
+
export function createButtonGroupEdit(options: ButtonGroupOptions) {
|
|
13
|
+
const alignments = options.alignments ?? DEFAULT_ALIGNMENTS
|
|
14
|
+
|
|
15
|
+
return function Edit({
|
|
16
|
+
attributes,
|
|
17
|
+
setAttributes,
|
|
18
|
+
}: {
|
|
19
|
+
attributes: ButtonGroupAttributes
|
|
20
|
+
setAttributes: (a: Partial<ButtonGroupAttributes>) => void
|
|
21
|
+
}) {
|
|
22
|
+
const {alignment} = attributes
|
|
23
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
24
|
+
blockClassName: [options.blockClassName ?? 'g-button-group wp-block-section', `--align-${alignment}`],
|
|
25
|
+
containerClassName: options.containerClassName ?? 'flex gap-3 g-button-group__inner',
|
|
26
|
+
allowedBlocks: options.allowedBlocks,
|
|
27
|
+
template: options.template,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
<InspectorControls>
|
|
33
|
+
<PanelBody title={__('Skupina tlačítek', 'brilo-blocks')}>
|
|
34
|
+
<ToggleGroupControl
|
|
35
|
+
label={__('Zarovnání', 'brilo-blocks')}
|
|
36
|
+
value={alignment}
|
|
37
|
+
onChange={(v) => setAttributes({alignment: v as ButtonGroupAlignment})}
|
|
38
|
+
isBlock
|
|
39
|
+
>
|
|
40
|
+
{alignments.map((a) => (
|
|
41
|
+
<ToggleGroupControlOption key={a.value} value={a.value} label={a.label} />
|
|
42
|
+
))}
|
|
43
|
+
</ToggleGroupControl>
|
|
44
|
+
</PanelBody>
|
|
45
|
+
</InspectorControls>
|
|
46
|
+
<div {...blockProps}>
|
|
47
|
+
<div {...innerBlocksProps} />
|
|
48
|
+
</div>
|
|
49
|
+
</>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
@layer base {
|
|
2
|
+
.g-button-group {
|
|
3
|
+
padding: 8px;
|
|
4
|
+
min-height: 44px;
|
|
5
|
+
|
|
6
|
+
&.--align-left {
|
|
7
|
+
--justify: flex-start;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&.--align-center {
|
|
11
|
+
--justify: center;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&.--align-right {
|
|
15
|
+
--justify: flex-end;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.g-button-group__inner {
|
|
21
|
+
flex-wrap: wrap;
|
|
22
|
+
justify-content: var(--justify, flex-start);
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {InnerBlocks} from '@wordpress/block-editor'
|
|
2
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import type {OptionArray} from '~/types'
|
|
5
|
+
import {DEFAULT_ALIGNMENTS} from './constants'
|
|
6
|
+
import {createButtonGroupEdit} from './edit'
|
|
7
|
+
import type {ButtonGroupAttributes, ButtonGroupOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export type {ButtonGroupAttributes, ButtonGroupOptions}
|
|
10
|
+
|
|
11
|
+
export function createButtonGroupBlock<TAlignments extends OptionArray = typeof DEFAULT_ALIGNMENTS>(
|
|
12
|
+
options: ButtonGroupOptions<TAlignments>,
|
|
13
|
+
): BlockConfiguration<ButtonGroupAttributes<TAlignments[number]['value']>> {
|
|
14
|
+
const alignments = options.alignments ?? DEFAULT_ALIGNMENTS
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
name: options.name,
|
|
18
|
+
title: options.title ?? __('Skupina tlačítek', 'brilo-blocks'),
|
|
19
|
+
description: options.description,
|
|
20
|
+
category: options.category ?? 'layout',
|
|
21
|
+
...(options.parent && {parent: options.parent}),
|
|
22
|
+
icon: options.icon ?? 'button',
|
|
23
|
+
supports: {html: false, customClassName: false},
|
|
24
|
+
attributes: {
|
|
25
|
+
alignment: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
default: alignments[1]?.value ?? alignments[0].value,
|
|
28
|
+
enum: alignments.map((a) => a.value),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
edit: createButtonGroupEdit(options as unknown as ButtonGroupOptions),
|
|
32
|
+
save: () => <InnerBlocks.Content />,
|
|
33
|
+
} as unknown as BlockConfiguration<ButtonGroupAttributes<TAlignments[number]['value']>>
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type {ButtonGroupAttributes, ButtonGroupOptions} from './types'
|
|
2
|
+
export {createButtonGroupBlock} from './factory'
|
|
3
|
+
|
|
4
|
+
import type {ButtonGroupOptions} from './types'
|
|
5
|
+
|
|
6
|
+
export const buttonGroupDefaults: ButtonGroupOptions = {
|
|
7
|
+
name: 'brilo/button-group',
|
|
8
|
+
parent: ['brilo/base-section'],
|
|
9
|
+
allowedBlocks: ['brilo/basic-button'],
|
|
10
|
+
template: [['brilo/basic-button', {}]],
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type {OptionArray, BriloBlockType} from '~/types'
|
|
2
|
+
import type {DEFAULT_ALIGNMENTS} from './constants'
|
|
3
|
+
|
|
4
|
+
export type ButtonGroupAlignment = (typeof DEFAULT_ALIGNMENTS)[number]['value']
|
|
5
|
+
|
|
6
|
+
export interface ButtonGroupAttributes<TAlignment extends string = ButtonGroupAlignment> extends Record<string, unknown> {
|
|
7
|
+
alignment: TAlignment
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ButtonGroupOptions<TAlignments extends OptionArray = typeof DEFAULT_ALIGNMENTS> extends BriloBlockType {
|
|
11
|
+
alignments?: TAlignments
|
|
12
|
+
}
|