@brilo/base-blocks 0.1.22 → 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.
Files changed (162) hide show
  1. package/build/.tsbuildinfo +1 -1
  2. package/build/blocks/anchor/anchor-group/constants.d.ts +24 -0
  3. package/build/blocks/anchor/anchor-group/constants.d.ts.map +1 -0
  4. package/build/blocks/anchor/anchor-group/constants.js +12 -0
  5. package/build/blocks/anchor/anchor-group/edit.d.ts +6 -0
  6. package/build/blocks/anchor/anchor-group/edit.d.ts.map +1 -0
  7. package/build/blocks/anchor/anchor-group/edit.js +28 -0
  8. package/build/blocks/anchor/anchor-group/factory.d.ts +7 -0
  9. package/build/blocks/anchor/anchor-group/factory.d.ts.map +1 -0
  10. package/build/blocks/anchor/anchor-group/factory.js +33 -0
  11. package/build/blocks/anchor/anchor-group/index.d.ts +6 -0
  12. package/build/blocks/anchor/anchor-group/index.d.ts.map +1 -0
  13. package/build/blocks/anchor/anchor-group/index.js +7 -0
  14. package/build/blocks/anchor/anchor-group/types.d.ts +13 -0
  15. package/build/blocks/anchor/anchor-group/types.d.ts.map +1 -0
  16. package/build/blocks/anchor/anchor-group/types.js +1 -0
  17. package/build/blocks/anchor/anchor-item/constants.d.ts +13 -0
  18. package/build/blocks/anchor/anchor-item/constants.d.ts.map +1 -0
  19. package/build/blocks/anchor/anchor-item/constants.js +7 -0
  20. package/build/blocks/anchor/anchor-item/edit.d.ts +6 -0
  21. package/build/blocks/anchor/anchor-item/edit.d.ts.map +1 -0
  22. package/build/blocks/anchor/anchor-item/edit.js +24 -0
  23. package/build/blocks/anchor/anchor-item/factory.d.ts +5 -0
  24. package/build/blocks/anchor/anchor-item/factory.d.ts.map +1 -0
  25. package/build/blocks/anchor/anchor-item/factory.js +25 -0
  26. package/build/blocks/anchor/anchor-item/index.d.ts +7 -0
  27. package/build/blocks/anchor/anchor-item/index.d.ts.map +1 -0
  28. package/build/blocks/anchor/anchor-item/index.js +9 -0
  29. package/build/blocks/anchor/anchor-item/types.d.ts +18 -0
  30. package/build/blocks/anchor/anchor-item/types.d.ts.map +1 -0
  31. package/build/blocks/anchor/anchor-item/types.js +1 -0
  32. package/build/blocks/layout/layout-aside/constants.d.ts +2 -0
  33. package/build/blocks/layout/layout-aside/constants.d.ts.map +1 -0
  34. package/build/blocks/layout/layout-aside/constants.js +1 -0
  35. package/build/blocks/layout/layout-aside/edit.d.ts +4 -0
  36. package/build/blocks/layout/layout-aside/edit.d.ts.map +1 -0
  37. package/build/blocks/layout/layout-aside/edit.js +13 -0
  38. package/build/blocks/layout/layout-aside/factory.d.ts +4 -0
  39. package/build/blocks/layout/layout-aside/factory.d.ts.map +1 -0
  40. package/build/blocks/layout/layout-aside/factory.js +20 -0
  41. package/build/blocks/layout/layout-aside/icon.d.ts +3 -0
  42. package/build/blocks/layout/layout-aside/icon.d.ts.map +1 -0
  43. package/build/blocks/layout/layout-aside/icon.js +2 -0
  44. package/build/blocks/layout/layout-aside/index.d.ts +5 -0
  45. package/build/blocks/layout/layout-aside/index.d.ts.map +1 -0
  46. package/build/blocks/layout/layout-aside/index.js +5 -0
  47. package/build/blocks/layout/layout-aside/types.d.ts +6 -0
  48. package/build/blocks/layout/layout-aside/types.d.ts.map +1 -0
  49. package/build/blocks/layout/layout-aside/types.js +1 -0
  50. package/build/blocks/layout/layout-content/constants.d.ts +2 -0
  51. package/build/blocks/layout/layout-content/constants.d.ts.map +1 -0
  52. package/build/blocks/layout/layout-content/constants.js +1 -0
  53. package/build/blocks/layout/layout-content/edit.d.ts +4 -0
  54. package/build/blocks/layout/layout-content/edit.d.ts.map +1 -0
  55. package/build/blocks/layout/layout-content/edit.js +13 -0
  56. package/build/blocks/layout/layout-content/factory.d.ts +4 -0
  57. package/build/blocks/layout/layout-content/factory.d.ts.map +1 -0
  58. package/build/blocks/layout/layout-content/factory.js +20 -0
  59. package/build/blocks/layout/layout-content/icon.d.ts +3 -0
  60. package/build/blocks/layout/layout-content/icon.d.ts.map +1 -0
  61. package/build/blocks/layout/layout-content/icon.js +2 -0
  62. package/build/blocks/layout/layout-content/index.d.ts +5 -0
  63. package/build/blocks/layout/layout-content/index.d.ts.map +1 -0
  64. package/build/blocks/layout/layout-content/index.js +5 -0
  65. package/build/blocks/layout/layout-content/types.d.ts +6 -0
  66. package/build/blocks/layout/layout-content/types.d.ts.map +1 -0
  67. package/build/blocks/layout/layout-content/types.js +1 -0
  68. package/build/blocks/layout/layout-content-w-aside/constants.d.ts +11 -0
  69. package/build/blocks/layout/layout-content-w-aside/constants.d.ts.map +1 -0
  70. package/build/blocks/layout/layout-content-w-aside/constants.js +6 -0
  71. package/build/blocks/layout/layout-content-w-aside/edit.d.ts +7 -0
  72. package/build/blocks/layout/layout-content-w-aside/edit.d.ts.map +1 -0
  73. package/build/blocks/layout/layout-content-w-aside/edit.js +22 -0
  74. package/build/blocks/layout/layout-content-w-aside/factory.d.ts +6 -0
  75. package/build/blocks/layout/layout-content-w-aside/factory.d.ts.map +1 -0
  76. package/build/blocks/layout/layout-content-w-aside/factory.js +26 -0
  77. package/build/blocks/layout/layout-content-w-aside/icon.d.ts +3 -0
  78. package/build/blocks/layout/layout-content-w-aside/icon.d.ts.map +1 -0
  79. package/build/blocks/layout/layout-content-w-aside/icon.js +2 -0
  80. package/build/blocks/layout/layout-content-w-aside/index.d.ts +5 -0
  81. package/build/blocks/layout/layout-content-w-aside/index.d.ts.map +1 -0
  82. package/build/blocks/layout/layout-content-w-aside/index.js +9 -0
  83. package/build/blocks/layout/layout-content-w-aside/types.d.ts +10 -0
  84. package/build/blocks/layout/layout-content-w-aside/types.d.ts.map +1 -0
  85. package/build/blocks/layout/layout-content-w-aside/types.js +1 -0
  86. package/build/blocks/post/posts-grid/constants.d.ts +4 -0
  87. package/build/blocks/post/posts-grid/constants.d.ts.map +1 -0
  88. package/build/blocks/post/posts-grid/constants.js +3 -0
  89. package/build/blocks/post/posts-grid/edit.d.ts +6 -0
  90. package/build/blocks/post/posts-grid/edit.d.ts.map +1 -0
  91. package/build/blocks/post/posts-grid/edit.js +21 -0
  92. package/build/blocks/post/posts-grid/factory.d.ts +5 -0
  93. package/build/blocks/post/posts-grid/factory.d.ts.map +1 -0
  94. package/build/blocks/post/posts-grid/factory.js +59 -0
  95. package/build/blocks/post/posts-grid/icon.d.ts +2 -0
  96. package/build/blocks/post/posts-grid/icon.d.ts.map +1 -0
  97. package/build/blocks/post/posts-grid/icon.js +2 -0
  98. package/build/blocks/post/posts-grid/index.d.ts +5 -0
  99. package/build/blocks/post/posts-grid/index.d.ts.map +1 -0
  100. package/build/blocks/post/posts-grid/index.js +5 -0
  101. package/build/blocks/post/posts-grid/types.d.ts +22 -0
  102. package/build/blocks/post/posts-grid/types.d.ts.map +1 -0
  103. package/build/blocks/post/posts-grid/types.js +1 -0
  104. package/build/blocks/sections/base-section/attributes.d.ts +4 -0
  105. package/build/blocks/sections/base-section/attributes.d.ts.map +1 -1
  106. package/build/blocks/sections/base-section/attributes.js +4 -0
  107. package/build/blocks/sections/base-section/constants.d.ts +7 -0
  108. package/build/blocks/sections/base-section/constants.d.ts.map +1 -1
  109. package/build/blocks/sections/base-section/constants.js +7 -0
  110. package/build/blocks/sections/base-section/controls.d.ts.map +1 -1
  111. package/build/blocks/sections/base-section/controls.js +23 -5
  112. package/build/blocks/sections/base-section/types.d.ts +18 -1
  113. package/build/blocks/sections/base-section/types.d.ts.map +1 -1
  114. package/build/index.d.ts +12 -0
  115. package/build/index.d.ts.map +1 -1
  116. package/build/index.js +6 -0
  117. package/package.json +1 -1
  118. package/src/blocks/anchor/anchor-group/constants.ts +14 -0
  119. package/src/blocks/anchor/anchor-group/edit.tsx +70 -0
  120. package/src/blocks/anchor/anchor-group/editor.scss +52 -0
  121. package/src/blocks/anchor/anchor-group/factory.tsx +43 -0
  122. package/src/blocks/anchor/anchor-group/index.ts +11 -0
  123. package/src/blocks/anchor/anchor-group/types.ts +19 -0
  124. package/src/blocks/anchor/anchor-item/constants.ts +10 -0
  125. package/src/blocks/anchor/anchor-item/edit.tsx +96 -0
  126. package/src/blocks/anchor/anchor-item/editor.scss +22 -0
  127. package/src/blocks/anchor/anchor-item/factory.tsx +29 -0
  128. package/src/blocks/anchor/anchor-item/index.ts +13 -0
  129. package/src/blocks/anchor/anchor-item/types.ts +16 -0
  130. package/src/blocks/layout/layout-aside/constants.ts +1 -0
  131. package/src/blocks/layout/layout-aside/edit.tsx +20 -0
  132. package/src/blocks/layout/layout-aside/editor.scss +9 -0
  133. package/src/blocks/layout/layout-aside/factory.tsx +24 -0
  134. package/src/blocks/layout/layout-aside/icon.tsx +12 -0
  135. package/src/blocks/layout/layout-aside/index.ts +9 -0
  136. package/src/blocks/layout/layout-aside/types.ts +5 -0
  137. package/src/blocks/layout/layout-content/constants.ts +1 -0
  138. package/src/blocks/layout/layout-content/edit.tsx +20 -0
  139. package/src/blocks/layout/layout-content/editor.scss +9 -0
  140. package/src/blocks/layout/layout-content/factory.tsx +24 -0
  141. package/src/blocks/layout/layout-content/icon.tsx +12 -0
  142. package/src/blocks/layout/layout-content/index.ts +9 -0
  143. package/src/blocks/layout/layout-content/types.ts +5 -0
  144. package/src/blocks/layout/layout-content-w-aside/constants.ts +7 -0
  145. package/src/blocks/layout/layout-content-w-aside/edit.tsx +52 -0
  146. package/src/blocks/layout/layout-content-w-aside/editor.scss +35 -0
  147. package/src/blocks/layout/layout-content-w-aside/factory.tsx +34 -0
  148. package/src/blocks/layout/layout-content-w-aside/icon.tsx +12 -0
  149. package/src/blocks/layout/layout-content-w-aside/index.ts +13 -0
  150. package/src/blocks/layout/layout-content-w-aside/types.ts +12 -0
  151. package/src/blocks/post/posts-grid/constants.ts +3 -0
  152. package/src/blocks/post/posts-grid/edit.tsx +105 -0
  153. package/src/blocks/post/posts-grid/factory.tsx +63 -0
  154. package/src/blocks/post/posts-grid/icon.tsx +8 -0
  155. package/src/blocks/post/posts-grid/index.ts +9 -0
  156. package/src/blocks/post/posts-grid/types.ts +25 -0
  157. package/src/blocks/sections/base-section/attributes.ts +4 -0
  158. package/src/blocks/sections/base-section/constants.ts +10 -0
  159. package/src/blocks/sections/base-section/controls.tsx +83 -4
  160. package/src/blocks/sections/base-section/types.ts +20 -1
  161. package/src/editor.scss +5 -0
  162. package/src/index.ts +19 -0
