@brilo/base-blocks 0.1.0

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 (254) hide show
  1. package/.editorconfig +12 -0
  2. package/.prettierrc +8 -0
  3. package/README.md +59 -0
  4. package/USAGE.md +263 -0
  5. package/biome.json +38 -0
  6. package/bun.lock +1392 -0
  7. package/docs/block-anatomy.md +73 -0
  8. package/docs/conventions.md +204 -0
  9. package/docs/new-block.md +179 -0
  10. package/package.json +41 -0
  11. package/src/blocks/column/column-group/edit.tsx +56 -0
  12. package/src/blocks/column/column-group/editor.scss +7 -0
  13. package/src/blocks/column/column-group/factory.tsx +29 -0
  14. package/src/blocks/column/column-group/index.ts +14 -0
  15. package/src/blocks/column/column-group/types.ts +8 -0
  16. package/src/blocks/column/column-item/constants.ts +1 -0
  17. package/src/blocks/column/column-item/edit.tsx +48 -0
  18. package/src/blocks/column/column-item/editor.scss +34 -0
  19. package/src/blocks/column/column-item/factory.tsx +25 -0
  20. package/src/blocks/column/column-item/index.ts +10 -0
  21. package/src/blocks/column/column-item/types.ts +7 -0
  22. package/src/blocks/compare/compare-group/constants.ts +1 -0
  23. package/src/blocks/compare/compare-group/edit.tsx +52 -0
  24. package/src/blocks/compare/compare-group/factory.tsx +29 -0
  25. package/src/blocks/compare/compare-group/icon.tsx +7 -0
  26. package/src/blocks/compare/compare-group/index.ts +13 -0
  27. package/src/blocks/compare/compare-group/types.ts +12 -0
  28. package/src/blocks/compare/compare-item/edit.tsx +38 -0
  29. package/src/blocks/compare/compare-item/editor.scss +15 -0
  30. package/src/blocks/compare/compare-item/factory.tsx +28 -0
  31. package/src/blocks/compare/compare-item/icon.tsx +9 -0
  32. package/src/blocks/compare/compare-item/index.ts +13 -0
  33. package/src/blocks/compare/compare-item/types.ts +9 -0
  34. package/src/blocks/compare/compare-option/constants.ts +7 -0
  35. package/src/blocks/compare/compare-option/edit.tsx +64 -0
  36. package/src/blocks/compare/compare-option/editor.scss +26 -0
  37. package/src/blocks/compare/compare-option/factory.tsx +35 -0
  38. package/src/blocks/compare/compare-option/icon.tsx +7 -0
  39. package/src/blocks/compare/compare-option/index.ts +8 -0
  40. package/src/blocks/compare/compare-option/types.ts +12 -0
  41. package/src/blocks/contact/contact-group/constants.ts +3 -0
  42. package/src/blocks/contact/contact-group/edit.tsx +57 -0
  43. package/src/blocks/contact/contact-group/editor.scss +20 -0
  44. package/src/blocks/contact/contact-group/factory.tsx +35 -0
  45. package/src/blocks/contact/contact-group/index.ts +12 -0
  46. package/src/blocks/contact/contact-group/types.ts +12 -0
  47. package/src/blocks/contact/contact-item/constants.ts +17 -0
  48. package/src/blocks/contact/contact-item/edit.tsx +93 -0
  49. package/src/blocks/contact/contact-item/editor.scss +38 -0
  50. package/src/blocks/contact/contact-item/factory.tsx +35 -0
  51. package/src/blocks/contact/contact-item/index.ts +23 -0
  52. package/src/blocks/contact/contact-item/types.ts +21 -0
  53. package/src/blocks/core/basic-button/constants.ts +17 -0
  54. package/src/blocks/core/basic-button/edit.tsx +107 -0
  55. package/src/blocks/core/basic-button/editor.scss +80 -0
  56. package/src/blocks/core/basic-button/factory.tsx +54 -0
  57. package/src/blocks/core/basic-button/index.ts +8 -0
  58. package/src/blocks/core/basic-button/types.ts +29 -0
  59. package/src/blocks/core/basic-heading/constants.ts +1 -0
  60. package/src/blocks/core/basic-heading/edit.tsx +76 -0
  61. package/src/blocks/core/basic-heading/editor.scss +8 -0
  62. package/src/blocks/core/basic-heading/factory.tsx +40 -0
  63. package/src/blocks/core/basic-heading/index.ts +8 -0
  64. package/src/blocks/core/basic-heading/types.ts +20 -0
  65. package/src/blocks/core/basic-overline/edit.tsx +28 -0
  66. package/src/blocks/core/basic-overline/editor.scss +14 -0
  67. package/src/blocks/core/basic-overline/factory.tsx +22 -0
  68. package/src/blocks/core/basic-overline/index.ts +8 -0
  69. package/src/blocks/core/basic-overline/types.ts +7 -0
  70. package/src/blocks/faq/faq-group/constants.ts +11 -0
  71. package/src/blocks/faq/faq-group/edit.tsx +55 -0
  72. package/src/blocks/faq/faq-group/editor.scss +11 -0
  73. package/src/blocks/faq/faq-group/factory.tsx +39 -0
  74. package/src/blocks/faq/faq-group/index.ts +11 -0
  75. package/src/blocks/faq/faq-group/types.ts +14 -0
  76. package/src/blocks/faq/faq-item/edit.tsx +50 -0
  77. package/src/blocks/faq/faq-item/editor.scss +57 -0
  78. package/src/blocks/faq/faq-item/factory.tsx +24 -0
  79. package/src/blocks/faq/faq-item/index.ts +9 -0
  80. package/src/blocks/faq/faq-item/types.ts +7 -0
  81. package/src/blocks/form/form-field/constants.ts +14 -0
  82. package/src/blocks/form/form-field/edit.tsx +178 -0
  83. package/src/blocks/form/form-field/editor.scss +71 -0
  84. package/src/blocks/form/form-field/factory.tsx +32 -0
  85. package/src/blocks/form/form-field/index.ts +10 -0
  86. package/src/blocks/form/form-field/types.ts +18 -0
  87. package/src/blocks/form/form-group/constants.ts +16 -0
  88. package/src/blocks/form/form-group/edit.tsx +190 -0
  89. package/src/blocks/form/form-group/editor.scss +41 -0
  90. package/src/blocks/form/form-group/factory.tsx +35 -0
  91. package/src/blocks/form/form-group/index.ts +18 -0
  92. package/src/blocks/form/form-group/types.ts +22 -0
  93. package/src/blocks/groups/banner-group/constants.ts +15 -0
  94. package/src/blocks/groups/banner-group/edit.tsx +122 -0
  95. package/src/blocks/groups/banner-group/editor.scss +18 -0
  96. package/src/blocks/groups/banner-group/factory.tsx +64 -0
  97. package/src/blocks/groups/banner-group/icon.tsx +13 -0
  98. package/src/blocks/groups/banner-group/index.ts +11 -0
  99. package/src/blocks/groups/banner-group/types.ts +30 -0
  100. package/src/blocks/groups/basic-header-group/constants.ts +9 -0
  101. package/src/blocks/groups/basic-header-group/edit.tsx +99 -0
  102. package/src/blocks/groups/basic-header-group/editor.scss +35 -0
  103. package/src/blocks/groups/basic-header-group/factory.tsx +46 -0
  104. package/src/blocks/groups/basic-header-group/icon.tsx +17 -0
  105. package/src/blocks/groups/basic-header-group/index.ts +9 -0
  106. package/src/blocks/groups/basic-header-group/types.ts +27 -0
  107. package/src/blocks/groups/button-group/constants.ts +7 -0
  108. package/src/blocks/groups/button-group/edit.tsx +52 -0
  109. package/src/blocks/groups/button-group/editor.scss +23 -0
  110. package/src/blocks/groups/button-group/factory.tsx +34 -0
  111. package/src/blocks/groups/button-group/index.ts +11 -0
  112. package/src/blocks/groups/button-group/types.ts +12 -0
  113. package/src/blocks/groups/text-and-media-group/constants.ts +43 -0
  114. package/src/blocks/groups/text-and-media-group/edit.tsx +241 -0
  115. package/src/blocks/groups/text-and-media-group/editor.scss +123 -0
  116. package/src/blocks/groups/text-and-media-group/factory.tsx +100 -0
  117. package/src/blocks/groups/text-and-media-group/icon.tsx +37 -0
  118. package/src/blocks/groups/text-and-media-group/index.ts +18 -0
  119. package/src/blocks/groups/text-and-media-group/types.ts +60 -0
  120. package/src/blocks/hero/hero-group/constants.ts +23 -0
  121. package/src/blocks/hero/hero-group/edit.tsx +85 -0
  122. package/src/blocks/hero/hero-group/editor.scss +0 -0
  123. package/src/blocks/hero/hero-group/factory.tsx +45 -0
  124. package/src/blocks/hero/hero-group/icon.tsx +28 -0
  125. package/src/blocks/hero/hero-group/index.ts +11 -0
  126. package/src/blocks/hero/hero-group/types.ts +22 -0
  127. package/src/blocks/hero/hero-item/constants.ts +15 -0
  128. package/src/blocks/hero/hero-item/edit.tsx +107 -0
  129. package/src/blocks/hero/hero-item/editor.scss +87 -0
  130. package/src/blocks/hero/hero-item/factory.tsx +49 -0
  131. package/src/blocks/hero/hero-item/index.ts +10 -0
  132. package/src/blocks/hero/hero-item/types.ts +38 -0
  133. package/src/blocks/map/map-group/constants.ts +20 -0
  134. package/src/blocks/map/map-group/edit.tsx +108 -0
  135. package/src/blocks/map/map-group/editor.scss +24 -0
  136. package/src/blocks/map/map-group/factory.tsx +51 -0
  137. package/src/blocks/map/map-group/index.ts +9 -0
  138. package/src/blocks/map/map-group/types.ts +16 -0
  139. package/src/blocks/newsletter/newsletter-form/constants.ts +5 -0
  140. package/src/blocks/newsletter/newsletter-form/edit.tsx +194 -0
  141. package/src/blocks/newsletter/newsletter-form/editor.scss +68 -0
  142. package/src/blocks/newsletter/newsletter-form/factory.tsx +59 -0
  143. package/src/blocks/newsletter/newsletter-form/index.ts +11 -0
  144. package/src/blocks/newsletter/newsletter-form/types.ts +45 -0
  145. package/src/blocks/post/post-slider-group/constants.ts +3 -0
  146. package/src/blocks/post/post-slider-group/edit.tsx +76 -0
  147. package/src/blocks/post/post-slider-group/factory.tsx +43 -0
  148. package/src/blocks/post/post-slider-group/icon.tsx +13 -0
  149. package/src/blocks/post/post-slider-group/index.ts +9 -0
  150. package/src/blocks/post/post-slider-group/types.ts +20 -0
  151. package/src/blocks/responsive-grid/responsive-grid-group/edit.tsx +95 -0
  152. package/src/blocks/responsive-grid/responsive-grid-group/factory.tsx +33 -0
  153. package/src/blocks/responsive-grid/responsive-grid-group/index.ts +13 -0
  154. package/src/blocks/responsive-grid/responsive-grid-group/types.ts +9 -0
  155. package/src/blocks/responsive-grid/responsive-grid-item/edit.tsx +19 -0
  156. package/src/blocks/responsive-grid/responsive-grid-item/factory.tsx +20 -0
  157. package/src/blocks/responsive-grid/responsive-grid-item/index.ts +9 -0
  158. package/src/blocks/responsive-grid/responsive-grid-item/types.ts +5 -0
  159. package/src/blocks/sections/base-section/attributes.ts +17 -0
  160. package/src/blocks/sections/base-section/constants.ts +18 -0
  161. package/src/blocks/sections/base-section/controls.tsx +70 -0
  162. package/src/blocks/sections/base-section/edit.tsx +34 -0
  163. package/src/blocks/sections/base-section/editor.scss +24 -0
  164. package/src/blocks/sections/base-section/factory.tsx +47 -0
  165. package/src/blocks/sections/base-section/icon.tsx +6 -0
  166. package/src/blocks/sections/base-section/index.ts +14 -0
  167. package/src/blocks/sections/base-section/types.ts +26 -0
  168. package/src/blocks/signpost/signpost-group/constants.ts +3 -0
  169. package/src/blocks/signpost/signpost-group/edit.tsx +75 -0
  170. package/src/blocks/signpost/signpost-group/editor.scss +0 -0
  171. package/src/blocks/signpost/signpost-group/factory.tsx +40 -0
  172. package/src/blocks/signpost/signpost-group/icon.tsx +19 -0
  173. package/src/blocks/signpost/signpost-group/index.ts +15 -0
  174. package/src/blocks/signpost/signpost-group/types.ts +9 -0
  175. package/src/blocks/signpost/signpost-item/constants.ts +4 -0
  176. package/src/blocks/signpost/signpost-item/edit.tsx +90 -0
  177. package/src/blocks/signpost/signpost-item/editor.scss +25 -0
  178. package/src/blocks/signpost/signpost-item/factory.tsx +29 -0
  179. package/src/blocks/signpost/signpost-item/icon.tsx +7 -0
  180. package/src/blocks/signpost/signpost-item/index.ts +10 -0
  181. package/src/blocks/signpost/signpost-item/types.ts +12 -0
  182. package/src/blocks/step/step-group/constants.ts +6 -0
  183. package/src/blocks/step/step-group/edit.tsx +64 -0
  184. package/src/blocks/step/step-group/editor.scss +19 -0
  185. package/src/blocks/step/step-group/factory.tsx +36 -0
  186. package/src/blocks/step/step-group/icon.tsx +27 -0
  187. package/src/blocks/step/step-group/index.ts +15 -0
  188. package/src/blocks/step/step-group/types.ts +13 -0
  189. package/src/blocks/step/step-item/constants.ts +6 -0
  190. package/src/blocks/step/step-item/edit.tsx +60 -0
  191. package/src/blocks/step/step-item/editor.scss +18 -0
  192. package/src/blocks/step/step-item/factory.tsx +27 -0
  193. package/src/blocks/step/step-item/index.ts +11 -0
  194. package/src/blocks/step/step-item/types.ts +12 -0
  195. package/src/blocks/testimonial/testimonial-group/constants.ts +27 -0
  196. package/src/blocks/testimonial/testimonial-group/edit.tsx +74 -0
  197. package/src/blocks/testimonial/testimonial-group/editor.scss +38 -0
  198. package/src/blocks/testimonial/testimonial-group/factory.tsx +44 -0
  199. package/src/blocks/testimonial/testimonial-group/icon.tsx +33 -0
  200. package/src/blocks/testimonial/testimonial-group/index.ts +15 -0
  201. package/src/blocks/testimonial/testimonial-group/types.ts +19 -0
  202. package/src/blocks/testimonial/testimonial-item/edit.tsx +48 -0
  203. package/src/blocks/testimonial/testimonial-item/editor.scss +20 -0
  204. package/src/blocks/testimonial/testimonial-item/factory.tsx +35 -0
  205. package/src/blocks/testimonial/testimonial-item/index.ts +9 -0
  206. package/src/blocks/testimonial/testimonial-item/types.ts +9 -0
  207. package/src/blocks/text-and-form/text-and-form-group/constants.ts +6 -0
  208. package/src/blocks/text-and-form/text-and-form-group/edit.tsx +59 -0
  209. package/src/blocks/text-and-form/text-and-form-group/editor.scss +21 -0
  210. package/src/blocks/text-and-form/text-and-form-group/factory.tsx +38 -0
  211. package/src/blocks/text-and-form/text-and-form-group/icon.tsx +23 -0
  212. package/src/blocks/text-and-form/text-and-form-group/index.ts +9 -0
  213. package/src/blocks/text-and-form/text-and-form-group/types.ts +23 -0
  214. package/src/blocks/text-and-form/text-and-form-text-column/constants.ts +10 -0
  215. package/src/blocks/text-and-form/text-and-form-text-column/edit.tsx +94 -0
  216. package/src/blocks/text-and-form/text-and-form-text-column/editor.scss +29 -0
  217. package/src/blocks/text-and-form/text-and-form-text-column/factory.tsx +41 -0
  218. package/src/blocks/text-and-form/text-and-form-text-column/index.ts +18 -0
  219. package/src/blocks/text-and-form/text-and-form-text-column/types.ts +23 -0
  220. package/src/blocks/usp/usp-group/constants.ts +54 -0
  221. package/src/blocks/usp/usp-group/edit.tsx +197 -0
  222. package/src/blocks/usp/usp-group/editor.scss +24 -0
  223. package/src/blocks/usp/usp-group/factory.tsx +113 -0
  224. package/src/blocks/usp/usp-group/icon.tsx +18 -0
  225. package/src/blocks/usp/usp-group/index.ts +15 -0
  226. package/src/blocks/usp/usp-group/types.ts +70 -0
  227. package/src/blocks/usp/usp-item/constants.ts +7 -0
  228. package/src/blocks/usp/usp-item/edit.tsx +65 -0
  229. package/src/blocks/usp/usp-item/editor.scss +17 -0
  230. package/src/blocks/usp/usp-item/factory.tsx +30 -0
  231. package/src/blocks/usp/usp-item/index.ts +11 -0
  232. package/src/blocks/usp/usp-item/types.ts +17 -0
  233. package/src/components/IconControl/IconControl.tsx +55 -0
  234. package/src/components/IconControl/editor.scss +53 -0
  235. package/src/components/IconControl/index.ts +2 -0
  236. package/src/components/IconControl/index.tsx +1 -0
  237. package/src/components/ImagePicker/ImagePicker.tsx +124 -0
  238. package/src/components/ImagePicker/editor.scss +79 -0
  239. package/src/components/ImagePicker/index.ts +2 -0
  240. package/src/components/ImagePicker/index.tsx +1 -0
  241. package/src/components/ItemIconControl/ItemIconControl.tsx +72 -0
  242. package/src/components/ItemIconControl/ItemIconModal.tsx +12 -0
  243. package/src/components/ItemIconControl/ItemIconPreview.tsx +93 -0
  244. package/src/components/ItemIconControl/editor.scss +52 -0
  245. package/src/components/ItemIconControl/index.ts +2 -0
  246. package/src/components/ItemIconControl/types.d.ts +30 -0
  247. package/src/constants.ts +20 -0
  248. package/src/editor.scss +34 -0
  249. package/src/globals.scss +237 -0
  250. package/src/hooks/useGroupBlock.ts +53 -0
  251. package/src/index.ts +122 -0
  252. package/src/types.ts +33 -0
  253. package/src/utils/createEditAdapter.ts +11 -0
  254. package/tsconfig.json +21 -0
