File tree 5 files changed +119
-19
lines changed
5 files changed +119
-19
lines changed Original file line number Diff line number Diff line change @@ -1393,12 +1393,35 @@ export default function ( {
1393
1393
{
1394
1394
positionValue : backgroundText . position ,
1395
1395
onPositionChange : ( value ) => {
1396
- newBackgroundText . position = value ;
1396
+ newBackgroundText . position . top =
1397
+ null != value ?. top
1398
+ ? value ?. top . match ( / ^ \d + $ / )
1399
+ ? `${ value ?. top } px`
1400
+ : value ?. top
1401
+ : undefined ;
1402
+ newBackgroundText . position . right =
1403
+ null != value ?. right
1404
+ ? value ?. right . match ( / ^ \d + $ / )
1405
+ ? `${ value ?. right } px`
1406
+ : value ?. right
1407
+ : undefined ;
1408
+ newBackgroundText . position . bottom =
1409
+ null != value ?. bottom
1410
+ ? value ?. bottom . match ( / ^ \d + $ / )
1411
+ ? `${ value ?. bottom } px`
1412
+ : value ?. bottom
1413
+ : undefined ;
1414
+ newBackgroundText . position . left =
1415
+ null != value ?. left
1416
+ ? value ?. left . match ( / ^ \d + $ / )
1417
+ ? `${ value ?. left } px`
1418
+ : value ?. left
1419
+ : undefined ;
1397
1420
1398
1421
setAttributes ( {
1399
- backgroundText : {
1422
+ backgroundText : cleanEmptyObject ( {
1400
1423
...newBackgroundText ,
1401
- } ,
1424
+ } ) ,
1402
1425
} ) ;
1403
1426
} ,
1404
1427
defaultValue :
Original file line number Diff line number Diff line change @@ -1177,12 +1177,35 @@ export default function ( {
1177
1177
{
1178
1178
positionValue : backgroundText . position ,
1179
1179
onPositionChange : ( value ) => {
1180
- newBackgroundText . position = value ;
1180
+ newBackgroundText . position . top =
1181
+ null != value ?. top
1182
+ ? value ?. top . match ( / ^ \d + $ / )
1183
+ ? `${ value ?. top } px`
1184
+ : value ?. top
1185
+ : undefined ;
1186
+ newBackgroundText . position . right =
1187
+ null != value ?. right
1188
+ ? value ?. right . match ( / ^ \d + $ / )
1189
+ ? `${ value ?. right } px`
1190
+ : value ?. right
1191
+ : undefined ;
1192
+ newBackgroundText . position . bottom =
1193
+ null != value ?. bottom
1194
+ ? value ?. bottom . match ( / ^ \d + $ / )
1195
+ ? `${ value ?. bottom } px`
1196
+ : value ?. bottom
1197
+ : undefined ;
1198
+ newBackgroundText . position . left =
1199
+ null != value ?. left
1200
+ ? value ?. left . match ( / ^ \d + $ / )
1201
+ ? `${ value ?. left } px`
1202
+ : value ?. left
1203
+ : undefined ;
1181
1204
1182
1205
setAttributes ( {
1183
- backgroundText : {
1206
+ backgroundText : cleanEmptyObject ( {
1184
1207
...newBackgroundText ,
1185
- } ,
1208
+ } ) ,
1186
1209
} ) ;
1187
1210
} ,
1188
1211
defaultValue :
Original file line number Diff line number Diff line change @@ -509,12 +509,35 @@ export default function ( {
509
509
{
510
510
positionValue : backgroundText . position ,
511
511
onPositionChange : ( value ) => {
512
- newBackgroundText . position = value ;
512
+ newBackgroundText . position . top =
513
+ null != value ?. top
514
+ ? value ?. top . match ( / ^ \d + $ / )
515
+ ? `${ value ?. top } px`
516
+ : value ?. top
517
+ : undefined ;
518
+ newBackgroundText . position . right =
519
+ null != value ?. right
520
+ ? value ?. right . match ( / ^ \d + $ / )
521
+ ? `${ value ?. right } px`
522
+ : value ?. right
523
+ : undefined ;
524
+ newBackgroundText . position . bottom =
525
+ null != value ?. bottom
526
+ ? value ?. bottom . match ( / ^ \d + $ / )
527
+ ? `${ value ?. bottom } px`
528
+ : value ?. bottom
529
+ : undefined ;
530
+ newBackgroundText . position . left =
531
+ null != value ?. left
532
+ ? value ?. left . match ( / ^ \d + $ / )
533
+ ? `${ value ?. left } px`
534
+ : value ?. left
535
+ : undefined ;
513
536
514
537
setAttributes ( {
515
- backgroundText : {
538
+ backgroundText : cleanEmptyObject ( {
516
539
...newBackgroundText ,
517
- } ,
540
+ } ) ,
518
541
} ) ;
519
542
} ,
520
543
defaultValue :
Original file line number Diff line number Diff line change @@ -1099,19 +1099,27 @@ export const generateStylesForSectionBackground = ( {
1099
1099
: undefined ;
1100
1100
styles [ '--smb-section--background-text-top' ] = ! ! backgroundText
1101
1101
?. position ?. top
1102
- ? backgroundText . position . top
1102
+ ? backgroundText . position . top . match ( / ^ \d + $ / )
1103
+ ? `${ backgroundText . position . top } px`
1104
+ : backgroundText . position . top
1103
1105
: undefined ;
1104
1106
styles [ '--smb-section--background-text-right' ] = ! ! backgroundText
1105
1107
?. position ?. right
1106
- ? backgroundText . position . right
1108
+ ? backgroundText . position . right . match ( / ^ \d + $ / )
1109
+ ? `${ backgroundText . position . right } px`
1110
+ : backgroundText . position . right
1107
1111
: undefined ;
1108
1112
styles [ '--smb-section--background-text-bottom' ] = ! ! backgroundText
1109
1113
?. position ?. bottom
1110
- ? backgroundText . position . bottom
1114
+ ? backgroundText . position . bottom . match ( / ^ \d + $ / )
1115
+ ? `${ backgroundText . position . bottom } px`
1116
+ : backgroundText . position . bottom
1111
1117
: undefined ;
1112
1118
styles [ '--smb-section--background-text-left' ] = ! ! backgroundText
1113
1119
?. position ?. left
1114
- ? backgroundText . position . left
1120
+ ? backgroundText . position . left . match ( / ^ \d + $ / )
1121
+ ? `${ backgroundText . position . left } px`
1122
+ : backgroundText . position . left
1115
1123
: undefined ;
1116
1124
}
1117
1125
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
17
17
import { useSelect } from '@wordpress/data' ;
18
18
import { __ } from '@wordpress/i18n' ;
19
19
20
- import { toNumber } from '@smb/helper' ;
20
+ import { toNumber , cleanEmptyObject } from '@smb/helper' ;
21
21
22
22
import { PanelBasicSettings } from './components/basic' ;
23
23
import { Edit as Header } from './components/header' ;
@@ -533,12 +533,35 @@ export default function ( {
533
533
{
534
534
positionValue : backgroundText . position ,
535
535
onPositionChange : ( value ) => {
536
- newBackgroundText . position = value ;
537
-
538
- setAttributes ( {
539
- backgroundText : {
536
+ newBackgroundText . position . top =
537
+ null != value ?. top
538
+ ? value ?. top . match ( / ^ \d + $ / )
539
+ ? `${ value ?. top } px`
540
+ : value ?. top
541
+ : undefined ;
542
+ newBackgroundText . position . right =
543
+ null != value ?. right
544
+ ? value ?. right . match ( / ^ \d + $ / )
545
+ ? `${ value ?. right } px`
546
+ : value ?. right
547
+ : undefined ;
548
+ newBackgroundText . position . bottom =
549
+ null != value ?. bottom
550
+ ? value ?. bottom . match ( / ^ \d + $ / )
551
+ ? `${ value ?. bottom } px`
552
+ : value ?. bottom
553
+ : undefined ;
554
+ newBackgroundText . position . left =
555
+ null != value ?. left
556
+ ? value ?. left . match ( / ^ \d + $ / )
557
+ ? `${ value ?. left } px`
558
+ : value ?. left
559
+ : undefined ;
560
+
561
+ setAttributes ( {
562
+ backgroundText : cleanEmptyObject ( {
540
563
...newBackgroundText ,
541
- } ,
564
+ } ) ,
542
565
} ) ;
543
566
} ,
544
567
defaultValue :
You can’t perform that action at this time.
0 commit comments