From c7a469f3f8977b5b9f02c6f6105c1e1fd40e5c33 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Tue, 15 Jan 2019 15:28:09 +0100 Subject: Add href and type to button component --- package-lock.json | 2 +- packages/forms/src/button/index.tsx | 73 +++++++++++++++++++++++++++--------- uidev/src/stories/button.stories.tsx | 25 +++++++++--- 3 files changed, 76 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6b10c8689..a432dda40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2724,7 +2724,7 @@ "requires": { "@mdi/js": "^3.3.92", "@mdi/react": "^1.1.0", - "@meetfranz/theme": "file:packages/theme", + "@meetfranz/theme": "^1.0.4", "react-html-attributes": "^1.4.3", "react-loader": "^2.4.5" }, diff --git a/packages/forms/src/button/index.tsx b/packages/forms/src/button/index.tsx index 784ead04c..92d69ae0e 100644 --- a/packages/forms/src/button/index.tsx +++ b/packages/forms/src/button/index.tsx @@ -8,16 +8,23 @@ import React, { Component } from 'react'; import injectStyle from 'react-jss'; import Loader from 'react-loader'; -import { IFormField, IWithStyle } from '../typings/generic'; +import { IFormField, IWithStyle, Omit } from '../typings/generic'; type ButtonType = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'inverted'; -interface IProps extends React.InputHTMLAttributes, IFormField, IWithStyle { +interface IProps extends IFormField, IWithStyle { + className?: string; + disabled?: boolean; + id?: string; + type?: string; + onClick: (event: React.MouseEvent | React.MouseEvent) => void; buttonType?: ButtonType; stretch?: boolean; loaded?: boolean; busy?: boolean; icon?: keyof typeof mdiIcons; + href?: string; + target?: string; } interface IState { @@ -28,7 +35,7 @@ const styles = (theme: Theme) => ({ button: { borderRadius: theme.borderRadiusSmall, border: 'none', - display: 'flex', + display: 'inline-flex', position: 'relative' as CSS.PositionProperty, transition: 'background .5s', textAlign: 'center' as CSS.TextAlignProperty, @@ -37,6 +44,7 @@ const styles = (theme: Theme) => ({ padding: 0, width: (props: IProps) => (props.stretch ? '100%' : 'auto') as CSS.WidthProperty, fontSize: theme.uiFontSize, + textDecoration: 'none', }, label: { margin: '10px 20px', @@ -127,6 +135,7 @@ class ButtonComponent extends Component { buttonType: 'primary' as ButtonType, stretch: false, busy: false, + // target: '_self' }; state = { @@ -163,6 +172,8 @@ class ButtonComponent extends Component { loaded, icon: iconName, busy: busyProp, + href, + target, } = this.props; const { @@ -185,19 +196,8 @@ class ButtonComponent extends Component { showLoader = busy; } - return ( - + ); + + let wrapperComponent = null; + + if (!href) { + wrapperComponent = ( + + ); + } else { + wrapperComponent = ( + + {content} + + ); + } + + return wrapperComponent; } } diff --git a/uidev/src/stories/button.stories.tsx b/uidev/src/stories/button.stories.tsx index b5906211a..d81808530 100644 --- a/uidev/src/stories/button.stories.tsx +++ b/uidev/src/stories/button.stories.tsx @@ -10,7 +10,6 @@ const defaultProps = { id: 'test1', name: 'test1', type: 'button', - onClick: (e: React.MouseEvent) => console.log('click event', e), disabled: false, }; @@ -22,13 +21,13 @@ const WithStoreButton = observer(({ store }: { store: any }) => ( <>