simple-translate/src/content/components/TranslateButton.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-02-21 16:43:45 +00:00
import React from "react";
import { getSettings } from "src/settings/settings";
import "../styles/TranslateButton.scss";
const calcPosition = () => {
const buttonSize = parseInt(getSettings("buttonSize"));
const offset = 10;
2019-02-23 08:33:14 +00:00
switch (getSettings("buttonDirection")) {
case "top":
return { top: -buttonSize - offset, left: -buttonSize / 2 };
case "bottom":
return { top: offset, left: -buttonSize / 2 };
case "right":
return { top: -buttonSize / 2, left: offset };
case "left":
return { top: -buttonSize / 2, left: -buttonSize - offset };
case "topRight":
2019-02-21 16:43:45 +00:00
return { top: -buttonSize - offset, left: offset };
2019-02-23 08:33:14 +00:00
case "topLeft":
2019-02-21 16:43:45 +00:00
return { top: -buttonSize - offset, left: -buttonSize - offset };
2019-02-23 08:33:14 +00:00
case "bottomLeft":
2019-02-21 16:43:45 +00:00
return { top: offset, left: -buttonSize - offset };
2019-02-23 08:33:14 +00:00
case "bottomRight":
default:
return { top: offset, left: offset };
2019-02-21 16:43:45 +00:00
}
};
export default props => {
const { position, shouldShow } = props;
const buttonSize = parseInt(getSettings("buttonSize"));
const { top, left } = calcPosition();
const buttonStyle = {
height: buttonSize,
width: buttonSize,
top: top + position.y,
left: left + position.x
};
return (
<button
style={buttonStyle}
className={`simple-translate-button ${shouldShow ? "isShow" : ""}`}
onClick={props.handleButtonClick}
/>
);
};