Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(column): add support for tablet width #2328

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions inc/css/blocks/class-advanced-column-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ function( $value ) use ( $block ) {
array(
'query' => '@media ( max-width: 960px )',
'properties' => array(
array(
'property' => 'flex-basis',
'value' => 'columnWidthTablet',
'unit' => '%',
'format' => function( $value, $attrs ) {
return floatval( $value );
},
),
array(
'property' => 'padding-top',
'value' => 'paddingTablet',
Expand Down
3 changes: 3 additions & 0 deletions src/blocks/blocks/section/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@
"columnWidth": {
"type": "string"
},
"columnWidthTablet": {
"type": "string"
},
"verticalAlign": {
"type": "string"
},
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/blocks/section/column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const Edit = ({
let background, overlayBackground, borderStyle, borderRadiusStyle, boxShadowStyle;

let stylesheet = {
flexBasis: `${ getValue( 'columnWidth' ) }%`,
paddingTop: getValue( 'padding' )?.top,
paddingRight: getValue( 'padding' )?.right,
paddingBottom: getValue( 'padding' )?.bottom,
Expand All @@ -183,6 +184,7 @@ const Edit = ({

if ( isTablet || isMobile ) {
const tabletStyle = pickBy({
flexBasis: getValue( 'columnWidthTablet' ) ? `${ getValue( 'columnWidthTablet' ) }%` : '50%',
paddingTop: getValue( 'paddingTablet' )?.top,
paddingRight: getValue( 'paddingTablet' )?.right,
paddingBottom: getValue( 'paddingTablet' )?.bottom,
Expand Down Expand Up @@ -265,7 +267,6 @@ const Edit = ({
};

const style = {
flexBasis: `${ attributes.columnWidth }%`,
...stylesheet,
...background,
...borderStyle,
Expand Down
50 changes: 40 additions & 10 deletions src/blocks/blocks/section/column/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,39 @@ const Inspector = ({

const [ tab, setTab ] = useTabSwitch( attributes.id, 'layout' );

const getWidthField = () => {
switch ( getView ) {
case 'Desktop':
return 'columnWidth';
case 'Tablet':
return 'columnWidthTablet';
default:
return undefined;
}
};

const getWidth = () => {
switch ( getView ) {
case 'Desktop':
return getValue( 'columnWidth' );
case 'Tablet':
return getValue( 'columnWidthTablet' ) ?? 50;
default:
return undefined;
}
};

const changeColumnWidth = value => {
const width = value || 10;
const nextWidth = ( Number( currentBlockWidth.current ) - width ) + Number( nextBlockWidth.current );
currentBlockWidth.current = width;
nextBlockWidth.current = nextWidth;
setAttributes({ columnWidth: width.toFixed( 2 ) });

const attributeTag = getWidthField();

setAttributes({ [attributeTag]: width.toFixed( 2 ) });
updateBlockAttributes( nextBlock.current, {
columnWidth: nextWidth.toFixed( 2 )
[attributeTag]: nextWidth.toFixed( 2 )
});
};

Expand Down Expand Up @@ -226,14 +251,19 @@ const Inspector = ({
title={ __( 'Column Structure', 'otter-blocks' ) }
>
{ ( 1 < parentBlock.innerBlocks.length ) && (
<RangeControl
label={ __( 'Column Width', 'otter-blocks' ) }
value={ Number( attributes.columnWidth ) }
onChange={ changeColumnWidth }
step={ 0.1 }
min={ 10 }
max={ ( Number( attributes.columnWidth ) + Number( nextBlockWidth.current ) ) - 10 }
/>
<ResponsiveControl
label={ __( 'Screen Type', 'otter-blocks' ) }
>
<RangeControl
label={ __( 'Column Width', 'otter-blocks' ) }
value={ Number( getWidth() ) }
onChange={ changeColumnWidth }
step={ 0.1 }
min={ 10 }
max={ 100 }
disabled={ 'Mobile' === getView }
/>
</ResponsiveControl>
) }

<SelectControl
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/blocks/section/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ html[lang="ja"], html[lang="ko"], html[lang="zh"], html[lang="zh-Hans"], html[la
.wp-block-themeisle-blocks-advanced-columns {
--background: transparent;
--columns-width: 100%;
--columns-width-tablet: 50%;
--horizontal-align: unset;

background: var( --background );
Expand Down Expand Up @@ -346,7 +347,7 @@ html[lang="ja"], html[lang="ko"], html[lang="zh"], html[lang="zh-Hans"], html[la
display: flex;
flex-basis: 100%;
word-break: keep-all;
max-width: var( --columns-width );
max-width: var( --columns-width-tablet );

.wp-block-themeisle-blocks-advanced-column {
position: relative;
Expand Down
Loading