@brilo/base-blocks 0.1.43 → 0.1.44

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 (99) hide show
  1. package/build/.tsbuildinfo +1 -1
  2. package/build/blocks/compare/compare-group/constants.d.ts +27 -0
  3. package/build/blocks/compare/compare-group/constants.d.ts.map +1 -1
  4. package/build/blocks/compare/compare-group/constants.js +23 -0
  5. package/build/blocks/compare/compare-group/edit.d.ts.map +1 -1
  6. package/build/blocks/compare/compare-group/edit.js +12 -7
  7. package/build/blocks/compare/compare-group/factory.d.ts.map +1 -1
  8. package/build/blocks/compare/compare-group/factory.js +10 -1
  9. package/build/blocks/compare/compare-group/index.d.ts +1 -1
  10. package/build/blocks/compare/compare-group/index.d.ts.map +1 -1
  11. package/build/blocks/compare/compare-group/types.d.ts +7 -1
  12. package/build/blocks/compare/compare-group/types.d.ts.map +1 -1
  13. package/build/blocks/compare/compare-item/edit.d.ts.map +1 -1
  14. package/build/blocks/compare/compare-item/edit.js +6 -4
  15. package/build/blocks/compare/compare-item/factory.d.ts.map +1 -1
  16. package/build/blocks/compare/compare-item/factory.js +4 -0
  17. package/build/blocks/compare/compare-item/types.d.ts +2 -0
  18. package/build/blocks/compare/compare-item/types.d.ts.map +1 -1
  19. package/build/blocks/core/basic-icon/buildPreviewStyle.d.ts +8 -0
  20. package/build/blocks/core/basic-icon/buildPreviewStyle.d.ts.map +1 -0
  21. package/build/blocks/core/basic-icon/buildPreviewStyle.js +22 -0
  22. package/build/blocks/core/basic-icon/constants.d.ts +84 -0
  23. package/build/blocks/core/basic-icon/constants.d.ts.map +1 -0
  24. package/build/blocks/core/basic-icon/constants.js +41 -0
  25. package/build/blocks/core/basic-icon/edit.d.ts +6 -0
  26. package/build/blocks/core/basic-icon/edit.d.ts.map +1 -0
  27. package/build/blocks/core/basic-icon/edit.js +22 -0
  28. package/build/blocks/core/basic-icon/factory.d.ts +5 -0
  29. package/build/blocks/core/basic-icon/factory.d.ts.map +1 -0
  30. package/build/blocks/core/basic-icon/factory.js +38 -0
  31. package/build/blocks/core/basic-icon/index.d.ts +5 -0
  32. package/build/blocks/core/basic-icon/index.d.ts.map +1 -0
  33. package/build/blocks/core/basic-icon/index.js +7 -0
  34. package/build/blocks/core/basic-icon/types.d.ts +30 -0
  35. package/build/blocks/core/basic-icon/types.d.ts.map +1 -0
  36. package/build/blocks/core/basic-icon/types.js +1 -0
  37. package/build/blocks/faq/faq-group/constants.d.ts +29 -0
  38. package/build/blocks/faq/faq-group/constants.d.ts.map +1 -1
  39. package/build/blocks/faq/faq-group/constants.js +15 -0
  40. package/build/blocks/faq/faq-group/edit.d.ts.map +1 -1
  41. package/build/blocks/faq/faq-group/edit.js +12 -5
  42. package/build/blocks/faq/faq-group/factory.d.ts.map +1 -1
  43. package/build/blocks/faq/faq-group/factory.js +35 -17
  44. package/build/blocks/faq/faq-group/index.d.ts +1 -1
  45. package/build/blocks/faq/faq-group/index.d.ts.map +1 -1
  46. package/build/blocks/faq/faq-group/types.d.ts +20 -1
  47. package/build/blocks/faq/faq-group/types.d.ts.map +1 -1
  48. package/build/blocks/review/review-group/constants.d.ts +10 -0
  49. package/build/blocks/review/review-group/constants.d.ts.map +1 -1
  50. package/build/blocks/review/review-group/constants.js +5 -0
  51. package/build/blocks/review/review-group/edit.d.ts.map +1 -1
  52. package/build/blocks/review/review-group/edit.js +8 -5
  53. package/build/blocks/review/review-group/factory.d.ts.map +1 -1
  54. package/build/blocks/review/review-group/factory.js +34 -21
  55. package/build/blocks/review/review-group/index.d.ts +1 -1
  56. package/build/blocks/review/review-group/index.d.ts.map +1 -1
  57. package/build/blocks/review/review-group/types.d.ts +10 -1
  58. package/build/blocks/review/review-group/types.d.ts.map +1 -1
  59. package/build/blocks/video/video-group/edit.d.ts.map +1 -1
  60. package/build/blocks/video/video-group/edit.js +2 -2
  61. package/build/blocks/video/video-group/factory.d.ts.map +1 -1
  62. package/build/blocks/video/video-group/factory.js +4 -0
  63. package/build/blocks/video/video-group/types.d.ts +1 -0
  64. package/build/blocks/video/video-group/types.d.ts.map +1 -1
  65. package/build/index.d.ts +2 -0
  66. package/build/index.d.ts.map +1 -1
  67. package/build/index.js +1 -0
  68. package/package.json +1 -1
  69. package/src/blocks/compare/compare-group/constants.ts +27 -0
  70. package/src/blocks/compare/compare-group/edit.tsx +27 -4
  71. package/src/blocks/compare/compare-group/factory.tsx +10 -1
  72. package/src/blocks/compare/compare-group/index.ts +7 -1
  73. package/src/blocks/compare/compare-group/types.ts +5 -1
  74. package/src/blocks/compare/compare-item/edit.tsx +32 -13
  75. package/src/blocks/compare/compare-item/editor.scss +16 -0
  76. package/src/blocks/compare/compare-item/factory.tsx +4 -0
  77. package/src/blocks/compare/compare-item/types.ts +2 -0
  78. package/src/blocks/core/basic-icon/buildPreviewStyle.ts +40 -0
  79. package/src/blocks/core/basic-icon/constants.ts +48 -0
  80. package/src/blocks/core/basic-icon/edit.tsx +170 -0
  81. package/src/blocks/core/basic-icon/editor.scss +119 -0
  82. package/src/blocks/core/basic-icon/factory.tsx +42 -0
  83. package/src/blocks/core/basic-icon/index.ts +17 -0
  84. package/src/blocks/core/basic-icon/types.ts +34 -0
  85. package/src/blocks/faq/faq-group/constants.ts +18 -0
  86. package/src/blocks/faq/faq-group/edit.tsx +118 -4
  87. package/src/blocks/faq/faq-group/factory.tsx +33 -13
  88. package/src/blocks/faq/faq-group/index.ts +9 -1
  89. package/src/blocks/faq/faq-group/types.ts +22 -1
  90. package/src/blocks/review/review-group/constants.ts +6 -0
  91. package/src/blocks/review/review-group/edit.tsx +47 -3
  92. package/src/blocks/review/review-group/factory.tsx +31 -16
  93. package/src/blocks/review/review-group/index.ts +10 -1
  94. package/src/blocks/review/review-group/types.ts +11 -1
  95. package/src/blocks/video/video-group/edit.tsx +8 -1
  96. package/src/blocks/video/video-group/factory.tsx +4 -0
  97. package/src/blocks/video/video-group/types.ts +1 -0
  98. package/src/editor.scss +1 -0
  99. package/src/index.ts +7 -0
