@brilo/base-blocks 0.1.40 → 0.1.41

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 (67) hide show
  1. package/build/.tsbuildinfo +1 -1
  2. package/build/blocks/career/career-benefits/constants.d.ts +17 -0
  3. package/build/blocks/career/career-benefits/constants.d.ts.map +1 -0
  4. package/build/blocks/career/career-benefits/constants.js +7 -0
  5. package/build/blocks/career/career-benefits/edit.d.ts +6 -0
  6. package/build/blocks/career/career-benefits/edit.d.ts.map +1 -0
  7. package/build/blocks/career/career-benefits/edit.js +14 -0
  8. package/build/blocks/career/career-benefits/factory.d.ts +5 -0
  9. package/build/blocks/career/career-benefits/factory.d.ts.map +1 -0
  10. package/build/blocks/career/career-benefits/factory.js +22 -0
  11. package/build/blocks/career/career-benefits/icon.d.ts +2 -0
  12. package/build/blocks/career/career-benefits/icon.d.ts.map +1 -0
  13. package/build/blocks/career/career-benefits/icon.js +2 -0
  14. package/build/blocks/career/career-benefits/index.d.ts +5 -0
  15. package/build/blocks/career/career-benefits/index.d.ts.map +1 -0
  16. package/build/blocks/career/career-benefits/index.js +5 -0
  17. package/build/blocks/career/career-benefits/types.d.ts +8 -0
  18. package/build/blocks/career/career-benefits/types.d.ts.map +1 -0
  19. package/build/blocks/career/career-benefits/types.js +1 -0
  20. package/build/blocks/career/career-header/constants.d.ts +16 -0
  21. package/build/blocks/career/career-header/constants.d.ts.map +1 -1
  22. package/build/blocks/career/career-header/constants.js +7 -0
  23. package/build/blocks/career/career-header/edit.d.ts.map +1 -1
  24. package/build/blocks/career/career-header/edit.js +7 -5
  25. package/build/blocks/career/career-header/factory.d.ts.map +1 -1
  26. package/build/blocks/career/career-header/factory.js +2 -0
  27. package/build/blocks/career/career-header/types.d.ts +2 -0
  28. package/build/blocks/career/career-header/types.d.ts.map +1 -1
  29. package/build/blocks/layout/box/controls.d.ts +8 -0
  30. package/build/blocks/layout/box/controls.d.ts.map +1 -0
  31. package/build/blocks/layout/box/controls.js +13 -0
  32. package/build/blocks/layout/box/edit.d.ts +4 -0
  33. package/build/blocks/layout/box/edit.d.ts.map +1 -0
  34. package/build/blocks/layout/box/edit.js +35 -0
  35. package/build/blocks/layout/box/factory.d.ts +4 -0
  36. package/build/blocks/layout/box/factory.d.ts.map +1 -0
  37. package/build/blocks/layout/box/factory.js +28 -0
  38. package/build/blocks/layout/box/icon.d.ts +2 -0
  39. package/build/blocks/layout/box/icon.d.ts.map +1 -0
  40. package/build/blocks/layout/box/icon.js +2 -0
  41. package/build/blocks/layout/box/index.d.ts +5 -0
  42. package/build/blocks/layout/box/index.d.ts.map +1 -0
  43. package/build/blocks/layout/box/index.js +6 -0
  44. package/build/blocks/layout/box/types.d.ts +25 -0
  45. package/build/blocks/layout/box/types.d.ts.map +1 -0
  46. package/build/blocks/layout/box/types.js +1 -0
  47. package/build/index.d.ts +4 -0
  48. package/build/index.d.ts.map +1 -1
  49. package/build/index.js +2 -0
  50. package/package.json +1 -1
  51. package/src/blocks/career/career-benefits/constants.ts +7 -0
  52. package/src/blocks/career/career-benefits/edit.tsx +55 -0
  53. package/src/blocks/career/career-benefits/factory.tsx +26 -0
  54. package/src/blocks/career/career-benefits/icon.tsx +10 -0
  55. package/src/blocks/career/career-benefits/index.ts +9 -0
  56. package/src/blocks/career/career-benefits/types.ts +9 -0
  57. package/src/blocks/career/career-header/constants.ts +8 -0
  58. package/src/blocks/career/career-header/edit.tsx +21 -4
  59. package/src/blocks/career/career-header/factory.tsx +2 -0
  60. package/src/blocks/career/career-header/types.ts +2 -0
  61. package/src/blocks/layout/box/controls.tsx +64 -0
  62. package/src/blocks/layout/box/edit.tsx +52 -0
  63. package/src/blocks/layout/box/factory.tsx +31 -0
  64. package/src/blocks/layout/box/icon.tsx +5 -0
  65. package/src/blocks/layout/box/index.ts +10 -0
  66. package/src/blocks/layout/box/types.ts +27 -0
  67. package/src/index.ts +4 -0
