-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(xod-client): fix bug of ColorPinWidget and ColorPicker with varia…
…dic inputs and avoid rendering a multiple ColorPickerWidgets at one time
Showing
10 changed files
with
122 additions
and
134 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
63 changes: 63 additions & 0 deletions
63
packages/xod-client/src/editor/components/inspectorWidgets/ColorPickerWidget.jsx
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,63 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import PointingPopup from '../PointingPopup'; | ||
import ColorPicker from '../ColorPicker'; | ||
import colorPropType from '../ColorPicker/colorPropType'; | ||
|
||
class ColorPickerWidget extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
color: props.color, | ||
}; | ||
|
||
this.onChange = this.onChange.bind(this); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if ( | ||
prevProps.color.hex !== this.props.color.hex && | ||
this.state.color.hex !== this.props.color.hex | ||
) { | ||
// Update the color stored in the state only if it changed | ||
// outside the ColorPicker. | ||
// E.G. user types the new hex color in the input. | ||
// eslint-disable-next-line react/no-did-update-set-state | ||
this.setState({ color: this.props.color }); | ||
} | ||
} | ||
|
||
onChange(color) { | ||
this.setState({ color }); | ||
this.props.onChange(color); | ||
} | ||
|
||
render() { | ||
return ( | ||
<PointingPopup | ||
className="ColorPickerWidget" | ||
isVisible={this.props.isVisible} | ||
selectorPointingAt={`#${this.props.widgetId}`} | ||
hidePopup={this.props.onClose} | ||
> | ||
<ColorPicker | ||
widgetId={this.props.widgetId} | ||
color={this.state.color} | ||
onChange={this.onChange} | ||
/> | ||
</PointingPopup> | ||
); | ||
} | ||
} | ||
|
||
ColorPickerWidget.propTypes = { | ||
color: colorPropType, | ||
isVisible: PropTypes.bool.isRequired, | ||
widgetId: PropTypes.string, | ||
onChange: PropTypes.func.isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ColorPickerWidget; |
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
84 changes: 0 additions & 84 deletions
84
packages/xod-client/src/editor/containers/ColorPickerWidget.jsx
This file was deleted.
Oops, something went wrong.
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