@brilo/base-blocks 0.1.47 → 0.1.49

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 (35) hide show
  1. package/build/.tsbuildinfo +1 -1
  2. package/build/blocks/contact/contact-group/constants.d.ts +71 -0
  3. package/build/blocks/contact/contact-group/constants.d.ts.map +1 -1
  4. package/build/blocks/contact/contact-group/constants.js +35 -0
  5. package/build/blocks/contact/contact-group/edit.d.ts.map +1 -1
  6. package/build/blocks/contact/contact-group/edit.js +40 -8
  7. package/build/blocks/contact/contact-group/factory.d.ts +3 -3
  8. package/build/blocks/contact/contact-group/factory.d.ts.map +1 -1
  9. package/build/blocks/contact/contact-group/factory.js +33 -8
  10. package/build/blocks/contact/contact-group/index.d.ts +2 -2
  11. package/build/blocks/contact/contact-group/index.d.ts.map +1 -1
  12. package/build/blocks/contact/contact-group/index.js +1 -1
  13. package/build/blocks/contact/contact-group/types.d.ts +29 -6
  14. package/build/blocks/contact/contact-group/types.d.ts.map +1 -1
  15. package/build/blocks/contact/contact-item/buildPreviewStyle.d.ts +24 -0
  16. package/build/blocks/contact/contact-item/buildPreviewStyle.d.ts.map +1 -0
  17. package/build/blocks/contact/contact-item/buildPreviewStyle.js +31 -0
  18. package/build/blocks/contact/contact-item/edit.d.ts.map +1 -1
  19. package/build/blocks/contact/contact-item/edit.js +10 -8
  20. package/build/blocks/contact/contact-item/factory.js +2 -2
  21. package/build/index.d.ts +2 -2
  22. package/build/index.d.ts.map +1 -1
  23. package/build/index.js +1 -1
  24. package/package.json +1 -1
  25. package/src/blocks/contact/contact-group/constants.ts +42 -0
  26. package/src/blocks/contact/contact-group/edit.tsx +200 -20
  27. package/src/blocks/contact/contact-group/editor.scss +19 -0
  28. package/src/blocks/contact/contact-group/factory.tsx +61 -8
  29. package/src/blocks/contact/contact-group/index.ts +10 -2
  30. package/src/blocks/contact/contact-group/types.ts +48 -6
  31. package/src/blocks/contact/contact-item/buildPreviewStyle.ts +69 -0
  32. package/src/blocks/contact/contact-item/edit.tsx +17 -30
  33. package/src/blocks/contact/contact-item/editor.scss +136 -7
  34. package/src/blocks/contact/contact-item/factory.tsx +2 -2
  35. package/src/index.ts +5 -0
@@ -1,7 +1,6 @@
1
1
  import {InspectorControls} from '@wordpress/block-editor'
2
2
  import {
3
3
  PanelBody,
4
- RangeControl,
5
4
  __experimentalToggleGroupControl as ToggleGroupControl,
6
5
  __experimentalToggleGroupControlOption as ToggleGroupControlOption,
7
6
  } from '@wordpress/components'
@@ -10,9 +9,11 @@ import clsx from 'clsx'
10
9
  import type {CSSProperties} from 'react'
11
10
  import {ItemIconControl, ItemIconPreview} from '~/components/ItemIconControl'
12
11
  import {useGroupBlock} from '~/hooks/useGroupBlock'
13
- import {CONTACT_COLUMNS_CONTEXT} from '../contact-group/constants'
14
- import {CONTACT_ICON_SIZE_DEFAULT, CONTACT_ICON_SIZE_RANGE, CONTACT_ICON_SIZES, CONTACT_ICON_TYPES} from './constants'
15
- import type {ContactIconSizeVariant, ContactItemAttributes, ContactItemOptions} from './types'
12
+ import {useTenantColorPalette} from '~/hooks/useTenantColorPalette'
13
+ import {CONTACT_COLUMNS_CONTEXT, CONTACT_STYLE_CONTEXT} from '../contact-group/constants'
14
+ import {buildContactPreviewStyle, type ContactSharedStyle} from './buildPreviewStyle'
15
+ import {CONTACT_ICON_TYPES} from './constants'
16
+ import type {ContactItemAttributes, ContactItemOptions} from './types'
16
17
 
