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

Convert the ColorPalette component to TypeScript #44632

Merged
merged 43 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b9b3fbc
Convert the ColorPalette component to TypeScript
kienstra Oct 2, 2022
2521cae
Correct the PR number in the CHANGELOG
kienstra Oct 2, 2022
54af17c
Apply Marco's suggestion to remove ts-ignore comments
kienstra Oct 12, 2022
c9f5d8a
Replace complex type with ReactNode, thanks to Marco's suggestion
kienstra Oct 12, 2022
4a602dd
Apply Marco's suggestions for TS verbatim
kienstra Oct 12, 2022
7fe648e
Prevent an error from colors possibly being undefined
kienstra Oct 12, 2022
fcd61ee
Rename Color and MultipleColors to ColorObject and PaletteObject
kienstra Oct 12, 2022
4629f7c
Alphabetize the imports again
kienstra Oct 12, 2022
6ee6987
Remove another needless ts-ignore comment
kienstra Oct 12, 2022
6a7c211
Revert "Prevent an error from colors possibly being undefined"
kienstra Oct 12, 2022
3fc9fa2
Make colors allow undefined
kienstra Oct 12, 2022
1ece323
Merge branch 'trunk' into update/color-palette-component-ts
kienstra Oct 12, 2022
a07c43f
Make actions optional, which I forgot before
kienstra Oct 18, 2022
90efcd9
Merge in trunk, resolve conflict
kienstra Oct 18, 2022
c420232
Commit Marco's changes, including a named export
kienstra Oct 19, 2022
9b770d3
Add default tags, thanks to Marco's idea
kienstra Oct 19, 2022
ea5b1f3
Apply Marco's suggestion to remove ts-ignore
kienstra Oct 19, 2022
a79c187
Apply Marco's suggestions, creating UnforwardedColorProps
kienstra Oct 19, 2022
e729c8f
Merge in trunk, resolve conflict
kienstra Oct 19, 2022
25e0ba2
Fix a linting error, remove needless className
kienstra Oct 19, 2022
8001f14
Commit Marco's suggestion: Update packages/components/src/color-palet…
kienstra Oct 21, 2022
e793921
Commit Marco's suggestion: Update packages/components/src/color-palet…
kienstra Oct 21, 2022
53c8beb
Rename test/index.js to test/indes.tsx, mv snapshot
kienstra Oct 21, 2022
06f7c4e
Add types to test/index.tsx
kienstra Oct 21, 2022
293fafe
Renamce styles.js to styles.ts
kienstra Oct 21, 2022
0af93a8
Commit Marco's suggestion: Update packages/components/src/color-palet…
kienstra Oct 24, 2022
d77ca5b
Revert "Add types to test/index.tsx"
kienstra Oct 24, 2022
626b25d
Paste Marco's description verbatim
kienstra Oct 24, 2022
905c40e
Copy props verbatim from types.ts into README.md
kienstra Oct 24, 2022
eee647c
Update the JSDoc description to be the same as the README.md description
kienstra Oct 24, 2022
0bb6561
Merge branch 'trunk' into update/color-palette-component-ts
kienstra Oct 24, 2022
73c17ea
Remove extra entry for Tooltip
kienstra Oct 24, 2022
bb25a62
Move the CHANGELOG entry up, to Unreleased
kienstra Oct 24, 2022
4fd5d9c
Move Usage section to the top of the README. remove experimental prop…
kienstra Oct 25, 2022
d65a832
Commit Marco's suggestion: Update packages/components/src/color-palet…
kienstra Oct 25, 2022
29984c0
Remove the example of the full props
kienstra Oct 25, 2022
988e940
Change the props format to match CONTRIBUTING.md
kienstra Oct 25, 2022
193fae3
Merge in trunk, resolve conflict
kienstra Oct 25, 2022
2df05c6
Commit Marco's suggestion: Update packages/components/src/color-palet…
kienstra Oct 25, 2022
e88cf95
Commit Marco's suggestion: Update packages/components/src/color-palet…
kienstra Oct 25, 2022
eb8c5c3
Commit Marco's suggestion: Update packages/components/src/color-palet…
kienstra Oct 25, 2022
a2aa2e0
Commit Marco's suggestion: Update packages/components/src/color-palet…
kienstra Oct 25, 2022
f741e4b
Merge branch 'trunk' into update/color-palette-component-ts
ciampo Oct 26, 2022
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- `Context`: updated to ignore `react/exhaustive-deps` eslint rule ([#45044](https://github.com/WordPress/gutenberg/pull/45044))
- `Button`: Refactor Storybook to controls and align docs ([#44105](https://github.com/WordPress/gutenberg/pull/44105)).
- `TabPanel`: updated to satisfy `react/exhaustive-deps` eslint rule ([#44935](https://github.com/WordPress/gutenberg/pull/44935))
- `ColorPalette`: Convert to TypeScript ([#44632](https://github.com/WordPress/gutenberg/pull/44632)).
- `UnitControl`: Add tests ([#45260](https://github.com/WordPress/gutenberg/pull/45260)).

## 21.3.0 (2022-10-19)
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/border-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type Border = {

export type Color = {
name: string;
color: CSSProperties[ 'color' ];
color: NonNullable< CSSProperties[ 'color' ] >;
};

export type ColorOrigin = {
Expand Down
34 changes: 14 additions & 20 deletions packages/components/src/circular-option-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import Button from '../button';
import Dropdown from '../dropdown';
import Tooltip from '../tooltip';

function Option( {
className,
isSelected,
selectedIconProps,
tooltipText,
...additionalProps
} ) {
function Option( props ) {
const {
className,
isSelected,
selectedIconProps,
tooltipText,
...additionalProps
} = props;
const optionButton = (
<Button
isPressed={ isSelected }
Expand Down Expand Up @@ -52,12 +53,8 @@ function Option( {
);
}

function DropdownLinkAction( {
buttonProps,
className,
dropdownProps,
linkText,
} ) {
function DropdownLinkAction( props ) {
const { buttonProps, className, dropdownProps, linkText } = props;
return (
<Dropdown
className={ classnames(
Expand All @@ -80,7 +77,8 @@ function DropdownLinkAction( {
);
}

function ButtonAction( { className, children, ...additionalProps } ) {
function ButtonAction( props ) {
const { className, children, ...additionalProps } = props;
return (
<Button
className={ classnames(
Expand All @@ -95,12 +93,8 @@ function ButtonAction( { className, children, ...additionalProps } ) {
);
}

export default function CircularOptionPicker( {
actions,
className,
options,
children,
} ) {
export default function CircularOptionPicker( props ) {
const { actions, className, options, children } = props;
return (
<div
className={ classnames(
Expand Down
100 changes: 51 additions & 49 deletions packages/components/src/color-palette/README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
# ColorPalette

## Props

The component accepts the following props.

{ colors, disableCustomColors = false, value, onChange, className, clearable = true }

### colors

Array with the colors to be shown.

- Type: `Array`
- Required: Yes

### disableCustomColors

Whether to allow custom color or not.

- Type: `Boolean`
- Required: No
- Default: false

### value

currently active value

- Type: `String`
- Required: No

### onChange

Callback called when a color is selected.

- Type: `Function`
- Required: Yes

### className

classes to be applied to the container.

- Type: `String`
- Required: No

### clearable

Whether the palette should have a clearing button or not.

- Type: `Boolean`
- Required: No
- Default: true
`ColorPalette` allows the user to pick a color from a list of pre-defined color entries.

## Usage

Expand Down Expand Up @@ -79,3 +31,53 @@ If you're using this component outside the editor, you can
for the `ColorPalette`'s color swatches, by rendering your `ColorPalette` with a
`Popover.Slot` further up the element tree and within a
`SlotFillProvider` overall.

## Props

The component accepts the following props.

### `colors`: `( PaletteObject | ColorObject )[]`

Array with the colors to be shown. When displaying multiple color palettes to choose from, the format of the array changes from an array of colors objects, to an array of color palettes.

- Required: No
- Default: `[]`

### `disableCustomColors`: `boolean`

Whether to allow the user to pick a custom color on top of the predefined choices (defined via the `colors` prop).

- Required: No
- Default: `false`

### `enableAlpha`: `boolean`

Whether the color picker should display the alpha channel both in the bottom inputs as well as in the color picker itself.

- Required: No
- Default: `false`

### `value`: `string`

currently active value

- Required: No

### `onChange`: `OnColorChange`

Callback called when a color is selected.

- Required: Yes

### `className`: `string`

classes to be applied to the container.

- Required: No

### `clearable`: `boolean`

Whether the palette should have a clearing button.

- Required: No
- Default: `true`
Loading