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

Storybook: Add ColorPicker component #18013

Merged
merged 6 commits into from
Oct 28, 2019
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
6 changes: 3 additions & 3 deletions packages/components/src/color-picker/hue.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { TAB } from '@wordpress/keycodes';
*/
import { calculateHueChange } from './utils';
import KeyboardShortcuts from '../keyboard-shortcuts';
import VisuallyHidden from '../visually-hidden';

export class Hue extends Component {
constructor() {
Expand Down Expand Up @@ -157,12 +158,11 @@ export class Hue extends Component {
style={ pointerLocation }
onKeyDown={ this.preventKeyEvents }
/>
<p
className="components-color-picker__hue-description screen-reader-text"
<VisuallyHidden as="p"
id={ `components-color-picker__hue-description-${ instanceId }` }
>
{ __( 'Move the arrow left or right to change hue.' ) }
</p>
</VisuallyHidden>
</div>
{ /* eslint-enable jsx-a11y/no-static-element-interactions */ }
</div>
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/color-picker/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { pure } from '@wordpress/compose';
*/
import IconButton from '../icon-button';
import TextControl from '../text-control';
import VisuallyHidden from '../visually-hidden';
import { isValidHex } from './utils';

/* Wrapper for TextControl, only used to handle intermediate state while typing. */
Expand Down Expand Up @@ -175,9 +176,9 @@ export class Inputs extends Component {
} else if ( this.state.view === 'rgb' ) {
return (
<fieldset>
<legend className="screen-reader-text">
<VisuallyHidden as="legend">
{ __( 'Color value in RGB' ) }
</legend>
</VisuallyHidden>
<div className="components-color-picker__inputs-fields">
<Input
source={ this.state.view }
Expand Down Expand Up @@ -228,9 +229,9 @@ export class Inputs extends Component {
} else if ( this.state.view === 'hsl' ) {
return (
<fieldset>
<legend className="screen-reader-text">
<VisuallyHidden as="legend">
{ __( 'Color value in HSL' ) }
</legend>
</VisuallyHidden>
<div className="components-color-picker__inputs-fields">
<Input
source={ this.state.view }
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/color-picker/saturation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { compose, pure, withInstanceId } from '@wordpress/compose';
*/
import { calculateSaturationChange } from './utils';
import KeyboardShortcuts from '../keyboard-shortcuts';
import VisuallyHidden from '../visually-hidden';

export class Saturation extends Component {
constructor( props ) {
Expand Down Expand Up @@ -171,13 +172,12 @@ export class Saturation extends Component {
style={ pointerLocation }
onKeyDown={ this.preventKeyEvents }
/>
<div
className="screen-reader-text"
<VisuallyHidden
id={ `color-picker-saturation-${ instanceId }` }>
{ __(
'Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.'
) }
</div>
</VisuallyHidden>
</div>
</KeyboardShortcuts>
);
Expand Down
39 changes: 39 additions & 0 deletions packages/components/src/color-picker/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import ColorPicker from '../';

export default { title: 'ColorPicker', component: ColorPicker };

const ColorPickerWithState = ( { ...props } ) => {
const [ color, setColor ] = useState( '#f00' );
return (
<ColorPicker
{ ...props }
color={ color }
onChangeComplete={ ( value ) => setColor( value.hex ) }
/>
);
};

export const _default = () => {
return (
<ColorPickerWithState
disableAlpha
/>
);
};

export const alphaEnabled = () => {
return (
<ColorPickerWithState
disableAlpha={ false }
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`ColorPicker should commit changes to all views on blur 1`] = `
}
/>
<div
className="screen-reader-text"
className="components-visually-hidden"
id="color-picker-saturation-2"
>
Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.
Expand Down Expand Up @@ -99,7 +99,7 @@ exports[`ColorPicker should commit changes to all views on blur 1`] = `
tabIndex="0"
/>
<p
className="components-color-picker__hue-description screen-reader-text"
className="components-visually-hidden"
id="components-color-picker__hue-description-2"
>
Move the arrow left or right to change hue.
Expand Down Expand Up @@ -213,7 +213,7 @@ exports[`ColorPicker should commit changes to all views on keyDown = DOWN 1`] =
}
/>
<div
className="screen-reader-text"
className="components-visually-hidden"
id="color-picker-saturation-4"
>
Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.
Expand Down Expand Up @@ -273,7 +273,7 @@ exports[`ColorPicker should commit changes to all views on keyDown = DOWN 1`] =
tabIndex="0"
/>
<p
className="components-color-picker__hue-description screen-reader-text"
className="components-visually-hidden"
id="components-color-picker__hue-description-4"
>
Move the arrow left or right to change hue.
Expand Down Expand Up @@ -387,7 +387,7 @@ exports[`ColorPicker should commit changes to all views on keyDown = ENTER 1`] =
}
/>
<div
className="screen-reader-text"
className="components-visually-hidden"
id="color-picker-saturation-5"
>
Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.
Expand Down Expand Up @@ -447,7 +447,7 @@ exports[`ColorPicker should commit changes to all views on keyDown = ENTER 1`] =
tabIndex="0"
/>
<p
className="components-color-picker__hue-description screen-reader-text"
className="components-visually-hidden"
id="components-color-picker__hue-description-5"
>
Move the arrow left or right to change hue.
Expand Down Expand Up @@ -561,7 +561,7 @@ exports[`ColorPicker should commit changes to all views on keyDown = UP 1`] = `
}
/>
<div
className="screen-reader-text"
className="components-visually-hidden"
id="color-picker-saturation-3"
>
Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.
Expand Down Expand Up @@ -621,7 +621,7 @@ exports[`ColorPicker should commit changes to all views on keyDown = UP 1`] = `
tabIndex="0"
/>
<p
className="components-color-picker__hue-description screen-reader-text"
className="components-visually-hidden"
id="components-color-picker__hue-description-3"
>
Move the arrow left or right to change hue.
Expand Down Expand Up @@ -735,7 +735,7 @@ exports[`ColorPicker should only update input view for draft changes 1`] = `
}
/>
<div
className="screen-reader-text"
className="components-visually-hidden"
id="color-picker-saturation-1"
>
Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.
Expand Down Expand Up @@ -795,7 +795,7 @@ exports[`ColorPicker should only update input view for draft changes 1`] = `
tabIndex="0"
/>
<p
className="components-color-picker__hue-description screen-reader-text"
className="components-visually-hidden"
id="components-color-picker__hue-description-1"
>
Move the arrow left or right to change hue.
Expand Down Expand Up @@ -909,7 +909,7 @@ exports[`ColorPicker should render color picker 1`] = `
}
/>
<div
className="screen-reader-text"
className="components-visually-hidden"
id="color-picker-saturation-0"
>
Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.
Expand Down Expand Up @@ -969,7 +969,7 @@ exports[`ColorPicker should render color picker 1`] = `
tabIndex="0"
/>
<p
className="components-color-picker__hue-description screen-reader-text"
className="components-visually-hidden"
id="components-color-picker__hue-description-0"
>
Move the arrow left or right to change hue.
Expand Down