@brilo/base-blocks 0.1.22 → 0.1.24
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/build/.tsbuildinfo +1 -1
- package/build/blocks/anchor/anchor-group/constants.d.ts +24 -0
- package/build/blocks/anchor/anchor-group/constants.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-group/constants.js +12 -0
- package/build/blocks/anchor/anchor-group/edit.d.ts +6 -0
- package/build/blocks/anchor/anchor-group/edit.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-group/edit.js +28 -0
- package/build/blocks/anchor/anchor-group/factory.d.ts +7 -0
- package/build/blocks/anchor/anchor-group/factory.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-group/factory.js +33 -0
- package/build/blocks/anchor/anchor-group/index.d.ts +6 -0
- package/build/blocks/anchor/anchor-group/index.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-group/index.js +7 -0
- package/build/blocks/anchor/anchor-group/types.d.ts +13 -0
- package/build/blocks/anchor/anchor-group/types.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-group/types.js +1 -0
- package/build/blocks/anchor/anchor-item/constants.d.ts +13 -0
- package/build/blocks/anchor/anchor-item/constants.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-item/constants.js +7 -0
- package/build/blocks/anchor/anchor-item/edit.d.ts +6 -0
- package/build/blocks/anchor/anchor-item/edit.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-item/edit.js +24 -0
- package/build/blocks/anchor/anchor-item/factory.d.ts +5 -0
- package/build/blocks/anchor/anchor-item/factory.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-item/factory.js +25 -0
- package/build/blocks/anchor/anchor-item/index.d.ts +7 -0
- package/build/blocks/anchor/anchor-item/index.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-item/index.js +9 -0
- package/build/blocks/anchor/anchor-item/types.d.ts +18 -0
- package/build/blocks/anchor/anchor-item/types.d.ts.map +1 -0
- package/build/blocks/anchor/anchor-item/types.js +1 -0
- package/build/blocks/layout/layout-aside/constants.d.ts +2 -0
- package/build/blocks/layout/layout-aside/constants.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/constants.js +1 -0
- package/build/blocks/layout/layout-aside/edit.d.ts +4 -0
- package/build/blocks/layout/layout-aside/edit.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/edit.js +13 -0
- package/build/blocks/layout/layout-aside/factory.d.ts +4 -0
- package/build/blocks/layout/layout-aside/factory.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/factory.js +20 -0
- package/build/blocks/layout/layout-aside/icon.d.ts +3 -0
- package/build/blocks/layout/layout-aside/icon.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/icon.js +2 -0
- package/build/blocks/layout/layout-aside/index.d.ts +5 -0
- package/build/blocks/layout/layout-aside/index.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/index.js +5 -0
- package/build/blocks/layout/layout-aside/types.d.ts +6 -0
- package/build/blocks/layout/layout-aside/types.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/types.js +1 -0
- package/build/blocks/layout/layout-content/constants.d.ts +2 -0
- package/build/blocks/layout/layout-content/constants.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/constants.js +1 -0
- package/build/blocks/layout/layout-content/edit.d.ts +4 -0
- package/build/blocks/layout/layout-content/edit.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/edit.js +13 -0
- package/build/blocks/layout/layout-content/factory.d.ts +4 -0
- package/build/blocks/layout/layout-content/factory.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/factory.js +20 -0
- package/build/blocks/layout/layout-content/icon.d.ts +3 -0
- package/build/blocks/layout/layout-content/icon.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/icon.js +2 -0
- package/build/blocks/layout/layout-content/index.d.ts +5 -0
- package/build/blocks/layout/layout-content/index.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/index.js +5 -0
- package/build/blocks/layout/layout-content/types.d.ts +6 -0
- package/build/blocks/layout/layout-content/types.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/types.js +1 -0
- package/build/blocks/layout/layout-content-w-aside/constants.d.ts +11 -0
- package/build/blocks/layout/layout-content-w-aside/constants.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/constants.js +6 -0
- package/build/blocks/layout/layout-content-w-aside/edit.d.ts +7 -0
- package/build/blocks/layout/layout-content-w-aside/edit.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/edit.js +22 -0
- package/build/blocks/layout/layout-content-w-aside/factory.d.ts +6 -0
- package/build/blocks/layout/layout-content-w-aside/factory.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/factory.js +26 -0
- package/build/blocks/layout/layout-content-w-aside/icon.d.ts +3 -0
- package/build/blocks/layout/layout-content-w-aside/icon.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/icon.js +2 -0
- package/build/blocks/layout/layout-content-w-aside/index.d.ts +5 -0
- package/build/blocks/layout/layout-content-w-aside/index.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/index.js +9 -0
- package/build/blocks/layout/layout-content-w-aside/types.d.ts +10 -0
- package/build/blocks/layout/layout-content-w-aside/types.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/types.js +1 -0
- package/build/blocks/post/posts-grid/constants.d.ts +4 -0
- package/build/blocks/post/posts-grid/constants.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/constants.js +3 -0
- package/build/blocks/post/posts-grid/edit.d.ts +6 -0
- package/build/blocks/post/posts-grid/edit.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/edit.js +21 -0
- package/build/blocks/post/posts-grid/factory.d.ts +5 -0
- package/build/blocks/post/posts-grid/factory.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/factory.js +59 -0
- package/build/blocks/post/posts-grid/icon.d.ts +2 -0
- package/build/blocks/post/posts-grid/icon.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/icon.js +2 -0
- package/build/blocks/post/posts-grid/index.d.ts +5 -0
- package/build/blocks/post/posts-grid/index.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/index.js +5 -0
- package/build/blocks/post/posts-grid/types.d.ts +22 -0
- package/build/blocks/post/posts-grid/types.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/types.js +1 -0
- package/build/blocks/sections/base-section/attributes.d.ts +4 -0
- package/build/blocks/sections/base-section/attributes.d.ts.map +1 -1
- package/build/blocks/sections/base-section/attributes.js +4 -0
- package/build/blocks/sections/base-section/constants.d.ts +7 -0
- package/build/blocks/sections/base-section/constants.d.ts.map +1 -1
- package/build/blocks/sections/base-section/constants.js +7 -0
- package/build/blocks/sections/base-section/controls.d.ts.map +1 -1
- package/build/blocks/sections/base-section/controls.js +23 -5
- package/build/blocks/sections/base-section/types.d.ts +18 -1
- package/build/blocks/sections/base-section/types.d.ts.map +1 -1
- package/build/index.d.ts +12 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -0
- package/package.json +1 -1
- package/src/blocks/anchor/anchor-group/constants.ts +14 -0
- package/src/blocks/anchor/anchor-group/edit.tsx +70 -0
- package/src/blocks/anchor/anchor-group/editor.scss +52 -0
- package/src/blocks/anchor/anchor-group/factory.tsx +43 -0
- package/src/blocks/anchor/anchor-group/index.ts +11 -0
- package/src/blocks/anchor/anchor-group/types.ts +19 -0
- package/src/blocks/anchor/anchor-item/constants.ts +10 -0
- package/src/blocks/anchor/anchor-item/edit.tsx +96 -0
- package/src/blocks/anchor/anchor-item/editor.scss +22 -0
- package/src/blocks/anchor/anchor-item/factory.tsx +29 -0
- package/src/blocks/anchor/anchor-item/index.ts +13 -0
- package/src/blocks/anchor/anchor-item/types.ts +16 -0
- package/src/blocks/layout/layout-aside/constants.ts +1 -0
- package/src/blocks/layout/layout-aside/edit.tsx +20 -0
- package/src/blocks/layout/layout-aside/editor.scss +9 -0
- package/src/blocks/layout/layout-aside/factory.tsx +24 -0
- package/src/blocks/layout/layout-aside/icon.tsx +12 -0
- package/src/blocks/layout/layout-aside/index.ts +9 -0
- package/src/blocks/layout/layout-aside/types.ts +5 -0
- package/src/blocks/layout/layout-content/constants.ts +1 -0
- package/src/blocks/layout/layout-content/edit.tsx +20 -0
- package/src/blocks/layout/layout-content/editor.scss +9 -0
- package/src/blocks/layout/layout-content/factory.tsx +24 -0
- package/src/blocks/layout/layout-content/icon.tsx +12 -0
- package/src/blocks/layout/layout-content/index.ts +9 -0
- package/src/blocks/layout/layout-content/types.ts +5 -0
- package/src/blocks/layout/layout-content-w-aside/constants.ts +7 -0
- package/src/blocks/layout/layout-content-w-aside/edit.tsx +52 -0
- package/src/blocks/layout/layout-content-w-aside/editor.scss +35 -0
- package/src/blocks/layout/layout-content-w-aside/factory.tsx +34 -0
- package/src/blocks/layout/layout-content-w-aside/icon.tsx +12 -0
- package/src/blocks/layout/layout-content-w-aside/index.ts +13 -0
- package/src/blocks/layout/layout-content-w-aside/types.ts +12 -0
- package/src/blocks/post/posts-grid/constants.ts +3 -0
- package/src/blocks/post/posts-grid/edit.tsx +105 -0
- package/src/blocks/post/posts-grid/factory.tsx +63 -0
- package/src/blocks/post/posts-grid/icon.tsx +8 -0
- package/src/blocks/post/posts-grid/index.ts +9 -0
- package/src/blocks/post/posts-grid/types.ts +25 -0
- package/src/blocks/sections/base-section/attributes.ts +4 -0
- package/src/blocks/sections/base-section/constants.ts +10 -0
- package/src/blocks/sections/base-section/controls.tsx +83 -4
- package/src/blocks/sections/base-section/types.ts +20 -1
- package/src/editor.scss +5 -0
- package/src/index.ts +19 -0
|
@@ -0,0 +1,70 @@
|
|
|
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 clsx from 'clsx'
|
|
9
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
10
|
+
import {ANCHOR_ALIGNMENTS, ANCHOR_COLUMNS} from './constants'
|
|
11
|
+
import type {AnchorAlignment, AnchorColumns, AnchorGroupAttributes, AnchorGroupOptions} from './types'
|
|
12
|
+
|
|
13
|
+
export function createAnchorGroupEdit(options: AnchorGroupOptions) {
|
|
14
|
+
const columnsOptions = options.columnsOptions ?? ANCHOR_COLUMNS
|
|
15
|
+
const alignments = options.alignments ?? ANCHOR_ALIGNMENTS
|
|
16
|
+
|
|
17
|
+
return function Edit({
|
|
18
|
+
attributes,
|
|
19
|
+
setAttributes,
|
|
20
|
+
}: {
|
|
21
|
+
attributes: AnchorGroupAttributes
|
|
22
|
+
setAttributes: (a: Partial<AnchorGroupAttributes>) => void
|
|
23
|
+
}) {
|
|
24
|
+
const {columns, align} = attributes
|
|
25
|
+
|
|
26
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
27
|
+
blockClassName: clsx(options.blockClassName ?? 'g-anchors'),
|
|
28
|
+
containerClassName: [
|
|
29
|
+
options.containerClassName ?? 'g-anchors__inner',
|
|
30
|
+
columns === 'auto' ? '--auto' : `u-grid-responsive --cols-${columns}`,
|
|
31
|
+
align === 'center' && 'justify-content-center',
|
|
32
|
+
],
|
|
33
|
+
allowedBlocks: options.allowedBlocks,
|
|
34
|
+
template: options.template,
|
|
35
|
+
layout: {type: 'default'},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<InspectorControls>
|
|
41
|
+
<PanelBody title={__('Kotvy', 'brilo-blocks')}>
|
|
42
|
+
<ToggleGroupControl
|
|
43
|
+
isBlock
|
|
44
|
+
label={__('Počet sloupců', 'brilo-blocks')}
|
|
45
|
+
value={columns}
|
|
46
|
+
onChange={(v) => setAttributes({columns: v as AnchorColumns})}
|
|
47
|
+
>
|
|
48
|
+
{columnsOptions.map((c) => (
|
|
49
|
+
<ToggleGroupControlOption key={c.value} value={c.value} label={c.label} />
|
|
50
|
+
))}
|
|
51
|
+
</ToggleGroupControl>
|
|
52
|
+
<ToggleGroupControl
|
|
53
|
+
isBlock
|
|
54
|
+
label={__('Zarovnání', 'brilo-blocks')}
|
|
55
|
+
value={align}
|
|
56
|
+
onChange={(v) => setAttributes({align: v as AnchorAlignment})}
|
|
57
|
+
>
|
|
58
|
+
{alignments.map((a) => (
|
|
59
|
+
<ToggleGroupControlOption key={a.value} value={a.value} label={a.label} />
|
|
60
|
+
))}
|
|
61
|
+
</ToggleGroupControl>
|
|
62
|
+
</PanelBody>
|
|
63
|
+
</InspectorControls>
|
|
64
|
+
<div {...blockProps}>
|
|
65
|
+
<div {...innerBlocksProps} />
|
|
66
|
+
</div>
|
|
67
|
+
</>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
@layer base {
|
|
2
|
+
.g-anchors {
|
|
3
|
+
border: 1px solid #eee;
|
|
4
|
+
padding: 16px;
|
|
5
|
+
|
|
6
|
+
.g-anchors__inner {
|
|
7
|
+
&.--auto {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
gap: 8px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// .u-grid-responsive itself is a frontoffice utility class, not loaded in the
|
|
14
|
+
// editor bundle — recreate just enough of it here for the admin preview.
|
|
15
|
+
&.u-grid-responsive {
|
|
16
|
+
display: grid;
|
|
17
|
+
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
|
|
18
|
+
gap: 16px;
|
|
19
|
+
|
|
20
|
+
&.--cols-2 {
|
|
21
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&.--cols-3 {
|
|
25
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&.--cols-4 {
|
|
29
|
+
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&.--cols-6 {
|
|
33
|
+
grid-template-columns: repeat(6, minmax(0, 1fr));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&.justify-content-center {
|
|
38
|
+
justify-content: center;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// WP core sets `margin-left/right: auto` on `.wp-block` children of containers whose
|
|
45
|
+
// layout type isn't flex/grid (ours is `default`). That rule is UNLAYERED, so a
|
|
46
|
+
// layered override can't beat it regardless of specificity — keep this UNLAYERED and
|
|
47
|
+
// bump above WP's (0,2,0) specificity to win. Matches contact-group's editor.scss.
|
|
48
|
+
.editor-styles-wrapper .g-anchors__inner > .wp-block {
|
|
49
|
+
margin-left: 0;
|
|
50
|
+
margin-right: 0;
|
|
51
|
+
max-width: none;
|
|
52
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 {ANCHOR_ALIGNMENTS, ANCHOR_COLUMNS} from './constants'
|
|
6
|
+
import {createAnchorGroupEdit} from './edit'
|
|
7
|
+
import type {AnchorGroupAttributes, AnchorGroupOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export type {AnchorGroupAttributes, AnchorGroupOptions}
|
|
10
|
+
|
|
11
|
+
export function createAnchorGroupBlock<
|
|
12
|
+
TColumnsOptions extends OptionArray = typeof ANCHOR_COLUMNS,
|
|
13
|
+
TAlignments extends OptionArray = typeof ANCHOR_ALIGNMENTS,
|
|
14
|
+
>(
|
|
15
|
+
options: AnchorGroupOptions<TColumnsOptions, TAlignments>,
|
|
16
|
+
): BlockConfiguration<AnchorGroupAttributes<TColumnsOptions[number]['value'], TAlignments[number]['value']>> {
|
|
17
|
+
const columnsOptions = options.columnsOptions ?? ANCHOR_COLUMNS
|
|
18
|
+
const alignments = options.alignments ?? ANCHOR_ALIGNMENTS
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
name: options.name,
|
|
22
|
+
title: options.title ?? __('Kotvy', 'brilo-blocks'),
|
|
23
|
+
description: options.description,
|
|
24
|
+
category: options.category ?? 'layout',
|
|
25
|
+
...(options.parent && {parent: options.parent}),
|
|
26
|
+
icon: options.icon ?? 'anchor',
|
|
27
|
+
supports: {html: false, customClassName: false},
|
|
28
|
+
attributes: {
|
|
29
|
+
columns: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
default: columnsOptions[columnsOptions.length - 1].value,
|
|
32
|
+
enum: columnsOptions.map((c) => c.value),
|
|
33
|
+
},
|
|
34
|
+
align: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
default: alignments[0].value,
|
|
37
|
+
enum: alignments.map((a) => a.value),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
edit: createAnchorGroupEdit(options as unknown as AnchorGroupOptions),
|
|
41
|
+
save: () => <InnerBlocks.Content />,
|
|
42
|
+
} as unknown as BlockConfiguration<AnchorGroupAttributes<TColumnsOptions[number]['value'], TAlignments[number]['value']>>
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type {AnchorAlignment, AnchorColumns, AnchorGroupAttributes, AnchorGroupOptions} from './types'
|
|
2
|
+
export {createAnchorGroupBlock} from './factory'
|
|
3
|
+
export {ANCHOR_ALIGNMENTS, ANCHOR_COLUMNS} from './constants'
|
|
4
|
+
|
|
5
|
+
import type {AnchorGroupOptions} from './types'
|
|
6
|
+
|
|
7
|
+
export const anchorGroupDefaults: AnchorGroupOptions = {
|
|
8
|
+
name: 'brilo/anchor-group',
|
|
9
|
+
allowedBlocks: ['brilo/anchor-item'],
|
|
10
|
+
template: [['brilo/anchor-item', {}]],
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type {BriloBlockType, OptionArray} from '~/types'
|
|
2
|
+
import type {ANCHOR_ALIGNMENTS, ANCHOR_COLUMNS} from './constants'
|
|
3
|
+
|
|
4
|
+
export type AnchorColumns = (typeof ANCHOR_COLUMNS)[number]['value']
|
|
5
|
+
export type AnchorAlignment = (typeof ANCHOR_ALIGNMENTS)[number]['value']
|
|
6
|
+
|
|
7
|
+
export interface AnchorGroupAttributes<TColumns extends string = AnchorColumns, TAlignment extends string = AnchorAlignment>
|
|
8
|
+
extends Record<string, unknown> {
|
|
9
|
+
columns: TColumns
|
|
10
|
+
align: TAlignment
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AnchorGroupOptions<
|
|
14
|
+
TColumnsOptions extends OptionArray = typeof ANCHOR_COLUMNS,
|
|
15
|
+
TAlignments extends OptionArray = typeof ANCHOR_ALIGNMENTS,
|
|
16
|
+
> extends BriloBlockType {
|
|
17
|
+
columnsOptions?: TColumnsOptions
|
|
18
|
+
alignments?: TAlignments
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {__} from '@wordpress/i18n'
|
|
2
|
+
|
|
3
|
+
export const ANCHOR_ICON_TYPES = [
|
|
4
|
+
{value: 'preselected', label: __('Předdefinovaná', 'brilo-blocks')},
|
|
5
|
+
{value: 'media', label: __('Médium', 'brilo-blocks')},
|
|
6
|
+
] as const
|
|
7
|
+
|
|
8
|
+
export const ANCHOR_ICON_SIZE_RANGE = {min: 8, max: 100} as const
|
|
9
|
+
|
|
10
|
+
export const ANCHOR_ICON_SIZE_DEFAULT = 32
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {ColorPalette, InspectorControls, RichText, useBlockProps} from '@wordpress/block-editor'
|
|
2
|
+
import {
|
|
3
|
+
BaseControl,
|
|
4
|
+
PanelBody,
|
|
5
|
+
RangeControl,
|
|
6
|
+
TextControl,
|
|
7
|
+
ToggleControl,
|
|
8
|
+
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
9
|
+
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
10
|
+
} from '@wordpress/components'
|
|
11
|
+
import {__} from '@wordpress/i18n'
|
|
12
|
+
import clsx from 'clsx'
|
|
13
|
+
import type {CSSProperties} from 'react'
|
|
14
|
+
import {ItemIconControl, ItemIconPreview} from '~/components/ItemIconControl'
|
|
15
|
+
import {useTenantColorPalette} from '~/hooks/useTenantColorPalette'
|
|
16
|
+
import {ANCHOR_ICON_SIZE_RANGE, ANCHOR_ICON_TYPES} from './constants'
|
|
17
|
+
import type {AnchorItemAttributes, AnchorItemOptions} from './types'
|
|
18
|
+
|
|
19
|
+
export function createAnchorItemEdit(options: AnchorItemOptions) {
|
|
20
|
+
return function Edit({
|
|
21
|
+
attributes,
|
|
22
|
+
setAttributes,
|
|
23
|
+
}: {
|
|
24
|
+
attributes: AnchorItemAttributes
|
|
25
|
+
setAttributes: (a: Partial<AnchorItemAttributes>) => void
|
|
26
|
+
}) {
|
|
27
|
+
const {title, url, icon, iconSize, iconColor, iconPosition} = attributes
|
|
28
|
+
const {paletteColors} = useTenantColorPalette()
|
|
29
|
+
const hasIcon = icon.src || icon.media?.id
|
|
30
|
+
|
|
31
|
+
const blockProps = useBlockProps({className: clsx(options.blockClassName ?? 'i-anchor')})
|
|
32
|
+
const iconPreviewStyle = {
|
|
33
|
+
maxWidth: iconSize,
|
|
34
|
+
flex: `0 0 ${iconSize}px`,
|
|
35
|
+
'--icon-color': iconColor || undefined,
|
|
36
|
+
} as CSSProperties
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<InspectorControls>
|
|
41
|
+
<PanelBody title={__('Odkaz', 'brilo-blocks')}>
|
|
42
|
+
<TextControl label={__('Titulek', 'brilo-blocks')} value={title} onChange={(v) => setAttributes({title: v})} />
|
|
43
|
+
<TextControl label={__('URL', 'brilo-blocks')} value={url.src} onChange={(v) => setAttributes({url: {...url, src: v}})} />
|
|
44
|
+
<ToggleControl
|
|
45
|
+
label={__('Otevřít v nové záložce', 'brilo-blocks')}
|
|
46
|
+
checked={url.blank}
|
|
47
|
+
onChange={(v) => setAttributes({url: {...url, blank: v}})}
|
|
48
|
+
/>
|
|
49
|
+
</PanelBody>
|
|
50
|
+
<PanelBody title={__('Ikona', 'brilo-blocks')}>
|
|
51
|
+
<ItemIconControl icon={icon} setAttributes={setAttributes} iconTypes={ANCHOR_ICON_TYPES} options={options} />
|
|
52
|
+
<RangeControl
|
|
53
|
+
label={__('Velikost ikony (px)', 'brilo-blocks')}
|
|
54
|
+
value={iconSize}
|
|
55
|
+
onChange={(v) => setAttributes({iconSize: v ?? ANCHOR_ICON_SIZE_RANGE.min})}
|
|
56
|
+
min={ANCHOR_ICON_SIZE_RANGE.min}
|
|
57
|
+
max={ANCHOR_ICON_SIZE_RANGE.max}
|
|
58
|
+
/>
|
|
59
|
+
<BaseControl label={__('Barva ikony', 'brilo-blocks')} id="anchor-item-icon-color">
|
|
60
|
+
<ColorPalette colors={paletteColors} value={iconColor || undefined} onChange={(v) => setAttributes({iconColor: v ?? ''})} />
|
|
61
|
+
</BaseControl>
|
|
62
|
+
<ToggleGroupControl
|
|
63
|
+
isBlock
|
|
64
|
+
label={__('Pozice ikony', 'brilo-blocks')}
|
|
65
|
+
value={iconPosition}
|
|
66
|
+
onChange={(v) => setAttributes({iconPosition: v as 'before' | 'after'})}
|
|
67
|
+
>
|
|
68
|
+
<ToggleGroupControlOption value="before" label={__('Před textem', 'brilo-blocks')} />
|
|
69
|
+
<ToggleGroupControlOption value="after" label={__('Za textem', 'brilo-blocks')} />
|
|
70
|
+
</ToggleGroupControl>
|
|
71
|
+
</PanelBody>
|
|
72
|
+
</InspectorControls>
|
|
73
|
+
<div {...blockProps}>
|
|
74
|
+
{hasIcon && iconPosition === 'before' && (
|
|
75
|
+
<span className="i-anchor__icon" style={iconPreviewStyle}>
|
|
76
|
+
<ItemIconPreview icon={icon} setAttributes={setAttributes} options={options} />
|
|
77
|
+
</span>
|
|
78
|
+
)}
|
|
79
|
+
<RichText
|
|
80
|
+
tagName="span"
|
|
81
|
+
className="i-anchor__title"
|
|
82
|
+
value={title}
|
|
83
|
+
onChange={(v) => setAttributes({title: v})}
|
|
84
|
+
placeholder={__('Titulek kotvy...', 'brilo-blocks')}
|
|
85
|
+
allowedFormats={[]}
|
|
86
|
+
/>
|
|
87
|
+
{hasIcon && iconPosition === 'after' && (
|
|
88
|
+
<span className="i-anchor__icon" style={iconPreviewStyle}>
|
|
89
|
+
<ItemIconPreview icon={icon} setAttributes={setAttributes} options={options} />
|
|
90
|
+
</span>
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
</>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@layer base {
|
|
2
|
+
.i-anchor {
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 8px;
|
|
6
|
+
border: 1px solid #eee;
|
|
7
|
+
padding: 8px 12px;
|
|
8
|
+
width: 100%;
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
|
|
11
|
+
.i-anchor__icon {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
flex-shrink: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.i-anchor__title {
|
|
19
|
+
flex: 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
2
|
+
import {__} from '@wordpress/i18n'
|
|
3
|
+
import {ANCHOR_ICON_SIZE_DEFAULT} from './constants'
|
|
4
|
+
import {createAnchorItemEdit} from './edit'
|
|
5
|
+
import type {AnchorItemAttributes, AnchorItemOptions} from './types'
|
|
6
|
+
|
|
7
|
+
export type {AnchorItemAttributes, AnchorItemOptions}
|
|
8
|
+
|
|
9
|
+
export function createAnchorItemBlock(options: AnchorItemOptions): BlockConfiguration<AnchorItemAttributes> {
|
|
10
|
+
return {
|
|
11
|
+
name: options.name,
|
|
12
|
+
title: options.title ?? __('Kotva', 'brilo-blocks'),
|
|
13
|
+
description: options.description,
|
|
14
|
+
category: options.category ?? 'text',
|
|
15
|
+
...(options.parent && {parent: options.parent}),
|
|
16
|
+
icon: options.icon ?? 'admin-links',
|
|
17
|
+
supports: {html: false, customClassName: false},
|
|
18
|
+
attributes: {
|
|
19
|
+
title: {type: 'string', default: ''},
|
|
20
|
+
url: {type: 'object', default: {src: '', blank: false}},
|
|
21
|
+
icon: {type: 'object', default: {type: 'preselected', src: '', media: {}}},
|
|
22
|
+
iconSize: {type: 'number', default: ANCHOR_ICON_SIZE_DEFAULT},
|
|
23
|
+
iconColor: {type: 'string', default: ''},
|
|
24
|
+
iconPosition: {type: 'string', default: 'before', enum: ['before', 'after']},
|
|
25
|
+
},
|
|
26
|
+
edit: createAnchorItemEdit(options),
|
|
27
|
+
save: () => null,
|
|
28
|
+
} as BlockConfiguration<AnchorItemAttributes>
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type {AnchorItemAttributes, AnchorItemOptions} from './types'
|
|
2
|
+
export {createAnchorItemBlock} from './factory'
|
|
3
|
+
export {createAnchorItemEdit} from './edit'
|
|
4
|
+
export {ANCHOR_ICON_SIZE_DEFAULT, ANCHOR_ICON_SIZE_RANGE, ANCHOR_ICON_TYPES} from './constants'
|
|
5
|
+
|
|
6
|
+
import type {AnchorItemOptions} from './types'
|
|
7
|
+
|
|
8
|
+
export const anchorItemDefaults: AnchorItemOptions = {
|
|
9
|
+
name: 'brilo/anchor-item',
|
|
10
|
+
parent: ['brilo/anchor-group'],
|
|
11
|
+
icons: [],
|
|
12
|
+
iconsSrc: '',
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type {BriloBlockType, Icon} from '~/types'
|
|
2
|
+
import type {IconType} from '~/components/IconControl'
|
|
3
|
+
|
|
4
|
+
export interface AnchorItemAttributes extends Record<string, unknown> {
|
|
5
|
+
title: string
|
|
6
|
+
url: {src: string; blank: boolean}
|
|
7
|
+
icon: Icon
|
|
8
|
+
iconSize: number
|
|
9
|
+
iconColor: string
|
|
10
|
+
iconPosition: 'before' | 'after'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AnchorItemOptions extends BriloBlockType {
|
|
14
|
+
icons: IconType[]
|
|
15
|
+
iconsSrc: string
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ASIDE_DEFAULTS = {}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
3
|
+
import type {AsideAttributes, AsideOptions} from './types'
|
|
4
|
+
|
|
5
|
+
export function createAsideEdit(options: AsideOptions) {
|
|
6
|
+
return function Edit() {
|
|
7
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
8
|
+
blockClassName: 'l-content-w-aside__aside',
|
|
9
|
+
containerClassName: 'l-content-w-aside__aside-container',
|
|
10
|
+
layout: {type: 'default'},
|
|
11
|
+
orientation: 'vertical',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<aside {...blockProps}>
|
|
16
|
+
<div {...innerBlocksProps} />
|
|
17
|
+
</aside>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {InnerBlocks} from '@wordpress/block-editor'
|
|
2
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import {createAsideEdit} from './edit'
|
|
6
|
+
import {icon as defaultIcon} from './icon'
|
|
7
|
+
import type {AsideAttributes, AsideOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export function createAsideBlock(
|
|
10
|
+
options: AsideOptions,
|
|
11
|
+
): BlockConfiguration<AsideAttributes> {
|
|
12
|
+
return {
|
|
13
|
+
name: options.name,
|
|
14
|
+
title: options.title ?? __('Postranní panel', 'brilo-blocks'),
|
|
15
|
+
description: options.description,
|
|
16
|
+
category: options.category ?? 'layout',
|
|
17
|
+
parent: options.parent,
|
|
18
|
+
icon: options.icon ?? {src: defaultIcon},
|
|
19
|
+
supports: {html: false, customClassName: false},
|
|
20
|
+
attributes: {},
|
|
21
|
+
edit: createAsideEdit(options),
|
|
22
|
+
save: () => <InnerBlocks.Content />,
|
|
23
|
+
} as BlockConfiguration<AsideAttributes>
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
export const icon = (
|
|
4
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
5
|
+
<path
|
|
6
|
+
fillRule="evenodd"
|
|
7
|
+
clipRule="evenodd"
|
|
8
|
+
d="M8 4H20V20H8V4ZM10 6H18V18H10V6Z"
|
|
9
|
+
fill="currentColor"
|
|
10
|
+
/>
|
|
11
|
+
</svg>
|
|
12
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type {AsideAttributes, AsideOptions} from './types'
|
|
2
|
+
export {createAsideBlock} from './factory'
|
|
3
|
+
|
|
4
|
+
import type {AsideOptions} from './types'
|
|
5
|
+
|
|
6
|
+
export const asideDefaults: AsideOptions = {
|
|
7
|
+
name: 'brilo/layout-aside',
|
|
8
|
+
parent: ['brilo/layout-content-w-aside'],
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CONTENT_DEFAULTS = {}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
3
|
+
import type {ContentAttributes, ContentOptions} from './types'
|
|
4
|
+
|
|
5
|
+
export function createContentEdit(options: ContentOptions) {
|
|
6
|
+
return function Edit() {
|
|
7
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
8
|
+
blockClassName: 'l-content-w-aside__content',
|
|
9
|
+
containerClassName: 'l-content-w-aside__content-container',
|
|
10
|
+
layout: {type: 'default'},
|
|
11
|
+
orientation: 'vertical',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div {...blockProps}>
|
|
16
|
+
<div {...innerBlocksProps} />
|
|
17
|
+
</div>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {InnerBlocks} from '@wordpress/block-editor'
|
|
2
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import {createContentEdit} from './edit'
|
|
6
|
+
import {icon as defaultIcon} from './icon'
|
|
7
|
+
import type {ContentAttributes, ContentOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export function createContentBlock(
|
|
10
|
+
options: ContentOptions,
|
|
11
|
+
): BlockConfiguration<ContentAttributes> {
|
|
12
|
+
return {
|
|
13
|
+
name: options.name,
|
|
14
|
+
title: options.title ?? __('Obsah', 'brilo-blocks'),
|
|
15
|
+
description: options.description,
|
|
16
|
+
category: options.category ?? 'layout',
|
|
17
|
+
parent: options.parent,
|
|
18
|
+
icon: options.icon ?? {src: defaultIcon},
|
|
19
|
+
supports: {html: false, customClassName: false},
|
|
20
|
+
attributes: {},
|
|
21
|
+
edit: createContentEdit(options),
|
|
22
|
+
save: () => <InnerBlocks.Content />,
|
|
23
|
+
} as BlockConfiguration<ContentAttributes>
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
export const icon = (
|
|
4
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
5
|
+
<path
|
|
6
|
+
fillRule="evenodd"
|
|
7
|
+
clipRule="evenodd"
|
|
8
|
+
d="M4 4H16V20H4V4ZM6 6H14V18H6V6Z"
|
|
9
|
+
fill="currentColor"
|
|
10
|
+
/>
|
|
11
|
+
</svg>
|
|
12
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type {ContentAttributes, ContentOptions} from './types'
|
|
2
|
+
export {createContentBlock} from './factory'
|
|
3
|
+
|
|
4
|
+
import type {ContentOptions} from './types'
|
|
5
|
+
|
|
6
|
+
export const contentDefaults: ContentOptions = {
|
|
7
|
+
name: 'brilo/layout-content',
|
|
8
|
+
parent: ['brilo/layout-content-w-aside'],
|
|
9
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {InspectorControls} from '@wordpress/block-editor'
|
|
2
|
+
import {PanelBody, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption} from '@wordpress/components'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
6
|
+
import {ASIDE_SIZES} from './constants'
|
|
7
|
+
import type {AsideSize, ContentWithAsideAttributes, ContentWithAsideOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export function createContentWithAsideEdit(options: ContentWithAsideOptions) {
|
|
10
|
+
const ASIDE_SIZES_OPTIONS = options.asideSizes ?? ASIDE_SIZES
|
|
11
|
+
|
|
12
|
+
return function Edit({
|
|
13
|
+
attributes,
|
|
14
|
+
setAttributes,
|
|
15
|
+
}: {
|
|
16
|
+
attributes: ContentWithAsideAttributes
|
|
17
|
+
setAttributes: (a: Partial<ContentWithAsideAttributes>) => void
|
|
18
|
+
}) {
|
|
19
|
+
const {asideSize} = attributes
|
|
20
|
+
|
|
21
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
22
|
+
blockClassName: 'l-content-w-aside',
|
|
23
|
+
containerClassName: `l-content-w-aside__container --aside-${asideSize}`,
|
|
24
|
+
template: options.template,
|
|
25
|
+
allowedBlocks: options.allowedBlocks,
|
|
26
|
+
orientation: 'horizontal',
|
|
27
|
+
layout: {type: 'default'},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
<InspectorControls>
|
|
33
|
+
<PanelBody title={__('Nastavení', 'brilo-blocks')}>
|
|
34
|
+
<ToggleGroupControl
|
|
35
|
+
isBlock
|
|
36
|
+
label={__('Velikost postranního panelu', 'brilo-blocks')}
|
|
37
|
+
value={asideSize}
|
|
38
|
+
onChange={(v) => setAttributes({asideSize: v as AsideSize})}
|
|
39
|
+
>
|
|
40
|
+
{ASIDE_SIZES_OPTIONS.map((s) => (
|
|
41
|
+
<ToggleGroupControlOption key={s.value} value={s.value} label={s.label} />
|
|
42
|
+
))}
|
|
43
|
+
</ToggleGroupControl>
|
|
44
|
+
</PanelBody>
|
|
45
|
+
</InspectorControls>
|
|
46
|
+
<div {...blockProps}>
|
|
47
|
+
<div {...innerBlocksProps} />
|
|
48
|
+
</div>
|
|
49
|
+
</>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
}
|