17
18
  export function createContactItemEdit(options: ContactItemOptions) {
18
19
  const iconOptions = {icons: options.icons ?? [], iconsSrc: options.iconsSrc ?? ''}
@@ -26,16 +27,18 @@ export function createContactItemEdit(options: ContactItemOptions) {
26
27
  setAttributes: (a: Partial<ContactItemAttributes>) => void
27
28
  context: Record<string, unknown>
28
29
  }) {
29
- const {colSpan, icon, iconSize} = attributes
30
+ const {colSpan, icon} = attributes
30
31
  const columns = Number(context[CONTACT_COLUMNS_CONTEXT] ?? 3)
31
32
  const span = Math.min(colSpan, columns)
32
33
 
33
- const sizePreset = CONTACT_ICON_SIZES.find((s) => s.value === iconSize.variant)
34
- const iconPx =
35
- iconSize.variant === 'custom' ? iconSize.custom : sizePreset && 'size' in sizePreset ? sizePreset.size : CONTACT_ICON_SIZE_DEFAULT
34
+ const {resolveHex} = useTenantColorPalette()
35
+ const {rootClassName, iconClassName, cssVars} = buildContactPreviewStyle(
36
+ context[CONTACT_STYLE_CONTEXT] as ContactSharedStyle | undefined,
37
+ resolveHex,
38
+ )
36
39
 
37
40
  const {blockProps, innerBlocksProps} = useGroupBlock({
38
- blockClassName: clsx(options.blockClassName ?? 'i-contact'),
41
+ blockClassName: clsx(options.blockClassName ?? 'i-contact', rootClassName),
39
42
  containerClassName: [options.containerClassName ?? 'i-contact__inner'],
40
43
  allowedBlocks: options.allowedBlocks,
41
44
  template: options.template,
@@ -60,29 +63,13 @@ export function createContactItemEdit(options: ContactItemOptions) {
60
63
  </PanelBody>
61
64
  <PanelBody title={__('Ikona', 'brilo-blocks')}>
62
65
  <ItemIconControl icon={icon} setAttributes={setAttributes} iconTypes={CONTACT_ICON_TYPES} options={iconOptions} />
63
- <ToggleGroupControl
64
- isBlock
65
- label={__('Velikost ikony', 'brilo-blocks')}
66
- value={iconSize.variant}
67
- onChange={(v) => setAttributes({iconSize: {...iconSize, variant: v as ContactIconSizeVariant}})}
68
- >
69
- {CONTACT_ICON_SIZES.map((s) => (
70
- <ToggleGroupControlOption key={s.value} value={s.value} label={s.label} />
71
- ))}
72
- </ToggleGroupControl>
73
- {iconSize.variant === 'custom' && (
74
- <RangeControl
75
- label={__('Vlastní velikost (px)', 'brilo-blocks')}
76
- value={iconSize.custom}
77
- min={CONTACT_ICON_SIZE_RANGE.min}
78
- max={CONTACT_ICON_SIZE_RANGE.max}
79
- onChange={(v) => setAttributes({iconSize: {...iconSize, custom: v ?? CONTACT_ICON_SIZE_RANGE.min}})}
80
- />
81
- )}
82
66
  </PanelBody>
83
67
  </InspectorControls>
84
- <div {...blockProps} style={{...(blockProps.style as CSSProperties), '--col-span': span} as CSSProperties}>
85
- <div className="i-contact__icon-wrap" style={{'--icon-size': `${iconPx}px`} as CSSProperties}>
68
+ <div
69
+ {...blockProps}
70
+ style={{...(blockProps.style as CSSProperties), ...cssVars, '--col-span': span} as CSSProperties}
71
+ >
72
+ <div className={clsx('i-contact__icon-wrap', iconClassName)}>
86
73
  <ItemIconPreview icon={icon} className="i-contact__icon" setAttributes={setAttributes} options={iconOptions} />
87
74
  </div>
88
75
  <div {...innerBlocksProps} />
@@ -9,18 +9,67 @@
9
9
  }
10
10
 
11
11
  .i-contact {
12
+ --icon-background-size: 0px;
13
+
12
14
  grid-column: span var(--col-span, 1);
13
15
  margin-inline: 0;
14
16
  width: 100%;
15
17
  box-sizing: border-box;
16
- border: 1px solid #eee;
18
+ display: flex;
19
+ flex-direction: column;
20
+ gap: 8px;
17
21
  padding: 8px;
22
+ border-radius: 4px;
23
+ align-items: var(--align-items, flex-start);
24
+ text-align: var(--text-align, left);
25
+
26
+ &.--direction-horizontal {
27
+ flex-direction: row;
28
+ }
29
+
30
+ &.--align-left {
31
+ --align-items: flex-start;
32
+ --text-align: left;
33
+ }
34
+
35
+ &.--align-center {
36
+ --align-items: center;
37
+ --text-align: center;
38
+ }
39
+
40
+ // Background size only reserves space when a background or outline is actually selected.
41
+ &.--icon-background,
42
+ &.--icon-bordered {
43
+ --icon-background-size: 88px;
44
+ }
45
+
46
+ &.--shadow {
47
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
48
+ }
49
+
50
+ &.--shadow-md {
51
+ box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
52
+ }
53
+
54
+ &.--border {
55
+ border: 1px solid var(--border-color, transparent);
56
+ }
57
+
58
+ &.--background-color {
59
+ background-color: var(--background-color, transparent);
60
+ }
61
+
62
+ &.--text-color {
63
+ color: var(--text-color);
64
+ }
18
65
 
19
66
  .i-contact__inner {
20
67
  display: flex;
21
68
  flex-direction: column;
22
69
  gap: 8px;
23
- width: 100%;
70
+ flex: 1;
71
+ min-width: 0;
72
+ text-align: inherit;
24
73
 
25
74
  p,
26
75
  h3,
@@ -29,14 +78,94 @@
29
78
  margin-block: 4px;
30
79
  }
31
80
  }
81
+ }
82
+
83
+ .i-contact__icon-wrap {
84
+ --icon-box-size: max(var(--icon-background-size, 0px), var(--icon-size, 88px));
85
+
86
+ width: var(--icon-box-size);
87
+ height: var(--icon-box-size);
88
+ flex: 0 0 var(--icon-box-size);
89
+ display: grid;
90
+ grid-template-areas: "pile";
91
+ place-items: center;
92
+ isolation: isolate;
93
+
94
+ &::before,
95
+ &::after {
96
+ content: "";
97
+ grid-area: pile;
98
+ width: var(--icon-background-size, 0px);
99
+ height: var(--icon-background-size, 0px);
100
+ border-radius: inherit;
101
+ clip-path: var(--icon-background-shape, none);
102
+ }
32
103
 
33
- .i-contact__icon-wrap {
34
- --icon-size: 32px;
104
+ &::before {
105
+ z-index: 0;
106
+ background-color: var(--icon-outline-color, transparent);
35
107
  }
36
108
 
37
- .i-contact__icon img {
38
- width: var(--icon-size);
39
- height: var(--icon-size);
109
+ &::after {
110
+ z-index: 1;
111
+ width: calc(var(--icon-background-size, 0px) - var(--icon-outline-width, 0px) * 2);
112
+ height: calc(var(--icon-background-size, 0px) - var(--icon-outline-width, 0px) * 2);
113
+ background-color: var(--icon-background-color, transparent);
114
+ }
115
+
116
+ .i-contact__icon,
117
+ img,
118
+ svg {
119
+ grid-area: pile;
120
+ position: relative;
121
+ z-index: 2;
122
+ width: var(--icon-size, 88px);
123
+ height: var(--icon-size, 88px);
40
124
  object-fit: contain;
41
125
  }
126
+
127
+ svg path {
128
+ fill: var(--icon-color, currentcolor);
129
+ }
130
+
131
+ &.--background-shape-circle {
132
+ --icon-background-shape: circle(50% at 50% 50%);
133
+ }
134
+
135
+ &.--background-shape-triangle {
136
+ --icon-background-shape: polygon(50% 0%, 0% 100%, 100% 100%);
137
+ }
138
+
139
+ &.--background-shape-rhombus {
140
+ --icon-background-shape: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
141
+ }
142
+
143
+ &.--background-shape-octagon {
144
+ --icon-background-shape: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%);
145
+ }
146
+
147
+ &.--background-shape-bevel {
148
+ --icon-background-shape: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);
149
+ }
150
+
151
+ &.--background-shape-rabbet {
152
+ --icon-background-shape: polygon(
153
+ 0% 15%,
154
+ 15% 15%,
155
+ 15% 0%,
156
+ 85% 0%,
157
+ 85% 15%,
158
+ 100% 15%,
159
+ 100% 85%,
160
+ 85% 85%,
161
+ 85% 100%,
162
+ 15% 100%,
163
+ 15% 85%,
164
+ 0% 85%
165
+ );
166
+ }
167
+
168
+ &.--background-shape-parallelogram {
169
+ --icon-background-shape: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
170
+ }
42
171
  }
@@ -3,7 +3,7 @@ import type {BlockConfiguration, BlockEditProps} from '@wordpress/blocks'
3
3
  import {__} from '@wordpress/i18n'
4
4
  import type {Icon} from '~/types'
5
5
  import type {IconType} from '~/components/IconControl/IconControl'
6
- import {CONTACT_COLUMNS_CONTEXT} from '../contact-group/constants'
6
+ import {CONTACT_COLUMNS_CONTEXT, CONTACT_STYLE_CONTEXT} from '../contact-group/constants'
7
7
  import {CONTACT_ICON_SIZE_DEFAULT, CONTACT_ICON_TYPES} from './constants'
8
8
  import type {ContactItemAttributes, ContactItemOptions} from './types'
9
9
 
@@ -24,7 +24,7 @@ export function createContactItemBlock<T extends ContactItemAttributes = Contact
24
24
  ...(options.parent && {parent: options.parent}),
25
25
  icon: options.icon ?? 'id-alt',
26
26
  supports: {html: false, customClassName: false},
27
- usesContext: [CONTACT_COLUMNS_CONTEXT],
27
+ usesContext: [CONTACT_COLUMNS_CONTEXT, CONTACT_STYLE_CONTEXT],
28
28
  attributes: {
29
29
  ...(options.attributes as any),
30
30
  colSpan: {type: 'number', default: 1},
package/src/index.ts CHANGED
@@ -11,12 +11,17 @@ export {
11
11
  } from './blocks/anchor/anchor-item'
12
12
  export type {
13
13
  ContactColumns,
14
+ ContactDirection,
14
15
  ContactGroupAttributes,
15
16
  ContactGroupOptions,
17
+ ContactIconBackgroundShape,
18
+ ContactShadow,
19
+ ContactTextAlign,
16
20
  } from './blocks/contact/contact-group'
17
21
  export {
18
22
  CONTACT_COLUMNS,
19
23
  CONTACT_COLUMNS_CONTEXT,
24
+ CONTACT_STYLE_CONTEXT,
20
25
  contactGroupDefaults,
21
26
  createContactGroupBlock,
22
27
  } from './blocks/contact/contact-group'