pixelplanet/src/components/CoordinatesBox.jsx

49 lines
946 B
React
Raw Normal View History

2020-01-02 16:58:06 +00:00
/**
*
* @flow
*/
import React from 'react';
import { connect } from 'react-redux';
import { t } from 'ttag';
import copy from '../utils/clipboard';
import { notify } from '../actions';
2020-01-02 16:58:06 +00:00
import type { State } from '../reducers';
function renderCoordinates(cell): string {
return `(${cell.join(', ')})`;
2020-01-02 16:58:06 +00:00
}
const CoordinatesBox = ({ view, hover, notifyCopy }) => (
<div
className="coorbox"
onClick={() => { copy(window.location.hash); notifyCopy(); }}
role="button"
title={t`Copy to Clipboard`}
tabIndex="0"
>{
renderCoordinates(hover
|| view.map(Math.round))
}</div>
2020-01-02 16:58:06 +00:00
);
function mapDispatchToProps(dispatch) {
return {
notifyCopy() {
dispatch(notify(t`Copied!`));
},
};
}
2020-01-02 16:58:06 +00:00
function mapStateToProps(state: State) {
const { view } = state.canvas;
const { hover } = state.gui;
return { view, hover };
2020-01-02 16:58:06 +00:00
}
export default connect(mapStateToProps, mapDispatchToProps)(CoordinatesBox);