@brilo/base-blocks 0.1.49 → 0.1.50

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.
Files changed (28) hide show
  1. package/build/.tsbuildinfo +1 -1
  2. package/build/blocks/person/person-group/constants.d.ts +17 -0
  3. package/build/blocks/person/person-group/constants.d.ts.map +1 -1
  4. package/build/blocks/person/person-group/constants.js +10 -0
  5. package/build/blocks/person/person-group/edit.d.ts.map +1 -1
  6. package/build/blocks/person/person-group/edit.js +6 -4
  7. package/build/blocks/person/person-group/factory.d.ts.map +1 -1
  8. package/build/blocks/person/person-group/factory.js +12 -1
  9. package/build/blocks/person/person-group/types.d.ts +11 -0
  10. package/build/blocks/person/person-group/types.d.ts.map +1 -1
  11. package/build/blocks/step/step-group/constants.d.ts +55 -0
  12. package/build/blocks/step/step-group/constants.d.ts.map +1 -1
  13. package/build/blocks/step/step-group/constants.js +29 -0
  14. package/build/blocks/step/step-group/edit.d.ts.map +1 -1
  15. package/build/blocks/step/step-group/edit.js +28 -3
  16. package/build/blocks/step/step-group/factory.d.ts.map +1 -1
  17. package/build/blocks/step/step-group/factory.js +16 -1
  18. package/build/blocks/step/step-group/types.d.ts +17 -1
  19. package/build/blocks/step/step-group/types.d.ts.map +1 -1
  20. package/package.json +1 -1
  21. package/src/blocks/person/person-group/constants.ts +13 -0
  22. package/src/blocks/person/person-group/edit.tsx +63 -3
  23. package/src/blocks/person/person-group/factory.tsx +12 -1
  24. package/src/blocks/person/person-group/types.ts +13 -0
  25. package/src/blocks/step/step-group/constants.ts +35 -0
  26. package/src/blocks/step/step-group/edit.tsx +163 -5
  27. package/src/blocks/step/step-group/factory.tsx +16 -1
  28. package/src/blocks/step/step-group/types.ts +20 -1
@@ -1,6 +1,10 @@
1
1
  import {InspectorControls} from '@wordpress/block-editor'