@@ -0,0 +1,70 @@
1
+ import {InspectorControls} from '@wordpress/block-editor'
2
+ import {
3
+ PanelBody,
4
+ __experimentalToggleGroupControl as ToggleGroupControl,
5
+ __experimentalToggleGroupControlOption as ToggleGroupControlOption,
6
+ } from '@wordpress/components'
7
+ import {__} from '@wordpress/i18n'
8
+ import clsx from 'clsx'
9
+ import {useGroupBlock} from '~/hooks/useGroupBlock'
10
+ import {ANCHOR_ALIGNMENTS, ANCHOR_COLUMNS} from './constants'
11
+ import type {AnchorAlignment, AnchorColumns, AnchorGroupAttributes, AnchorGroupOptions} from './types'
12
+
13
+ export function createAnchorGroupEdit(options: AnchorGroupOptions) {
14
+ const columnsOptions = options.columnsOptions ?? ANCHOR_COLUMNS
15
+ const alignments = options.alignments ?? ANCHOR_ALIGNMENTS
16
+
17
+ return function Edit({
18
+ attributes,
19
+ setAttributes,
20
+ }: {
21
+ attributes: AnchorGroupAttributes
22
+ setAttributes: (a: Partial<AnchorGroupAttributes>) => void
23
+ }) {
24
+ const {columns, align} = attributes
25
+
26
+ const {blockProps, innerBlocksProps} = useGroupBlock({
27
+ blockClassName: clsx(options.blockClassName ?? 'g-anchors'),
28
+ containerClassName: [
29
+ options.containerClassName ?? 'g-anchors__inner',
30
+ columns === 'auto' ? '--auto' : `u-grid-responsive --cols-${columns}`,
31
+ align === 'center' && 'justify-content-center',
32
+ ],
33
+ allowedBlocks: options.allowedBlocks,
34
+ template: options.template,
35
+ layout: {type: 'default'},
36
+ })
37
+
38
+ return (
39
+ <>
40
+ <InspectorControls>
41
+ <PanelBody title={__('Kotvy', 'brilo-blocks')}>
42
+ <ToggleGroupControl
43
+ isBlock
44
+ label={__('Počet sloupců', 'brilo-blocks')}
45
+ value={columns}
46
+ onChange={(v) => setAttributes({columns: v as AnchorColumns})}
47
+ >
48
+ {columnsOptions.map((c) => (
49
+ <ToggleGroupControlOption key={c.value} value={c.value} label={c.label} />
50
+ ))}
51
+ </ToggleGroupControl>
52
+ <ToggleGroupControl
53
+ isBlock
54
+ label={__('Zarovnání', 'brilo-blocks')}
55
+ value={align}
56
+ onChange={(v) => setAttributes({align: v as AnchorAlignment})}
57
+ >
58
+ {alignments.map((a) => (
59
+ <ToggleGroupControlOption key={a.value} value={a.value} label={a.label} />
60
+ ))}
61
+ </ToggleGroupControl>
62
+ </PanelBody>
63
+ </InspectorControls>
64
+ <div {...blockProps}>
65
+ <div {...innerBlocksProps} />
66
+ </div>
67
+ </>
68
+ )
69
+ }
70
+ }
@@ -0,0 +1,52 @@
1
+ @layer base {
2
+ .g-anchors {
3
+ border: 1px solid #eee;
4
+ padding: 16px;
5
+
6
+ .g-anchors__inner {
7
+ &.--auto {
8
+ display: flex;
9
+ flex-wrap: wrap;
10
+ gap: 8px;
11
+ }
12
+
13
+ // .u-grid-responsive itself is a frontoffice utility class, not loaded in the
14
+ // editor bundle — recreate just enough of it here for the admin preview.
15
+ &.u-grid-responsive {
16
+ display: grid;
17
+ grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
18
+ gap: 16px;
19
+
20
+ &.--cols-2 {
21
+ grid-template-columns: repeat(2, minmax(0, 1fr));
22
+ }
23
+
24
+ &.--cols-3 {
25
+ grid-template-columns: repeat(3, minmax(0, 1fr));
26
+ }
27
+
28
+ &.--cols-4 {
29
+ grid-template-columns: repeat(4, minmax(0, 1fr));
30
+ }
31
+
32
+ &.--cols-6 {
33
+ grid-template-columns: repeat(6, minmax(0, 1fr));
34
+ }
35
+ }
36
+
37
+ &.justify-content-center {
38
+ justify-content: center;
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ // WP core sets `margin-left/right: auto` on `.wp-block` children of containers whose
45
+ // layout type isn't flex/grid (ours is `default`). That rule is UNLAYERED, so a
46
+ // layered override can't beat it regardless of specificity — keep this UNLAYERED and
47
+ // bump above WP's (0,2,0) specificity to win. Matches contact-group's editor.scss.
48
+ .editor-styles-wrapper .g-anchors__inner > .wp-block {
49
+ margin-left: 0;
50
+ margin-right: 0;
51
+ max-width: none;
52
+ }
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export const ASIDE_DEFAULTS = {}
@@ -0,0 +1,20 @@
1
+ import React from 'react'
2
+ import {useGroupBlock} from '~/hooks/useGroupBlock'
3
+ import type {AsideAttributes, AsideOptions} from './types'
4
+
5
+ export function createAsideEdit(options: AsideOptions) {
6
+ return function Edit() {
7
+ const {blockProps, innerBlocksProps} = useGroupBlock({
8
+ blockClassName: 'l-content-w-aside__aside',
9
+ containerClassName: 'l-content-w-aside__aside-container',
10
+ layout: {type: 'default'},
11
+ orientation: 'vertical',
12
+ })
13
+
14
+ return (
15
+ <aside {...blockProps}>
16
+ <div {...innerBlocksProps} />
17
+ </aside>
18
+ )
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ @layer base {
2
+ .l-content-w-aside__aside {
3
+ width: var(--aside-width, 300px);
4
+ border: 2px dashed #0073aa;
5
+ box-sizing: border-box;
6
+ padding: 8px;
7
+ min-height: 120px;
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ import {InnerBlocks} from '@wordpress/block-editor'
2
+ import type {BlockConfiguration} from '@wordpress/blocks'
3
+ import {__} from '@wordpress/i18n'
4
+ import React from 'react'
5
+ import {createAsideEdit} from './edit'
6
+ import {icon as defaultIcon} from './icon'
7
+ import type {AsideAttributes, AsideOptions} from './types'
8
+
9
+ export function createAsideBlock(
10
+ options: AsideOptions,
11
+ ): BlockConfiguration<AsideAttributes> {
12
+ return {
13
+ name: options.name,
14
+ title: options.title ?? __('Postranní panel', 'brilo-blocks'),
15
+ description: options.description,
16
+ category: options.category ?? 'layout',
17
+ parent: options.parent,
18
+ icon: options.icon ?? {src: defaultIcon},
19
+ supports: {html: false, customClassName: false},
20
+ attributes: {},
21
+ edit: createAsideEdit(options),
22
+ save: () => <InnerBlocks.Content />,
23
+ } as BlockConfiguration<AsideAttributes>
24
+ }
@@ -0,0 +1,12 @@
1
+ import React from 'react'
2
+
3
+ export const icon = (
4
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
5
+ <path
6
+ fillRule="evenodd"
7
+ clipRule="evenodd"
8
+ d="M8 4H20V20H8V4ZM10 6H18V18H10V6Z"
9
+ fill="currentColor"
10
+ />
11
+ </svg>
12
+ )
@@ -0,0 +1,9 @@
1
+ export type {AsideAttributes, AsideOptions} from './types'
2
+ export {createAsideBlock} from './factory'
3
+
4
+ import type {AsideOptions} from './types'
5
+
6
+ export const asideDefaults: AsideOptions = {
7
+ name: 'brilo/layout-aside',
8
+ parent: ['brilo/layout-content-w-aside'],
9
+ }
@@ -0,0 +1,5 @@
1
+ import type {BriloBlockType} from '~/types'
2
+
3
+ export interface AsideAttributes extends Record<string, unknown> {}
4
+
5
+ export interface AsideOptions extends BriloBlockType {}
@@ -0,0 +1 @@
1
+ export const CONTENT_DEFAULTS = {}
@@ -0,0 +1,20 @@
1
+ import React from 'react'
2
+ import {useGroupBlock} from '~/hooks/useGroupBlock'
3
+ import type {ContentAttributes, ContentOptions} from './types'
4
+
5
+ export function createContentEdit(options: ContentOptions) {
6
+ return function Edit() {
7
+ const {blockProps, innerBlocksProps} = useGroupBlock({
8
+ blockClassName: 'l-content-w-aside__content',
9
+ containerClassName: 'l-content-w-aside__content-container',
10
+ layout: {type: 'default'},
11
+ orientation: 'vertical',
12
+ })
13
+
14
+ return (
15
+ <div {...blockProps}>
16
+ <div {...innerBlocksProps} />
17
+ </div>
18
+ )
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ @layer base {
2
+ .l-content-w-aside__content {
3
+ border: 2px dashed #0073aa;
4
+ width: 100%;
5
+ box-sizing: border-box;
6
+ padding: 8px;
7
+ min-height: 120px;
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ import {InnerBlocks} from '@wordpress/block-editor'
2
+ import type {BlockConfiguration} from '@wordpress/blocks'
3
+ import {__} from '@wordpress/i18n'
4
+ import React from 'react'
5
+ import {createContentEdit} from './edit'
6
+ import {icon as defaultIcon} from './icon'
7
+ import type {ContentAttributes, ContentOptions} from './types'
8
+
9
+ export function createContentBlock(
10
+ options: ContentOptions,
11
+ ): BlockConfiguration<ContentAttributes> {
12
+ return {
13
+ name: options.name,
14
+ title: options.title ?? __('Obsah', 'brilo-blocks'),
15
+ description: options.description,
16
+ category: options.category ?? 'layout',
17
+ parent: options.parent,
18
+ icon: options.icon ?? {src: defaultIcon},
19
+ supports: {html: false, customClassName: false},
20
+ attributes: {},
21
+ edit: createContentEdit(options),
22
+ save: () => <InnerBlocks.Content />,
23
+ } as BlockConfiguration<ContentAttributes>
24
+ }
@@ -0,0 +1,12 @@
1
+ import React from 'react'
2
+
3
+ export const icon = (
4
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
5
+ <path
6
+ fillRule="evenodd"
7
+ clipRule="evenodd"
8
+ d="M4 4H16V20H4V4ZM6 6H14V18H6V6Z"
9
+ fill="currentColor"
10
+ />
11
+ </svg>
12
+ )
@@ -0,0 +1,9 @@
1
+ export type {ContentAttributes, ContentOptions} from './types'
2
+ export {createContentBlock} from './factory'
3
+
4
+ import type {ContentOptions} from './types'
5
+
6
+ export const contentDefaults: ContentOptions = {
7
+ name: 'brilo/layout-content',
8
+ parent: ['brilo/layout-content-w-aside'],
9
+ }
@@ -0,0 +1,5 @@
1
+ import type {BriloBlockType} from '~/types'
2
+
3
+ export interface ContentAttributes extends Record<string, unknown> {}
4
+
5
+ export interface ContentOptions extends BriloBlockType {}
@@ -0,0 +1,7 @@
1
+ import {__} from '@wordpress/i18n'
2
+
3
+ export const ASIDE_SIZES = [
4
+ {value: 'sm', label: __('Malá', 'brilo-blocks')},
5
+ {value: 'md', label: __('Střední', 'brilo-blocks')},
6
+ {value: 'lg', label: __('Velká', 'brilo-blocks')},
7
+ ] as const
@@ -0,0 +1,52 @@
1
+ import {InspectorControls} from '@wordpress/block-editor'
2
+ import {PanelBody, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption} from '@wordpress/components'
3
+ import {__} from '@wordpress/i18n'
4
+ import React from 'react'
5
+ import {useGroupBlock} from '~/hooks/useGroupBlock'
6
+ import {ASIDE_SIZES} from './constants'
7
+ import type {AsideSize, ContentWithAsideAttributes, ContentWithAsideOptions} from './types'
8
+
9
+ export function createContentWithAsideEdit(options: ContentWithAsideOptions) {
10
+ const ASIDE_SIZES_OPTIONS = options.asideSizes ?? ASIDE_SIZES
11
+
12
+ return function Edit({
13
+ attributes,
14
+ setAttributes,
15
+ }: {
16
+ attributes: ContentWithAsideAttributes
17
+ setAttributes: (a: Partial<ContentWithAsideAttributes>) => void
18
+ }) {
19
+ const {asideSize} = attributes
20
+
21
+ const {blockProps, innerBlocksProps} = useGroupBlock({
22
+ blockClassName: 'l-content-w-aside',
23
+ containerClassName: `l-content-w-aside__container --aside-${asideSize}`,
24
+ template: options.template,
25
+ allowedBlocks: options.allowedBlocks,
26
+ orientation: 'horizontal',
27
+ layout: {type: 'default'},
28
+ })
29
+
30
+ return (
31
+ <>
32
+ <InspectorControls>
33
+ <PanelBody title={__('Nastavení', 'brilo-blocks')}>
34
+ <ToggleGroupControl
35
+ isBlock
36
+ label={__('Velikost postranního panelu', 'brilo-blocks')}
37
+ value={asideSize}
38
+ onChange={(v) => setAttributes({asideSize: v as AsideSize})}
39
+ >
40
+ {ASIDE_SIZES_OPTIONS.map((s) => (
41
+ <ToggleGroupControlOption key={s.value} value={s.value} label={s.label} />
42
+ ))}
43
+ </ToggleGroupControl>
44
+ </PanelBody>
45
+ </InspectorControls>
46
+ <div {...blockProps}>
47
+ <div {...innerBlocksProps} />
48
+ </div>
49
+ </>
50
+ )
51
+ }
52
+ }