Skip to content

Commit

Permalink
Initial commit:
Browse files Browse the repository at this point in the history
- Add changelog for changes merged in #45681
- Test case for Popover
  • Loading branch information
ramonjd committed Nov 27, 2022
1 parent 0b1998c commit 428bc8e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

### Enhancements

- `TabPanel`: Add ability to set icon only tab buttons ([#45005](https://github.com/WordPress/gutenberg/pull/45005)).
- `TabPanel`: Add ability to set icon only tab buttons ([#45005](https://github.com/WordPress/gutenberg/pull/45005)).
- `PaletteEdit`: Global styles: add onChange actions to color palette items [#45681](https://github.com/WordPress/gutenberg/pull/45681)

### Internal

Expand Down
7 changes: 6 additions & 1 deletion packages/components/src/palette-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function getNameForPosition( elements, slugPrefix ) {
);
}

function ColorPickerPopover( {
export function ColorPickerPopover( {
isGradient,
element,
onChange,
Expand All @@ -101,6 +101,11 @@ function ColorPickerPopover( {
offset={ 20 }
className="components-palette-edit__popover"
onClose={ onClose }
aria-label={
! isGradient
? __( 'Select a new color' )
: __( 'Select a new gradient' )
}
>
{ ! isGradient && (
<ColorPicker
Expand Down
39 changes: 38 additions & 1 deletion packages/components/src/palette-edit/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* External dependencies
*/
import { render, screen } from '@testing-library/react';

/**
* Internal dependencies
*/
import { getNameForPosition } from '../';
import PaletteEdit, { getNameForPosition, ColorPickerPopover } from '../';

describe( 'getNameForPosition', () => {
test( 'should return 1 by default', () => {
Expand Down Expand Up @@ -61,3 +66,35 @@ describe( 'getNameForPosition', () => {
);
} );
} );

describe( 'ColorPickerPopover', () => {
it( 'renders the color picker', () => {
render(
<ColorPickerPopover
isGradient={ false }
element={ {
color: '#FFFFFF',
} }
onChange={ () => {} }
/>
);
expect(
screen.getByLabelText( 'Select a new color' )
).toBeInTheDocument();
} );

it( 'renders the gradient picker', () => {
render(
<ColorPickerPopover
isGradient={ true }
element={ {
gradient: 'linear-gradient(160deg, #D1D1E4, #D1DFE4)',
} }
onChange={ () => {} }
/>
);
expect(
screen.getByLabelText( 'Select a new gradient' )
).toBeInTheDocument();
} );
} );

0 comments on commit 428bc8e

Please sign in to comment.