-
Notifications
You must be signed in to change notification settings - Fork 842
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
EuiColorPicker
opacity support
#2850
Merged
Merged
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
78e8187
alpha range
thompsongl 00f84a6
alpha tests
thompsongl 59addfa
docs
thompsongl 6af0bed
wip: rgba support
thompsongl 3a95340
maintain alpha value
thompsongl 9900dd9
prevent track visibility; clean up
thompsongl 1465d18
Merge branch 'master' into colorpicker-opacity
thompsongl 52c6aee
display toggles
thompsongl 34a654a
docs validation
thompsongl 3320fac
use rgba for swatches
thompsongl 0338379
Merge branch 'master' into colorpicker-opacity
thompsongl db5b934
use rgba for css
thompsongl 4a87871
better hue and format throughput
thompsongl cd89265
Merge branch 'master' into colorpicker-opacity
thompsongl 2976b67
color stops validation
thompsongl ddc394a
more docs
thompsongl f0471f2
better format output
thompsongl 8f21a0c
Merge branch 'master' into colorpicker-opacity
thompsongl cfc4c5e
disallow opacity when showAlpha=false
thompsongl 7676221
Merge branch 'master' into colorpicker-opacity
thompsongl 73bb0db
clean up
thompsongl f7f9948
Merge branch 'master' into colorpicker-opacity
thompsongl 9e3471c
updated opacity and validity logic
thompsongl 41733d6
fix button example
thompsongl 9b0bea8
better format detection for null
thompsongl 1345587
alpha channel for color stops
thompsongl 522d598
allow empty range value
thompsongl 887cd3d
sanitize rgb strings
thompsongl 1de8de3
more resiliant sanitization
thompsongl 99285c4
feedback
thompsongl 48c42c3
clean up
thompsongl bac43b4
Merge branch 'master' into colorpicker-opacity
thompsongl 5fd717f
usesEffect; clean up
thompsongl 64dc808
utils tests
thompsongl b71ae10
comment
thompsongl 751685d
Merge branch 'master' into colorpicker-opacity
thompsongl 010f310
CL
thompsongl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
|
||
import { EuiColorPicker, EuiFormRow } from '../../../../src/components'; | ||
import { useColorPicker } from './utils'; | ||
|
||
export const Alpha = () => { | ||
const [color, setColor, errors] = useColorPicker('#D36086'); | ||
const [color2, setColor2, errors2] = useColorPicker('211, 96, 134'); | ||
|
||
const customSwatches = [ | ||
'#54B399', | ||
'#6092C0', | ||
'#D36086', | ||
'#9170B8', | ||
'#CA8EAE', | ||
'#54B39940', | ||
'#6092C040', | ||
'#D3608640', | ||
'#9170B840', | ||
'#CA8EAE40', | ||
]; | ||
|
||
const customSwatches2 = [ | ||
'211, 96, 134, 0.25', | ||
'211, 96, 134, 0.5', | ||
'211, 96, 134, 0.75', | ||
'211, 96, 134', | ||
]; | ||
|
||
return ( | ||
<> | ||
<EuiFormRow | ||
label="Pick a color with optional opacity" | ||
isInvalid={!!errors} | ||
error={errors}> | ||
<EuiColorPicker | ||
onChange={setColor} | ||
color={color} | ||
showAlpha={true} | ||
isInvalid={!!errors} | ||
swatches={customSwatches} | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label="Using RGBa format" | ||
isInvalid={!!errors2} | ||
error={errors2}> | ||
<EuiColorPicker | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onChange={setColor2} | ||
color={color2} | ||
showAlpha={true} | ||
format="rgba" | ||
isInvalid={!!errors2} | ||
swatches={customSwatches2} | ||
/> | ||
</EuiFormRow> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,13 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
|
||
import { EuiColorPicker, EuiFormRow } from '../../../../src/components'; | ||
import { isValidHex } from '../../../../src/services'; | ||
|
||
export class ColorPicker extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
color: '#D36086', | ||
}; | ||
} | ||
|
||
handleChange = value => { | ||
this.setState({ color: value }); | ||
}; | ||
|
||
render() { | ||
const hasErrors = !isValidHex(this.state.color) && this.state.color !== ''; | ||
|
||
let errors; | ||
if (hasErrors) { | ||
errors = ['Provide a valid hex value']; | ||
} | ||
|
||
return ( | ||
<EuiFormRow label="Pick a color" isInvalid={hasErrors} error={errors}> | ||
<EuiColorPicker | ||
onChange={this.handleChange} | ||
color={this.state.color} | ||
isInvalid={hasErrors} | ||
/> | ||
</EuiFormRow> | ||
); | ||
} | ||
} | ||
import { useColorPicker } from './utils'; | ||
|
||
export const ColorPicker = () => { | ||
const [color, setColor, errors] = useColorPicker('#D36086'); | ||
return ( | ||
<EuiFormRow label="Pick a color" isInvalid={!!errors} error={errors}> | ||
<EuiColorPicker onChange={setColor} color={color} isInvalid={!!errors} /> | ||
</EuiFormRow> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
|
||
import { EuiColorPicker, EuiFormRow } from '../../../../src/components'; | ||
import { useColorPicker } from './utils'; | ||
|
||
export const Formats = () => { | ||
const [color, setColor, errors] = useColorPicker('#D36086'); | ||
const [color2, setColor2, errors2] = useColorPicker('#D36086'); | ||
const [color3, setColor3, errors3] = useColorPicker('211, 96, 134'); | ||
return ( | ||
<> | ||
<EuiFormRow label="Auto format" isInvalid={!!errors} error={errors}> | ||
<EuiColorPicker | ||
onChange={setColor} | ||
color={color} | ||
isInvalid={!!errors} | ||
/> | ||
</EuiFormRow> | ||
<EuiFormRow label="Hex format" isInvalid={!!errors2} error={errors2}> | ||
<EuiColorPicker | ||
format="hex" | ||
onChange={setColor2} | ||
color={color2} | ||
isInvalid={!!errors2} | ||
/> | ||
</EuiFormRow> | ||
<EuiFormRow label="RGBa format" isInvalid={!!errors3} error={errors3}> | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<EuiColorPicker | ||
format="rgba" | ||
onChange={setColor3} | ||
color={color3} | ||
isInvalid={!!errors3} | ||
/> | ||
</EuiFormRow> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
useColorPicker
is probably a service we'll want to document and export if it's this helpful in a consuming application?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to open an issue for this. I hadn't thought about it, but it does seem really useful and could be something of a pattern for other relatively simple form-like components.