From 3c9f6f1f9d44ac484e0e76f5cd0563f76461ca9b Mon Sep 17 00:00:00 2001 From: Santhosh C Date: Wed, 18 May 2022 23:33:07 +0530 Subject: Remove duplicated Button.js component (#176) --- src/components/ui/Button.js | 92 -------------------------------------- src/components/ui/button/index.tsx | 16 ++++--- 2 files changed, 11 insertions(+), 97 deletions(-) delete mode 100644 src/components/ui/Button.js (limited to 'src/components/ui') diff --git a/src/components/ui/Button.js b/src/components/ui/Button.js deleted file mode 100644 index 882b39e69..000000000 --- a/src/components/ui/Button.js +++ /dev/null @@ -1,92 +0,0 @@ -import { Component } from 'react'; -import PropTypes from 'prop-types'; -import { observer, inject } from 'mobx-react'; -import Loader from 'react-loader'; -import classnames from 'classnames'; - -// Can this file be merged into the './/button/index.tsx' file? -class Button extends Component { - static propTypes = { - className: PropTypes.string, - label: PropTypes.string.isRequired, - disabled: PropTypes.bool, - onClick: PropTypes.func, - type: PropTypes.string, - buttonType: PropTypes.string, - loaded: PropTypes.bool, - htmlForm: PropTypes.string, - stores: PropTypes.shape({ - settings: PropTypes.shape({ - app: PropTypes.shape({ - accentColor: PropTypes.string.isRequired, - }).isRequired, - }).isRequired, - }).isRequired, - }; - - static defaultProps = { - className: null, - disabled: false, - onClick: () => {}, - type: 'button', - buttonType: '', - loaded: true, - htmlForm: '', - }; - - render() { - const { - label, - className, - disabled, - onClick, - type, - buttonType, - loaded, - htmlForm, - } = this.props; - - const buttonProps = { - className: classnames({ - 'franz-form__button': true, - [`franz-form__button--${buttonType}`]: buttonType, - [`${className}`]: className, - }), - type, - }; - - if (disabled) { - buttonProps.disabled = true; - } - - if (onClick) { - buttonProps.onClick = onClick; - } - - if (htmlForm) { - buttonProps.form = htmlForm; - } - - return ( - // disabling rule as button has type defined in `buttonProps` - /* eslint-disable react/button-has-type */ - - /* eslint-enable react/button-has-type */ - ); - } -} - -export default inject('stores')(observer(Button)); diff --git a/src/components/ui/button/index.tsx b/src/components/ui/button/index.tsx index 11369dcbd..9c64e909a 100644 --- a/src/components/ui/button/index.tsx +++ b/src/components/ui/button/index.tsx @@ -30,12 +30,17 @@ interface IProps extends IFormField, WithStylesProps { icon?: string; href?: string; target?: string; + htmlForm?: string; } let buttonTransition: string = 'none'; let loaderContainerTransition: string = 'none'; -if (window && window.matchMedia('(prefers-reduced-motion: no-preference)')) { +if ( + typeof window !== 'undefined' && + window && + window.matchMedia('(prefers-reduced-motion: no-preference)') +) { buttonTransition = 'background .5s, opacity 0.3s'; loaderContainerTransition = 'all 0.3s'; } @@ -187,10 +192,10 @@ class ButtonComponent extends Component { icon, href, target, + htmlForm, } = this.props; const { busy } = this.state; - let showLoader = false; if (loaded) { showLoader = !loaded; @@ -235,6 +240,7 @@ class ButtonComponent extends Component { })} disabled={disabled} data-type="franz-button" + {...(htmlForm && { form: htmlForm })} > {content} @@ -259,6 +265,6 @@ class ButtonComponent extends Component { } } -export const Button = injectStyle(styles, { injectTheme: true })( - ButtonComponent, -); +const Button = injectStyle(styles, { injectTheme: true })(ButtonComponent); + +export default Button; -- cgit v1.2.3-54-g00ecf