@brilo/base-blocks 0.1.16 → 0.1.18
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/signpost/signpost-item/index.js +1 -1
- package/build/blocks/usp/usp-group/constants.d.ts +48 -35
- package/build/blocks/usp/usp-group/constants.d.ts.map +1 -1
- package/build/blocks/usp/usp-group/constants.js +27 -17
- package/build/blocks/usp/usp-group/edit.d.ts.map +1 -1
- package/build/blocks/usp/usp-group/edit.js +10 -7
- package/build/blocks/usp/usp-group/factory.d.ts +2 -2
- package/build/blocks/usp/usp-group/factory.d.ts.map +1 -1
- package/build/blocks/usp/usp-group/factory.js +27 -19
- package/build/blocks/usp/usp-group/types.d.ts +19 -13
- package/build/blocks/usp/usp-group/types.d.ts.map +1 -1
- package/build/blocks/usp/usp-item/buildPreviewStyle.d.ts +25 -0
- package/build/blocks/usp/usp-item/buildPreviewStyle.d.ts.map +1 -0
- package/build/blocks/usp/usp-item/buildPreviewStyle.js +30 -0
- package/build/blocks/usp/usp-item/edit.d.ts +5 -1
- package/build/blocks/usp/usp-item/edit.d.ts.map +1 -1
- package/build/blocks/usp/usp-item/edit.js +7 -3
- package/build/blocks/usp/usp-item/factory.d.ts.map +1 -1
- package/build/blocks/usp/usp-item/factory.js +1 -0
- package/build/components/ItemIconControl/ItemIconPreview.d.ts +1 -1
- package/build/components/ItemIconControl/ItemIconPreview.d.ts.map +1 -1
- package/build/components/ItemIconControl/ItemIconPreview.js +4 -4
- package/package.json +1 -1
- package/src/blocks/groups/text-and-media-group/editor.scss +14 -0
- package/src/blocks/signpost/signpost-item/index.ts +1 -1
- package/src/blocks/usp/usp-group/constants.ts +29 -17
- package/src/blocks/usp/usp-group/edit.tsx +109 -34
- package/src/blocks/usp/usp-group/factory.tsx +19 -27
- package/src/blocks/usp/usp-group/types.ts +22 -16
- package/src/blocks/usp/usp-item/buildPreviewStyle.ts +66 -0
- package/src/blocks/usp/usp-item/edit.tsx +15 -2
- package/src/blocks/usp/usp-item/editor.scss +140 -1
- package/src/blocks/usp/usp-item/factory.tsx +1 -0
- package/src/components/ItemIconControl/ItemIconPreview.tsx +4 -4
- package/src/components/ItemIconControl/types.d.ts +2 -0
|
@@ -3,7 +3,7 @@ import clsx from 'clsx';
|
|
|
3
3
|
import { useState } from '@wordpress/element';
|
|
4
4
|
import { useMediaUrl } from '../../components/ImagePicker';
|
|
5
5
|
import { ItemIconModal } from './ItemIconModal';
|
|
6
|
-
export function ItemIconPreview({ icon, className, options, setAttributes }) {
|
|
6
|
+
export function ItemIconPreview({ icon, className, modifierClassName, style, options, setAttributes }) {
|
|
7
7
|
var _a;
|
|
8
8
|
var _b;
|
|
9
9
|
const [isModalOpen, setModalOpen] = useState(false);
|
|
@@ -13,19 +13,19 @@ export function ItemIconPreview({ icon, className, options, setAttributes }) {
|
|
|
13
13
|
var _a;
|
|
14
14
|
if (icon.type === 'preselected') {
|
|
15
15
|
if (preselectedIconUrl) {
|
|
16
|
-
return (_jsx("div", { className: clsx('i-item-icon', className), children: _jsx("img", { src: preselectedIconUrl, alt: "", className: clsx(className ? `${className}-img` : 'i-item-icon__img'), width: 40, height: 40 }) }));
|
|
16
|
+
return (_jsx("div", { className: clsx('i-item-icon', className, modifierClassName), style: style, children: _jsx("img", { src: preselectedIconUrl, alt: "", className: clsx(className ? `${className}-img` : 'i-item-icon__img'), width: 40, height: 40 }) }));
|
|
17
17
|
}
|
|
18
18
|
return (_jsx("button", { type: "button", className: clsx('i-item-icon', className ? `${className}-placeholder` : null, 'i-item-icon__placeholder', !isModalOpen && '--clickable'), onClick: () => setModalOpen(true), children: _jsx("span", { children: "\u2606" }) }));
|
|
19
19
|
}
|
|
20
20
|
if (icon.type === 'media') {
|
|
21
21
|
if (((_a = icon.media) === null || _a === void 0 ? void 0 : _a.id) && mediaIconUrl) {
|
|
22
|
-
return (_jsx("div", { className: clsx('i-item-icon', className), children: _jsx("img", { src: mediaIconUrl, alt: icon.media.alt, className: clsx(className ? `${className}-img` : null, 'i-item-icon__img') }) }));
|
|
22
|
+
return (_jsx("div", { className: clsx('i-item-icon', className, modifierClassName), style: style, children: _jsx("img", { src: mediaIconUrl, alt: icon.media.alt, className: clsx(className ? `${className}-img` : null, 'i-item-icon__img') }) }));
|
|
23
23
|
}
|
|
24
24
|
return (_jsx("div", { className: clsx('i-item-icon', className ? `${className}-placeholder` : 'i-item-icon__placeholder'), children: _jsx("span", { children: "\u2606" }) }));
|
|
25
25
|
}
|
|
26
26
|
if (icon.type === 'number') {
|
|
27
27
|
if (icon.src) {
|
|
28
|
-
return (_jsx("div", { className: clsx('i-item-icon', className), children: _jsx("span", { className: clsx(className ? `${className}-number` : 'i-item-icon__number'), children: icon.src }) }));
|
|
28
|
+
return (_jsx("div", { className: clsx('i-item-icon', className, modifierClassName), style: style, children: _jsx("span", { className: clsx(className ? `${className}-number` : 'i-item-icon__number'), children: icon.src }) }));
|
|
29
29
|
}
|
|
30
30
|
return (_jsx("div", { className: clsx('i-item-icon', className ? `${className}-placeholder` : 'i-item-icon__placeholder'), children: _jsx("span", { children: "\u2606" }) }));
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -82,6 +82,12 @@
|
|
|
82
82
|
.g-text-and-media__inner-blocks {
|
|
83
83
|
margin-top: 8px;
|
|
84
84
|
min-height: 40px;
|
|
85
|
+
|
|
86
|
+
p,
|
|
87
|
+
ul,
|
|
88
|
+
ol {
|
|
89
|
+
margin-block: 8px;
|
|
90
|
+
}
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
.g-text-and-media__chip {
|
|
@@ -121,3 +127,11 @@
|
|
|
121
127
|
}
|
|
122
128
|
}
|
|
123
129
|
}
|
|
130
|
+
|
|
131
|
+
.g-text-and-media__inner-blocks {
|
|
132
|
+
p,
|
|
133
|
+
ul,
|
|
134
|
+
ol {
|
|
135
|
+
margin-block: 8px;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -6,5 +6,5 @@ import type {SignpostItemOptions} from './types'
|
|
|
6
6
|
export const signpostItemDefaults: SignpostItemOptions = {
|
|
7
7
|
name: 'brilo/signpost-item',
|
|
8
8
|
parent: ['brilo/signpost-group'],
|
|
9
|
-
allowedBlocks: ['core/paragraph', 'core/list', 'core/
|
|
9
|
+
allowedBlocks: ['core/heading', 'core/paragraph', 'core/list', 'core/group', 'brilo/link-item'],
|
|
10
10
|
}
|
|
@@ -25,27 +25,39 @@ export const DEFAULT_SHADOWS = [
|
|
|
25
25
|
{value: 'md', label: __('Střední', 'brilo-blocks')},
|
|
26
26
|
] as const
|
|
27
27
|
|
|
28
|
-
export const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{value:
|
|
28
|
+
export const DEFAULT_ICON_SIZE = 88
|
|
29
|
+
export const ICON_SIZE_MIN = 4
|
|
30
|
+
export const ICON_SIZE_MAX = 128
|
|
31
|
+
|
|
32
|
+
export const DEFAULT_ICON_SIZE_PRESETS = [
|
|
33
|
+
{value: 8, label: __('XS', 'brilo-blocks')},
|
|
34
|
+
{value: 16, label: __('SM', 'brilo-blocks')},
|
|
35
|
+
{value: 24, label: __('MD', 'brilo-blocks')},
|
|
36
|
+
{value: 32, label: __('LG', 'brilo-blocks')},
|
|
37
|
+
{value: 48, label: __('XL', 'brilo-blocks')},
|
|
34
38
|
] as const
|
|
35
39
|
|
|
36
|
-
export const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
{value:
|
|
40
|
+
export const DEFAULT_ICON_BACKGROUND_SIZE = 88
|
|
41
|
+
export const ICON_BACKGROUND_SIZE_MIN = 16
|
|
42
|
+
export const ICON_BACKGROUND_SIZE_MAX = 240
|
|
43
|
+
|
|
44
|
+
export const DEFAULT_ICON_BACKGROUND_SIZE_PRESETS = [
|
|
45
|
+
{value: 48, label: __('XS', 'brilo-blocks')},
|
|
46
|
+
{value: 64, label: __('SM', 'brilo-blocks')},
|
|
47
|
+
{value: 88, label: __('Výchozí', 'brilo-blocks')},
|
|
48
|
+
{value: 104, label: __('LG', 'brilo-blocks')},
|
|
49
|
+
{value: 128, label: __('XL', 'brilo-blocks')},
|
|
42
50
|
] as const
|
|
43
51
|
|
|
44
|
-
export const
|
|
45
|
-
{value: 'none', label: __('
|
|
46
|
-
{value: '
|
|
47
|
-
{value: '
|
|
48
|
-
{value: '
|
|
52
|
+
export const DEFAULT_ICON_BACKGROUND_SHAPES = [
|
|
53
|
+
{value: 'none', label: __('Žádný', 'brilo-blocks')},
|
|
54
|
+
{value: 'circle', label: __('Kruh', 'brilo-blocks')},
|
|
55
|
+
{value: 'triangle', label: __('Trojúhelník', 'brilo-blocks')},
|
|
56
|
+
{value: 'rhombus', label: __('Kosočtverec', 'brilo-blocks')},
|
|
57
|
+
{value: 'octagon', label: __('Osmiúhelník', 'brilo-blocks')},
|
|
58
|
+
{value: 'bevel', label: __('Zkosený', 'brilo-blocks')},
|
|
59
|
+
{value: 'rabbet', label: __('Drážkovaný', 'brilo-blocks')},
|
|
60
|
+
{value: 'parallelogram', label: __('Rovnoběžník', 'brilo-blocks')},
|
|
49
61
|
] as const
|
|
50
62
|
|
|
51
63
|
export const DEFAULT_ALIGNMENTS = [
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {InspectorControls} from '@wordpress/block-editor'
|
|
2
2
|
import {
|
|
3
3
|
PanelBody,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
Button,
|
|
5
|
+
RangeControl,
|
|
6
6
|
BaseControl,
|
|
7
7
|
ColorPalette,
|
|
8
|
+
SelectControl,
|
|
8
9
|
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
9
10
|
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
10
11
|
} from '@wordpress/components'
|
|
@@ -18,11 +19,15 @@ import {
|
|
|
18
19
|
DEFAULT_CONTENT_SIZES,
|
|
19
20
|
DEFAULT_DIRECTIONS,
|
|
20
21
|
DEFAULT_HEADING_STYLES,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
DEFAULT_ICON_BACKGROUND_SHAPES,
|
|
23
|
+
DEFAULT_ICON_BACKGROUND_SIZE_PRESETS,
|
|
24
|
+
DEFAULT_ICON_SIZE_PRESETS,
|
|
24
25
|
DEFAULT_SHADOWS,
|
|
25
26
|
HEADING_LEVELS,
|
|
27
|
+
ICON_BACKGROUND_SIZE_MAX,
|
|
28
|
+
ICON_BACKGROUND_SIZE_MIN,
|
|
29
|
+
ICON_SIZE_MAX,
|
|
30
|
+
ICON_SIZE_MIN,
|
|
26
31
|
} from './constants'
|
|
27
32
|
import type {
|
|
28
33
|
UspAlignment,
|
|
@@ -32,20 +37,48 @@ import type {
|
|
|
32
37
|
UspGroupOptions,
|
|
33
38
|
UspHeadingLevel,
|
|
34
39
|
UspHeadingStyle,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
UspIconSize,
|
|
40
|
+
UspIconBackgroundShape,
|
|
41
|
+
UspSizePreset,
|
|
38
42
|
UspShadow,
|
|
39
43
|
} from './types'
|
|
40
44
|
|
|
45
|
+
function PresetSizeControl({
|
|
46
|
+
label,
|
|
47
|
+
value,
|
|
48
|
+
presets,
|
|
49
|
+
min,
|
|
50
|
+
max,
|
|
51
|
+
onChange,
|
|
52
|
+
}: {
|
|
53
|
+
label: string
|
|
54
|
+
value: number
|
|
55
|
+
presets: readonly UspSizePreset[]
|
|
56
|
+
min: number
|
|
57
|
+
max: number
|
|
58
|
+
onChange: (v: number) => void
|
|
59
|
+
}) {
|
|
60
|
+
return (
|
|
61
|
+
<BaseControl label={label} id={`usp-group-size-${label}`}>
|
|
62
|
+
<div style={{display: 'flex', gap: 4, marginBottom: 8, flexWrap: 'wrap'}}>
|
|
63
|
+
{presets.map((p) => (
|
|
64
|
+
<Button key={p.label} variant={value === p.value ? 'primary' : 'secondary'} size="small" onClick={() => onChange(p.value)}>
|
|
65
|
+
{p.label}
|
|
66
|
+
</Button>
|
|
67
|
+
))}
|
|
68
|
+
</div>
|
|
69
|
+
<RangeControl value={value} onChange={(v) => onChange(v ?? min)} min={min} max={max} step={1} withInputField />
|
|
70
|
+
</BaseControl>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
41
74
|
export function createUspGroupEdit(options: UspGroupOptions) {
|
|
42
75
|
const COLUMNS = options.columns ?? DEFAULT_COLUMNS
|
|
43
76
|
const DIRECTIONS = options.directions ?? DEFAULT_DIRECTIONS
|
|
44
77
|
const HEADING_STYLES = options.headingStyles ?? DEFAULT_HEADING_STYLES
|
|
45
78
|
const SHADOWS = options.shadows ?? DEFAULT_SHADOWS
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
79
|
+
const ICON_SIZE_PRESETS = options.iconSizePresets ?? DEFAULT_ICON_SIZE_PRESETS
|
|
80
|
+
const ICON_BACKGROUND_SIZE_PRESETS = options.iconBackgroundSizePresets ?? DEFAULT_ICON_BACKGROUND_SIZE_PRESETS
|
|
81
|
+
const ICON_BACKGROUND_SHAPES = options.iconBackgroundShapes ?? DEFAULT_ICON_BACKGROUND_SHAPES
|
|
49
82
|
const ALIGNMENTS = options.alignments ?? DEFAULT_ALIGNMENTS
|
|
50
83
|
const CONTENT_SIZES = options.contentSizes ?? DEFAULT_CONTENT_SIZES
|
|
51
84
|
|
|
@@ -110,6 +143,18 @@ export function createUspGroupEdit(options: UspGroupOptions) {
|
|
|
110
143
|
))}
|
|
111
144
|
</ToggleGroupControl>
|
|
112
145
|
)}
|
|
146
|
+
{style.direction === 'vertical' && (
|
|
147
|
+
<ToggleGroupControl
|
|
148
|
+
isBlock
|
|
149
|
+
label={__('Zarovnání textu', 'brilo-blocks')}
|
|
150
|
+
value={style.textAlign}
|
|
151
|
+
onChange={(v) => setAttributes({style: {...style, textAlign: (v as string) ?? ''}})}
|
|
152
|
+
>
|
|
153
|
+
{ALIGNMENTS.map((a) => (
|
|
154
|
+
<ToggleGroupControlOption key={a.value} value={a.value} label={a.label} />
|
|
155
|
+
))}
|
|
156
|
+
</ToggleGroupControl>
|
|
157
|
+
)}
|
|
113
158
|
<ToggleGroupControl
|
|
114
159
|
isBlock
|
|
115
160
|
label={__('Úroveň nadpisu položek', 'brilo-blocks')}
|
|
@@ -180,33 +225,63 @@ export function createUspGroupEdit(options: UspGroupOptions) {
|
|
|
180
225
|
</BaseControl>
|
|
181
226
|
</PanelBody>
|
|
182
227
|
<PanelBody title={__('Ikona', 'brilo-blocks')} initialOpen={false}>
|
|
183
|
-
<
|
|
184
|
-
isBlock
|
|
228
|
+
<PresetSizeControl
|
|
185
229
|
label={__('Velikost', 'brilo-blocks')}
|
|
186
230
|
value={style.icon.size}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
{
|
|
190
|
-
|
|
191
|
-
))}
|
|
192
|
-
</ToggleGroupControl>
|
|
193
|
-
<SelectControl<string>
|
|
194
|
-
label={__('Barva', 'brilo-blocks')}
|
|
195
|
-
value={style.icon.color}
|
|
196
|
-
options={[...ICON_COLORS]}
|
|
197
|
-
onChange={(v) => setAttributes({style: {...style, icon: {...style.icon, color: v as UspIconColor}}})}
|
|
231
|
+
presets={ICON_SIZE_PRESETS}
|
|
232
|
+
min={ICON_SIZE_MIN}
|
|
233
|
+
max={ICON_SIZE_MAX}
|
|
234
|
+
onChange={(v) => setAttributes({style: {...style, icon: {...style.icon, size: v}}})}
|
|
198
235
|
/>
|
|
199
|
-
<
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
236
|
+
<BaseControl label={__('Barva', 'brilo-blocks')} id="usp-group-icon-color">
|
|
237
|
+
<ColorPalette
|
|
238
|
+
colors={paletteColors}
|
|
239
|
+
value={style.icon.color || undefined}
|
|
240
|
+
onChange={(value) => setAttributes({style: {...style, icon: {...style.icon, color: value ?? ''}}})}
|
|
241
|
+
/>
|
|
242
|
+
</BaseControl>
|
|
243
|
+
<BaseControl label={__('Pozadí', 'brilo-blocks')} id="usp-group-icon-background-color">
|
|
244
|
+
<ColorPalette
|
|
245
|
+
colors={paletteColors}
|
|
246
|
+
value={style.icon.background || undefined}
|
|
247
|
+
onChange={(value) => setAttributes({style: {...style, icon: {...style.icon, background: value ?? ''}}})}
|
|
248
|
+
/>
|
|
249
|
+
</BaseControl>
|
|
250
|
+
<PresetSizeControl
|
|
251
|
+
label={__('Velikost pozadí', 'brilo-blocks')}
|
|
252
|
+
value={style.icon.backgroundSize}
|
|
253
|
+
presets={ICON_BACKGROUND_SIZE_PRESETS}
|
|
254
|
+
min={ICON_BACKGROUND_SIZE_MIN}
|
|
255
|
+
max={ICON_BACKGROUND_SIZE_MAX}
|
|
256
|
+
onChange={(v) => setAttributes({style: {...style, icon: {...style.icon, backgroundSize: v}}})}
|
|
204
257
|
/>
|
|
205
|
-
{style.icon.background
|
|
206
|
-
<
|
|
207
|
-
label={__('
|
|
208
|
-
|
|
209
|
-
|
|
258
|
+
{style.icon.background && (
|
|
259
|
+
<SelectControl<string>
|
|
260
|
+
label={__('Tvar pozadí', 'brilo-blocks')}
|
|
261
|
+
value={style.icon.backgroundShape}
|
|
262
|
+
options={[...ICON_BACKGROUND_SHAPES]}
|
|
263
|
+
onChange={(v) => setAttributes({style: {...style, icon: {...style.icon, backgroundShape: v as UspIconBackgroundShape}}})}
|
|
264
|
+
/>
|
|
265
|
+
)}
|
|
266
|
+
<BaseControl
|
|
267
|
+
label={__('Barva ohraničení', 'brilo-blocks')}
|
|
268
|
+
help={__('Bez vybrané barvy se okraj nevykreslí.', 'brilo-blocks')}
|
|
269
|
+
id="usp-group-icon-border-color"
|
|
270
|
+
>
|
|
271
|
+
<ColorPalette
|
|
272
|
+
colors={paletteColors}
|
|
273
|
+
value={style.icon.borderColor || undefined}
|
|
274
|
+
onChange={(value) => setAttributes({style: {...style, icon: {...style.icon, borderColor: value ?? ''}}})}
|
|
275
|
+
/>
|
|
276
|
+
</BaseControl>
|
|
277
|
+
{style.icon.borderColor && (
|
|
278
|
+
<RangeControl
|
|
279
|
+
label={__('Šířka ohraničení (px)', 'brilo-blocks')}
|
|
280
|
+
value={style.icon.borderWidth}
|
|
281
|
+
onChange={(v) => setAttributes({style: {...style, icon: {...style.icon, borderWidth: v ?? 0}}})}
|
|
282
|
+
min={0}
|
|
283
|
+
max={10}
|
|
284
|
+
step={1}
|
|
210
285
|
/>
|
|
211
286
|
)}
|
|
212
287
|
</PanelBody>
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
DEFAULT_CONTENT_SIZES,
|
|
9
9
|
DEFAULT_DIRECTIONS,
|
|
10
10
|
DEFAULT_HEADING_STYLES,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
DEFAULT_ICON_BACKGROUND_SHAPES,
|
|
12
|
+
DEFAULT_ICON_BACKGROUND_SIZE,
|
|
13
|
+
DEFAULT_ICON_SIZE,
|
|
14
14
|
DEFAULT_SHADOWS,
|
|
15
15
|
HEADING_LEVELS,
|
|
16
16
|
} from './constants'
|
|
@@ -25,32 +25,18 @@ export function createUspGroupBlock<
|
|
|
25
25
|
TDirections extends OptionArray = typeof DEFAULT_DIRECTIONS,
|
|
26
26
|
THeadingStyles extends OptionArray = typeof DEFAULT_HEADING_STYLES,
|
|
27
27
|
TShadows extends OptionArray = typeof DEFAULT_SHADOWS,
|
|
28
|
-
|
|
29
|
-
TIconColors extends OptionArray = typeof DEFAULT_ICON_COLORS,
|
|
30
|
-
TIconBackgrounds extends OptionArray = typeof DEFAULT_ICON_BACKGROUNDS,
|
|
28
|
+
TIconBackgroundShapes extends OptionArray = typeof DEFAULT_ICON_BACKGROUND_SHAPES,
|
|
31
29
|
TAlignments extends OptionArray = typeof DEFAULT_ALIGNMENTS,
|
|
32
30
|
TContentSizes extends OptionArray = typeof DEFAULT_CONTENT_SIZES,
|
|
33
31
|
>(
|
|
34
|
-
options: UspGroupOptions<
|
|
35
|
-
TColumns,
|
|
36
|
-
TDirections,
|
|
37
|
-
THeadingStyles,
|
|
38
|
-
TShadows,
|
|
39
|
-
TIconSizes,
|
|
40
|
-
TIconColors,
|
|
41
|
-
TIconBackgrounds,
|
|
42
|
-
TAlignments,
|
|
43
|
-
TContentSizes
|
|
44
|
-
>,
|
|
32
|
+
options: UspGroupOptions<TColumns, TDirections, THeadingStyles, TShadows, TIconBackgroundShapes, TAlignments, TContentSizes>,
|
|
45
33
|
): BlockConfiguration<
|
|
46
34
|
UspGroupAttributes<
|
|
47
35
|
TColumns[number],
|
|
48
36
|
TDirections[number]['value'],
|
|
49
37
|
THeadingStyles[number]['value'],
|
|
50
38
|
TShadows[number]['value'],
|
|
51
|
-
|
|
52
|
-
TIconColors[number]['value'],
|
|
53
|
-
TIconBackgrounds[number]['value'],
|
|
39
|
+
TIconBackgroundShapes[number]['value'],
|
|
54
40
|
TAlignments[number]['value'],
|
|
55
41
|
TContentSizes[number]['value']
|
|
56
42
|
>
|
|
@@ -59,9 +45,7 @@ export function createUspGroupBlock<
|
|
|
59
45
|
const directions = options.directions ?? DEFAULT_DIRECTIONS
|
|
60
46
|
const headingStyles = options.headingStyles ?? DEFAULT_HEADING_STYLES
|
|
61
47
|
const shadows = options.shadows ?? DEFAULT_SHADOWS
|
|
62
|
-
const
|
|
63
|
-
const iconColors = options.iconColors ?? DEFAULT_ICON_COLORS
|
|
64
|
-
const iconBackgrounds = options.iconBackgrounds ?? DEFAULT_ICON_BACKGROUNDS
|
|
48
|
+
const iconBackgroundShapes = options.iconBackgroundShapes ?? DEFAULT_ICON_BACKGROUND_SHAPES
|
|
65
49
|
const alignments = options.alignments ?? DEFAULT_ALIGNMENTS
|
|
66
50
|
const contentSizes = options.contentSizes ?? DEFAULT_CONTENT_SIZES
|
|
67
51
|
|
|
@@ -73,6 +57,7 @@ export function createUspGroupBlock<
|
|
|
73
57
|
...(options.parent && {parent: options.parent}),
|
|
74
58
|
icon: options.icon ?? {src: defaultIcon},
|
|
75
59
|
supports: {html: false, customClassName: false},
|
|
60
|
+
providesContext: {'brilo/usp-style': 'style'},
|
|
76
61
|
attributes: {
|
|
77
62
|
columns: {
|
|
78
63
|
type: 'number',
|
|
@@ -91,10 +76,19 @@ export function createUspGroupBlock<
|
|
|
91
76
|
card: false,
|
|
92
77
|
direction: directions[0].value,
|
|
93
78
|
align: alignments[0].value,
|
|
79
|
+
textAlign: '',
|
|
94
80
|
borderColor: '',
|
|
95
81
|
backgroundColor: '',
|
|
96
82
|
textColor: '',
|
|
97
|
-
icon: {
|
|
83
|
+
icon: {
|
|
84
|
+
size: DEFAULT_ICON_SIZE,
|
|
85
|
+
color: '',
|
|
86
|
+
background: '',
|
|
87
|
+
backgroundSize: DEFAULT_ICON_BACKGROUND_SIZE,
|
|
88
|
+
backgroundShape: iconBackgroundShapes[0].value,
|
|
89
|
+
borderColor: '',
|
|
90
|
+
borderWidth: 1,
|
|
91
|
+
},
|
|
98
92
|
},
|
|
99
93
|
},
|
|
100
94
|
},
|
|
@@ -106,9 +100,7 @@ export function createUspGroupBlock<
|
|
|
106
100
|
TDirections[number]['value'],
|
|
107
101
|
THeadingStyles[number]['value'],
|
|
108
102
|
TShadows[number]['value'],
|
|
109
|
-
|
|
110
|
-
TIconColors[number]['value'],
|
|
111
|
-
TIconBackgrounds[number]['value'],
|
|
103
|
+
TIconBackgroundShapes[number]['value'],
|
|
112
104
|
TAlignments[number]['value'],
|
|
113
105
|
TContentSizes[number]['value']
|
|
114
106
|
>
|
|
@@ -5,9 +5,7 @@ import type {
|
|
|
5
5
|
DEFAULT_CONTENT_SIZES,
|
|
6
6
|
DEFAULT_DIRECTIONS,
|
|
7
7
|
DEFAULT_HEADING_STYLES,
|
|
8
|
-
|
|
9
|
-
DEFAULT_ICON_COLORS,
|
|
10
|
-
DEFAULT_ICON_SIZES,
|
|
8
|
+
DEFAULT_ICON_BACKGROUND_SHAPES,
|
|
11
9
|
DEFAULT_SHADOWS,
|
|
12
10
|
HEADING_LEVELS,
|
|
13
11
|
} from './constants'
|
|
@@ -18,19 +16,20 @@ export type UspHeadingLevel = (typeof HEADING_LEVELS)[number]
|
|
|
18
16
|
export type UspHeadingStyle = (typeof DEFAULT_HEADING_STYLES)[number]['value']
|
|
19
17
|
export type UspShadow = (typeof DEFAULT_SHADOWS)[number]['value']
|
|
20
18
|
export type UspAlignment = (typeof DEFAULT_ALIGNMENTS)[number]['value']
|
|
21
|
-
export type UspIconSize = (typeof DEFAULT_ICON_SIZES)[number]['value']
|
|
22
|
-
export type UspIconColor = (typeof DEFAULT_ICON_COLORS)[number]['value']
|
|
23
|
-
export type UspIconBackground = (typeof DEFAULT_ICON_BACKGROUNDS)[number]['value']
|
|
24
19
|
export type UspContentSize = (typeof DEFAULT_CONTENT_SIZES)[number]['value']
|
|
20
|
+
export type UspIconBackgroundShape = (typeof DEFAULT_ICON_BACKGROUND_SHAPES)[number]['value']
|
|
21
|
+
|
|
22
|
+
export interface UspSizePreset {
|
|
23
|
+
value: number
|
|
24
|
+
label: string
|
|
25
|
+
}
|
|
25
26
|
|
|
26
27
|
export interface UspGroupAttributes<
|
|
27
28
|
TColumn extends number = UspColumns,
|
|
28
29
|
TDirection extends string = UspDirection,
|
|
29
30
|
THeadingStyle extends string = UspHeadingStyle,
|
|
30
31
|
TShadow extends string = UspShadow,
|
|
31
|
-
|
|
32
|
-
TIconColor extends string = UspIconColor,
|
|
33
|
-
TIconBackground extends string = UspIconBackground,
|
|
32
|
+
TIconBackgroundShape extends string = UspIconBackgroundShape,
|
|
34
33
|
TAlignment extends string = UspAlignment,
|
|
35
34
|
TContentSize extends string = UspContentSize,
|
|
36
35
|
> extends Record<string, unknown> {
|
|
@@ -42,10 +41,19 @@ export interface UspGroupAttributes<
|
|
|
42
41
|
card: boolean
|
|
43
42
|
direction: TDirection
|
|
44
43
|
align: TAlignment
|
|
44
|
+
textAlign: string
|
|
45
45
|
borderColor: string
|
|
46
46
|
backgroundColor: string
|
|
47
47
|
textColor: string
|
|
48
|
-
icon: {
|
|
48
|
+
icon: {
|
|
49
|
+
size: number
|
|
50
|
+
color: string
|
|
51
|
+
background: string
|
|
52
|
+
backgroundSize: number
|
|
53
|
+
backgroundShape: TIconBackgroundShape
|
|
54
|
+
borderColor: string
|
|
55
|
+
borderWidth: number
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
|
|
@@ -54,9 +62,7 @@ export interface UspGroupOptions<
|
|
|
54
62
|
TDirections extends OptionArray = typeof DEFAULT_DIRECTIONS,
|
|
55
63
|
THeadingStyles extends OptionArray = typeof DEFAULT_HEADING_STYLES,
|
|
56
64
|
TShadows extends OptionArray = typeof DEFAULT_SHADOWS,
|
|
57
|
-
|
|
58
|
-
TIconColors extends OptionArray = typeof DEFAULT_ICON_COLORS,
|
|
59
|
-
TIconBackgrounds extends OptionArray = typeof DEFAULT_ICON_BACKGROUNDS,
|
|
65
|
+
TIconBackgroundShapes extends OptionArray = typeof DEFAULT_ICON_BACKGROUND_SHAPES,
|
|
60
66
|
TAlignments extends OptionArray = typeof DEFAULT_ALIGNMENTS,
|
|
61
67
|
TContentSizes extends OptionArray = typeof DEFAULT_CONTENT_SIZES,
|
|
62
68
|
> extends BriloBlockType {
|
|
@@ -65,9 +71,9 @@ export interface UspGroupOptions<
|
|
|
65
71
|
directions?: TDirections
|
|
66
72
|
headingStyles?: THeadingStyles
|
|
67
73
|
shadows?: TShadows
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
iconSizePresets?: readonly UspSizePreset[]
|
|
75
|
+
iconBackgroundSizePresets?: readonly UspSizePreset[]
|
|
76
|
+
iconBackgroundShapes?: TIconBackgroundShapes
|
|
71
77
|
alignments?: TAlignments
|
|
72
78
|
contentSizes?: TContentSizes
|
|
73
79
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import clsx from 'clsx'
|
|
2
|
+
|
|
3
|
+
export interface UspSharedStyle {
|
|
4
|
+
direction?: string
|
|
5
|
+
align?: string
|
|
6
|
+
textAlign?: string
|
|
7
|
+
shadow?: string
|
|
8
|
+
borderColor?: string
|
|
9
|
+
backgroundColor?: string
|
|
10
|
+
textColor?: string
|
|
11
|
+
icon?: {
|
|
12
|
+
size?: number
|
|
13
|
+
color?: string
|
|
14
|
+
background?: string
|
|
15
|
+
backgroundSize?: number
|
|
16
|
+
backgroundShape?: string
|
|
17
|
+
borderColor?: string
|
|
18
|
+
borderWidth?: number
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface UspPreviewStyle {
|
|
23
|
+
rootClassName: string
|
|
24
|
+
iconClassName: string
|
|
25
|
+
cssVars: Record<string, string>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function buildUspPreviewStyle(shared?: UspSharedStyle, resolveHex: (value: string) => string = (value) => value): UspPreviewStyle {
|
|
29
|
+
if (!shared) {
|
|
30
|
+
return {rootClassName: '', iconClassName: '', cssVars: {}}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const icon = shared.icon ?? {}
|
|
34
|
+
|
|
35
|
+
const rootClassName = clsx(
|
|
36
|
+
shared.direction && `--direction-${shared.direction}`,
|
|
37
|
+
shared.align && `--align-${shared.align}`,
|
|
38
|
+
shared.textAlign && `--body-align-${shared.textAlign}`,
|
|
39
|
+
shared.shadow && shared.shadow !== 'none' && `--shadow --shadow-${shared.shadow}`,
|
|
40
|
+
icon.background && '--icon-background',
|
|
41
|
+
icon.color && '--icon-color',
|
|
42
|
+
icon.borderColor && '--icon-bordered',
|
|
43
|
+
shared.backgroundColor && '--background-color',
|
|
44
|
+
shared.borderColor && '--border',
|
|
45
|
+
shared.textColor && '--text-color',
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
const iconClassName = clsx(
|
|
49
|
+
icon.backgroundShape && icon.backgroundShape !== 'none' && `--background-shape --background-shape-${icon.backgroundShape}`,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const cssVars: Record<string, string> = {}
|
|
53
|
+
if (shared.borderColor) cssVars['--border-color'] = resolveHex(shared.borderColor)
|
|
54
|
+
if (shared.backgroundColor) cssVars['--background-color'] = resolveHex(shared.backgroundColor)
|
|
55
|
+
if (shared.textColor) cssVars['--text-color'] = resolveHex(shared.textColor)
|
|
56
|
+
if (icon.background) cssVars['--icon-background-color'] = resolveHex(icon.background)
|
|
57
|
+
if (icon.color) cssVars['--icon-color'] = resolveHex(icon.color)
|
|
58
|
+
if (icon.size) cssVars['--icon-size'] = `${icon.size}px`
|
|
59
|
+
if (icon.backgroundSize) cssVars['--icon-background-size'] = `${icon.backgroundSize}px`
|
|
60
|
+
if (icon.borderColor) {
|
|
61
|
+
cssVars['--icon-outline-color'] = resolveHex(icon.borderColor)
|
|
62
|
+
cssVars['--icon-outline-width'] = `${icon.borderWidth || 1}px`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {rootClassName, iconClassName, cssVars}
|
|
66
|
+
}
|
|
@@ -3,6 +3,8 @@ import {PanelBody, ToggleControl, TextControl} from '@wordpress/components'
|
|
|
3
3
|
import {__} from '@wordpress/i18n'
|
|
4
4
|
import clsx from 'clsx'
|
|
5
5
|
import {ItemIconControl, ItemIconPreview} from '~/components/ItemIconControl'
|
|
6
|
+
import {useTenantColorPalette} from '~/hooks/useTenantColorPalette'
|
|
7
|
+
import {buildUspPreviewStyle, type UspSharedStyle} from './buildPreviewStyle'
|
|
6
8
|
import {ICON_TYPES} from './constants'
|
|
7
9
|
import type {UspItemAttributes, UspItemOptions} from './types'
|
|
8
10
|
|
|
@@ -10,13 +12,17 @@ export function createUspItemEdit(options: UspItemOptions) {
|
|
|
10
12
|
return function Edit({
|
|
11
13
|
attributes,
|
|
12
14
|
setAttributes,
|
|
15
|
+
context,
|
|
13
16
|
}: {
|
|
14
17
|
attributes: UspItemAttributes
|
|
15
18
|
setAttributes: (a: Partial<UspItemAttributes>) => void
|
|
19
|
+
context?: {'brilo/usp-style'?: UspSharedStyle}
|
|
16
20
|
}) {
|
|
17
21
|
const {title, content, url, icon} = attributes
|
|
22
|
+
const {resolveHex} = useTenantColorPalette()
|
|
23
|
+
const {rootClassName, iconClassName, cssVars} = buildUspPreviewStyle(context?.['brilo/usp-style'], resolveHex)
|
|
18
24
|
|
|
19
|
-
const blockProps = useBlockProps({className: 'i-usp'})
|
|
25
|
+
const blockProps = useBlockProps({className: clsx('i-usp', rootClassName), style: cssVars})
|
|
20
26
|
|
|
21
27
|
return (
|
|
22
28
|
<>
|
|
@@ -36,7 +42,14 @@ export function createUspItemEdit(options: UspItemOptions) {
|
|
|
36
42
|
|
|
37
43
|
<div {...blockProps}>
|
|
38
44
|
<div className="i-usp__inner wp-block-inner">
|
|
39
|
-
<ItemIconPreview
|
|
45
|
+
<ItemIconPreview
|
|
46
|
+
icon={icon}
|
|
47
|
+
className="i-usp__icon"
|
|
48
|
+
modifierClassName={iconClassName}
|
|
49
|
+
style={cssVars}
|
|
50
|
+
setAttributes={setAttributes}
|
|
51
|
+
options={options}
|
|
52
|
+
/>
|
|
40
53
|
|
|
41
54
|
<div className={clsx('i-usp__body', 'grow')}>
|
|
42
55
|
<RichText
|