@brilo/base-blocks 0.1.23 → 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/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/editor.scss +2 -0
- package/src/index.ts +11 -0
|
@@ -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
|
+
}
|
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,
|