From e257f37bb4a51439622e0994ccaa4a13273e9054 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Sun, 20 Oct 2024 18:31:31 +0900 Subject: [PATCH] Refactor PaddingControl with wordpress components --- src/controls/padding-control.tsx | 76 ++++++++++++++++++++------------ src/controls/style.scss | 60 ------------------------- 2 files changed, 49 insertions(+), 87 deletions(-) diff --git a/src/controls/padding-control.tsx b/src/controls/padding-control.tsx index 8403a70..f84f824 100644 --- a/src/controls/padding-control.tsx +++ b/src/controls/padding-control.tsx @@ -15,6 +15,8 @@ import { Flex, FlexBlock, FlexItem, + __experimentalGrid as Grid, + __experimentalHStack as HStack, __experimentalVStack as VStack, __experimentalText as Text, __experimentalUnitControl as UnitControl, @@ -122,40 +124,60 @@ export default function PaddingControl( { -
- - { isLinked && ( - - ) } + + + + { isLinked && ( +
+ +
+ ) } +
+ { ! isLinked && ( -
- { SIDE_CONTROLS.map( ( item ) => ( - handleOnFocus( item.value ) } - onChange={ ( value ) => handleOnChange( value, item.value ) } - size="__unstable-large" - /> - ) ) } -
+ + { SIDE_CONTROLS.map( ( item ) => { + const gridStyles = ( value: SideValue ) => { + if ( value === 'top' || value === 'bottom' ) { + return { + gridColumn: 'span 2', + margin: '0 auto', + }; + } + if ( value === 'right' ) { + return { gridColumn: 2, display: 'flex', justifyContent: 'flex-end' }; + } + return { gridRow: 2 }; + }; + return ( +
+ handleOnFocus( item.value ) } + onChange={ ( value ) => handleOnChange( value, item.value ) } + size="__unstable-large" + __unstableInputWidth="110px" + /> +
+ ); + } ) } +
) } diff --git a/src/controls/style.scss b/src/controls/style.scss index cb40db3..a50670e 100644 --- a/src/controls/style.scss +++ b/src/controls/style.scss @@ -1,63 +1,3 @@ -// Linked button common styles. -.ftb-padding-control__header-linked-button, -.ftb-color-control__header-linked-button { - - &.components-button { - display: block; - } -} - -// Header control styles. -.ftb-padding-control__header-control { - display: flex; - align-items: center; - justify-content: space-between; - min-height: 40px !important; - - .components-unit-control-wrapper { - max-width: 104px; - margin-right: auto; - margin-bottom: 0; - } -} - -// Input controls styles. -.ftb-padding-control__input-controls { - display: grid; - gap: 8px; - grid-template-columns: repeat(2, 1fr); - padding-top: 8px; - - .components-unit-control-wrapper.components-unit-control-wrapper { - margin-bottom: 0; - } - - .components-unit-control-wrapper { - - &:nth-child(1) { - margin: 0 auto; - max-width: 116px; - grid-column: span 2; - } - - &:nth-child(2) { - grid-row: 2; - grid-column: 2; - } - - &:nth-child(3) { - margin: 0 auto; - max-width: 116px; - grid-column: span 2; - } - - &:nth-child(4) { - grid-row: 2; - grid-column: 1; - } - } -} - // Color indicator button styles. .ftb-color-indicator-button { position: relative;