Skip to content

Commit ea7b1d1

Browse files
author
Nagesh Pai
committed
Handle color changes
1 parent 1fb5dec commit ea7b1d1

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed

assets/infotip/infotip-web-component.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class BlaBlaBlocksInfotip extends HTMLElement {
1010
'icon-position',
1111
'icon-color',
1212
'icon-type',
13+
'offset',
14+
'placement',
15+
'overlay-text-color',
16+
'overlay-background-color',
1317
];
1418
}
1519

@@ -106,6 +110,10 @@ class BlaBlaBlocksInfotip extends HTMLElement {
106110
const iconEnabled = this.getAttribute( 'icon-enabled' ) === 'true';
107111
const iconPosition = this.getAttribute( 'icon-position' ) ?? 'left';
108112
const iconColor = this.getAttribute( 'icon-color' ) ?? 'currentColor';
113+
const overlayTextColor =
114+
this.getAttribute( 'overlay-text-color' ) ?? '#FFFFFF';
115+
const overlayBackgroundColor =
116+
this.getAttribute( 'overlay-background-color' ) ?? '#222';
109117

110118
let style = `
111119
.wrapper {
@@ -125,15 +133,15 @@ class BlaBlaBlocksInfotip extends HTMLElement {
125133
position: fixed;
126134
top: 0px;
127135
left: 0px;
128-
background: #222;
129-
color: white;
136+
background: ${ overlayBackgroundColor };
137+
color: ${ overlayTextColor };
130138
padding: 10px;
131139
border-radius: 4px;
132140
font-size: 90%;
133141
}
134142
.infotip .arrow {
135143
position: absolute;
136-
background: #222;
144+
background: ${ overlayBackgroundColor };
137145
width: 8px;
138146
height: 8px;
139147
transform: rotate(45deg);
@@ -258,6 +266,13 @@ class BlaBlaBlocksInfotip extends HTMLElement {
258266
this.updatePosition();
259267
}
260268

269+
if (
270+
name === 'overlay-text-color' ||
271+
name === 'overlay-background-color'
272+
) {
273+
this.showTooltip();
274+
}
275+
261276
const style = shadow.querySelector( 'style' );
262277
style.textContent = this.renderStyle();
263278
}

src/infotip/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,9 @@ export const infotip = {
6565
'icon-position': 'icon-position',
6666
'icon-color': 'icon-color',
6767
'icon-type': 'icon-type',
68+
offset: 'offset',
69+
placement: 'placement',
70+
'overlay-text-color': 'overlay-text-color',
71+
'overlay-background-color': 'overlay-background-color',
6872
},
6973
};

src/infotip/inline-ui.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,42 @@ function TextTabContent( {
110110
*
111111
* @return {JSX.Element} - The rendered overlay tab content.
112112
*/
113-
function OverlayTabContent() {
113+
function OverlayTabContent( {
114+
activeAttributes,
115+
updateAttributes,
116+
removeAttributes,
117+
} ) {
114118
return (
115119
<Grid columns={ 2 } templateColumns="3fr 7fr" alignment="center">
116-
{ /* row 1 - Offset */ }
117120
<div className="overlay-tab-label">
118121
{ __( 'Offset', 'blablablocks-formats' ) }
119122
</div>
120123
<NumberControl
121124
hideLabelFromVision={ true }
122125
label={ __( 'Offset', 'blablablocks-formats' ) }
123-
value={ 0 }
126+
value={ 6 }
124127
__next40pxDefaultSize={ true }
125128
onChange={ () => {} }
129+
style={ { width: '5rem' } }
130+
min={ 6 }
131+
max={ 20 }
126132
/>
127133

128-
{ /* row 2 - Position */ }
129-
<div className="overlay-tab-label">
134+
<div
135+
className="overlay-tab-label"
136+
style={ { alignSelf: 'flex-start', paddingTop: '0.5rem' } }
137+
>
130138
{ __( 'Position', 'blablablocks-formats' ) }
131139
</div>
132140
<AlignmentMatrixControl
133141
hideLabelFromVision={ true }
134142
label={ __( 'Position', 'blablablocks-formats' ) }
135143
/>
136144

137-
{ /* row 3 - Colors */ }
138-
<div className="overlay-tab-label">
145+
<div
146+
className="overlay-tab-label"
147+
style={ { alignSelf: 'flex-start' } }
148+
>
139149
{ __( 'Colors', 'blablablocks-formats' ) }
140150
</div>
141151
<PanelColorSettings
@@ -144,13 +154,25 @@ function OverlayTabContent() {
144154
colorSettings={ [
145155
{
146156
label: __( 'Background', 'blablablocks-formats' ),
147-
value: '#000000',
148-
onChange: () => {},
157+
value:
158+
activeAttributes[ 'overlay-background-color' ] ||
159+
'#222',
160+
onChange: ( newValue ) => {
161+
updateAttributes( {
162+
'overlay-background-color': newValue,
163+
} );
164+
},
149165
},
150166
{
151167
label: __( 'Text', 'blablablocks-formats' ),
152-
value: '#FFFFFF',
153-
onChange: () => {},
168+
value:
169+
activeAttributes[ 'overlay-text-color' ] ||
170+
'#FFFFFF',
171+
onChange: ( newValue ) => {
172+
updateAttributes( {
173+
'overlay-text-color': newValue,
174+
} );
175+
},
154176
},
155177
] }
156178
/>
@@ -450,7 +472,13 @@ export function InlineUI( {
450472
{
451473
name: 'overlay',
452474
title: __( 'Overlay', 'blablablocks-formats' ),
453-
content: <OverlayTabContent />,
475+
content: (
476+
<OverlayTabContent
477+
activeAttributes={ activeAttributes }
478+
updateAttributes={ updateAttributes }
479+
removeAttributes={ removeAttributes }
480+
/>
481+
),
454482
disabled: ! activeAttributes.content,
455483
},
456484
{

0 commit comments

Comments
 (0)