diff options
author | eug-vs <eug-vs@keemail.me> | 2021-03-14 03:03:12 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2021-03-14 03:03:12 +0300 |
commit | e1fc8ea5904de90f94d3f63287555c75067846ac (patch) | |
tree | 0046cb821cba9153a202ab7e21f291b69bafe926 /src/components/Button.tsx | |
parent | 64a537425a05a15ecfac3bf314735876dbbd8ed7 (diff) | |
download | commercel-ui-e1fc8ea5904de90f94d3f63287555c75067846ac.tar.gz |
feat: add Page component
Diffstat (limited to 'src/components/Button.tsx')
-rw-r--r-- | src/components/Button.tsx | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 8f2398b..5724b40 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -1,6 +1,9 @@ -import React from 'react'; +import React, { useCallback } from 'react'; +import { useHistory } from 'react-router-dom'; interface Props { + onClick?: () => void; + route?: string; variant?: 'contained' | 'outlined'; size?: 'sm' | 'md' | 'lg'; children: string; @@ -18,10 +21,14 @@ const sizes = { sm: 'p-3', }; -const Button: React.FC<Props> = ({ variant = 'contained', size = 'md', children }) => { +const Button: React.FC<Props> = ({ onClick, route, variant = 'contained', size = 'md', children }) => { + const history = useHistory(); + const navigateRoute = useCallback(() => history.push(route || '/'), [route, history]); + return ( <button type="button" + onClick={route ? navigateRoute : onClick} className={`m-3 font-bold tracking-wide hover:underline focus:outline-none ${variants[variant]} ${sizes[size]}`} > {children} |