Skip to content

Commit

Permalink
Swatch: Remove component in favor of ColorIndicator (#43068)
Browse files Browse the repository at this point in the history
* Swatch: Remove component in favor of ColorIndicator

* Fix button

* Update CHANGELOG.md

* Use HStack and fix jumping text when changing colors

Co-Authored-By: Marco Ciampini <[email protected]>

Co-authored-by: Marco Ciampini <[email protected]>
  • Loading branch information
Petter Walbø Johnsgård and ciampo authored Aug 11, 2022
1 parent e2c1e20 commit 546d93d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 65 deletions.
2 changes: 1 addition & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- `InputControl`: Fix incorrect `size` prop passing ([#42793](https://github.com/WordPress/gutenberg/pull/42793)).
- `Placeholder`: Convert to TypeScript ([#42990](https://github.com/WordPress/gutenberg/pull/42990)).
- `Popover`: rewrite Storybook examples using controls [#42903](https://github.com/WordPress/gutenberg/pull/42903)).
- `Swatch`: Convert to TypeScript ([#42162](https://github.com/WordPress/gutenberg/pull/42162)).
- `Swatch`: Remove component in favor of `ColorIndicator` [#43068](https://github.com/WordPress/gutenberg/pull/43068)).

## 19.16.0 (2022-07-27)

Expand Down
18 changes: 15 additions & 3 deletions packages/components/src/color-list-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { swatch } from '@wordpress/icons';

/**
* Internal dependencies
*/
import Button from '../button';
import ColorPalette from '../color-palette';
import Swatch from '../swatch';
import ColorIndicator from '../color-indicator';
import Icon from '../icon';
import { HStack } from '../h-stack';

function ColorOption( {
label,
Expand All @@ -23,10 +26,19 @@ function ColorOption( {
<>
<Button
className="components-color-list-picker__swatch-button"
icon={ <Swatch fill={ value } /> }
onClick={ () => setIsOpen( ( prev ) => ! prev ) }
>
{ label }
<HStack justify="flex-start" spacing={ 2 }>
{ value ? (
<ColorIndicator
colorValue={ value }
className="components-color-list-picker__swatch-color"
/>
) : (
<Icon icon={ swatch } />
) }
<span>{ label }</span>
</HStack>
</Button>
{ isOpen && (
<ColorPalette
Expand Down
11 changes: 11 additions & 0 deletions packages/components/src/color-list-picker/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
.components-color-list-picker__color-picker {
margin: $grid-unit-10 0;
}

.components-color-list-picker__swatch-button {
// Used to simulate styles as a .button.has-icon (which this component can't
// opt into, because it has to show more than a simple SVG as the "icon")
padding: 6px;
}

.components-color-list-picker__swatch-color {
// Match the 24px size of the `swatch` icon (used when no color is set)
margin: 2px;
}
17 changes: 12 additions & 5 deletions packages/components/src/duotone-picker/duotone-swatch.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/**
* Internal dependencies
* WordPress dependencies
*/
import Swatch from '../swatch';
import { swatch } from '@wordpress/icons';

/**
* Internal dependencies
*/
import ColorIndicator from '../color-indicator';
import Icon from '../icon';
import { getGradientFromCSSColors } from './utils';

function DuotoneSwatch( { values } ) {
return (
<Swatch
fill={ values && getGradientFromCSSColors( values, '135deg' ) }
return values ? (
<ColorIndicator
colorValue={ getGradientFromCSSColors( values, '135deg' ) }
/>
) : (
<Icon icon={ swatch } />
);
}

Expand Down
1 change: 0 additions & 1 deletion packages/components/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
@import "./search-control/style.scss";
@import "./select-control/style.scss";
@import "./snackbar/style.scss";
@import "./swatch/style.scss";
@import "./tab-panel/style.scss";
@import "./text-control/style.scss";
@import "./tip/style.scss";
Expand Down
22 changes: 0 additions & 22 deletions packages/components/src/swatch/index.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions packages/components/src/swatch/style.scss

This file was deleted.

11 changes: 0 additions & 11 deletions packages/components/src/swatch/types.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"src/spacer/**/*",
"src/spinner/**/*",
"src/surface/**/*",
"src/swatch/**/*",
"src/text/**/*",
"src/text-control/**/*",
"src/text-highlight/**/*",
Expand Down

0 comments on commit 546d93d

Please sign in to comment.