From 6eb5937039b4d416d2c0558d3f4b29783cc6d533 Mon Sep 17 00:00:00 2001 From: André Oliveira Date: Tue, 17 May 2022 08:42:04 +0100 Subject: Revert "remove duplicate Button component" This reverts commit bbde4a9d54d9c7dc03f34ca4113061a605dd5040. --- src/components/ui/Button.js | 92 ++++++++++++++++++++++++++++++++++++++ src/components/ui/button/index.tsx | 12 ++--- 2 files changed, 96 insertions(+), 8 deletions(-) create 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 new file mode 100644 index 000000000..882b39e69 --- /dev/null +++ b/src/components/ui/Button.js @@ -0,0 +1,92 @@ +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 822ddf48f..11369dcbd 100644 --- a/src/components/ui/button/index.tsx +++ b/src/components/ui/button/index.tsx @@ -35,11 +35,7 @@ interface IProps extends IFormField, WithStylesProps { let buttonTransition: string = 'none'; let loaderContainerTransition: string = 'none'; -if ( - typeof window !== 'undefined' && - window && - window.matchMedia('(prefers-reduced-motion: no-preference)') -) { +if (window && window.matchMedia('(prefers-reduced-motion: no-preference)')) { buttonTransition = 'background .5s, opacity 0.3s'; loaderContainerTransition = 'all 0.3s'; } @@ -263,6 +259,6 @@ class ButtonComponent extends Component { } } -const Button = injectStyle(styles, { injectTheme: true })(ButtonComponent); - -export default Button; +export const Button = injectStyle(styles, { injectTheme: true })( + ButtonComponent, +); -- cgit v1.2.3-70-g09d2