-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mostly working extra actions example
- Loading branch information
Showing
11 changed files
with
173 additions
and
17 deletions.
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
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,93 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
import { | ||
EuiColorPicker, | ||
EuiFormRow, | ||
EuiIcon, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiButtonIcon, | ||
EuiToolTip, | ||
} from '../../../../src/components'; | ||
|
||
import { isValidHex } from '../../../../src/services'; | ||
|
||
export class ExtraActions extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
color: "", | ||
customSwatches: ['#F44337', '#E92362', '#9C28B0', '#3F51B5', '#2196F3', '#18A9F5', '#1ABCD4', '#129688', '#4CAF50', '#CDDC38'], | ||
}; | ||
} | ||
|
||
handleChange = (value) => { | ||
this.setState({ color: value }); | ||
}; | ||
|
||
addColor = (color) => { | ||
this.state.customSwatches.push(color); | ||
|
||
const addedSwatches = this.state.customSwatches; | ||
console.log(addedSwatches); | ||
|
||
this.setState({ customSwatches: addedSwatches }); | ||
} | ||
|
||
removeColor = (color) => { | ||
const trimmedSwatches = this.state.customSwatches.filter(swatch => swatch !== color); | ||
|
||
this.setState({ customSwatches: trimmedSwatches }); | ||
} | ||
|
||
render() { | ||
const hasErrors = !isValidHex(this.state.color) && (this.state.color !== ""); | ||
|
||
let errors; | ||
if (hasErrors) { | ||
errors = ['Provide a valid hex value']; | ||
} | ||
|
||
const customSwatches = this.state.customSwatches.map(color => ({ | ||
color: color, | ||
extraAction: ( | ||
<button onClick={this.removeColor.bind(this, color)} className="euiColorPickerSwatch__remove"> | ||
<EuiIcon type="cross" className="euiColorPickerSwatch__removeIcon" size="s" /> | ||
</button> | ||
) | ||
})); | ||
|
||
return ( | ||
<div style={{ marginBottom: 100 }}> | ||
<EuiFormRow | ||
label="Pick a color" | ||
isInvalid={hasErrors} | ||
error={errors} | ||
> | ||
<EuiFlexGroup alignItems="center" gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiColorPicker | ||
onChange={this.handleChange} | ||
color={this.state.color} | ||
isInvalid={hasErrors} | ||
swatches={customSwatches} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiToolTip content={`Save color ${this.state.color} to my global palette`}> | ||
<EuiButtonIcon | ||
iconType="plusInCircle" | ||
onClick={this.addColor.bind(this, this.state.color)} | ||
aria-label="Add this color to the palette" | ||
color="text" | ||
/> | ||
</EuiToolTip> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFormRow> | ||
</div> | ||
); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/components/color_picker/__snapshots__/color_picker_swatch.test.js.snap
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,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiColorPickerSwatch is rendered 1`] = ` | ||
<button | ||
aria-label="aria-label" | ||
class="euiColorPickerSwatch testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
/> | ||
`; |
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 |
---|---|---|
|
@@ -11,4 +11,8 @@ | |
max-width: ($euiSizeL * 5) + ($euiSizeS * 6) + 2px; | ||
|
||
} | ||
|
||
.euiColorPicker__flexItem { | ||
position: relative; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@import "../form/form_control_layout/mixins"; | ||
|
||
@import "color_picker"; | ||
@import "color_picker_swatch"; |
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