@@ -1,13 +1,14 @@
1
1
  import {InspectorControls} from '@wordpress/block-editor'
2
2
  import {
3
3
  PanelBody,
4
+ SelectControl,
4
5
  __experimentalToggleGroupControl as ToggleGroupControl,
5
6
  __experimentalToggleGroupControlOption as ToggleGroupControlOption,
6
7
  } from '@wordpress/components'
7
8
  import {__} from '@wordpress/i18n'
8
9
  import {useGroupBlock} from '~/hooks/useGroupBlock'
9
- import {HEADING_LEVELS} from './constants'
10
- import type {CompareGroupAttributes, CompareGroupOptions} from './types'
10
+ import {DEFAULT_IMAGE_CLIP_PATHS, HEADING_LEVELS, IMAGE_CLIP_PATH_VALUES, RATIOS} from './constants'
11
+ import type {CompareGroupAttributes, CompareGroupOptions, CompareImageClipPath} from './types'
11
12
 
12
13
  export function createCompareGroupEdit(options: CompareGroupOptions) {
13
14
  return function Edit({
@@ -17,10 +18,16 @@ export function createCompareGroupEdit(options: CompareGroupOptions) {
17
18
  attributes: CompareGroupAttributes
18
19
  setAttributes: (a: Partial<CompareGroupAttributes>) => void
19
20
  }) {
20
- const {headingLevel} = attributes
21
+ const {headingLevel, ratio, img} = attributes
22
+ const clipPath = img?.clipPath ?? 'none'
23
+
21
24
  const {blockProps, innerBlocksProps} = useGroupBlock({
22
25
  blockClassName: options.blockClassName ?? 'g-compare wp-block-section',
23
- containerClassName: [options.containerClassName ?? 'u-grid-responsive'],
26
+ containerClassName: [options.containerClassName ?? 'u-grid-responsive', `--ratio-${ratio.replace(':', '-')}`],
27
+ containerStyle: {
28
+ // Inherited by every compare item inside the container.
29
+ ...(IMAGE_CLIP_PATH_VALUES[clipPath] && {'--compare-image-clip-path': IMAGE_CLIP_PATH_VALUES[clipPath]}),
30
+ },
24
31
  allowedBlocks: options.allowedBlocks,
25
32
  orientation: 'horizontal',
26
33
  template: options.template,
@@ -41,6 +48,22 @@ export function createCompareGroupEdit(options: CompareGroupOptions) {
41
48
  <ToggleGroupControlOption key={l} value={String(l)} label={`H${l}`} />
42
49
  ))}
43
50
  </ToggleGroupControl>
51
+ <ToggleGroupControl
52
+ isBlock
53
+ label={__('Poměr stran obrázku', 'brilo-blocks')}
54
+ value={ratio}
55
+ onChange={(v) => setAttributes({ratio: v as CompareGroupAttributes['ratio']})}
56
+ >
57
+ {RATIOS.map((r) => (
58
+ <ToggleGroupControlOption key={r} value={r} label={r} />
59
+ ))}
60
+ </ToggleGroupControl>
61
+ <SelectControl<string>
62
+ label={__('Tvar výřezu obrázku', 'brilo-blocks')}
63
+ value={clipPath}
64
+ options={[...DEFAULT_IMAGE_CLIP_PATHS]}
65
+ onChange={(v) => setAttributes({img: {...img, clipPath: v as CompareImageClipPath}})}
66
+ />
44
67
  </PanelBody>
45
68
  </InspectorControls>
46
69
  <div {...blockProps}>
@@ -3,7 +3,7 @@ import type {BlockConfiguration} from '@wordpress/blocks'
3
3
  import {__} from '@wordpress/i18n'
4
4
  import {createCompareGroupEdit} from './edit'
5
5
  import {icon as defaultIcon} from './icon'
6
- import {HEADING_LEVELS} from './constants'
6
+ import {DEFAULT_IMAGE_CLIP_PATHS, HEADING_LEVELS, RATIOS} from './constants'
7
7
  import type {CompareGroupAttributes, CompareGroupOptions} from './types'
8
8
 
9
9
  export type {CompareGroupAttributes, CompareGroupOptions}
@@ -22,6 +22,15 @@ export function createCompareGroupBlock(options: CompareGroupOptions): BlockConf
22
22
  type: 'number',
23
23
  default: HEADING_LEVELS[1],
24
24
  },
25
+ ratio: {
26
+ type: 'string',
27
+ default: RATIOS[0],
28
+ enum: [...RATIOS],
29
+ },
30
+ img: {
31
+ type: 'object',
32
+ default: {clipPath: DEFAULT_IMAGE_CLIP_PATHS[0].value},
33
+ },
25
34
  },
26
35
  edit: createCompareGroupEdit(options),
27
36
  save: () => <InnerBlocks.Content />,
@@ -1,4 +1,10 @@
1
- export type {CompareGroupAttributes, CompareGroupOptions} from './types'
1
+ export type {
2
+ CompareGroupAttributes,
3
+ CompareGroupOptions,
4
+ CompareHeadingLevel,
5
+ CompareImageClipPath,
6
+ CompareRatio,
7
+ } from './types'
2
8
  export {createCompareGroupBlock} from './factory'
3
9
  import type {CompareGroupOptions} from './types'
4
10
 
@@ -1,10 +1,14 @@
1
- import type {HEADING_LEVELS} from './constants'
2
1
  import type {BriloBlockType} from '~/types'
2
+ import type {DEFAULT_IMAGE_CLIP_PATHS, HEADING_LEVELS, RATIOS} from './constants'
3
3
 
4
4
  export type CompareHeadingLevel = (typeof HEADING_LEVELS)[number]
5
+ export type CompareRatio = (typeof RATIOS)[number]
6
+ export type CompareImageClipPath = (typeof DEFAULT_IMAGE_CLIP_PATHS)[number]['value']
5
7
 
6
8
  export interface CompareGroupAttributes extends Record<string, unknown> {
7
9
  headingLevel: CompareHeadingLevel
10
+ ratio: CompareRatio
11
+ img: {clipPath: CompareImageClipPath}
8
12
  }
9
13
 
10
14
  export interface CompareGroupOptions extends BriloBlockType {
@@ -1,5 +1,7 @@
1
- import {RichText, useBlockProps, useInnerBlocksProps} from '@wordpress/block-editor'
1
+ import {InspectorControls, RichText, useBlockProps, useInnerBlocksProps} from '@wordpress/block-editor'
2
+ import {PanelBody} from '@wordpress/components'
2
3
  import {__} from '@wordpress/i18n'
4
+ import {ImagePickerControl} from '~/components/ImagePicker'
3
5
  import type {CompareItemAttributes, CompareItemOptions} from './types'
4
6
 
5
7
  export function createCompareItemEdit(options: CompareItemOptions) {
@@ -10,7 +12,7 @@ export function createCompareItemEdit(options: CompareItemOptions) {
10
12
  attributes: CompareItemAttributes
11
13
  setAttributes: (a: Partial<CompareItemAttributes>) => void
12
14
  }) {
13
- const {title} = attributes
15
+ const {title, img} = attributes
14
16
  const blockProps = useBlockProps({className: 'i-compare'})
15
17
  const innerBlocksProps = useInnerBlocksProps(
16
18
  {className: 'i-compare__options wp-block-inner-content'},
@@ -21,18 +23,35 @@ export function createCompareItemEdit(options: CompareItemOptions) {
21
23
  )
22
24
 
23
25
  return (
24
- <div {...blockProps}>
25
- <div className={'i-compare__inner'}>
26
- <RichText
27
- tagName={'div'}
28
- className="i-compare__title u-text-editable"
29
- value={title}
30
- onChange={(v) => setAttributes({title: v})}
31
- placeholder={__('Nadpis...', 'brilo-blocks')}
32
- />
33
- <div {...innerBlocksProps} />
26
+ <>
27
+ <InspectorControls>
28
+ <PanelBody title={__('Obrázek', 'brilo-blocks')}>
29
+ <ImagePickerControl value={img} onChange={(val) => setAttributes({img: val})} />
30
+ </PanelBody>
31
+ </InspectorControls>
32
+
33
+ <div {...blockProps}>
34
+ <div className={'i-compare__inner'}>
35
+ <div className="i-compare__image-wrapper">
36
+ {img.id ? (
37
+ <ImagePickerControl value={img} onChange={(val) => setAttributes({img: val})} size={[128, 128]} />
38
+ ) : (
39
+ <div className="i-compare__image-placeholder">
40
+ <ImagePickerControl value={img} onChange={(val) => setAttributes({img: val})} />
41
+ </div>
42
+ )}
43
+ </div>
44
+ <RichText
45
+ tagName={'div'}
46
+ className="i-compare__title u-text-editable"
47
+ value={title}
48
+ onChange={(v) => setAttributes({title: v})}
49
+ placeholder={__('Nadpis...', 'brilo-blocks')}
50
+ />
51
+ <div {...innerBlocksProps} />
52
+ </div>
34
53
  </div>
35
- </div>
54
+ </>
36
55
  )
37
56
  }
38
57
  }
@@ -12,4 +12,20 @@
12
12
  .i-compare {
13
13
  width: 100%;
14
14
  }
15
+
16
+ .i-compare__image-placeholder {
17
+ border: 1px dashed #0073aa;
18
+ padding: 16px 8px 8px;
19
+ }
20
+
21
+ .i-compare__image-wrapper {
22
+ .c-image-picker-control__row {
23
+ flex-direction: column;
24
+ }
25
+
26
+ // Set by the parent compare group on the inner blocks container.
27
+ .c-image-picker-control__thumb {
28
+ clip-path: var(--compare-image-clip-path, none);
29
+ }
30
+ }
15
31
  }
@@ -21,6 +21,10 @@ export function createCompareItemBlock(options: CompareItemOptions): BlockConfig
21
21
  type: 'string',
22
22
  default: '',
23
23
  },
