UNPKG

ultra-design

Version:
54 lines (45 loc) 2.56 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties'; import { buttonStyles } from './button-style.js'; import { forwardRef } from 'react'; import LoadingIcon from './loading-icon.js'; import { useMergeProps } from '../utils/mergeProps.js'; import clsx from 'clsx'; import withStyle from '../utils/withStyle.js'; import { jsxs, jsx } from '@emotion/react/jsx-runtime'; var _excluded = ["children", "onClick", "loading", "disabled", "type", "className"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } var defaultProps = {}; var ButtonComponent = /*#__PURE__*/forwardRef(function (p, ref) { var props = useMergeProps(defaultProps, p); var children = props.children, onClick = props.onClick, loading = props.loading, disabled = props.disabled, type = props.type, className = props.className, rest = _objectWithoutProperties(props, _excluded); var clickHandler = function clickHandler(e) { if (loading || disabled) { e.preventDefault(); return; } onClick === null || onClick === void 0 ? void 0 : onClick(e); }; return jsxs("button", _objectSpread(_objectSpread({ ref: ref, css: buttonStyles(props), onClick: clickHandler, className: clsx('ultra-button', "ultra-button--".concat(type), disabled && 'ultra-button--disabled', className) }, rest), {}, { children: [loading && jsx(LoadingIcon, {}), jsx("span", { className: "ultra-button__text", children: children })] })); }); var Button = withStyle(ButtonComponent); Button.displayName = 'UltraButton'; var Button$1 = Button; export { Button$1 as default };