DocSpace-client/packages/asc-web-components/button/index.js

94 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-09-24 11:11:34 +00:00
import React from "react";
import PropTypes from "prop-types";
import Loader from "../loader";
import StyledButton from "./styled-button";
2021-02-25 21:19:45 +00:00
import Base from "../themes/base";
// eslint-disable-next-line no-unused-vars, react/prop-types
const Button = React.forwardRef((props, ref) => {
2022-03-14 15:26:13 +00:00
const { primary, size, isLoading, icon, label } = props;
return (
<StyledButton innerRef={ref} {...props}>
2022-03-11 14:21:52 +00:00
<div className="button-content">
2022-03-14 15:26:13 +00:00
{(isLoading || icon) &&
(isLoading ? (
2022-03-11 14:21:52 +00:00
<Loader
type="oval"
size={
size === "medium" ? "20px" : size === "normal" ? "16px" : "12px"
}
color={primary ? "#FFFFFF" : "#333333"}
className="loader"
/>
) : (
2022-03-14 15:26:13 +00:00
<div className="icon">{icon}</div>
))}
2022-03-11 14:21:52 +00:00
{label}
</div>
</StyledButton>
);
});
Button.propTypes = {
/** Button text */
label: PropTypes.string,
/** Tells when the button should be primary */
2019-07-01 07:01:57 +00:00
primary: PropTypes.bool,
2022-03-11 11:16:17 +00:00
/** Size of button.
The normal size equals 36px and 40px in height on the Desktop and Touchcreen devices. */
2022-04-13 15:05:41 +00:00
size: PropTypes.oneOf([
"extraSmall",
"small",
"normal",
"medium",
"normalDesktop",
"normalTouchscreen",
]),
/** Scale width of button to 100% */
scale: PropTypes.bool,
/** Icon node element */
2019-07-02 08:04:54 +00:00
icon: PropTypes.node,
/** Button tab index */
tabIndex: PropTypes.number,
/** Accepts class */
className: PropTypes.string,
/** Accepts id */
id: PropTypes.string,
/** Accepts CSS style */
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
/** Tells when the button should present a hovered state */
isHovered: PropTypes.bool,
/** Disable hover effect */
disableHover: PropTypes.bool,
/** Tells when the button should present a clicked state */
2019-07-01 07:01:57 +00:00
isClicked: PropTypes.bool,
/** Tells when the button should present a disabled state */
isDisabled: PropTypes.bool,
/** Tells when the button should show loader icon */
isLoading: PropTypes.bool,
/** Sets the nim width of the button */
2020-08-06 11:47:16 +00:00
minwidth: PropTypes.string,
/** What the button will trigger when clicked */
onClick: PropTypes.func,
};
Button.defaultProps = {
2020-09-24 11:11:34 +00:00
label: "",
primary: false,
2022-03-11 10:46:32 +00:00
size: "extraSmall",
theme: Base,
scale: false,
2019-07-02 08:04:54 +00:00
icon: null,
tabIndex: -1,
2020-08-06 11:47:16 +00:00
minwidth: null,
2019-07-01 07:01:57 +00:00
isHovered: false,
disableHover: false,
2019-07-01 07:01:57 +00:00
isClicked: false,
isDisabled: false,
isLoading: false,
};
Button.displayName = "Button";
export default Button;