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

85 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-09-24 11:11:34 +00:00
import React from "react";
import PropTypes from "prop-types";
2021-02-25 21:19:45 +00:00
import Base from "../themes/base";
import Loader from "../loader";
import StyledButton from "./styled-button";
2022-08-12 15:07:44 +00:00
import { ColorTheme, ThemeType } from "@docspace/common/components/ColorTheme";
// eslint-disable-next-line no-unused-vars, react/prop-types
const Button = React.forwardRef((props, ref) => {
const { isLoading, icon, label } = props;
return (
<ColorTheme {...props} innerRef={ref} themeId={ThemeType.Button}>
2022-03-11 14:21:52 +00:00
<div className="button-content">
{isLoading && <Loader className="loader" type="track" {...props} />}
{icon && <div className="icon">{icon}</div>}
2022-03-11 14:21:52 +00:00
{label}
</div>
</ColorTheme>
);
});
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,
/** Size of button.
2022-03-11 11:16:17 +00:00
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;