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

Update ColorPalette component to accept disableAlpha parameter #18175

Merged
merged 2 commits into from
Oct 30, 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
8 changes: 8 additions & 0 deletions packages/components/src/color-palette/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ Whether the palette should have a clearing button or not.
- Required: No
- Default: true

### disableAlpha

Whether to disable alpha channel controls or not.

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


## Usage
```jsx
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/color-palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function ColorPalette( {
clearable = true,
className,
colors,
disableAlpha = true,
mkaz marked this conversation as resolved.
Show resolved Hide resolved
disableCustomColors = false,
onChange,
value,
Expand Down Expand Up @@ -55,7 +56,7 @@ export default function ColorPalette( {
<ColorPicker
color={ value }
onChangeComplete={ ( color ) => onChange( color.hex ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I know hex colors format don't include "alpha" information in it. This make me think this PR is not complete yet as there's no way for the users of this component to get the value of the selected alpha.

Should we switch to rgba if disableAlpha is false? should we do it every time? do we need a format prop? should we pass the whole color object. These are all options.

Copy link
Member

Choose a reason for hiding this comment

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

Should this PR be reverted?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah... that might explain why it was disabled in the first place.
I think we should revert and then we can add to address other issues.
I prepped this PR for the revert: #18220

disableAlpha
disableAlpha={ disableAlpha }
/>
),
[ value ]
Expand Down
14 changes: 14 additions & 0 deletions packages/components/src/color-palette/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,17 @@ export const withKnobs = () => {
);
};

export const withAlpha = () => {
const colors = [
object( 'Red', { name: 'red', color: '#f00' } ),
object( 'White', { name: 'white', color: '#fff' } ),
object( 'Blue', { name: 'blue', color: '#00f' } ),
];

return (
<ColorPaletteWithState
colors={ colors }
disableAlpha={ false }
/>
);
};