File size: 1,845 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Button } from '@automattic/components';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import {
	getImageEditorFileInfo,
	imageEditorHasChanges,
} from 'calypso/state/editor/image-editor/selectors';

const noop = () => {};

class ImageEditorButtons extends Component {
	static propTypes = {
		src: PropTypes.string,
		hasChanges: PropTypes.bool,
		resetImageEditorState: PropTypes.func,
		onDone: PropTypes.func,
		onCancel: PropTypes.func,
		onReset: PropTypes.func,
		doneButtonText: PropTypes.string,
	};

	static defaultProps = {
		src: '',
		hasChanges: false,
		resetImageEditorState: noop,
		onDone: noop,
		onCancel: noop,
		onReset: noop,
		doneButtonText: '',
	};

	render() {
		const { hasChanges, onCancel, src, onDone, onReset, translate, doneButtonText } = this.props;

		return (
			<div className="image-editor__buttons">
				{ onCancel && (
					<Button
						className="image-editor__buttons-button"
						onClick={ onCancel }
						data-e2e-button="cancel"
					>
						{ translate( 'Cancel' ) }
					</Button>
				) }
				<Button
					className="image-editor__buttons-button"
					disabled={ ! hasChanges }
					onClick={ onReset }
					data-e2e-button="reset"
				>
					{ translate( 'Reset' ) }
				</Button>
				<Button
					className="image-editor__buttons-button"
					disabled={ ! src }
					primary
					onClick={ onDone }
					data-e2e-button="done"
					data-tip-target="image-editor-button-done"
				>
					{ doneButtonText || translate( ' Done ' ) }
				</Button>
			</div>
		);
	}
}

export default connect( ( state ) => {
	const { src } = getImageEditorFileInfo( state );
	const hasChanges = imageEditorHasChanges( state );

	return {
		src,
		hasChanges,
	};
} )( localize( ImageEditorButtons ) );