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

ColorPalette: Add an accessible color picker based on ChromePicker #10564

Merged
merged 38 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
26a129e
Add color picker component
ryelle Oct 9, 2018
d9b3335
Add color picker styles to build
ryelle Oct 10, 2018
4ea5ab0
Update to buttons for focus handles
ryelle Oct 10, 2018
989828c
Update styles
ryelle Oct 10, 2018
6f83fd3
Update class name
ryelle Oct 12, 2018
fbda218
Add color-picker component to exports
ryelle Oct 12, 2018
5558b02
Update name to ColorPicker
ryelle Oct 12, 2018
57fc98e
Add labels to color input groups
ryelle Oct 12, 2018
392e842
Fix describedby prop name
ryelle Oct 12, 2018
1e5ea75
Update view to use `getDerivedStateFromProps`
ryelle Oct 12, 2018
32bbe05
Add “Input” component to handle intermediate state when entering values
ryelle Oct 12, 2018
3490a88
Add space around text inputs
ryelle Oct 12, 2018
1c4a97c
Translate toggle label
ryelle Oct 13, 2018
8efef93
Add focus styles to colourpicker pointers.
sarahmonster Oct 16, 2018
2f4347e
Remove react-color dependency
oandregal Oct 18, 2018
a608fdf
Add class name to better find the component in the devtools
oandregal Oct 18, 2018
7b28872
Add tinycolor2 dependency
oandregal Oct 18, 2018
e64b978
Add reference to react-color license & copyright
oandregal Oct 18, 2018
93ec99e
Better label
oandregal Oct 18, 2018
0ded7a4
Update snapshot
oandregal Oct 18, 2018
42fe0f7
Decouple valueKey and label
oandregal Oct 18, 2018
2a82ff7
Use createRef
tofumatt Oct 18, 2018
4aa5569
Normalize HSV / HSL values
oandregal Oct 18, 2018
aa90ddf
Omit `valueKey` from being passed to input
ryelle Oct 18, 2018
9cc60b7
Use KeyboardShortcuts component to avoid separate instances of Mousetrap
ryelle Oct 16, 2018
3f6a606
Use createRef in all components
ryelle Oct 18, 2018
c18f63f
Update saturation handle label
ryelle Oct 18, 2018
f26b84f
Prevent key events on slider handles
ryelle Oct 18, 2018
45203c9
Use a focusable div for slider handle
ryelle Oct 18, 2018
40d3687
Apply focus style to alpha handle
ryelle Oct 18, 2018
b0c3896
Add description to hue controls
tofumatt Oct 19, 2018
13b3730
Add speak commands for view change
tofumatt Oct 19, 2018
4ce80dc
Update snapshot
oandregal Oct 19, 2018
9324a6b
Remove test as the component API surface changed
oandregal Oct 19, 2018
28b5cba
Add README, tests and update Changelog
gziolo Oct 19, 2018
fc2740f
Remove react-color dependency
oandregal Oct 19, 2018
330ff58
Add docs manifest file
tofumatt Oct 19, 2018
5610380
Merge branch 'master' into add/a11y-color-picker
tofumatt Oct 19, 2018
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: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/components/src/color-palette/README.md",
"parent": "components"
},
{
"title": "ColorPicker",
"slug": "color-picker",
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/components/src/color-picker/README.md",
"parent": "components"
},
{
"title": "Dashicon",
"slug": "dashicon",
Expand Down
33 changes: 4 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 4.2.0 (Unreleased)

### New Feature

- Added a new `ColorPicker` component ([#10564](https://github.com/WordPress/gutenberg/pull/10564)).

### Deprecation

- `wp.components.PanelColor` has been deprecated in favor of `wp.editor.PanelColorSettings`.
Expand Down
4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"mousetrap": "^1.6.2",
"re-resizable": "^4.7.1",
"react-click-outside": "^2.3.1",
"react-color": "^2.13.4",
"react-dates": "^17.1.1",
"rememo": "^3.0.0",
"tinycolor2": "^1.4.1",
"uuid": "^3.1.0"
},
"devDependencies": {
Expand All @@ -54,4 +54,4 @@
"publishConfig": {
"access": "public"
}
}
}
4 changes: 2 additions & 2 deletions packages/components/src/color-palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { ChromePicker } from 'react-color';
import { map } from 'lodash';

/**
Expand All @@ -16,6 +15,7 @@ import { __, sprintf } from '@wordpress/i18n';
import Button from '../button';
import Dropdown from '../dropdown';
import Tooltip from '../tooltip';
import ColorPicker from '../color-picker';

export default function ColorPalette( { colors, disableCustomColors = false, value, onChange, className } ) {
function applyOrUnset( color ) {
Expand Down Expand Up @@ -71,7 +71,7 @@ export default function ColorPalette( { colors, disableCustomColors = false, val
</Tooltip>
) }
renderContent={ () => (
<ChromePicker
<ColorPicker
color={ value }
onChangeComplete={ ( color ) => onChange( color.hex ) }
disableAlpha
Expand Down
115 changes: 83 additions & 32 deletions packages/components/src/color-palette/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -1,38 +1,89 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ColorPalette Dropdown .renderContent should render dropdown content 1`] = `
<Chrome
color="#f00"
disableAlpha={true}
hex="#ff0000"
hsl={
Object {
"a": 1,
"h": 0,
"l": 0.5,
"s": 1,
}
}
hsv={
Object {
"a": 1,
"h": 0,
"s": 1,
"v": 1,
}
}
oldHue={0}
onChange={[Function]}
onChangeComplete={[Function]}
rgb={
Object {
"a": 1,
"b": 0,
"g": 0,
"r": 255,
}
}
/>
<div
className="components-color-picker is-alpha-disabled"
>
<div
className="components-color-picker__saturation"
>
<WithInstanceId(Saturation)
hsl={
Object {
"a": 1,
"h": 0,
"l": 50,
"s": 100,
}
}
hsv={
Object {
"a": 1,
"h": 0,
"s": 100,
"v": 100,
}
}
onChange={[Function]}
/>
</div>
<div
className="components-color-picker__body"
>
<div
className="components-color-picker__controls"
>
<div
className="components-color-picker__swatch"
>
<div
className="components-color-picker__active"
style={
Object {
"backgroundColor": "rgb(255, 0, 0)",
}
}
/>
</div>
<div
className="components-color-picker__toggles"
>
<WithInstanceId(Hue)
hsl={
Object {
"a": 1,
"h": 0,
"l": 50,
"s": 100,
}
}
onChange={[Function]}
/>
</div>
</div>
<Inputs
disableAlpha={true}
hex="#ff0000"
hsl={
Object {
"a": 1,
"h": 0,
"l": 50,
"s": 100,
}
}
onChange={[Function]}
rgb={
Object {
"a": 1,
"b": 0,
"g": 0,
"r": 255,
}
}
/>
</div>
</div>
`;

exports[`ColorPalette Dropdown .renderToggle should render dropdown content 1`] = `
Expand Down
7 changes: 0 additions & 7 deletions packages/components/src/color-palette/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ describe( 'ColorPalette', () => {
test( 'should render dropdown content', () => {
expect( renderedContent ).toMatchSnapshot();
} );

test( 'should call onToggle on click.', () => {
renderedContent.simulate( 'changeComplete', { hex: currentColor } );

expect( onChange ).toHaveBeenCalledTimes( 1 );
expect( onChange ).toHaveBeenCalledWith( currentColor );
} );
} );
} );
} );
23 changes: 23 additions & 0 deletions packages/components/src/color-picker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ColorPicker

Accessible color picker.

_Parts of the source code were derived and modified from [react-color](https://github.com/casesandberg/react-color/), released under the MIT license._

## Usage
```jsx
import { ColorPicker } from '@wordpress/components';
import { withState } from '@wordpress/compose';

const MyColorPicker = withState( {
color: '#f00',
} )( ( { color, setState } ) => {
return (
<ColorPicker
color={ color }
onChangeComplete={ ( value ) => setState( value.hex ) }
disableAlpha
/>
);
} );
```
Loading