@@ -0,0 +1,28 @@
1
+ import {RichText, useBlockProps} from '@wordpress/block-editor'
2
+ import {__} from '@wordpress/i18n'
3
+ import type {BasicOverlineAttributes, BasicOverlineOptions} from './types'
4
+
5
+ export function createBasicOverlineEdit(options: BasicOverlineOptions) {
6
+ return function Edit({
7
+ attributes,
8
+ setAttributes,
9
+ }: {
10
+ attributes: BasicOverlineAttributes
11
+ setAttributes: (a: Partial<BasicOverlineAttributes>) => void
12
+ }) {
13
+ const blockProps = useBlockProps({className: options.blockClassName ?? 'i-overline'})
14
+
15
+ return (
16
+ <div {...blockProps}>
17
+ <RichText
18
+ tagName="span"
19
+ className="i-overline__text u-text-editable"
20
+ value={attributes.title}
21
+ onChange={(value) => setAttributes({title: value})}
22
+ placeholder={__('Overline...', 'brilo-blocks')}
23
+ allowedFormats={[]}
24
+ />
25
+ </div>
26
+ )
27
+ }
28
+ }
@@ -0,0 +1,14 @@
1
+ @layer base {
2
+ .i-overline {
3
+ padding: 4px;
4
+ }
5
+
6
+ .i-overline__text {
7
+ display: inline-block;
8
+ font-size: 12px;
9
+ font-weight: 600;
10
+ text-transform: uppercase;
11
+ letter-spacing: 1px;
12
+ color: #888;
13
+ }
14
+ }
@@ -0,0 +1,22 @@
1
+ import type {BlockConfiguration} from '@wordpress/blocks'
2
+ import {__} from '@wordpress/i18n'
3
+ import {createBasicOverlineEdit} from './edit'
4
+ import type {BasicOverlineAttributes, BasicOverlineOptions} from './types'
5
+
6
+ export type {BasicOverlineAttributes, BasicOverlineOptions}
7
+
8
+ export function createBasicOverlineBlock(options: BasicOverlineOptions): BlockConfiguration<BasicOverlineAttributes> {
9
+ return {
10
+ name: options.name,
11
+ title: options.title ?? __('Overline', 'brilo-blocks'),
12
+ description: options.description,
13
+ category: options.category ?? 'text',
14
+ supports: {html: false, customClassName: false},
15
+ icon: options.icon ?? 'text',
16
+ attributes: {
17
+ title: {type: 'string', default: ''},
18
+ },
19
+ edit: createBasicOverlineEdit(options),
20
+ save: () => null,
21
+ } as unknown as BlockConfiguration<BasicOverlineAttributes>
22
+ }
@@ -0,0 +1,8 @@
1
+ export type {BasicOverlineAttributes, BasicOverlineOptions} from './types'
2
+ export {createBasicOverlineBlock} from './factory'
3
+
4
+ import type {BasicOverlineOptions} from './types'
5
+
6
+ export const basicOverlineDefaults: BasicOverlineOptions = {
7
+ name: 'brilo/basic-overline',
8
+ }
@@ -0,0 +1,7 @@
1
+ import {BriloBlockType} from '~/types'
2
+
3
+ export interface BasicOverlineAttributes extends Record<string, unknown> {
4
+ title: string
5
+ }
6
+
7
+ export interface BasicOverlineOptions extends BriloBlockType {}
@@ -0,0 +1,11 @@
1
+ import {__} from '@wordpress/i18n'
2
+
3
+ export const FAQ_HEADING_LEVELS = ['2', '3'] as const
4
+
5
+ export const DEFAULT_ICON_VARIANTS = [
6
+ {value: 'none', label: __('Nic', 'brilo-blocks')},
7
+ {value: 'question', label: __('Otazník', 'brilo-blocks')},
8
+ {value: 'exclamation', label: __('Vykřičník', 'brilo-blocks')},
9
+ {value: 'info', label: __('Informace', 'brilo-blocks')},
10
+ {value: 'message', label: __('Zpráva', 'brilo-blocks')},
11
+ ] as const
@@ -0,0 +1,55 @@
1
+ import {InspectorControls} from '@wordpress/block-editor'
2
+ import {PanelBody, SelectControl} from '@wordpress/components'
3
+ import {__} from '@wordpress/i18n'
4
+ import {useGroupBlock} from '~/hooks/useGroupBlock'
5
+ import {DEFAULT_ICON_VARIANTS, FAQ_HEADING_LEVELS} from './constants'
6
+ import type {FaqGroupAttributes, FaqGroupOptions, FaqHeadingLevel, FaqIconVariant} from './types'
7
+
8
+ export function createFaqGroupEdit(options: FaqGroupOptions) {
9
+ const ICON_VARIANTS = options.iconVariants ?? DEFAULT_ICON_VARIANTS
10
+
11
+ return function Edit({
12
+ attributes,
13
+ setAttributes,
14
+ }: {
15
+ attributes: FaqGroupAttributes
16
+ setAttributes: (a: Partial<FaqGroupAttributes>) => void
17
+ }) {
18
+ const {headingLevel, iconVariant} = attributes
19
+
20
+ const {blockProps, innerBlocksProps} = useGroupBlock({
21
+ blockClassName: options.blockClassName ?? 'g-faq wp-block-section',
22
+ containerClassName: options.containerClassName ?? 'g-faq__items',
23
+ allowedBlocks: options.allowedBlocks,
24
+ template: options.template,
25
+ orientation: 'vertical',
26
+ layout: {type: 'default'},
27
+ })
28
+
29
+ return (
30
+ <>
31
+ <InspectorControls>
32
+ <PanelBody title={__('Nadpis', 'brilo-blocks')}>
33
+ <SelectControl
34
+ label={__('Level nadpisu FAQ', 'brilo-blocks')}
35
+ value={headingLevel}
36
+ options={FAQ_HEADING_LEVELS.map((level) => ({value: level, label: `H${level}`}))}
37
+ onChange={(value) => setAttributes({headingLevel: value as FaqHeadingLevel})}
38
+ />
39
+ </PanelBody>
40
+ <PanelBody title={__('Ikona', 'brilo-blocks')}>
41
+ <SelectControl
42
+ label={__('Typ ikonky', 'brilo-blocks')}
43
+ value={iconVariant}
44
+ options={ICON_VARIANTS.map((v) => ({value: v.value, label: v.label}))}
45
+ onChange={(value) => setAttributes({iconVariant: value as FaqIconVariant})}
46
+ />
47
+ </PanelBody>
48
+ </InspectorControls>
49
+ <div {...blockProps}>
50
+ <div {...innerBlocksProps} />
51
+ </div>
52
+ </>
53
+ )
54
+ }
55
+ }
@@ -0,0 +1,11 @@
1
+ .g-faq {
2
+ .g-faq__items {
3
+ display: flex;
4
+ flex-direction: column;
5
+ gap: 8px;
6
+
7
+ .faq-item {
8
+ margin-inline: 0;
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,39 @@
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 {DEFAULT_ICON_VARIANTS, FAQ_HEADING_LEVELS} from './constants'
6
+ import {createFaqGroupEdit} from './edit'
7
+ import type {FaqGroupAttributes, FaqGroupOptions} from './types'
8
+
9
+ export type {FaqGroupAttributes, FaqGroupOptions}
10
+
11
+ export function createFaqGroupBlock<TIconVariants extends OptionArray = typeof DEFAULT_ICON_VARIANTS>(
12
+ options: FaqGroupOptions<TIconVariants>,
13
+ ): BlockConfiguration<FaqGroupAttributes<TIconVariants[number]['value']>> {
14
+ const iconVariants = options.iconVariants ?? DEFAULT_ICON_VARIANTS
15
+
16
+ return {
17
+ name: options.name,
18
+ title: options.title ?? __('FAQ', 'brilo-blocks'),
19
+ description: options.description,
20
+ category: options.category ?? 'layout',
21
+ ...(options.parent && {parent: options.parent}),
22
+ icon: options.icon ?? 'editor-help',
23
+ supports: {html: false, customClassName: false},
24
+ attributes: {
25
+ headingLevel: {
26
+ type: 'string',
27
+ default: FAQ_HEADING_LEVELS[1],
28
+ enum: [...FAQ_HEADING_LEVELS],
29
+ },
30
+ iconVariant: {
31
+ type: 'string',
32
+ default: iconVariants[1]?.value ?? iconVariants[0].value,
33
+ enum: iconVariants.map((v) => v.value),
34
+ },
35
+ },
36
+ edit: createFaqGroupEdit(options as unknown as FaqGroupOptions),
37
+ save: () => <InnerBlocks.Content />,
38
+ } as unknown as BlockConfiguration<FaqGroupAttributes<TIconVariants[number]['value']>>
39
+ }
@@ -0,0 +1,11 @@
1
+ export type {FaqGroupAttributes, FaqGroupOptions} from './types'
2
+ export {createFaqGroupBlock} from './factory'
3
+
4
+ import type {FaqGroupOptions} from './types'
5
+
6
+ export const faqGroupDefaults: FaqGroupOptions = {
7
+ name: 'brilo/faq-group',
8
+ parent: ['brilo/base-section'],
9
+ allowedBlocks: ['brilo/faq-item'],
10
+ template: [['brilo/faq-item', {}]],
11
+ }
@@ -0,0 +1,14 @@
1
+ import type {BriloBlockType, OptionArray} from '~/types'
2
+ import type {DEFAULT_ICON_VARIANTS, FAQ_HEADING_LEVELS} from './constants'
3
+
4
+ export type FaqHeadingLevel = (typeof FAQ_HEADING_LEVELS)[number]
5
+ export type FaqIconVariant = (typeof DEFAULT_ICON_VARIANTS)[number]['value']
6
+
7
+ export interface FaqGroupAttributes<TIconVariant extends string = FaqIconVariant> extends Record<string, unknown> {
8
+ headingLevel: FaqHeadingLevel
9
+ iconVariant: TIconVariant
10
+ }
11
+
12
+ export interface FaqGroupOptions<TIconVariants extends OptionArray = typeof DEFAULT_ICON_VARIANTS> extends BriloBlockType {
13
+ iconVariants?: TIconVariants
14
+ }
@@ -0,0 +1,50 @@
1
+ import {InspectorControls, RichText, useBlockProps, useInnerBlocksProps} from '@wordpress/block-editor'
2
+ import {BaseControl, PanelBody} from '@wordpress/components'
3
+ import {Icon, chevronDown} from '@wordpress/icons'
4
+ import {__} from '@wordpress/i18n'
5
+ import clsx from 'clsx'
6
+ import type {FaqItemAttributes, FaqItemOptions} from './types'
7
+
8
+ export function createFaqItemEdit(_options: FaqItemOptions) {
9
+ return function Edit({
10
+ attributes,
11
+ setAttributes,
12
+ }: {
13
+ attributes: FaqItemAttributes
14
+ setAttributes: (a: Partial<FaqItemAttributes>) => void
15
+ }) {
16
+ const {title} = attributes
17
+
18
+ const blockProps = useBlockProps({className: clsx('faq-item')})
19
+ const innerBlocksProps = useInnerBlocksProps(
20
+ {},
21
+ {allowedBlocks: ['core/paragraph', 'core/list', 'core/image', 'core/table', 'brilo/button-group']},
22
+ )
23
+
24
+ return (
25
+ <>
26
+ <div {...blockProps}>
27
+ <header className="faq-item__header flex gap-2">
28
+ <RichText
29
+ identifier="title"
30
+ className="title u-text-editable grow"
31
+ tagName="h3"
32
+ value={title}
33
+ allowedFormats={[]}
34
+ onChange={(value: string) => setAttributes({title: value})}
35
+ placeholder={__('Nadpis prvku', 'brilo-blocks')}
36
+ data-custom-placeholder={true}
37
+ />
38
+ <label className="faq-item__dropdown flex items-center justify-center cursor-pointer">
39
+ <Icon icon={chevronDown} size={32} className="faq-item__dropdown-icon" color="white" />
40
+ <input type="checkbox" defaultChecked />
41
+ </label>
42
+ </header>
43
+ <BaseControl label={__('Odpověď:', 'brilo-blocks')} className="faq-item__content">
44
+ <div {...innerBlocksProps} />
45
+ </BaseControl>
46
+ </div>
47
+ </>
48
+ )
49
+ }
50
+ }
@@ -0,0 +1,57 @@
1
+ .wp-block-brilo-faq-item {
2
+ padding: 16px;
3
+ border: 1px solid var(--border-color);
4
+ background: white;
5
+ }
6
+
7
+ .faq-item {
8
+ --dropdown-scale: -1;
9
+ --content-display: block;
10
+
11
+ &:has(input:checked) {
12
+ --dropdown-scale: 1;
13
+ --content-display: none;
14
+ }
15
+
16
+ .block-editor-block-list__layout {
17
+ p {
18
+ margin-block: 0;
19
+ }
20
+ }
21
+ }
22
+
23
+ .faq-item__content {
24
+ border: 1px solid var(--border-color);
25
+ padding: 12px;
26
+ display: var(--content-display);
27
+ }
28
+
29
+ .faq-item__dropdown {
30
+ height: 32px;
31
+ width: 32px;
32
+ margin-top: 21px;
33
+ border-radius: 4px;
34
+ position: relative;
35
+ background-color: #2271b1;
36
+ transition: background-color 0.3s ease;
37
+
38
+ &:hover {
39
+ background-color: #135e96;
40
+ }
41
+
42
+ svg {
43
+ fill: white;
44
+ }
45
+
46
+ input {
47
+ position: absolute;
48
+ bottom: 100%;
49
+ left: 0;
50
+ display: none;
51
+ }
52
+ }
53
+
54
+ .faq-item__dropdown-icon {
55
+ transition: transform 0.3s ease;
56
+ transform: scale(var(--dropdown-scale));
57
+ }
@@ -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 {createFaqItemEdit} from './edit'
5
+ import type {FaqItemAttributes, FaqItemOptions} from './types'
6
+
7
+ export type {FaqItemAttributes, FaqItemOptions}
8
+
9
+ export function createFaqItemBlock(options: FaqItemOptions): BlockConfiguration<FaqItemAttributes> {
10
+ return {
11
+ name: options.name,
12
+ title: options.title ?? __('FAQ položka', 'brilo-blocks'),
13
+ description: options.description,
14
+ category: options.category ?? 'layout',
15
+ ...(options.parent && {parent: options.parent}),
16
+ icon: options.icon ?? 'editor-help',
17
+ supports: {html: false, customClassName: false},
18
+ attributes: {
19
+ title: {type: 'string', default: ''},
20
+ },
21
+ edit: createFaqItemEdit(options),
22
+ save: () => <InnerBlocks.Content />,
23
+ } as unknown as BlockConfiguration<FaqItemAttributes>
24
+ }
@@ -0,0 +1,9 @@
1
+ export type {FaqItemAttributes, FaqItemOptions} from './types'
2
+ export {createFaqItemBlock} from './factory'
3
+
4
+ import type {FaqItemOptions} from './types'
5
+
6
+ export const faqItemDefaults: FaqItemOptions = {
7
+ name: 'brilo/faq-item',
8
+ parent: ['brilo/faq-group'],
9
+ }
@@ -0,0 +1,7 @@
1
+ import type {BriloBlockType} from '~/types'
2
+
3
+ export interface FaqItemAttributes extends Record<string, unknown> {
4
+ title: string
5
+ }
6
+
7
+ export interface FaqItemOptions extends BriloBlockType {}
@@ -0,0 +1,14 @@
1
+ import {__} from '@wordpress/i18n'
2
+
3
+ export const FIELD_TYPE_VALUES = ['text', 'textarea', 'select', 'hidden'] as const
4
+
5
+ export const FIELD_TYPES = [
6
+ {value: FIELD_TYPE_VALUES[0], label: __('Text', 'brilo-blocks')},
7
+ {value: FIELD_TYPE_VALUES[1], label: __('Textarea', 'brilo-blocks')},
8
+ {value: FIELD_TYPE_VALUES[2], label: __('Select', 'brilo-blocks')},
9
+ {value: FIELD_TYPE_VALUES[3], label: __('Hidden', 'brilo-blocks')},
10
+ ] as const
11
+
12
+ export const FIELD_COLUMNS_RANGE = {min: 1, max: 12} as const
13
+
14
+ export const FIELD_COLUMNS_DEFAULT = 6
@@ -0,0 +1,178 @@
1
+ import {InspectorControls, useBlockProps} from '@wordpress/block-editor'
2
+ import {Button, FormTokenField, PanelBody, RangeControl, SelectControl, TextControl, ToggleControl} from '@wordpress/components'
3
+ import {__} from '@wordpress/i18n'
4
+ import clsx from 'clsx'
5
+ import {FIELD_COLUMNS_DEFAULT, FIELD_COLUMNS_RANGE, FIELD_TYPES} from './constants'
6
+ import type {FormFieldAttributes, FormFieldOptions, FormFieldType} from './types'
7
+
8
+ const {min: MIN_COLUMNS, max: MAX_COLUMNS} = FIELD_COLUMNS_RANGE
9
+
10
+ function sanitizeHtmlName(raw: string): string {
11
+ return (raw ?? '')
12
+ .normalize('NFD')
13
+ .replace(/\p{Diacritic}/gu, '')
14
+ .replace(/[\s_]+/g, '-')
15
+ .replace(/[^a-zA-Z0-9_-]/g, '')
16
+ .replace(/[-_]{2,}/g, '-')
17
+ .replace(/^[-_]+/g, '')
18
+ .toLowerCase()
19
+ }
20
+
21
+ export function createFormFieldEdit(_options: FormFieldOptions) {
22
+ return function Edit({
23
+ attributes,
24
+ setAttributes,
25
+ }: {
26
+ attributes: FormFieldAttributes
27
+ setAttributes: (a: Partial<FormFieldAttributes>) => void
28
+ }) {
29
+ const currentColumns = Math.max(MIN_COLUMNS, Math.min(MAX_COLUMNS, attributes.columns || MIN_COLUMNS))
30
+
31
+ const blockProps = useBlockProps({
32
+ className: clsx('i-form-field', `--type-${attributes.type}`, `--cols-${currentColumns}`, attributes.required && '--required'),
33
+ })
34
+
35
+ const options = Array.isArray(attributes.options) ? attributes.options.filter((opt): opt is string => typeof opt === 'string') : []
36
+
37
+ const selectOptions = [{label: __('Žádná', 'brilo-blocks'), value: ''}, ...options.map((opt) => ({label: opt, value: opt}))]
38
+
39
+ return (
40
+ <>
41
+ <InspectorControls>
42
+ <PanelBody title={__('Pole formuláře', 'brilo-blocks')}>
43
+ <SelectControl
44
+ label={__('Typ inputu', 'brilo-blocks')}
45
+ value={attributes.type}
46
+ options={FIELD_TYPES.map((t) => ({label: t.label, value: t.value}))}
47
+ onChange={(type) => setAttributes({type: type as FormFieldType})}
48
+ />
49
+
50
+ {attributes.type !== 'hidden' && (
51
+ <>
52
+ <TextControl label={__('Popisek', 'brilo-blocks')} value={attributes.label} onChange={(label) => setAttributes({label})} />
53
+ <ToggleControl
54
+ label={__('Povinné', 'brilo-blocks')}
55
+ checked={attributes.required}
56
+ onChange={(required) => setAttributes({required})}
57
+ />
58
+ <TextControl
59
+ label={__('Název html atributu', 'brilo-blocks')}
60
+ value={attributes.name}
61
+ help={__(
62
+ 'Použijte pouze bezpečné znaky: a-z, 0-9, pomlčka a podtržítko. Např. city-born-to. Mezery a diakritika se automaticky odstraní.',
63
+ 'brilo-blocks',
64
+ )}
65
+ onChange={(name) => setAttributes({name: sanitizeHtmlName(name)})}
66
+ />
67
+ <TextControl
68
+ label={__('Placeholder', 'brilo-blocks')}
69
+ value={attributes.placeholder}
70
+ onChange={(placeholder) => setAttributes({placeholder})}
71
+ />
72
+ </>
73
+ )}
74
+
75
+ {attributes.type === 'select' && (
76
+ <>
77
+ <FormTokenField
78
+ label={__('Možnosti', 'brilo-blocks')}
79
+ value={options}
80
+ onChange={(nextOptions) =>
81
+ setAttributes({
82
+ options: (nextOptions ?? [])
83
+ .map((opt) => (typeof opt === 'string' ? opt : (opt as {value?: unknown}).value))
84
+ .filter((opt): opt is string => typeof opt === 'string' && opt.length > 0),
85
+ })
86
+ }
87
+ />
88
+
89
+ <SelectControl
90
+ label={__('Výchozí hodnota', 'brilo-blocks')}
91
+ value={attributes.defaultValue ?? ''}
92
+ options={selectOptions}
93
+ onChange={(defaultValue) => setAttributes({defaultValue: defaultValue ?? ''})}
94
+ />
95
+ </>
96
+ )}
97
+
98
+ {attributes.type === 'hidden' && (
99
+ <>
100
+ <TextControl
101
+ label={__('Hodnota', 'brilo-blocks')}
102
+ value={attributes.value ?? ''}
103
+ onChange={(value) => setAttributes({value})}
104
+ help={__('Hodnota, která bude odeslána s formulářem.', 'brilo-blocks')}
105
+ />
106
+ <TextControl
107
+ label={__('Název html atributu', 'brilo-blocks')}
108
+ value={attributes.name}
109
+ help={__(
110
+ 'Použijte pouze bezpečné znaky: a-z, 0-9, pomlčka a podtržítko. Mezery a diakritika se automaticky odstraní.',
111
+ 'brilo-blocks',
112
+ )}
113
+ onChange={(name) => setAttributes({name: sanitizeHtmlName(name)})}
114
+ />
115
+ </>
116
+ )}
117
+
118
+ {attributes.type !== 'hidden' && (
119
+ <RangeControl
120
+ label={__('Počet sloupců', 'brilo-blocks')}
121
+ value={currentColumns}
122
+ min={MIN_COLUMNS}
123
+ max={MAX_COLUMNS}
124
+ onChange={(columns) =>
125
+ setAttributes({columns: Math.max(MIN_COLUMNS, Math.min(MAX_COLUMNS, columns ?? FIELD_COLUMNS_DEFAULT))})
126
+ }
127
+ />
128
+ )}
129
+ </PanelBody>
130
+ </InspectorControls>
131
+
132
+ <div {...blockProps}>
133
+ <div className="i-form-field__wrapper">
134
+ {attributes.type === 'hidden' ? (
135
+ <>
136
+ <strong>{__('Skryté pole', 'brilo-blocks')}</strong>
137
+ <div>
138
+ {__('Hodnota', 'brilo-blocks')}: {attributes.value ?? ''}
139
+ </div>
140
+ <div>
141
+ {__('Název', 'brilo-blocks')}: {attributes.name ?? ''}
142
+ </div>
143
+ </>
144
+ ) : (
145
+ <>
146
+ <strong>{attributes.label || __('Pole', 'brilo-blocks')}</strong>
147
+ <div>{attributes.type}</div>
148
+ <div className="i-form-field__columns-control">
149
+ <Button
150
+ size="small"
151
+ variant="secondary"
152
+ onClick={() => setAttributes({columns: Math.max(MIN_COLUMNS, currentColumns - 1)})}
153
+ disabled={currentColumns <= MIN_COLUMNS}
154
+ aria-label={__('Snížit počet sloupců', 'brilo-blocks')}
155
+ >
156
+ -
157
+ </Button>
158
+
159
+ <div className="i-form-field__columns-value">{`${currentColumns}/${MAX_COLUMNS}`}</div>
160
+
161
+ <Button
162
+ size="small"
163
+ variant="secondary"
164
+ onClick={() => setAttributes({columns: Math.min(MAX_COLUMNS, currentColumns + 1)})}
165
+ disabled={currentColumns >= MAX_COLUMNS}
166
+ aria-label={__('Zvýšit počet sloupců', 'brilo-blocks')}
167
+ >
168
+ +
169
+ </Button>
170
+ </div>
171
+ </>
172
+ )}
173
+ </div>
174
+ </div>
175
+ </>
176
+ )
177
+ }
178
+ }
@@ -0,0 +1,71 @@
1
+ .i-form-field {
2
+ width: 100%;
3
+ margin-block: 0;
4
+
5
+ &.--cols-1 {
6
+ grid-column: span 1;
7
+ }
8
+ &.--cols-2 {
9
+ grid-column: span 2;
10
+ }
11
+ &.--cols-3 {
12
+ grid-column: span 3;
13
+ }
14
+ &.--cols-4 {
15
+ grid-column: span 4;
16
+ }
17
+ &.--cols-5 {
18
+ grid-column: span 5;
19
+ }
20
+ &.--cols-6 {
21
+ grid-column: span 6;
22
+ }
23
+ &.--cols-7 {
24
+ grid-column: span 7;
25
+ }
26
+ &.--cols-8 {
27
+ grid-column: span 8;
28
+ }
29
+ &.--cols-9 {
30
+ grid-column: span 9;
31
+ }
32
+ &.--cols-10 {
33
+ grid-column: span 10;
34
+ }
35
+ &.--cols-11 {
36
+ grid-column: span 11;
37
+ }
38
+ &.--cols-12 {
39
+ grid-column: span 12;
40
+ }
41
+
42
+ // Hidden fields span the full row — no column control
43
+ &.--type-hidden {
44
+ grid-column: span 12;
45
+ }
46
+
47
+ &.--type-hidden .i-form-field__wrapper {
48
+ background: #f6f7f7;
49
+ border-style: dotted;
50
+ }
51
+ }
52
+
53
+ .i-form-field__wrapper {
54
+ padding: 12px;
55
+ border: 1px dashed rgba(0, 0, 0, 0.25);
56
+ background: #fff;
57
+ }
58
+
59
+ .i-form-field__columns-control {
60
+ margin-top: 10px;
61
+ display: flex;
62
+ align-items: center;
63
+ justify-content: space-between;
64
+ gap: 8px;
65
+ }
66
+
67
+ .i-form-field__columns-value {
68
+ flex: 1;
69
+ text-align: center;
70
+ font-weight: 600;
71
+ }