2
2
  import {
3
+ BaseControl,
4
+ Button,
5
+ ColorPalette,
3
6
  PanelBody,
7
+ RangeControl,
4
8
  ToggleControl,
5
9
  __experimentalToggleGroupControl as ToggleGroupControl,
6
10
  __experimentalToggleGroupControlOption as ToggleGroupControlOption,
@@ -9,21 +13,87 @@ import {__} from '@wordpress/i18n'
9
13
  import clsx from 'clsx'
10
14
  import {ItemSpacingPanel, itemSpacingStyle} from '~/components/ItemSpacingControl'
11
15
  import {useGroupBlock} from '~/hooks/useGroupBlock'
16
+ import {useTenantColorPalette} from '~/hooks/useTenantColorPalette'
12
17
  import type {OptionArray} from '~/types'
13
- import type {StepGroupAttributes, StepGroupOptions, StepVariant} from './types'
14
- import {DEFAULT_VARIANTS} from './constants'
18
+ import type {StepGroupAttributes, StepGroupOptions, StepShadow, StepTextAlign} from './types'
19
+ import {
20
+ DEFAULT_ICON_BACKGROUND_SIZE,
21
+ DEFAULT_ICON_BACKGROUND_SIZE_PRESETS,
22
+ DEFAULT_ICON_SIZE,
23
+ DEFAULT_ICON_SIZE_PRESETS,
24
+ DEFAULT_SHADOWS,
25
+ DEFAULT_VARIANTS,
26
+ ICON_BACKGROUND_SIZE_MAX,
27
+ ICON_BACKGROUND_SIZE_MIN,
28
+ ICON_SIZE_MAX,
29
+ ICON_SIZE_MIN,
30
+ TEXT_ALIGNS,
31
+ } from './constants'
32
+
33
+ // Older step-group blocks were saved before `style` / `style.icon` existed. WordPress does
34
+ // not deep-merge object-attribute defaults, so normalise here to stay backward compatible.
35
+ function normaliseStyle(saved: Partial<StepGroupAttributes['style']> | undefined): StepGroupAttributes['style'] {
36
+ return {
37
+ shadow: 'none',
38
+ borderColor: '',
39
+ backgroundColor: '',
40
+ textColor: '',
41
+ headingColor: '',
42
+ textAlign: 'left',
43
+ ...saved,
44
+ icon: {
45
+ size: DEFAULT_ICON_SIZE,
46
+ background: '',
47
+ backgroundSize: DEFAULT_ICON_BACKGROUND_SIZE,
48
+ ...saved?.icon,
49
+ },
50
+ }
51
+ }
52
+
53
+ function PresetSizeControl({
54
+ label,
55
+ id,
56
+ value,
57
+ presets,
58
+ min,
59
+ max,
60
+ onChange,
61
+ }: {
62
+ label: string
63
+ id: string
64
+ value: number
65
+ presets: readonly {value: number; label: string}[]
66
+ min: number
67
+ max: number
68
+ onChange: (v: number) => void
69
+ }) {
70
+ return (
71
+ <BaseControl label={label} id={id}>
72
+ <div style={{display: 'flex', gap: 4, marginBottom: 8, flexWrap: 'wrap'}}>
73
+ {presets.map((p) => (
74
+ <Button key={p.label} variant={value === p.value ? 'primary' : 'secondary'} size="small" onClick={() => onChange(p.value)}>
75
+ {p.label}
76
+ </Button>
77
+ ))}
78
+ </div>
79
+ <RangeControl value={value} onChange={(v) => onChange(v ?? min)} min={min} max={max} step={1} withInputField />
80
+ </BaseControl>
81
+ )
82
+ }
15
83
 
16
84
  export function createStepGroupEdit<TVariants extends OptionArray = typeof DEFAULT_VARIANTS>(options: StepGroupOptions<TVariants>) {
17
85
  const VARIANTS = options.variants ?? DEFAULT_VARIANTS
18
86
 
19
87
  return function Edit({
20
- attributes,
21
- setAttributes,
22
- }: {
88
+ attributes,
89
+ setAttributes,
90
+ }: {
23
91
  attributes: StepGroupAttributes
24
92
  setAttributes: (a: Partial<StepGroupAttributes>) => void
25
93
  }) {
26
94
  const {variant, disableIcon, spacing} = attributes
95
+ const style = normaliseStyle(attributes.style as Partial<StepGroupAttributes['style']> | undefined)
96
+ const {paletteColors} = useTenantColorPalette()
27
97
 
28
98
  const {blockProps, innerBlocksProps} = useGroupBlock({
29
99
  blockClassName: clsx(options.blockClassName ?? 'g-step wp-block-section', `--variant-${variant}`, disableIcon && '--disable-icon'),
@@ -55,6 +125,94 @@ export function createStepGroupEdit<TVariants extends OptionArray = typeof DEFAU
55
125
  onChange={(v) => setAttributes({disableIcon: v})}
56
126
  />
57
127
  </PanelBody>
128
+ {style && (
129
+ <PanelBody title={__('Styl', 'brilo-blocks')}>
130
+ <ToggleGroupControl
131
+ isBlock
132
+ label={__('Stín', 'brilo-blocks')}
133
+ value={style.shadow}
134
+ onChange={(v) => setAttributes({style: {...style, shadow: v as StepShadow}})}
135
+ >
136
+ {DEFAULT_SHADOWS.map((s) => (
137
+ <ToggleGroupControlOption key={s.value} value={s.value} label={s.label} />
138
+ ))}
139
+ </ToggleGroupControl>
140
+ <BaseControl
141
+ label={__('Barva okraje', 'brilo-blocks')}
142
+ help={__('Bez vybrané barvy se okraj nevykreslí.', 'brilo-blocks')}
143
+ id="step-group-border-color"
144
+ >
145
+ <ColorPalette
146
+ colors={paletteColors}
147
+ value={style.borderColor || undefined}
148
+ onChange={(value) => setAttributes({style: {...style, borderColor: value ?? ''}})}
149
+ />
150
+ </BaseControl>
151
+ <BaseControl label={__('Barva pozadí', 'brilo-blocks')} id="step-group-background-color">
152
+ <ColorPalette
153
+ colors={paletteColors}
154
+ value={style.backgroundColor || undefined}
155
+ onChange={(value) => setAttributes({style: {...style, backgroundColor: value ?? ''}})}
156
+ />
157
+ </BaseControl>
158
+ <BaseControl label={__('Barva textu', 'brilo-blocks')} id="step-group-text-color">
159
+ <ColorPalette
160
+ colors={paletteColors}
161
+ value={style.textColor || undefined}
162
+ onChange={(value) => setAttributes({style: {...style, textColor: value ?? ''}})}
163
+ />
164
+ </BaseControl>
165
+ <BaseControl label={__('Barva nadpisu', 'brilo-blocks')} id="step-group-heading-color">
166
+ <ColorPalette
167
+ colors={paletteColors}
168
+ value={style.headingColor || undefined}
169
+ onChange={(value) => setAttributes({style: {...style, headingColor: value ?? ''}})}
170
+ />
171
+ </BaseControl>
172
+ <ToggleGroupControl
173
+ isBlock
174
+ label={__('Zarovnání textu', 'brilo-blocks')}
175
+ value={style.textAlign}
176
+ onChange={(v) => setAttributes({style: {...style, textAlign: v as StepTextAlign}})}
177
+ >
178
+ {TEXT_ALIGNS.map((a) => (
179
+ <ToggleGroupControlOption key={a.value} value={a.value} label={a.label} />
180
+ ))}
181
+ </ToggleGroupControl>
182
+ </PanelBody>
183
+ )}
184
+
185
+ <PanelBody title={__('Ikona', 'brilo-blocks')} initialOpen={false}>
186
+ <PresetSizeControl
187
+ label={__('Velikost', 'brilo-blocks')}
188
+ id="step-group-icon-size"
189
+ value={style.icon.size}
190
+ presets={DEFAULT_ICON_SIZE_PRESETS}
191
+ min={ICON_SIZE_MIN}
192
+ max={ICON_SIZE_MAX}
193
+ onChange={(v) => setAttributes({style: {...style, icon: {...style.icon, size: v}}})}
194
+ />
195
+ <BaseControl
196
+ label={__('Barva pozadí', 'brilo-blocks')}
197
+ help={__('Ovládá i barvu spojnice mezi kroky.', 'brilo-blocks')}
198
+ id="step-group-icon-background"
199
+ >
200
+ <ColorPalette
201
+ colors={paletteColors}
202
+ value={style.icon.background || undefined}
203
+ onChange={(value) => setAttributes({style: {...style, icon: {...style.icon, background: value ?? ''}}})}
204
+ />
205
+ </BaseControl>
206
+ <PresetSizeControl
207
+ label={__('Velikost pozadí', 'brilo-blocks')}
208
+ id="step-group-icon-background-size"
209
+ value={style.icon.backgroundSize}
210
+ presets={DEFAULT_ICON_BACKGROUND_SIZE_PRESETS}
211
+ min={ICON_BACKGROUND_SIZE_MIN}
212
+ max={ICON_BACKGROUND_SIZE_MAX}
213
+ onChange={(v) => setAttributes({style: {...style, icon: {...style.icon, backgroundSize: v}}})}
214
+ />
215
+ </PanelBody>
58
216
  <ItemSpacingPanel spacing={spacing} onChange={(v) => setAttributes({spacing: v})} />
59
217
  </InspectorControls>
60
218
  <div {...blockProps}>
@@ -1,7 +1,7 @@
1
1
  import {InnerBlocks} from '@wordpress/block-editor'
2
2
  import type {BlockConfiguration} from '@wordpress/blocks'
3
3
  import {__} from '@wordpress/i18n'
4
- import {DEFAULT_VARIANTS} from './constants'
4
+ import {DEFAULT_ICON_BACKGROUND_SIZE, DEFAULT_ICON_SIZE, DEFAULT_SHADOWS, DEFAULT_VARIANTS, TEXT_ALIGNS} from './constants'
5
5
  import {createStepGroupEdit} from './edit'
6
6
  import type {StepGroupAttributes, StepGroupOptions} from './types'
7
7
  import {icon} from '~/blocks/step/step-group/icon'
@@ -30,6 +30,21 @@ export function createStepGroupBlock<TVariants extends OptionArray = typeof DEFA
30
30
  type: 'boolean',
31
31
  default: false,
32
32
  },
33
+ style: {
34
+ type: 'object',
35
+ default: {
36
+ shadow: DEFAULT_SHADOWS[0].value,
37
+ borderColor: '',
38
+ backgroundColor: '',
39
+ textColor: '',
40
+ headingColor: '',
41
+ textAlign: TEXT_ALIGNS[0].value,
42
+ icon: {
43
+ background: '',
44
+ backgroundSize: DEFAULT_ICON_BACKGROUND_SIZE,
45
+ },
46
+ },
47
+ },
33
48
  ...ITEM_SPACING_ATTRIBUTE,
34
49
  },
35
50
  edit: createStepGroupEdit(options as unknown as StepGroupOptions),
@@ -1,11 +1,30 @@
1
1
  import type {BriloBlockType, OptionArray} from '~/types'
2
- import type {DEFAULT_VARIANTS} from './constants'
2
+ import type {DEFAULT_SHADOWS, DEFAULT_VARIANTS, TEXT_ALIGNS} from './constants'
3
3
 
4
4
  export type StepVariant = (typeof DEFAULT_VARIANTS)[number]['value']
5
5
 
6
+ export type StepShadow = (typeof DEFAULT_SHADOWS)[number]['value']
7
+
8
+ export type StepTextAlign = (typeof TEXT_ALIGNS)[number]['value']
9
+
10
+ export interface StepIconStyle {
11
+ size: number
12
+ background: string
13
+ backgroundSize: number
14
+ }
15
+
6
16
  export interface StepGroupAttributes<TVariant extends string = StepVariant> extends Record<string, unknown> {
7
17
  variant: TVariant
8
18
  disableIcon: boolean
19
+ style: {
20
+ shadow: StepShadow
21
+ borderColor: string
22
+ backgroundColor: string
23
+ textColor: string
24
+ headingColor: string
25
+ textAlign: StepTextAlign
26
+ icon: StepIconStyle
27
+ }
9
28
  spacing?: number
10
29
  }
11
30