Skip to content

Commit 7eca0ff

Browse files
OpenTable Block: CSS Class to counter button padding (#15642)
The opentable button is within an iframe and has default padding. A new CSS class has been added to apply a negative margin to the container matching the default padding. This class can be toggled through a new setting in the block's advanced settings. Co-authored-by: Ben Dwyer <[email protected]>
1 parent 2c734c9 commit 7eca0ff

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

extensions/blocks/opentable/attributes.js

+4
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ export const defaultAttributes = {
6161
default: false,
6262
type: 'boolean',
6363
},
64+
negativeMargin: {
65+
default: false,
66+
type: 'boolean',
67+
},
6468
};

extensions/blocks/opentable/edit.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@ function OpenTableEdit( {
5656
setAttributes( validatedAttributes );
5757
}
5858

59-
const { align, rid, style, iframe, domain, lang, newtab, __isBlockPreview } = attributes;
59+
const {
60+
align,
61+
rid,
62+
style,
63+
iframe,
64+
domain,
65+
lang,
66+
newtab,
67+
negativeMargin,
68+
__isBlockPreview,
69+
} = attributes;
6070
const isPlaceholder = isEmpty( rid );
6171

6272
useEffect( () => {
@@ -166,6 +176,13 @@ function OpenTableEdit( {
166176
onChange={ () => setAttributes( { iframe: ! iframe } ) }
167177
className="is-opentable"
168178
/>
179+
{ 'button' === style && (
180+
<ToggleControl
181+
label={ __( 'Remove button margin', 'jetpack' ) }
182+
checked={ negativeMargin }
183+
onChange={ () => setAttributes( { negativeMargin: ! negativeMargin } ) }
184+
/>
185+
) }
169186
</InspectorAdvancedControls>
170187
<BlockStylesSelector
171188
clientId={ clientId }
@@ -224,6 +241,7 @@ function OpenTableEdit( {
224241
'is-placeholder': isPlaceholder,
225242
'is-multi': 'multi' === getTypeAndTheme( style )[ 0 ],
226243
[ `align${ align }` ]: align,
244+
'has-no-margin': negativeMargin,
227245
} );
228246

229247
return (

extensions/blocks/opentable/editor.scss

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@
9999
}
100100
}
101101

102+
&-theme-button {
103+
&.has-no-margin {
104+
iframe {
105+
margin: -14px;
106+
}
107+
}
108+
}
109+
102110
.editor-styles-wrapper & .components-form-token-field__suggestions-list {
103111
font-family: $default-font;
104112
text-align: left;

extensions/blocks/opentable/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const settings = {
5555
domain: 'com',
5656
lang: 'en-US',
5757
newtab: false,
58+
negativeMargin: false,
5859
},
5960
},
6061
transforms: {

extensions/blocks/opentable/opentable.php

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ function load_assets( $attributes ) {
100100
if ( array_key_exists( 'rid', $attributes ) && is_array( $attributes['rid'] ) && count( $attributes['rid'] ) > 1 ) {
101101
$classes[] = 'is-multi';
102102
}
103+
if ( array_key_exists( 'negativeMargin', $attributes ) && $attributes['negativeMargin'] ) {
104+
$classes[] = 'has-no-margin';
105+
}
103106
$classes = Jetpack_Gutenberg::block_classes(
104107
FEATURE_NAME,
105108
$attributes,

extensions/blocks/opentable/view.scss

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
&.aligncenter iframe {
4141
width: 210px !important;
4242
}
43+
44+
&.has-no-margin {
45+
> div[id^="ot-widget-container"] {
46+
margin: -14px;
47+
}
48+
}
4349
}
4450

4551
.ot-dtp-picker {

0 commit comments

Comments
 (0)