@etsoo/materialui
Version:
TypeScript Material-UI Implementation
40 lines (39 loc) • 1.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackButton = BackButton;
const jsx_runtime_1 = require("react/jsx-runtime");
const ArrowBack_1 = __importDefault(require("@mui/icons-material/ArrowBack"));
const IconButton_1 = __importDefault(require("@mui/material/IconButton"));
const styles_1 = require("@mui/material/styles");
const react_router_1 = require("react-router");
/**
* BackButton
* @param props Props
* @returns Component
*/
function BackButton(props) {
// Destruct
const { color = "primary", size = "small", onClick, ...rest } = props;
// Theme
const theme = (0, styles_1.useTheme)();
// Navigate
const navigate = (0, react_router_1.useNavigate)();
// Color
const pColor = color != "inherit" && color != "default" && color in theme.palette
? theme.palette[color]
: theme.palette.primary;
// Click handler
const onClickLocal = async (event) => {
if (onClick)
onClick(event);
// Navigate
navigate(-1);
};
return ((0, jsx_runtime_1.jsx)(IconButton_1.default, { "aria-label": "Back", color: color, size: size, onClick: onClickLocal, sx: {
backgroundColor: pColor.contrastText,
border: `1px solid ${pColor.light}`
}, ...rest, children: (0, jsx_runtime_1.jsx)(ArrowBack_1.default, {}) }));
}