@churchapps/apphelper
Version:
Library of helper functions for React and NextJS ChurchApps
25 lines • 1.31 kB
JavaScript
"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import { Button, Icon, Tooltip } from "@mui/material";
import { Navigate } from "react-router-dom";
export const SmallButton = React.forwardRef((props, ref) => {
const [redirectUrl, setRedirectUrl] = React.useState("");
const handleClick = (e) => {
e.preventDefault();
if (props.href)
setRedirectUrl(props.href);
else if (props.onClick)
props.onClick(e);
};
const style = (props.text)
? { backgroundColor: props.color, "& span": { marginRight: 1 } }
: { minWidth: "auto", padding: "4px 4px" };
if (redirectUrl)
return _jsx(Navigate, { to: redirectUrl });
else {
return (_jsx(Tooltip, { title: props.toolTip || "", arrow: true, placement: "top", children: _jsxs(Button, { sx: style, disabled: props.disabled, variant: props.text ? "outlined" : "text", color: props.color, "aria-label": props.ariaLabel || "editButton", onClick: handleClick, size: "small", "data-testid": props["data-testid"] || `small-button-${props.icon}`, children: [_jsx(Icon, { children: props.icon }), (props.text) ? props.text : ""] }) }));
}
});
SmallButton.displayName = "SmallButton";
//# sourceMappingURL=SmallButton.js.map