Skip to content

TagSpaces is an offline, open source, document manager with tagging support

migration to hooks

Ilian Sapundshiev13ada55a3887
diff --git a/app/components/dialogs/ColorPickerDialog.js b/app/components/dialogs/ColorPickerDialog.js
index f60b86ae6..e473dfa56 100644
--- a/app/components/dialogs/ColorPickerDialog.js
+++ b/app/components/dialogs/ColorPickerDialog.js
@@ -17,7 +17,7 @@
* @flow
*/
-import React from 'react';
+import React, { useState } from 'react';
import Button from '@material-ui/core/Button';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
@@ -33,6 +33,7 @@ const presetColors = ['#ffffff', '#000000', '#ac725e', '#d06b64', '#f83a22', '#f
'#cabdbf', '#cca6ac', '#f691b2', '#cd74e6', '#a47ae2'];
type Props = {
+ classes: Object,
open: boolean,
color: string,
setColor: (color: string) => void,
@@ -40,11 +41,6 @@ type Props = {
onClose: () => void
};
-type State = {
- color: string,
- colorHex: string
-};
-
const styles = {
noBorder: {
padding: '0 !important',
@@ -52,85 +48,85 @@ const styles = {
backgroundColor: 'transparent !important'
}
};
-class ColorPickerDialog extends React.Component<Props, State> {
- state = {
- color: undefined,
- colorHex: undefined
- };
- onConfirm = () => {
- const { color, colorHex } = this.state;
+const ColorPickerDialog = (props: Props) => {
+ const [color, setColor] = useState(undefined);
+ const [colorHex, setColorHex] = useState(undefined);
+
+ function onConfirm() {
if (color && colorHex) {
const hexAlphaColor = colorHex + Math.round(color.a * 255).toString(16);
- this.props.setColor(hexAlphaColor);
+ props.setColor(hexAlphaColor);
}
- this.props.onClose();
- };
-
- handleChangeComplete = (color) => {
- this.setState({
- color: color.rgb,
- colorHex: color.hex
- });
- };
+ props.onClose();
+ }
- renderTitle = () => (
- <DialogTitle data-tid="colorPickerDialogTitle" >
- {i18n.t('core:colorPickerDialogTitle')}
- </DialogTitle>
- );
+ function handleChangeComplete(newColor: Object) {
+ setColor(newColor.rgb);
+ setColorHex(newColor.hex);
+ }
- renderContent = () => (
- <DialogContent
- style={{
- marginLeft: 'auto',
- marginRight: 'auto'
- }}
- >
- <SketchPicker
- className={this.props.classes.noBorder}
- name="color"
- presetColors={this.props.presetColors ? this.props.presetColors : presetColors}
- color={this.state.color ? this.state.color : this.props.color}
- onChangeComplete={this.handleChangeComplete}
- />
- </DialogContent>
- );
+ function renderTitle() {
+ return (
+ <DialogTitle data-tid="colorPickerDialogTitle" >
+ {i18n.t('core:colorPickerDialogTitle')}
+ </DialogTitle>
+ );
+ }
- renderActions = () => (
- <DialogActions>
- <Button
- data-tid="colorPickerCloseDialog"
- onClick={this.props.onClose}
- color="primary"
- >
- {i18n.t('core:cancel')}
- </Button>
- <Button
- onClick={this.onConfirm}
- data-tid="colorPickerConfirm"
- color="primary"
+ function renderContent() {
+ return (
+ <DialogContent
+ style={{
+ marginLeft: 'auto',
+ marginRight: 'auto'
+ }}
>
- {i18n.t('core:ok')}
- </Button>
- </DialogActions>
- );
+ <SketchPicker
+ className={props.classes.noBorder}
+ name="color"
+ presetColors={props.presetColors ? props.presetColors : presetColors}
+ color={color || props.color}
+ onChangeComplete={handleChangeComplete}
+ />
+ </DialogContent>
+ );
+ }
- render() {
- const {
- open = false,
- onClose
- } = this.props;
+ function renderActions() {
return (
- <GenericDialog
- open={open}
- onClose={onClose}
- renderTitle={this.renderTitle}
- renderContent={this.renderContent}
- renderActions={this.renderActions}
- />
+ <DialogActions>
+ <Button
+ data-tid="colorPickerCloseDialog"
+ onClick={props.onClose}
+ color="primary"
+ >
+ {i18n.t('core:cancel')}
+ </Button>
+ <Button
+ onClick={onConfirm}
+ data-tid="colorPickerConfirm"
+ color="primary"
+ >
+ {i18n.t('core:ok')}
+ </Button>
+ </DialogActions>
);
}
-}
+
+ const {
+ open = false,
+ onClose
+ } = props;
+ return (
+ <GenericDialog
+ open={open}
+ onClose={onClose}
+ renderTitle={renderTitle}
+ renderContent={renderContent}
+ renderActions={renderActions}
+ />
+ );
+};
export default withStyles(styles)(ColorPickerDialog);