Skip to content

Commit 5ec5a99

Browse files
committed
hover state
1 parent 8d7ed8a commit 5ec5a99

File tree

3 files changed

+67
-24
lines changed

3 files changed

+67
-24
lines changed

src/plugins/global-settings/block-layouts/editor-loader.js

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,64 @@ const renderGlobalStyles = ( blockLayouts, setStyles, breakDesktop = 1024, break
1919
let css = ''
2020

2121
const desktopCss = []
22-
const tabletMobileCss = []
2322
const tabletCss = []
2423
const mobileCss = []
2524

26-
const getDeclaration = ( property, value ) => {
27-
if ( typeof value === 'object' ) {
28-
return `${ property }: ${ value.top }px ${ value.right }px ${ value.left }px ${ value.bottom }px;`
29-
}
30-
31-
return `${ property }: ${ value };`
25+
const getUnit = ( property, state ) => {
26+
return blockLayouts[ property ][ `${ state }Unit` ] ?? 'px'
3227
}
3328

34-
Object.keys( blockLayouts ).forEach( property => {
35-
const desktop = blockLayouts[ property ].desktop
36-
const tablet = blockLayouts[ property ].tablet
37-
const mobile = blockLayouts[ property ].mobile
29+
const getValue = ( _property, state, value, unit ) => {
30+
let property = _property
3831

39-
if ( desktop ) {
40-
desktopCss.push( getDeclaration( property, desktop ) )
32+
if ( state.indexOf( 'ParentHover' ) !== -1 ) {
33+
property += '-parent-hover'
34+
} else if ( state.indexOf( 'Hover' ) !== -1 ) {
35+
property += '-hover'
4136
}
4237

43-
if ( tablet && mobile ) {
44-
tabletCss.push( getDeclaration( property, tablet ) )
45-
} else if ( tablet && ! mobile ) {
46-
tabletMobileCss.push( getDeclaration( property, tablet ) )
38+
if ( property.indexOf( 'shadow' ) !== -1 ) {
39+
return `${ property }: ${ value };`
4740
}
4841

49-
if ( mobile ) {
50-
mobileCss.push( getDeclaration( property, mobile ) )
42+
if ( typeof value === 'object' ) {
43+
return `${ property }: ${ value.top }${ unit } ${ value.right }${ unit } ${ value.left }${ unit } ${ value.bottom }${ unit };`
5144
}
45+
46+
return `${ property }: ${ value }${ unit };`
47+
}
48+
49+
Object.keys( blockLayouts ).forEach( property => {
50+
const values = Object.keys( blockLayouts[ property ] )
51+
.filter( key => key.indexOf( 'Unit' ) === -1 )
52+
.reduce( ( obj, key ) => {
53+
return {
54+
...obj,
55+
[ key ]: blockLayouts[ property ][ key ],
56+
}
57+
}, {} )
58+
59+
Object.entries( values ).forEach( ( [ state, value ] ) => {
60+
const unit = getUnit( property, state )
61+
62+
if ( state.indexOf( 'desktop' ) !== -1 ) {
63+
desktopCss.push( getValue( property, state, value, unit ) )
64+
}
65+
66+
if ( state.indexOf( 'tablet' ) !== -1 ) {
67+
tabletCss.push( getValue( property, state, value, unit ) )
68+
}
69+
70+
if ( state.indexOf( 'mobile' ) !== -1 ) {
71+
mobileCss.push( getValue( property, state, value, unit ) )
72+
}
73+
} )
5274
} )
5375

5476
css += `:root { ${ compact( desktopCss ).join( '' ) }}`
5577

56-
if ( tabletMobileCss.length > 0 ) {
57-
css += `@media screen and (max-width: ${ breakDesktop - 1 }px){ :root { ${ compact( tabletMobileCss ).join( '' ) }} }`
58-
}
59-
6078
if ( tabletCss.length > 0 ) {
61-
css += `@media screen and (min-width: ${ breakTablet }px) and (max-width: ${ breakDesktop - 1 }px){:root { ${ compact( tabletCss ).join( '' ) }}}`
79+
css += `@media screen and (max-width: ${ breakDesktop - 1 }px){ :root { ${ compact( tabletCss ).join( '' ) }} }`
6280
}
6381

6482
if ( mobileCss.length > 0 ) {

src/styles/block-design-system-blocks.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,19 @@
7575
// Containers
7676
.stk-container:not(.stk--no-padding) {
7777
padding: cssvar(container-padding);
78+
79+
&:hover {
80+
padding: cssvar(container-padding-hover);
81+
}
82+
}
83+
.stk--is-hovered .stk-container:not(.stk--no-padding) {
84+
padding: cssvar(container-padding-hover);
85+
}
86+
87+
:where(.stk-hover-parent:hover, .stk-hover-parent.stk--is-hovered) .stk-container:not(.stk--no-padding) {
88+
padding: cssvar(container-padding-parent-hover);
7889
}
90+
7991
.stk--container-small .stk-container:not(.stk--no-padding) {
8092
#{ '--stk-container-padding' }: cssvar(container-padding-small);
8193
}
@@ -87,6 +99,15 @@
8799
}
88100
.stk-container-padding {
89101
padding: cssvar(container-padding);
102+
&:hover {
103+
padding: cssvar(container-padding-hover);
104+
}
105+
}
106+
.stk--is-hovered .stk-container-padding {
107+
padding: cssvar(container-padding-hover);
108+
}
109+
:where(.stk-hover-parent:hover, .stk-hover-parent.stk--is-hovered) .stk-container-padding {
110+
padding: cssvar(container-padding-parent-hover);
90111
}
91112

92113
// Columns

src/styles/block-design-system.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ $block-design-system: (
2424
desktop: 32px 32px,
2525
mobile: 24px 24px,
2626
),
27+
28+
container-padding-hover: cssvar(container-padding),
29+
container-padding-parent-hover: cssvar(container-padding),
30+
2731
container-padding-large: (
2832
desktop: 64px 80px,
2933
mobile: 32px 24px,

0 commit comments

Comments
 (0)