Skip to content

Commit 96d9333

Browse files
committed
refactor buttonproptypes and remove href
1 parent 2f41565 commit 96d9333

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/components/Button/Button.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const Button = ({ addClass, backgroundColor, size, label, textColor, type, ...pr
1616
</button>
1717
)
1818

19-
Button.propTypes = {
19+
export const buttonPropTypes = {
2020
addClass: PropTypes.string,
2121
backgroundColor: PropTypes.string,
2222
label: PropTypes.string.isRequired,
@@ -26,6 +26,8 @@ Button.propTypes = {
2626
type: PropTypes.string,
2727
}
2828

29+
Button.propTypes = { ...buttonPropTypes }
30+
2931
Button.defaultProps = {
3032
addClass: '',
3133
backgroundColor: '#000000',

src/compounds/LinkedButton/LinkedButton.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import Link from 'next/link'
33
import PropTypes from 'prop-types'
4-
import Button from '../../components/Button/Button'
4+
import Button, { buttonPropTypes } from '../../components/Button/Button'
55
import './linked-button.css'
66

77
/**
@@ -16,18 +16,22 @@ const LinkedButton = ({ addClass, buttonProps, path }) => (
1616
<ButtonLinkWrapper
1717
addClass={addClass}
1818
buttonProps={buttonProps}
19-
href={path}
2019
/>
2120
</Link>
2221
)
2322

24-
const ButtonLinkWrapper = React.forwardRef(({ addClass, buttonProps, href }, ref) => (
25-
<a href={href} ref={ref} className={addClass}>
26-
<Button {...buttonProps} />
27-
</a>
28-
))
23+
const ButtonLinkWrapper = React.forwardRef(({ ...props }, ref) => {
24+
// eslint-disable-next-line react/prop-types
25+
const { addClass, buttonProps, href } = props
2926

30-
const { onClick, ...remainingPropTypes } = Button.propTypes
27+
return (
28+
<a href={href} ref={ref} className={addClass}>
29+
<Button {...buttonProps} />
30+
</a>
31+
)
32+
})
33+
34+
const { onClick, ...remainingPropTypes } = buttonPropTypes
3135

3236
LinkedButton.propTypes = {
3337
buttonProps: PropTypes.shape(remainingPropTypes).isRequired,
@@ -45,7 +49,6 @@ LinkedButton.defaultProps = {
4549
ButtonLinkWrapper.propTypes = {
4650
addClass: PropTypes.string,
4751
buttonProps: PropTypes.shape(remainingPropTypes).isRequired,
48-
href: PropTypes.string.isRequired,
4952
}
5053

5154
ButtonLinkWrapper.defaultProps = {

0 commit comments

Comments
 (0)