Skip to content

Commit

Permalink
Swatch: Convert component to TypeScript (#42162)
Browse files Browse the repository at this point in the history
* Swatch: Refactor component to TypeScript

* Update CHANGELOG.md

* Update tsconfig.json

* Apply suggestions from code review

Co-authored-by: Lena Morita <lena@jaguchi.com>

Co-authored-by: Lena Morita <lena@jaguchi.com>
  • Loading branch information
Petter Walbø Johnsgård and mirka authored Aug 5, 2022
1 parent 1933820 commit d910ebe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- `Flex`, `FlexItem`, `FlexBlock`: Convert to TypeScript ([#42537](https://github.com/WordPress/gutenberg/pull/42537)).
- `InputControl`: Fix incorrect `size` prop passing ([#42793](https://github.com/WordPress/gutenberg/pull/42793)).
- `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)).

## 19.16.0 (2022-07-27)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { swatch } from '@wordpress/icons';
* Internal dependencies
*/
import Icon from '../icon';
import type { SwatchProps } from './types';

function Swatch( { fill } ) {
// This component will be deprecated. Use `ColorIndicator` instead.
// TODO: Consolidate this component with `ColorIndicator`.
function Swatch( { fill }: SwatchProps ) {
return fill ? (
<span className="components-swatch" style={ { background: fill } } />
) : (
Expand Down
11 changes: 11 additions & 0 deletions packages/components/src/swatch/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* External dependencies
*/
import type { CSSProperties } from 'react';

export type SwatchProps = {
/**
* The color to display in the swatch.
*/
fill?: CSSProperties[ 'background' ];
};
1 change: 1 addition & 0 deletions packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"src/spacer/**/*",
"src/spinner/**/*",
"src/surface/**/*",
"src/swatch/**/*",
"src/text/**/*",
"src/text-control/**/*",
"src/text-highlight/**/*",
Expand Down

0 comments on commit d910ebe

Please sign in to comment.