@@ -0,0 +1,10 @@
1
+ export const icon = (
2
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <path d="M3 5.5L5 7.5L9 3.5" stroke="black" strokeWidth="1.2" fill="none" />
4
+ <path d="M3 10.5L5 12.5L9 8.5" stroke="black" strokeWidth="1.2" fill="none" />
5
+ <path d="M3 15.5L5 17.5L9 13.5" stroke="black" strokeWidth="1.2" fill="none" />
6
+ <line x1="11" y1="5" x2="18" y2="5" stroke="black" />
7
+ <line x1="11" y1="10" x2="18" y2="10" stroke="black" />
8
+ <line x1="11" y1="15" x2="18" y2="15" stroke="black" />
9
+ </svg>
10
+ )
@@ -0,0 +1,9 @@
1
+ export type {CareerBenefitsAttributes, CareerBenefitsOptions} from './types'
2
+ export {createCareerBenefitsBlock} from './factory'
3
+
4
+ import type {CareerBenefitsOptions} from './types'
5
+
6
+ export const careerBenefitsDefaults: CareerBenefitsOptions = {
7
+ name: 'brilo/career-benefits',
8
+ parent: ['brilo/base-section'],
9
+ }
@@ -0,0 +1,9 @@
1
+ import type {BriloBlockType} from '~/types'
2
+
3
+ export interface CareerBenefitsAttributes extends Record<string, unknown> {
4
+ title: string
5
+ titleColor: string
6
+ titleStyle: string
7
+ }
8
+
9
+ export type CareerBenefitsOptions = BriloBlockType
@@ -1 +1,9 @@
1
1
  export const DEFAULT_ALLOWED_BLOCKS: string[] = ['brilo/button-group']
2
+
3
+ export const TITLE_STYLES = [
4
+ {value: 'h1', label: 'H1'},
5
+ {value: 'h2', label: 'H2'},
6
+ {value: 'h3', label: 'H3'},
7
+ {value: 'h4', label: 'H4'},
8
+ {value: 'h5', label: 'H5'},
9
+ ] as const
@@ -1,7 +1,8 @@
1
- import {InspectorControls, useBlockProps, useInnerBlocksProps} from '@wordpress/block-editor'
2
- import {PanelBody, ToggleControl} from '@wordpress/components'
1
+ import {ColorPalette, InspectorControls, useBlockProps, useInnerBlocksProps} from '@wordpress/block-editor'
2
+ import {PanelBody, SelectControl, ToggleControl} from '@wordpress/components'
3
3
  import {__} from '@wordpress/i18n'
4
- import {DEFAULT_ALLOWED_BLOCKS} from './constants'
4
+ import {useTenantColorPalette} from '~/hooks/useTenantColorPalette'
5
+ import {DEFAULT_ALLOWED_BLOCKS, TITLE_STYLES} from './constants'
5
6
  import type {CareerHeaderAttributes, CareerHeaderOptions} from './types'
6
7
 
