Skip to content

Commit

Permalink
Simplify color control (#220)
Browse files Browse the repository at this point in the history
* Refactor: simplify ColorControl component

* Change indicator label

* Fix e2e test
  • Loading branch information
t-hamano authored Oct 20, 2024
1 parent ca37ee7 commit 67ec55a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
38 changes: 16 additions & 22 deletions src/controls/color-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,22 @@ export default function ColorControl( {
{ __( 'Reset', 'flexible-table-block' ) }
</Button>
</div>
<div className="ftb-color-control__controls">
<div className="ftb-color-control__controls-inner">
<div className="ftb-color-control__controls-row">
<ColorIndicatorButton
label={ __( 'All', 'flexible-table-block' ) }
value={ value }
onClick={ handleOnPickerOpen }
isNone={ ! value }
isTransparent={ value === 'transparent' }
/>
{ isPickerOpen && (
<Popover className="ftb-color-control__popover" onClose={ handleOnPickerClose }>
<ColorPalette
colors={ [ ...colors, ...colorsProp ] }
value={ value || '' }
onChange={ handleOnChange }
/>
</Popover>
) }
</div>
</div>
</div>
<ColorIndicatorButton
label={ __( 'Color', 'flexible-table-block' ) }
value={ value }
onClick={ handleOnPickerOpen }
isNone={ ! value }
isTransparent={ value === 'transparent' }
/>
{ isPickerOpen && (
<Popover className="ftb-color-control__popover" onClose={ handleOnPickerClose }>
<ColorPalette
colors={ [ ...colors, ...colorsProp ] }
value={ value || '' }
onChange={ handleOnChange }
/>
</Popover>
) }
</div>
{ /* @ts-ignore Slot is not currently typed on Popover */ }
<Popover.Slot />
Expand Down
2 changes: 0 additions & 2 deletions src/controls/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@

// Controls styles.
.ftb-border-color-control__controls,
.ftb-color-control__controls,
.ftb-border-spacing-control__controls {
display: flex;
align-items: flex-start;
Expand All @@ -213,7 +212,6 @@

// Controls row styles.
.ftb-border-color-control__controls-row,
.ftb-color-control__controls-row,
.ftb-border-spacing-control__controls-row {
display: flex;
align-items: center;
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/specs/global-setting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test.describe( 'Global Setting', () => {
for ( let i = 0; i < tableColors.length; i++ ) {
await page
.getByRole( 'dialog', { name: 'Flexible Table Block Global setting' } )
.getByRole( 'button', { name: 'All' } )
.getByRole( 'button', { name: 'Color' } )
.nth( i )
.click();
await pageUtils.pressKeys( 'Enter' );
Expand All @@ -69,7 +69,7 @@ test.describe( 'Global Setting', () => {
for ( let i = 0; i < cellColors.length; i++ ) {
await page
.getByRole( 'dialog', { name: 'Flexible Table Block Global setting' } )
.getByRole( 'button', { name: 'All' } )
.getByRole( 'button', { name: 'Color' } )
.nth( i )
.click();
await pageUtils.pressKeys( 'Enter' );
Expand All @@ -82,7 +82,7 @@ test.describe( 'Global Setting', () => {
await page.getByRole( 'spinbutton', { name: 'Right' } ).fill( '2' );
await page.getByRole( 'spinbutton', { name: 'Bottom' } ).fill( '3' );
await page.getByRole( 'spinbutton', { name: 'Left' } ).fill( '4' );
// Change cell border with.
// Change cell border width.
await page.getByRole( 'spinbutton', { name: 'All' } ).fill( '2' );
// Change cell border style.
await page.getByRole( 'button', { name: 'Dotted' } ).click();
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/table-style.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function applyCellStyles( page, pageUtils ) {
const cellTextColorId = await page.getByText( 'Cell text color' ).getAttribute( 'id' );
await page
.locator( `[aria-labelledby="${ cellTextColorId }"]` )
.getByRole( 'button', { name: 'All' } )
.getByRole( 'button', { name: 'Color' } )
.click();
await pageUtils.pressKeys( 'Enter' );
await page.getByRole( 'textbox', { name: 'Hex color' } ).fill( '111111' );
Expand All @@ -34,7 +34,7 @@ async function applyCellStyles( page, pageUtils ) {
.getAttribute( 'id' );
await page
.locator( `[aria-labelledby="${ cellBackgroundColorId }"]` )
.getByRole( 'button', { name: 'All' } )
.getByRole( 'button', { name: 'Color' } )
.click();
await pageUtils.pressKeys( 'Enter' );
await page.getByRole( 'textbox', { name: 'Hex color' } ).fill( '333333' );
Expand Down

0 comments on commit 67ec55a

Please sign in to comment.