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: Make selected color more obvious #20258

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
type="button"
/>
<svg
aria-hidden="true"
fill="#111111"
focusable="false"
height={24}
role="img"
Expand Down
15 changes: 13 additions & 2 deletions packages/components/src/circular-option-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import Button from '../button';
import Dropdown from '../dropdown';
import Tooltip from '../tooltip';

function Option( { className, isSelected, tooltipText, ...additionalProps } ) {
function Option( {
className,
isSelected,
selectedIconProps,
tooltipText,
...additionalProps
} ) {
const optionButton = (
<Button
isPressed={ isSelected }
Expand All @@ -33,7 +39,12 @@ function Option( { className, isSelected, tooltipText, ...additionalProps } ) {
) : (
optionButton
) }
{ isSelected && <Icon icon={ check } /> }
{ isSelected && (
<Icon
icon={ check }
{ ...( selectedIconProps ? selectedIconProps : {} ) }
/>
) }
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/circular-option-picker/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ $color-palette-circle-spacing: 12px;
box-shadow: inset 0 0 0 4px;
position: relative;
z-index: z-index(".components-circular-option-picker__option.is-pressed");
overflow: visible;

& + svg {
position: absolute;
left: 2px;
top: 2px;
border-radius: 50%;
z-index: z-index(".components-circular-option-picker__option.is-pressed + svg");
background: $white;
pointer-events: none;
}
}
Expand Down
12 changes: 11 additions & 1 deletion packages/components/src/color-palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { map } from 'lodash';
import tinycolor from 'tinycolor2';

/**
* WordPress dependencies
Expand Down Expand Up @@ -29,12 +30,21 @@ export default function ColorPalette( {
<CircularOptionPicker.Option
key={ color }
isSelected={ value === color }
selectedIconProps={
value === color
? {
fill: tinycolor
.mostReadable( color, [ '#111', '#fff' ] )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use #000 instead? cc @jasmussen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should. How much more black could it be? And the answer is none. None more black.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Updated.

.toHexString(),
}
: {}
}
tooltipText={
name ||
// translators: %s: color hex code e.g: "#f00".
sprintf( __( 'Color code: %s' ), color )
}
style={ { color } }
style={ { backgroundColor: color, color } }
onClick={
value === color ? clearColor : () => onChange( color )
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,14 @@ exports[`ColorPalette should allow disabling custom color picker 1`] = `
aria-label="Color: red"
isSelected={true}
onClick={[Function]}
selectedIconProps={
Object {
"fill": "#111111",
}
}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
Expand All @@ -156,8 +162,10 @@ exports[`ColorPalette should allow disabling custom color picker 1`] = `
aria-label="Color: white"
isSelected={false}
onClick={[Function]}
selectedIconProps={Object {}}
style={
Object {
"backgroundColor": "#fff",
"color": "#fff",
}
}
Expand All @@ -167,8 +175,10 @@ exports[`ColorPalette should allow disabling custom color picker 1`] = `
aria-label="Color: blue"
isSelected={false}
onClick={[Function]}
selectedIconProps={Object {}}
style={
Object {
"backgroundColor": "#00f",
"color": "#00f",
}
}
Expand Down Expand Up @@ -230,8 +240,14 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
aria-label="Color: red"
isSelected={true}
onClick={[Function]}
selectedIconProps={
Object {
"fill": "#111111",
}
}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
Expand All @@ -241,8 +257,10 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
aria-label="Color: white"
isSelected={false}
onClick={[Function]}
selectedIconProps={Object {}}
style={
Object {
"backgroundColor": "#fff",
"color": "#fff",
}
}
Expand All @@ -252,8 +270,10 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
aria-label="Color: blue"
isSelected={false}
onClick={[Function]}
selectedIconProps={Object {}}
style={
Object {
"backgroundColor": "#00f",
"color": "#00f",
}
}
Expand All @@ -270,8 +290,14 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
isSelected={true}
key="#f00"
onClick={[Function]}
selectedIconProps={
Object {
"fill": "#111111",
}
}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
Expand All @@ -295,6 +321,7 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
Expand All @@ -311,6 +338,7 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
Expand All @@ -319,6 +347,7 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
</ForwardRef(Button)>
</Tooltip>
<Icon
fill="#111111"
icon={
<SVG
viewBox="-2 -2 24 24"
Expand All @@ -331,13 +360,15 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
}
>
<SVG
fill="#111111"
height={24}
viewBox="-2 -2 24 24"
width={24}
xmlns="http://www.w3.org/2000/svg"
>
<svg
aria-hidden="true"
fill="#111111"
focusable="false"
height={24}
role="img"
Expand All @@ -362,8 +393,10 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
isSelected={false}
key="#fff"
onClick={[Function]}
selectedIconProps={Object {}}
style={
Object {
"backgroundColor": "#fff",
"color": "#fff",
}
}
Expand All @@ -387,6 +420,7 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#fff",
"color": "#fff",
}
}
Expand All @@ -403,6 +437,7 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#fff",
"color": "#fff",
}
}
Expand All @@ -417,8 +452,10 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
isSelected={false}
key="#00f"
onClick={[Function]}
selectedIconProps={Object {}}
style={
Object {
"backgroundColor": "#00f",
"color": "#00f",
}
}
Expand All @@ -442,6 +479,7 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#00f",
"color": "#00f",
}
}
Expand All @@ -458,6 +496,7 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#00f",
"color": "#00f",
}
}
Expand Down
6 changes: 6 additions & 0 deletions storybook/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,7 @@ exports[`Storyshots Components/ColorPalette Default 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
Expand All @@ -1984,6 +1985,7 @@ exports[`Storyshots Components/ColorPalette Default 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#fff",
"color": "#fff",
}
}
Expand All @@ -2005,6 +2007,7 @@ exports[`Storyshots Components/ColorPalette Default 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#00f",
"color": "#00f",
}
}
Expand Down Expand Up @@ -2057,6 +2060,7 @@ exports[`Storyshots Components/ColorPalette With Knobs 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
Expand All @@ -2078,6 +2082,7 @@ exports[`Storyshots Components/ColorPalette With Knobs 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#fff",
"color": "#fff",
}
}
Expand All @@ -2099,6 +2104,7 @@ exports[`Storyshots Components/ColorPalette With Knobs 1`] = `
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#00f",
"color": "#00f",
}
}
Expand Down