From 563d6a21570c4792965c30a95733d44b277d0790 Mon Sep 17 00:00:00 2001
From: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
Date: Sun, 20 Oct 2024 12:57:50 +0900
Subject: [PATCH] Quality: Removed redundant BaseControl wrapper from
UnitControl component (#225)
---
src/editor.scss | 21 +-
.../global-settings/setting-modal.tsx | 77 +++----
src/settings/table-caption-settings.tsx | 48 ++--
src/settings/table-cell-settings.tsx | 104 ++++-----
src/settings/table-settings.tsx | 205 ++++++++----------
5 files changed, 187 insertions(+), 268 deletions(-)
diff --git a/src/editor.scss b/src/editor.scss
index beaef0c..a5174f5 100644
--- a/src/editor.scss
+++ b/src/editor.scss
@@ -446,24 +446,9 @@
}
.ftb-percent-group {
- margin-top: 8px;
-}
-
-.ftb-font-size-control,
-.ftb-width-control {
+ margin-top: -8px;
- .components-input-control.components-input-control {
- max-width: 100px;
- margin-bottom: 0;
+ &:has(+ .components-base-control) {
+ margin-bottom: 16px;
}
}
-
-.ftb-width-control .components-unit-control .components-unit-control__select {
- background-color: transparent;
- background-image: none;
-}
-
-.ftb-line-height-control .components-text-control__input {
- display: block;
- max-width: 72px;
-}
diff --git a/src/settings/global-settings/setting-modal.tsx b/src/settings/global-settings/setting-modal.tsx
index a6e6f14..b2a5627 100644
--- a/src/settings/global-settings/setting-modal.tsx
+++ b/src/settings/global-settings/setting-modal.tsx
@@ -12,7 +12,6 @@ import { createInterpolateElement, useState } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import apiFetch from '@wordpress/api-fetch';
import {
- BaseControl,
Button,
Notice,
Modal,
@@ -229,54 +228,42 @@ export default function SettingModal( { options, isAdministrator, setIsSettingMo
{ __( 'Default table styles', 'flexible-table-block' ) }
-
- {
- setCurrentOptions( {
- ...currentOptions,
- block_style: {
- ...currentOptions.block_style,
- table_width: sanitizeUnitValue( value ),
- },
- } );
- } }
- size="__unstable-large"
- />
-
+ units={ tableWidthUnits }
+ value={ currentOptions.block_style?.table_width }
+ min={ 0 }
+ onChange={ ( value ) => {
+ setCurrentOptions( {
+ ...currentOptions,
+ block_style: {
+ ...currentOptions.block_style,
+ table_width: sanitizeUnitValue( value ),
+ },
+ } );
+ } }
+ size="__unstable-large"
+ __unstableInputWidth="100px"
+ />
-
- {
- setCurrentOptions( {
- ...currentOptions,
- block_style: {
- ...currentOptions.block_style,
- table_max_width: sanitizeUnitValue( value ),
- },
- } );
- } }
- size="__unstable-large"
- />
-
+ units={ tableWidthUnits }
+ value={ currentOptions.block_style?.table_max_width }
+ min={ 0 }
+ onChange={ ( value ) => {
+ setCurrentOptions( {
+ ...currentOptions,
+ block_style: {
+ ...currentOptions.block_style,
+ table_max_width: sanitizeUnitValue( value ),
+ },
+ } );
+ } }
+ size="__unstable-large"
+ __unstableInputWidth="100px"
+ />
-
+
-
-
-
-
-
+ __next40pxDefaultSize
+ />
-
-
-
-
+
-
-
+ __next40pxDefaultSize
+ />
-
+
-
-
- { [ 25, 50, 75, 100 ].map( ( perWidth ) => {
- const isPressed = cellStylesObj?.width === `${ perWidth }%`;
- return (
-
- );
- } ) }
-
-
+ { [ 25, 50, 75, 100 ].map( ( perWidth ) => {
+ const isPressed = cellStylesObj?.width === `${ perWidth }%`;
+ return (
+
+ );
+ } ) }
+
-
+
-
- {
+ const isPressed = tableStylesObj?.width === `${ perWidth }%`;
+ return (
+
+ );
+ } ) }
+
-
-
+
+
+
-
- {
+ const isPressed = tableStylesObj?.maxWidth === `${ perWidth }%`;
+ return (
+
+ onChangeMaxWidth( isPressed ? '' : sanitizeUnitValue( `${ perWidth }%` ) )
+ }
+ size="small"
+ >
+ { `${ perWidth }%` }
+
+ );
+ } ) }
+ onChangeMaxWidth( tableStylesObj?.maxWidth === 'none' ? '' : 'none' ) }
+ size="small"
>
- { [ 25, 50, 75, 100 ].map( ( perWidth ) => {
- const isPressed = tableStylesObj?.maxWidth === `${ perWidth }%`;
- return (
-
- onChangeMaxWidth( isPressed ? '' : sanitizeUnitValue( `${ perWidth }%` ) )
- }
- size="small"
- >
- { `${ perWidth }%` }
-
- );
- } ) }
- onChangeMaxWidth( tableStylesObj?.maxWidth === 'none' ? '' : 'none' ) }
- size="small"
- >
- { _x( 'none', 'width', 'flexible-table-block' ) }
-
-
-
-
+
+
+
-
-
- { [ 25, 50, 75, 100 ].map( ( perWidth ) => {
- const isPressed = tableStylesObj?.minWidth === `${ perWidth }%`;
- return (
- onChangeMinWidth( isPressed ? '' : `${ perWidth }%` ) }
- size="small"
- >
- { `${ perWidth }%` }
-
- );
- } ) }
-
-
+ { [ 25, 50, 75, 100 ].map( ( perWidth ) => {
+ const isPressed = tableStylesObj?.minWidth === `${ perWidth }%`;
+ return (
+ onChangeMinWidth( isPressed ? '' : `${ perWidth }%` ) }
+ size="small"
+ >
+ { `${ perWidth }%` }
+
+ );
+ } ) }
+