Skip to content

Commit 17300c1

Browse files
author
Nagesh Pai
committed
Add reset button
1 parent 65e8a6a commit 17300c1

File tree

1 file changed

+109
-76
lines changed

1 file changed

+109
-76
lines changed

src/infotip/inline-ui.js

Lines changed: 109 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ function TextTabContent( {
110110
*
111111
* @return {JSX.Element} - The rendered overlay tab content.
112112
*/
113-
function OverlayTabContent( { activeAttributes, updateAttributes } ) {
113+
function OverlayTabContent( {
114+
activeAttributes,
115+
updateAttributes,
116+
removeAttributes,
117+
} ) {
114118
const placementOptions = [
115119
{
116120
label: __( 'Top', 'blablablocks-formats' ),
@@ -162,86 +166,114 @@ function OverlayTabContent( { activeAttributes, updateAttributes } ) {
162166
},
163167
];
164168

169+
const overLaySettingsEnabled =
170+
activeAttributes[ 'overlay-placement' ] ||
171+
activeAttributes[ 'overlay-background-color' ] ||
172+
activeAttributes[ 'overlay-text-color' ] ||
173+
activeAttributes.offset;
174+
165175
return (
166-
<Grid columns={ 2 } templateColumns="3fr 7fr" alignment="center">
167-
<div className="overlay-tab-label">
168-
{ __( 'Offset', 'blablablocks-formats' ) }
169-
</div>
170-
<NumberControl
171-
hideLabelFromVision={ true }
172-
label={ __( 'Offset', 'blablablocks-formats' ) }
173-
value={ activeAttributes.offset || 6 }
174-
__next40pxDefaultSize={ true }
175-
onChange={ ( newValue ) => {
176-
updateAttributes( {
177-
offset: newValue || 6,
178-
} );
179-
} }
180-
style={ { width: '5rem' } }
181-
min={ 6 }
182-
max={ 20 }
183-
/>
176+
<>
177+
<Grid columns={ 2 } templateColumns="3fr 7fr" alignment="center">
178+
<div className="overlay-tab-label">
179+
{ __( 'Offset', 'blablablocks-formats' ) }
180+
</div>
181+
<NumberControl
182+
hideLabelFromVision={ true }
183+
label={ __( 'Offset', 'blablablocks-formats' ) }
184+
value={ activeAttributes.offset || 6 }
185+
__next40pxDefaultSize={ true }
186+
onChange={ ( newValue ) => {
187+
updateAttributes( {
188+
offset: newValue || 6,
189+
} );
190+
} }
191+
style={ { width: '5rem' } }
192+
min={ 6 }
193+
max={ 20 }
194+
/>
184195

185-
<div
186-
className="overlay-tab-label"
187-
style={ { alignSelf: 'flex-start', paddingTop: '0.5rem' } }
188-
>
189-
{ __( 'Placement', 'blablablocks-formats' ) }
190-
</div>
191-
<SelectControl
192-
label={ __( 'Placement', 'blablablocks-formats' ) }
193-
hideLabelFromVision={ true }
194-
__next40pxDefaultSize={ true }
195-
__nextHasNoMarginBottom={ true }
196-
value={ activeAttributes[ 'overlay-placement' ] || 'top' }
197-
options={ placementOptions }
198-
onChange={ ( selectedOption ) => {
199-
updateAttributes( {
200-
'overlay-placement': selectedOption,
201-
} );
202-
} }
203-
onClick={ ( event ) => {
204-
// Prevent the popover from closing when clicking the select control.
205-
event.stopPropagation();
206-
} }
207-
/>
196+
<div
197+
className="overlay-tab-label"
198+
style={ { alignSelf: 'flex-start', paddingTop: '0.5rem' } }
199+
>
200+
{ __( 'Placement', 'blablablocks-formats' ) }
201+
</div>
202+
<SelectControl
203+
label={ __( 'Placement', 'blablablocks-formats' ) }
204+
hideLabelFromVision={ true }
205+
__next40pxDefaultSize={ true }
206+
__nextHasNoMarginBottom={ true }
207+
value={ activeAttributes[ 'overlay-placement' ] || 'top' }
208+
options={ placementOptions }
209+
onChange={ ( selectedOption ) => {
210+
updateAttributes( {
211+
'overlay-placement': selectedOption,
212+
} );
213+
} }
214+
onClick={ ( event ) => {
215+
// Prevent the popover from closing when clicking the select control.
216+
event.stopPropagation();
217+
} }
218+
/>
208219

209-
<div
210-
className="overlay-tab-label"
211-
style={ { alignSelf: 'flex-start' } }
212-
>
213-
{ __( 'Colors', 'blablablocks-formats' ) }
214-
</div>
215-
<PanelColorSettings
216-
className="overlay-color-settings"
217-
label={ __( 'Colors', 'blablablocks-formats' ) }
218-
colorSettings={ [
219-
{
220-
label: __( 'Background', 'blablablocks-formats' ),
221-
value:
222-
activeAttributes[ 'overlay-background-color' ] ||
223-
'#222222',
224-
onChange: ( newColor ) => {
225-
updateAttributes( {
226-
'overlay-background-color':
227-
newColor || '#222222',
228-
} );
220+
<div
221+
className="overlay-tab-label"
222+
style={ { alignSelf: 'flex-start' } }
223+
>
224+
{ __( 'Colors', 'blablablocks-formats' ) }
225+
</div>
226+
<PanelColorSettings
227+
className="overlay-color-settings"
228+
label={ __( 'Colors', 'blablablocks-formats' ) }
229+
colorSettings={ [
230+
{
231+
label: __( 'Background', 'blablablocks-formats' ),
232+
value:
233+
activeAttributes[
234+
'overlay-background-color'
235+
] || '#222222',
236+
onChange: ( newColor ) => {
237+
updateAttributes( {
238+
'overlay-background-color':
239+
newColor || '#222222',
240+
} );
241+
},
229242
},
230-
},
231-
{
232-
label: __( 'Text', 'blablablocks-formats' ),
233-
value:
234-
activeAttributes[ 'overlay-text-color' ] ||
235-
'#FFFFFF',
236-
onChange: ( newColor ) => {
237-
updateAttributes( {
238-
'overlay-text-color': newColor || '#FFFFFF',
239-
} );
243+
{
244+
label: __( 'Text', 'blablablocks-formats' ),
245+
value:
246+
activeAttributes[ 'overlay-text-color' ] ||
247+
'#FFFFFF',
248+
onChange: ( newColor ) => {
249+
updateAttributes( {
250+
'overlay-text-color': newColor || '#FFFFFF',
251+
} );
252+
},
240253
},
241-
},
242-
] }
243-
/>
244-
</Grid>
254+
] }
255+
/>
256+
</Grid>
257+
<Flex justify="flex-end" style={ { marginTop: '1rem' } }>
258+
<Button
259+
accessibleWhenDisabled={ true }
260+
className="reset-button"
261+
disabled={ ! overLaySettingsEnabled }
262+
onClick={ () => {
263+
removeAttributes( [
264+
'overlay-placement',
265+
'overlay-background-color',
266+
'overlay-text-color',
267+
'offset',
268+
] );
269+
} }
270+
variant="tertiary"
271+
__next40pxDefaultSize={ true }
272+
>
273+
{ __( 'Reset', 'blablablocks-formats' ) }
274+
</Button>
275+
</Flex>
276+
</>
245277
);
246278
}
247279

@@ -554,6 +586,7 @@ export function InlineUI( {
554586
<OverlayTabContent
555587
activeAttributes={ activeAttributes }
556588
updateAttributes={ updateAttributes }
589+
removeAttributes={ removeAttributes }
557590
/>
558591
),
559592
disabled: ! activeAttributes.content,

0 commit comments

Comments
 (0)