@brilo/base-blocks 0.1.23 → 0.1.25
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/link/link-item/edit.d.ts.map +1 -1
- package/build/blocks/link/link-item/edit.js +1 -1
- package/build/blocks/link/link-item/factory.js +1 -1
- package/build/blocks/link/link-item/types.d.ts +1 -0
- package/build/blocks/link/link-item/types.d.ts.map +1 -1
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -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/link/link-item/edit.tsx +6 -0
- package/src/blocks/link/link-item/factory.tsx +1 -1
- package/src/blocks/link/link-item/types.ts +1 -0
- package/src/editor.scss +2 -0
- package/src/index.ts +11 -0
|
@@ -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
|
+
}
|
|
@@ -75,6 +75,12 @@ export function createLinkItemEdit(options: LinkItemOptions) {
|
|
|
75
75
|
max={80}
|
|
76
76
|
step={1}
|
|
77
77
|
/>
|
|
78
|
+
<p>{__('Barva ikony', 'brilo-blocks')}</p>
|
|
79
|
+
<ColorPalette
|
|
80
|
+
colors={paletteColors}
|
|
81
|
+
value={icon.color || undefined}
|
|
82
|
+
onChange={(v) => setAttributes({icon: {...icon, color: v ?? ''}})}
|
|
83
|
+
/>
|
|
78
84
|
</>
|
|
79
85
|
)}
|
|
80
86
|
</PanelBody>
|
|
@@ -18,7 +18,7 @@ export function createLinkItemBlock(options: LinkItemOptions): BlockConfiguratio
|
|
|
18
18
|
url: {type: 'object', default: {src: '', blank: false}},
|
|
19
19
|
icon: {
|
|
20
20
|
type: 'object',
|
|
21
|
-
default: {type: 'none', src: '', media: {}, position: 'after', size: 24},
|
|
21
|
+
default: {type: 'none', src: '', media: {}, position: 'after', size: 24, color: ''},
|
|
22
22
|
},
|
|
23
23
|
color: {type: 'string', default: ''},
|
|
24
24
|
size: {type: 'number', default: 16},
|
package/src/editor.scss
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
export type {AnchorAlignment, AnchorColumns, AnchorGroupAttributes, AnchorGroupOptions} from './blocks/anchor/anchor-group'
|
|
2
|
+
export {ANCHOR_ALIGNMENTS, ANCHOR_COLUMNS, anchorGroupDefaults, createAnchorGroupBlock} from './blocks/anchor/anchor-group'
|
|
3
|
+
export type {AnchorItemAttributes, AnchorItemOptions} from './blocks/anchor/anchor-item'
|
|
4
|
+
export {
|
|
5
|
+
ANCHOR_ICON_SIZE_DEFAULT,
|
|
6
|
+
ANCHOR_ICON_SIZE_RANGE,
|
|
7
|
+
ANCHOR_ICON_TYPES,
|
|
8
|
+
anchorItemDefaults,
|
|
9
|
+
createAnchorItemBlock,
|
|
10
|
+
createAnchorItemEdit,
|
|
11
|
+
} from './blocks/anchor/anchor-item'
|
|
1
12
|
export type {
|
|
2
13
|
ContactColumns,
|
|
3
14
|
ContactGroupAttributes,
|