24
+ img: {
25
+ type: 'object',
26
+ default: {id: 0, alt: ''},
27
+ },
24
28
  },
25
29
  edit: createCompareItemEdit(options),
26
30
  save: () => <InnerBlocks.Content />,
@@ -1,7 +1,9 @@
1
+ import type {ImageValue} from '~/components/ImagePicker/ImagePicker'
1
2
  import type {BriloBlockType} from '~/types'
2
3
 
3
4
  export interface CompareItemAttributes extends Record<string, unknown> {
4
5
  title: string
6
+ img: ImageValue
5
7
  }
6
8
 
7
9
  export interface CompareItemOptions extends BriloBlockType {
@@ -0,0 +1,40 @@
1
+ import clsx from 'clsx'
2
+ import type {BasicIconStyle} from './types'
3
+
4
+ export interface BasicIconPreviewStyle {
5
+ rootClassName: string
6
+ iconClassName: string
7
+ cssVars: Record<string, string>
8
+ }
9
+
10
+ export function buildBasicIconPreviewStyle(
11
+ style: BasicIconStyle,
12
+ resolveHex: (value: string) => string = (value) => value,
13
+ ): BasicIconPreviewStyle {
14
+ const icon = style.icon ?? ({} as BasicIconStyle['icon'])
15
+
16
+ const rootClassName = clsx(
17
+ style.align && `--align-${style.align}`,
18
+ icon.background && icon.background !== 'none' && '--icon-background',
19
+ icon.color && icon.color !== 'none' && '--icon-color',
20
+ icon.borderColor && '--icon-bordered',
21
+ )
22
+
23
+ const iconClassName = clsx(
24
+ icon.backgroundShape && icon.backgroundShape !== 'none' && `--background-shape --background-shape-${icon.backgroundShape}`,
25
+ )
26
+
27
+ const cssVars: Record<string, string> = {}
28
+ if (icon.background && icon.background !== 'none') cssVars['--icon-background-color'] = resolveHex(icon.background)
29
+ if (icon.color && icon.color !== 'none') cssVars['--icon-color'] = resolveHex(icon.color)
30
+ if (icon.size) cssVars['--icon-size'] = `${icon.size}px`
31
+ if (icon.background && icon.background !== 'none' && icon.backgroundSize) {
32
+ cssVars['--icon-background-size'] = `${icon.backgroundSize}px`
33
+ }
34
+ if (icon.borderColor) {
35
+ cssVars['--icon-outline-color'] = resolveHex(icon.borderColor)
36
+ cssVars['--icon-outline-width'] = `${icon.borderWidth || 1}px`
37
+ }
38
+
39
+ return {rootClassName, iconClassName, cssVars}
40
+ }
@@ -0,0 +1,48 @@
1
+ import {__} from '@wordpress/i18n'
2
+
3
+ export const ICON_TYPES = [
4
+ {value: 'preselected', label: __('Předvolená', 'brilo-blocks')},
5
+ {value: 'media', label: __('Obrázek', 'brilo-blocks')},
6
+ {value: 'number', label: __('Číslo', 'brilo-blocks')},
7
+ ] as const
8
+
9
+ export const DEFAULT_ALIGNMENTS = [
10
+ {value: 'left', label: __('Vlevo', 'brilo-blocks')},
11
+ {value: 'center', label: __('Na střed', 'brilo-blocks')},
12
+ {value: 'right', label: __('Vpravo', 'brilo-blocks')},
13
+ ] as const
14
+
15
+ export const DEFAULT_ICON_SIZE = 88
16
+ export const ICON_SIZE_MIN = 4
17
+ export const ICON_SIZE_MAX = 128
18
+
19
+ export const DEFAULT_ICON_SIZE_PRESETS = [
20
+ {value: 8, label: __('XS', 'brilo-blocks')},
21
+ {value: 16, label: __('SM', 'brilo-blocks')},
22
+ {value: 24, label: __('MD', 'brilo-blocks')},
23
+ {value: 32, label: __('LG', 'brilo-blocks')},
24
+ {value: 48, label: __('XL', 'brilo-blocks')},
25
+ ] as const
26
+
27
+ export const DEFAULT_ICON_BACKGROUND_SIZE = 88
28
+ export const ICON_BACKGROUND_SIZE_MIN = 16
29
+ export const ICON_BACKGROUND_SIZE_MAX = 240
30
+
31
+ export const DEFAULT_ICON_BACKGROUND_SIZE_PRESETS = [
32
+ {value: 48, label: __('XS', 'brilo-blocks')},
33
+ {value: 64, label: __('SM', 'brilo-blocks')},
34
+ {value: 88, label: __('Výchozí', 'brilo-blocks')},
35
+ {value: 104, label: __('LG', 'brilo-blocks')},
36
+ {value: 128, label: __('XL', 'brilo-blocks')},
37
+ ] as const
38
+
39
+ export const DEFAULT_ICON_BACKGROUND_SHAPES = [
40
+ {value: 'none', label: __('Žádný', 'brilo-blocks')},
41
+ {value: 'circle', label: __('Kruh', 'brilo-blocks')},
42
+ {value: 'triangle', label: __('Trojúhelník', 'brilo-blocks')},
43
+ {value: 'rhombus', label: __('Kosočtverec', 'brilo-blocks')},
44
+ {value: 'octagon', label: __('Osmiúhelník', 'brilo-blocks')},
45
+ {value: 'bevel', label: __('Zkosený', 'brilo-blocks')},
46
+ {value: 'rabbet', label: __('Drážkovaný', 'brilo-blocks')},
47
+ {value: 'parallelogram', label: __('Rovnoběžník', 'brilo-blocks')},
48
+ ] as const
@@ -0,0 +1,170 @@
1
+ import {InspectorControls, useBlockProps} from '@wordpress/block-editor'
2
+ import {
3
+ BaseControl,
4
+ Button,
5
+ ColorPalette,
6
+ PanelBody,
7
+ RangeControl,
8
+ SelectControl,
9
+ __experimentalToggleGroupControl as ToggleGroupControl,
10
+ __experimentalToggleGroupControlOption as ToggleGroupControlOption,
11
+ } from '@wordpress/components'
12
+ import {__} from '@wordpress/i18n'
13
+ import clsx from 'clsx'
14
+ import {ItemIconControl, ItemIconPreview} from '~/components/ItemIconControl'
15
+ import {useTenantColorPalette} from '~/hooks/useTenantColorPalette'
16
+ import {buildBasicIconPreviewStyle} from './buildPreviewStyle'
17
+ import {
18
+ DEFAULT_ALIGNMENTS,
19
+ DEFAULT_ICON_BACKGROUND_SHAPES,
20
+ DEFAULT_ICON_BACKGROUND_SIZE_PRESETS,
21
+ DEFAULT_ICON_SIZE_PRESETS,
22
+ ICON_BACKGROUND_SIZE_MAX,
23
+ ICON_BACKGROUND_SIZE_MIN,
24
+ ICON_SIZE_MAX,
25
+ ICON_SIZE_MIN,
26
+ ICON_TYPES,
27
+ } from './constants'
28
+ import type {BasicIconAlignment, BasicIconAttributes, BasicIconBackgroundShape, BasicIconOptions, BasicIconSizePreset} from './types'
29
+
30
+ function PresetSizeControl({
31
+ label,
32
+ value,
33
+ presets,
34
+ min,
35
+ max,
36
+ onChange,
37
+ }: {
38
+ label: string
39
+ value: number
40
+ presets: readonly BasicIconSizePreset[]
41
+ min: number
42
+ max: number
43
+ onChange: (v: number) => void
44
+ }) {
45
+ return (
46
+ <BaseControl label={label} id={`basic-icon-size-${label}`}>
47
+ <div style={{display: 'flex', gap: 4, marginBottom: 8, flexWrap: 'wrap'}}>
48
+ {presets.map((p) => (
49
+ <Button key={p.label} variant={value === p.value ? 'primary' : 'secondary'} size="small" onClick={() => onChange(p.value)}>
50
+ {p.label}
51
+ </Button>
52
+ ))}
53
+ </div>
54
+ <RangeControl value={value} onChange={(v) => onChange(v ?? min)} min={min} max={max} step={1} withInputField />
55
+ </BaseControl>
56
+ )
57
+ }
58
+
59
+ export function createBasicIconEdit(options: BasicIconOptions) {
60
+ return function Edit({
61
+ attributes,
62
+ setAttributes,
63
+ }: {
64
+ attributes: BasicIconAttributes
65
+ setAttributes: (a: Partial<BasicIconAttributes>) => void
66
+ }) {
67
+ const {icon, style} = attributes
68
+ const {paletteColors, resolveHex} = useTenantColorPalette()
69
+ const {rootClassName, iconClassName, cssVars} = buildBasicIconPreviewStyle(style, resolveHex)
70
+
71
+ const blockProps = useBlockProps({className: clsx('i-basic-icon', rootClassName)})
72
+
73
+ const setIcon = (patch: Partial<BasicIconAttributes['style']['icon']>) =>
74
+ setAttributes({style: {...style, icon: {...style.icon, ...patch}}})
75
+
76
+ return (
77
+ <>
78
+ <InspectorControls>
79
+ <PanelBody title={__('Ikona', 'brilo-blocks')}>
80
+ <ItemIconControl icon={icon} setAttributes={setAttributes} iconTypes={ICON_TYPES} options={options} />
81
+ </PanelBody>
82
+ <PanelBody title={__('Zarovnání', 'brilo-blocks')}>
83
+ <ToggleGroupControl
84
+ isBlock
85
+ label={__('Zarovnání', 'brilo-blocks')}
86
+ value={style.align}
87
+ onChange={(v) => setAttributes({style: {...style, align: v as BasicIconAlignment}})}
88
+ >
89
+ {DEFAULT_ALIGNMENTS.map((a) => (
90
+ <ToggleGroupControlOption key={a.value} value={a.value} label={a.label} />
91
+ ))}
92
+ </ToggleGroupControl>
93
+ </PanelBody>
94
+ <PanelBody title={__('Styl ikony', 'brilo-blocks')} initialOpen={false}>
95
+ <PresetSizeControl
96
+ label={__('Velikost', 'brilo-blocks')}
97
+ value={style.icon.size}
98
+ presets={DEFAULT_ICON_SIZE_PRESETS}
99
+ min={ICON_SIZE_MIN}
100
+ max={ICON_SIZE_MAX}
101
+ onChange={(v) => setIcon({size: v})}
102
+ />
103
+ <BaseControl label={__('Barva', 'brilo-blocks')} id="basic-icon-color">
104
+ <ColorPalette
105
+ colors={paletteColors}
106
+ value={style.icon.color || undefined}
107
+ onChange={(value) => setIcon({color: value ?? ''})}
108
+ />
109
+ </BaseControl>
110
+ <BaseControl label={__('Pozadí', 'brilo-blocks')} id="basic-icon-background-color">
111
+ <ColorPalette
112
+ colors={paletteColors}
113
+ value={style.icon.background || undefined}
114
+ onChange={(value) => setIcon({background: value ?? ''})}
115
+ />
116
+ </BaseControl>
117
+ <PresetSizeControl
118
+ label={__('Velikost pozadí', 'brilo-blocks')}
119
+ value={style.icon.backgroundSize}
120
+ presets={DEFAULT_ICON_BACKGROUND_SIZE_PRESETS}
121
+ min={ICON_BACKGROUND_SIZE_MIN}
122
+ max={ICON_BACKGROUND_SIZE_MAX}
123
+ onChange={(v) => setIcon({backgroundSize: v})}
124
+ />
125
+ {style.icon.background && (
126
+ <SelectControl<string>
127
+ label={__('Tvar pozadí', 'brilo-blocks')}
128
+ value={style.icon.backgroundShape}
129
+ options={[...DEFAULT_ICON_BACKGROUND_SHAPES]}
130
+ onChange={(v) => setIcon({backgroundShape: v as BasicIconBackgroundShape})}
131
+ />
132
+ )}
133
+ <BaseControl
134
+ label={__('Barva ohraničení', 'brilo-blocks')}
135
+ help={__('Bez vybrané barvy se okraj nevykreslí.', 'brilo-blocks')}
136
+ id="basic-icon-border-color"
137
+ >
138
+ <ColorPalette
139
+ colors={paletteColors}
140
+ value={style.icon.borderColor || undefined}
141
+ onChange={(value) => setIcon({borderColor: value ?? ''})}
142
+ />
143
+ </BaseControl>
144
+ {style.icon.borderColor && (
145
+ <RangeControl
146
+ label={__('Šířka ohraničení (px)', 'brilo-blocks')}
147
+ value={style.icon.borderWidth}
148
+ onChange={(v) => setIcon({borderWidth: v ?? 0})}
149
+ min={0}
150
+ max={10}
151
+ step={1}
152
+ />
153
+ )}
154
+ </PanelBody>
155
+ </InspectorControls>
156
+
157
+ <div {...blockProps}>
158
+ <ItemIconPreview
159
+ icon={icon}
160
+ className="i-basic-icon__icon"
161
+ modifierClassName={iconClassName}
162
+ style={cssVars}
163
+ setAttributes={setAttributes}
164
+ options={options}
165
+ />
166
+ </div>
167
+ </>
168
+ )
169
+ }
170
+ }
@@ -0,0 +1,119 @@
1
+ .i-basic-icon {
2
+ display: flex;
3
+ --icon-background-size: 0px;
4
+
5
+ // Background size only reserves space when a background or outline is actually selected.
6
+ &.--icon-background,
7
+ &.--icon-bordered {
8
+ --icon-background-size: 88px;
9
+ }
10
+
11
+ &.--align-left {
12
+ justify-content: flex-start;
13
+ }
14
+
15
+ &.--align-center {
16
+ justify-content: center;
17
+ }
18
+
19
+ &.--align-right {
20
+ justify-content: flex-end;
21
+ }
22
+ }
23
+
24
+ .i-basic-icon__icon {
25
+ --icon-box-size: max(var(--icon-background-size, 0px), var(--icon-size, 88px));
26
+
27
+ width: var(--icon-box-size);
28
+ height: var(--icon-box-size);
29
+ flex: 0 0 var(--icon-box-size);
30
+ display: grid;
31
+ grid-template-areas: "pile";
32
+ place-items: center;
33
+ isolation: isolate;
34
+
35
+ &::before,
36
+ &::after {
37
+ content: "";
38
+ grid-area: pile;
39
+ width: var(--icon-background-size, 0px);
40
+ height: var(--icon-background-size, 0px);
41
+ border-radius: inherit;
42
+ clip-path: var(--icon-background-shape, none);
43
+ }
44
+
45
+ &::before {
46
+ z-index: 0;
47
+ background-color: var(--icon-outline-color, transparent);
48
+ }
49
+
50
+ &::after {
51
+ z-index: 1;
52
+ width: calc(var(--icon-background-size, 0px) - var(--icon-outline-width, 0px) * 2);
53
+ height: calc(var(--icon-background-size, 0px) - var(--icon-outline-width, 0px) * 2);
54
+ background-color: var(--icon-background-color, transparent);
55
+ }
56
+
57
+ img,
58
+ svg,
59
+ span {
60
+ grid-area: pile;
61
+ position: relative;
62
+ z-index: 2;
63
+ width: var(--icon-size, 88px);
64
+ height: var(--icon-size, 88px);
65
+ object-fit: contain;
66
+ }
67
+
68
+ svg path {
69
+ fill: var(--icon-color, currentcolor);
70
+ }
71
+
72
+ span {
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: center;
76
+ color: var(--icon-color, currentcolor);
77
+ }
78
+
79
+ &.--background-shape-circle {
80
+ --icon-background-shape: circle(50% at 50% 50%);
81
+ }
82
+
83
+ &.--background-shape-triangle {
84
+ --icon-background-shape: polygon(50% 0%, 0% 100%, 100% 100%);
85
+ }
86
+
87
+ &.--background-shape-rhombus {
88
+ --icon-background-shape: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
89
+ }
90
+
91
+ &.--background-shape-octagon {
92
+ --icon-background-shape: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%);
93
+ }
94
+
95
+ &.--background-shape-bevel {
96
+ --icon-background-shape: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);
97
+ }
98
+
99
+ &.--background-shape-rabbet {
100
+ --icon-background-shape: polygon(
101
+ 0% 15%,
102
+ 15% 15%,
103
+ 15% 0%,
104
+ 85% 0%,
105
+ 85% 15%,
106
+ 100% 15%,
107
+ 100% 85%,
108
+ 85% 85%,
109
+ 85% 100%,
110
+ 15% 100%,
111
+ 15% 85%,
112
+ 0% 85%
113
+ );
114
+ }
115
+
116
+ &.--background-shape-parallelogram {
117
+ --icon-background-shape: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
118
+ }
119
+ }
@@ -0,0 +1,42 @@
1
+ import type {BlockConfiguration} from '@wordpress/blocks'
2
+ import {__} from '@wordpress/i18n'
3
+ import {DEFAULT_ALIGNMENTS, DEFAULT_ICON_BACKGROUND_SHAPES, DEFAULT_ICON_BACKGROUND_SIZE, DEFAULT_ICON_SIZE, ICON_TYPES} from './constants'
4
+ import {createBasicIconEdit} from './edit'
5
+ import type {BasicIconAttributes, BasicIconOptions} from './types'
6
+
7
+ export type {BasicIconAttributes, BasicIconOptions}
8
+
9
+ export function createBasicIconBlock(options: BasicIconOptions): BlockConfiguration<BasicIconAttributes> {
10
+ return {
11
+ name: options.name,
12
+ title: options.title ?? __('Ikona', 'brilo-blocks'),
13
+ description: options.description,
14
+ category: options.category ?? 'layout',
15
+ ...(options.parent && {parent: options.parent}),
16
+ icon: options.icon ?? 'star-filled',
17
+ supports: {html: false, customClassName: false},
18
+ attributes: {
19
+ icon: {
20
+ type: 'object',
21
+ default: {type: ICON_TYPES[0].value, src: '', media: {id: 0, alt: ''}},
22
+ },
23
+ style: {
24
+ type: 'object',
25
+ default: {
26
+ align: DEFAULT_ALIGNMENTS[0].value,
27
+ icon: {
28
+ size: DEFAULT_ICON_SIZE,
29
+ color: '',
30
+ background: '',
31
+ backgroundSize: DEFAULT_ICON_BACKGROUND_SIZE,
32
+ backgroundShape: DEFAULT_ICON_BACKGROUND_SHAPES[0].value,
33
+ borderColor: '',
34
+ borderWidth: 1,
35
+ },
36
+ },
37
+ },
38
+ },
39
+ edit: createBasicIconEdit(options),
40
+ save: () => null,
41
+ } as unknown as BlockConfiguration<BasicIconAttributes>
42
+ }
@@ -0,0 +1,17 @@
1
+ export type {
2
+ BasicIconAlignment,
3
+ BasicIconAttributes,
4
+ BasicIconBackgroundShape,
5
+ BasicIconOptions,
6
+ BasicIconStyle,
7
+ } from './types'
8
+ export {createBasicIconBlock} from './factory'
9
+
10
+ import type {BasicIconOptions} from './types'
11
+
12
+ export const basicIconDefaults: BasicIconOptions = {
13
+ name: 'brilo/basic-icon',
14
+ parent: ['brilo/base-section'],
15
+ icons: [],
16
+ iconsSrc: '',
17
+ }