@zohodesk/components
Version:
Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development
77 lines (70 loc) • 2.31 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react'; // props
import { defaultProps } from "./props/defaultProps";
import { propTypes } from "./props/propTypes"; // methods
import cssJSLogic from "./css/cssJSLogic";
import { mergeStyle } from '@zohodesk/utils'; // component registry
import { withComponentRegistrar } from '@zohodesk/dotkit/es/react/ComponentRegistry'; // css
import style from "./css/Button.module.css";
/*
Button text and children props?
use children for both cases
toLowerCase check needed?
*/
function Button(props) {
let {
text,
disabled,
onClick,
status,
children,
dataId,
needAppearance,
getRef,
title,
dataSelectorId,
customProps,
customStyle,
a11y,
id
} = props;
const finalStyle = mergeStyle(style, customStyle);
const {
buttonClass,
loaderParentClass,
loaderChildClass
} = cssJSLogic({
props,
style: finalStyle
});
let statusLower = status.toLowerCase();
return /*#__PURE__*/React.createElement("button", _extends({
className: buttonClass,
"data-id": disabled ? `${dataId}_disabled` : dataId,
"data-test-id": disabled ? `${dataId}_disabled` : dataId,
disabled: disabled || statusLower === 'loading',
onClick: onClick,
"data-title": title,
type: "button",
ref: getRef,
"data-selector-id": dataSelectorId
}, customProps, a11y, {
id: id
}), children ? children : text, statusLower !== 'none' && needAppearance && /*#__PURE__*/React.createElement("div", {
className: finalStyle.overlay
}, /*#__PURE__*/React.createElement("div", {
className: loaderParentClass
}, /*#__PURE__*/React.createElement("div", {
className: loaderChildClass
}))));
}
Button.defaultProps = defaultProps;
Button.propTypes = propTypes;
export default withComponentRegistrar(Button, {
name: 'ZDC_Button'
}); // if (__DOCS__) {
// Button.docs = {
// componentGroup: 'Form Elements',
// folderName: 'Style Guide'
// };
// }