File size: 824 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
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { Component } from 'react';
import Gridicon from './gridicons';

const noop = () => {};

export class NavButton extends Component {
	static propTypes = {
		iconName: PropTypes.string.isRequired,
		className: PropTypes.string,
		isEnabled: PropTypes.bool.isRequired,
		navigate: PropTypes.func.isRequired,
	};

	navigate = ( event ) => {
		event.stopPropagation();
		event.preventDefault();

		this.props.navigate();
	};

	render() {
		const { className, iconName, isEnabled } = this.props;

		return (
			<button
				className={ clsx( className, { disabled: ! isEnabled } ) }
				disabled={ ! isEnabled }
				onClick={ isEnabled ? this.navigate : noop }
			>
				<Gridicon icon={ iconName } size={ 18 } />
			</button>
		);
	}
}

export default NavButton;