Skip to content

Commit 8043e55

Browse files
author
Nagesh Pai
committed
Handle offset changes
1 parent 67488d6 commit 8043e55

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

assets/infotip/infotip-web-component.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BlaBlaBlocksInfotip extends HTMLElement {
1111
'icon-color',
1212
'icon-type',
1313
'offset',
14-
'placement',
14+
'overlay-placement',
1515
'overlay-text-color',
1616
'overlay-background-color',
1717
];
@@ -48,13 +48,16 @@ class BlaBlaBlocksInfotip extends HTMLElement {
4848
const anchorText = this.shadowRoot.querySelector( '.text' );
4949
const infotip = this.shadowRoot.querySelector( '.infotip' );
5050
const arrow = infotip.querySelector( '.arrow' );
51+
const overlayPlacement =
52+
this.getAttribute( 'overlay-placement' ) ?? 'top';
53+
const offset = this.getAttribute( 'offset' ) ?? 6;
5154

5255
floatingUIDOM
5356
.computePosition( anchorText, infotip, {
54-
placement: 'top',
57+
placement: overlayPlacement,
5558
strategy: 'fixed',
5659
middleware: [
57-
floatingUIDOM.offset( 6 ),
60+
floatingUIDOM.offset( parseInt( offset ) ),
5861
floatingUIDOM.flip(),
5962
floatingUIDOM.shift( { padding: 5 } ),
6063
floatingUIDOM.arrow( { element: arrow } ),
@@ -273,6 +276,11 @@ class BlaBlaBlocksInfotip extends HTMLElement {
273276
this.showTooltip();
274277
}
275278

279+
if ( name === 'offset' ) {
280+
this.updatePosition();
281+
this.showTooltip();
282+
}
283+
276284
const style = shadow.querySelector( 'style' );
277285
style.textContent = this.renderStyle();
278286
}

src/infotip/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const infotip = {
6666
'icon-color': 'icon-color',
6767
'icon-type': 'icon-type',
6868
offset: 'offset',
69-
placement: 'placement',
69+
'overlay-placement': 'overlay-placement',
7070
'overlay-text-color': 'overlay-text-color',
7171
'overlay-background-color': 'overlay-background-color',
7272
},

src/infotip/inline-ui.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,13 @@ function OverlayTabContent( {
123123
<NumberControl
124124
hideLabelFromVision={ true }
125125
label={ __( 'Offset', 'blablablocks-formats' ) }
126-
value={ 6 }
126+
value={ activeAttributes.offset || 6 }
127127
__next40pxDefaultSize={ true }
128-
onChange={ () => {} }
128+
onChange={ ( newValue ) => {
129+
updateAttributes( {
130+
offset: newValue || 6,
131+
} );
132+
} }
129133
style={ { width: '5rem' } }
130134
min={ 6 }
131135
max={ 20 }
@@ -135,11 +139,13 @@ function OverlayTabContent( {
135139
className="overlay-tab-label"
136140
style={ { alignSelf: 'flex-start', paddingTop: '0.5rem' } }
137141
>
138-
{ __( 'Position', 'blablablocks-formats' ) }
142+
{ __( 'Placement', 'blablablocks-formats' ) }
139143
</div>
140144
<AlignmentMatrixControl
141145
hideLabelFromVision={ true }
142-
label={ __( 'Position', 'blablablocks-formats' ) }
146+
label={ __( 'Placement', 'blablablocks-formats' ) }
147+
value={ activeAttributes[ 'overlay-placement' ] || 'top' }
148+
onChange={ () => {} }
143149
/>
144150

145151
<div
@@ -157,10 +163,10 @@ function OverlayTabContent( {
157163
value:
158164
activeAttributes[ 'overlay-background-color' ] ||
159165
'#222222',
160-
onChange: ( newValue ) => {
166+
onChange: ( newColor ) => {
161167
updateAttributes( {
162168
'overlay-background-color':
163-
newValue || '#222222',
169+
newColor || '#222222',
164170
} );
165171
},
166172
},
@@ -169,9 +175,9 @@ function OverlayTabContent( {
169175
value:
170176
activeAttributes[ 'overlay-text-color' ] ||
171177
'#FFFFFF',
172-
onChange: ( newValue ) => {
178+
onChange: ( newColor ) => {
173179
updateAttributes( {
174-
'overlay-text-color': newValue || '#FFFFFF',
180+
'overlay-text-color': newColor || '#FFFFFF',
175181
} );
176182
},
177183
},

0 commit comments

Comments
 (0)