summaryrefslogtreecommitdiff
blob: 80385891a26569d84fdc2d2ffba384b329c63912 (plain)
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
81
/**
 * External dependencies
 */
import {
	Button,
	Dashicon,
	Panel,
	PanelBody,
	TextareaControl,
	TextControl,
} from '@wordpress/components';
import { Component } from '@wordpress/element';

/**
 * Internal dependencies
 */
import './style.scss';

export class Locations extends Component {
	constructor() {
		super( ...arguments );
		this.state = {
			selectedCell: null,
		};
	}

	onDeletePoint = e => {
		const index = parseInt( e.target.getAttribute( 'data-id' ) );
		const { points, onChange } = this.props;

		const newPoints = points.slice( 0 );
		newPoints.splice( index, 1 );
		onChange( newPoints );
	};

	setMarkerField( field, value, index ) {
		const { points, onChange } = this.props;

		const newPoints = points.slice( 0 );
		newPoints[ index ][ field ] = value;
		onChange( newPoints );
	}

	render() {
		const { points } = this.props;
		const rows = points.map( ( point, index ) => (
			<PanelBody title={ point.placeTitle } key={ point.id } initialOpen={ false }>
				<TextControl
					label="Marker Title"
					value={ point.title }
					onChange={ title => this.setMarkerField( 'title', title, index ) }
				/>
				<TextareaControl
					label="Marker Caption"
					value={ point.caption }
					rows="3"
					onChange={ caption => this.setMarkerField( 'caption', caption, index ) }
				/>
				<Button
					data-id={ index }
					onClick={ this.onDeletePoint }
					className="component__locations__delete-btn"
				>
					<Dashicon icon="trash" size="15" /> Delete Marker
				</Button>
			</PanelBody>
		) );
		return (
			<div className="component__locations">
				<Panel className="component__locations__panel">{ rows }</Panel>
			</div>
		);
	}
}

Locations.defaultProps = {
	points: Object.freeze( [] ),
	onChange: () => {},
};

export default Locations;