7
8
  export function createCareerHeaderEdit(options: CareerHeaderOptions) {
@@ -12,7 +13,8 @@ export function createCareerHeaderEdit(options: CareerHeaderOptions) {
12
13
  attributes: CareerHeaderAttributes
13
14
  setAttributes: (a: Partial<CareerHeaderAttributes>) => void
14
15
  }) {
15
- const {showExcerpt, showLocation, showSalary, showBenefits, showEmploymentType} = attributes
16
+ const {showExcerpt, showLocation, showSalary, showBenefits, showEmploymentType, titleColor, titleStyle} = attributes
17
+ const {paletteColors} = useTenantColorPalette()
16
18
 
17
19
  const blockProps = useBlockProps({className: 'wp-block-section'})
18
20
  const innerBlocksProps = useInnerBlocksProps({}, {allowedBlocks: options.allowedBlocks ?? DEFAULT_ALLOWED_BLOCKS})
@@ -47,6 +49,21 @@ export function createCareerHeaderEdit(options: CareerHeaderOptions) {
47
49
  onChange={(value) => setAttributes({showEmploymentType: value})}
48
50
  />
49
51
  </PanelBody>
52
+
53
+ <PanelBody title={__('Titulek', 'brilo-blocks')}>
54
+ <SelectControl
55
+ label={__('Styl titulku', 'brilo-blocks')}
56
+ value={titleStyle}
57
+ options={TITLE_STYLES.map((s): {value: string; label: string} => ({value: s.value, label: s.label}))}
58
+ onChange={(value) => setAttributes({titleStyle: value})}
59
+ />
60
+ <p>{__('Barva titulku', 'brilo-blocks')}</p>
61
+ <ColorPalette
62
+ colors={paletteColors}
63
+ value={titleColor || undefined}
64
+ onChange={(value) => setAttributes({titleColor: value ?? ''})}
65
+ />
66
+ </PanelBody>
50
67
  </InspectorControls>
51
68
 
52
69
  <div {...blockProps}>
@@ -22,6 +22,8 @@ export function createCareerHeaderBlock(options: CareerHeaderOptions): BlockConf
22
22
  showSalary: {type: 'boolean', default: true},
23
23
  showBenefits: {type: 'boolean', default: true},
24
24
  showEmploymentType: {type: 'boolean', default: true},
25
+ titleColor: {type: 'string', default: ''},
26
+ titleStyle: {type: 'string', default: 'h2'},
25
27
  },
26
28
  edit: createCareerHeaderEdit(options),
27
29
  save: () => <InnerBlocks.Content />,
@@ -6,6 +6,8 @@ export interface CareerHeaderAttributes extends Record<string, unknown> {
6
6
  showSalary: boolean
7
7
  showBenefits: boolean
8
8
  showEmploymentType: boolean
9
+ titleColor: string
10
+ titleStyle: string
9
11
  }
10
12
 
11
13
  export type CareerHeaderOptions = BriloBlockType
@@ -0,0 +1,64 @@
1
+ import * as blockEditor from '@wordpress/block-editor'
2
+ import {ColorPalette, ContrastChecker} from '@wordpress/block-editor'
3
+ import {BoxControl, PanelBody, __experimentalUnitControl as UnitControl} from '@wordpress/components'
4
+ import {__} from '@wordpress/i18n'
5
+ import type {ComponentType} from 'react'
6
+ import {useTenantColorPalette} from '~/hooks/useTenantColorPalette'
7
+ import type {BoxAttributes, BoxBorderRadius} from './types'
8
+
9
+ // `__experimentalBorderRadiusControl` is a real runtime export of @wordpress/block-editor (see
10
+ // packages/block-editor/src/components/border-radius-control) but isn't covered by the community
11
+ // @types/wordpress__block-editor typings, so it's pulled off the namespace import and cast by hand.
12
+ interface BorderRadiusControlProps {
13
+ values?: string | BoxBorderRadius
14
+ onChange: (next: string | BoxBorderRadius | undefined) => void
15
+ }
16
+ const BorderRadiusControl = (blockEditor as unknown as {__experimentalBorderRadiusControl: ComponentType<BorderRadiusControlProps>})
17
+ .__experimentalBorderRadiusControl
18
+
19
+ interface BoxControlsProps {
20
+ attributes: BoxAttributes
21
+ setAttributes: (attrs: Partial<BoxAttributes>) => void
22
+ }
23
+
24
+ export function BoxControls({attributes, setAttributes}: BoxControlsProps) {
25
+ const {padding, margin, borderRadius, borderWidth, borderColor, background, textColor} = attributes
26
+ const {paletteColors, resolveHex} = useTenantColorPalette()
27
+
28
+ return (
29
+ <>
30
+ <PanelBody title={__('Rozestupy', 'brilo-blocks')}>
31
+ <BoxControl label={__('Padding', 'brilo-blocks')} values={padding} onChange={(next) => setAttributes({padding: next})} />
32
+ <BoxControl label={__('Margin', 'brilo-blocks')} values={margin} onChange={(next) => setAttributes({margin: next})} />
33
+ </PanelBody>
34
+
35
+ <PanelBody title={__('Ohraničení', 'brilo-blocks')}>
36
+ <UnitControl
37
+ label={__('Šířka okraje', 'brilo-blocks')}
38
+ value={borderWidth}
39
+ min={0}
40
+ onChange={(next) => setAttributes({borderWidth: (next as string) ?? ''})}
41
+ />
42
+ <p>{__('Barva okraje', 'brilo-blocks')}</p>
43
+ <ColorPalette
44
+ colors={paletteColors}
45
+ value={borderColor || undefined}
46
+ onChange={(value) => setAttributes({borderColor: value ?? ''})}
47
+ />
48
+ <BorderRadiusControl values={borderRadius} onChange={(next) => setAttributes({borderRadius: next ?? ''})} />
49
+ </PanelBody>
50
+
51
+ <PanelBody title={__('Barvy', 'brilo-blocks')}>
52
+ <p>{__('Pozadí', 'brilo-blocks')}</p>
53
+ <ColorPalette
54
+ colors={paletteColors}
55
+ value={background || undefined}
56
+ onChange={(value) => setAttributes({background: value ?? ''})}
57
+ />
58
+ <p>{__('Barva textu', 'brilo-blocks')}</p>
59
+ <ColorPalette colors={paletteColors} value={textColor || undefined} onChange={(value) => setAttributes({textColor: value ?? ''})} />
60
+ {!!background && !!textColor && <ContrastChecker backgroundColor={resolveHex(background)} textColor={resolveHex(textColor)} />}
61
+ </PanelBody>
62
+ </>
63
+ )
64
+ }
@@ -0,0 +1,52 @@
1
+ import {InspectorControls, useBlockProps, useInnerBlocksProps} from '@wordpress/block-editor'
2
+ import type {BlockEditProps} from '@wordpress/blocks'
3
+ import type {CSSProperties} from 'react'
4
+ import {BoxControls} from './controls'
5
+ import type {BoxAttributes, BoxOptions} from './types'
6
+
7
+ export function createBoxEdit(options: BoxOptions) {
8
+ return function Edit({attributes, setAttributes}: BlockEditProps<BoxAttributes>) {
9
+ const {padding, margin, borderRadius, borderWidth, borderColor, background, textColor} = attributes
10
+
11
+ const style: CSSProperties = {
12
+ ...(padding?.top && {paddingTop: padding.top}),
13
+ ...(padding?.right && {paddingRight: padding.right}),
14
+ ...(padding?.bottom && {paddingBottom: padding.bottom}),
15
+ ...(padding?.left && {paddingLeft: padding.left}),
16
+ ...(margin?.top && {marginTop: margin.top}),
17
+ ...(margin?.right && {marginRight: margin.right}),
18
+ ...(margin?.bottom && {marginBottom: margin.bottom}),
19
+ ...(margin?.left && {marginLeft: margin.left}),
20
+ ...(typeof borderRadius === 'string' && borderRadius && {borderRadius}),
21
+ ...(typeof borderRadius === 'object' && borderRadius !== null
22
+ ? {
23
+ ...(borderRadius.topLeft && {borderTopLeftRadius: borderRadius.topLeft}),
24
+ ...(borderRadius.topRight && {borderTopRightRadius: borderRadius.topRight}),
25
+ ...(borderRadius.bottomLeft && {borderBottomLeftRadius: borderRadius.bottomLeft}),
26
+ ...(borderRadius.bottomRight && {borderBottomRightRadius: borderRadius.bottomRight}),
27
+ }
28
+ : {}),
29
+ ...(borderWidth && {borderWidth, borderStyle: 'solid' as CSSProperties['borderStyle']}),
30
+ ...(borderColor && {borderColor}),
31
+ ...(background && {backgroundColor: background}),
32
+ ...(textColor && {color: textColor}),
33
+ }
34
+
35
+ const blockProps = useBlockProps({className: options.blockClassName ?? 'g-box', style})
36
+ const innerBlocksProps = useInnerBlocksProps(
37
+ {className: options.containerClassName ?? 'g-box__inner'},
38
+ {allowedBlocks: options.allowedBlocks, template: options.template, templateLock: false},
39
+ )
40
+
41
+ return (
42
+ <>
43
+ <InspectorControls>
44
+ <BoxControls attributes={attributes} setAttributes={setAttributes} />
45
+ </InspectorControls>
46
+ <div {...blockProps}>
47
+ <div {...innerBlocksProps} />
48
+ </div>
49
+ </>
50
+ )
51
+ }
52
+ }
@@ -0,0 +1,31 @@
1
+ import {InnerBlocks} from '@wordpress/block-editor'
2
+ import type {BlockConfiguration} from '@wordpress/blocks'
3
+ import {__} from '@wordpress/i18n'
4
+ import {createBoxEdit} from './edit'
5
+ import {icon as defaultIcon} from './icon'
6
+ import type {BoxAttributes, BoxOptions} from './types'
7
+
8
+ export function createBoxBlock(options: BoxOptions): BlockConfiguration<BoxAttributes> {
9
+ return {
10
+ name: options.name,
11
+ title: options.title ?? __('Box', 'brilo-blocks'),
12
+ description:
13
+ options.description ??
14
+ __('Obecné pouzdro pro libovolný obsah s vlastním paddingem, marginem, ohraničením a barvami.', 'brilo-blocks'),
15
+ category: options.category ?? 'layout',
16
+ icon: options.icon ?? {src: defaultIcon},
17
+ ...(options.parent && {parent: options.parent}),
18
+ supports: {html: false, customClassName: false},
19
+ attributes: {
20
+ padding: {type: 'object', default: {}},
21
+ margin: {type: 'object', default: {}},
22
+ borderRadius: {type: ['string', 'object'], default: ''},
23
+ borderWidth: {type: 'string', default: ''},
24
+ borderColor: {type: 'string', default: ''},
25
+ background: {type: 'string', default: ''},
26
+ textColor: {type: 'string', default: ''},
27
+ },
28
+ edit: createBoxEdit(options),
29
+ save: () => <InnerBlocks.Content />,
30
+ } as BlockConfiguration<BoxAttributes>
31
+ }
@@ -0,0 +1,5 @@
1
+ export const icon = (
2
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <rect x="1.5" y="1.5" width="17" height="17" rx="2" stroke="black" fill="none" />
4
+ </svg>
5
+ )
@@ -0,0 +1,10 @@
1
+ export type {BoxAttributes, BoxBorderRadius, BoxOptions, BoxSpacing} from './types'
2
+ export {createBoxBlock} from './factory'
3
+
4
+ import type {BoxOptions} from './types'
5
+
6
+ export const boxDefaults: BoxOptions = {
7
+ name: 'brilo/box',
8
+ blockClassName: 'g-box',
9
+ containerClassName: 'g-box__inner',
10
+ }
@@ -0,0 +1,27 @@
1
+ import type {BriloBlockType} from '~/types'
2
+
3
+ export interface BoxSpacing {
4
+ top?: string
5
+ right?: string
6
+ bottom?: string
7
+ left?: string
8
+ }
9
+
10
+ export interface BoxBorderRadius {
11
+ topLeft?: string
12
+ topRight?: string
13
+ bottomLeft?: string
14
+ bottomRight?: string
15
+ }
16
+
17
+ export interface BoxAttributes extends Record<string, unknown> {
18
+ padding: BoxSpacing
19
+ margin: BoxSpacing
20
+ borderRadius: string | BoxBorderRadius
21
+ borderWidth: string
22
+ borderColor: string
23
+ background: string
24
+ textColor: string
25
+ }
26
+
27
+ export interface BoxOptions extends BriloBlockType {}
package/src/index.ts CHANGED
@@ -219,7 +219,11 @@ export type {
219
219
  export {createJobPositionGroupBlock, jobPositionGroupDefaults, JobPositionsSelectModal} from './blocks/career/job-position-group'
220
220
  export type {CareerHeaderAttributes, CareerHeaderOptions} from './blocks/career/career-header'
221
221
  export {createCareerHeaderBlock, careerHeaderDefaults} from './blocks/career/career-header'
222
+ export type {CareerBenefitsAttributes, CareerBenefitsOptions} from './blocks/career/career-benefits'
223
+ export {createCareerBenefitsBlock, careerBenefitsDefaults} from './blocks/career/career-benefits'
222
224
  export type {PostContentAttributes, PostContentOptions} from './blocks/post/post-content'
223
225
  export {createPostContentBlock, postContentDefaults} from './blocks/post/post-content'
224
226
  export type {ShareAttributes, ShareOptions} from './blocks/share/share'
225
227
  export {createShareBlock, shareDefaults} from './blocks/share/share'
228
+ export type {BoxAttributes, BoxBorderRadius, BoxOptions, BoxSpacing} from './blocks/layout/box'
229
+ export {createBoxBlock, boxDefaults} from './blocks/layout/box'