Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swatch: Remove component in favor of ColorIndicator #43068

Merged
merged 5 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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