UNPKG

design-system-simplefi

Version:

Design System for SimpleFi Applications

101 lines 5.42 kB
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var _a; import React from 'react'; import PropTypes from 'prop-types'; import { isNotNull, isNotUndefined, isNull, noop } from 'ramda-adjunct'; import styled from 'styled-components'; import { IconTypes, SFIIconsNames } from '../../theme/icons/icons.enums'; import { SpacingSizeValuePropType } from '../../types/spacing.types'; import { pxToRem } from '../../utils'; import { Spinner } from '../Spinner'; import StyledButton from './StyledButton'; import StyledIcon from './StyledIcon'; import { ButtonColors, ButtonSizes, ButtonVariants } from './Button.enums'; import { requireRouterLink } from '../../utils/require-router-link'; var LoadingText = styled.span(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding-left: ", ";\n"], ["\n padding-left: ", ";\n"])), function (_a) { var size = _a.size; return size === ButtonSizes.sm ? pxToRem(5) : pxToRem(10); }); var spinnerSizes = (_a = {}, _a[ButtonSizes.lg] = 20, _a[ButtonSizes.md] = 16, _a[ButtonSizes.sm] = 10, _a); var Button = function (_a) { var children = _a.children, _b = _a.variant, variant = _b === void 0 ? ButtonVariants.solid : _b, _c = _a.color, color = _c === void 0 ? ButtonColors.primary : _c, _d = _a.size, size = _d === void 0 ? ButtonSizes.md : _d, iconName = _a.iconName, _e = _a.iconType, iconType = _e === void 0 ? IconTypes.sfi : _e, _f = _a.as, as = _f === void 0 ? null : _f, _g = _a.href, href = _g === void 0 ? null : _g, _h = _a.to, to = _h === void 0 ? null : _h, _j = _a.margin, margin = _j === void 0 ? 'none' : _j, _k = _a.onClick, onClick = _k === void 0 ? noop : _k, _l = _a.isDisabled, isDisabled = _l === void 0 ? false : _l, _m = _a.isLoading, isLoading = _m === void 0 ? false : _m, _o = _a.isExpanded, isExpanded = _o === void 0 ? false : _o, _p = _a.loadingText, loadingText = _p === void 0 ? 'Loading' : _p, props = __rest(_a, ["children", "variant", "color", "size", "iconName", "iconType", "as", "href", "to", "margin", "onClick", "isDisabled", "isLoading", "isExpanded", "loadingText"]); var RouterLink = null; if (isNull(as) && isNotNull(to)) { RouterLink = requireRouterLink(); } var domTag = isNotNull(href) ? 'a' // render 'a' tag if 'href' is present : isNotNull(to) ? RouterLink // render 'Link' if 'to' is present : undefined; // use default if (isNull(RouterLink) && isNull(domTag)) { return null; } var content = isLoading ? (React.createElement(React.Fragment, null, React.createElement(Spinner, { borderWidth: 2, colorPalette: variant !== ButtonVariants.solid, height: spinnerSizes[size], verticalMargin: 0, width: spinnerSizes[size] }), React.createElement(LoadingText, { size: size, variant: variant }, loadingText))) : isNotUndefined(iconName) ? (React.createElement(React.Fragment, null, React.createElement(StyledIcon, { name: iconName, size: size, type: iconType }), children)) : (children); return (React.createElement(StyledButton, __assign({ as: domTag, color: color, disabled: isDisabled || isLoading, href: href, isExpanded: isExpanded, isLoading: isLoading, margin: margin, rel: href ? 'noopener noreferrer' : null, size: size, target: href ? '_blank' : null, to: to, variant: variant, onClick: onClick }, props), content)); }; Button.propTypes = { variant: PropTypes.oneOf(Object.values(ButtonVariants)), size: PropTypes.oneOf(Object.values(ButtonSizes)), color: PropTypes.oneOf(Object.values(ButtonColors)), isDisabled: PropTypes.bool, isLoading: PropTypes.bool, isExpanded: PropTypes.bool, margin: SpacingSizeValuePropType, href: PropTypes.string, to: PropTypes.oneOfType([ PropTypes.string, PropTypes.shape({ pathname: PropTypes.string, search: PropTypes.string, hash: PropTypes.string, }), ]), className: PropTypes.string, iconName: PropTypes.oneOfType([ PropTypes.oneOf(Object.values(SFIIconsNames)), PropTypes.string, ]), iconType: PropTypes.oneOfType([ PropTypes.oneOf(Object.values(IconTypes)), PropTypes.string, ]), loadingText: PropTypes.string, onClick: PropTypes.func, }; export default Button; var templateObject_1; //# sourceMappingURL=Button.js.map