-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EuiButton, EuiButtonEmpty and EuiButtonIcon can now take an HREF #316
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiButtonEmpty, | ||
EuiButtonIcon, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
} from '../../../../src/components'; | ||
|
||
export default () => ( | ||
<EuiFlexGroup gutterSize="s" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton href="http://www.elastic.co"> | ||
Link to elastic.co | ||
</EuiButton> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty href="http://www.elastic.co"> | ||
Link to elastic.co | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonIcon href="http://www.elastic.co" iconType="link" aria-label="This is a link" /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
import checkHrefAndOnClick from '../../services/prop-types/check_href_and_onclick'; | ||
|
||
import { | ||
ICON_TYPES, | ||
EuiIcon, | ||
|
@@ -32,6 +33,15 @@ const iconSideToClassNameMap = { | |
|
||
export const ICON_SIDES = Object.keys(iconSideToClassNameMap); | ||
|
||
// const checkHrefAndOnClick = (props, propName, componentName) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Kiiiiillll... meeeeee......" - this code |
||
// if (props.href && props.onClick) { | ||
// throw new Error( | ||
// `${componentName} must either specify an href property (if it should be a link) ` + | ||
// `or an onClick property (if it should be a button), but not both.` | ||
// ); | ||
// } | ||
// }; | ||
|
||
export const EuiButton = ({ | ||
children, | ||
className, | ||
|
@@ -41,6 +51,8 @@ export const EuiButton = ({ | |
size, | ||
fill, | ||
isDisabled, | ||
href, | ||
onClick, | ||
...rest | ||
}) => { | ||
|
||
|
@@ -69,18 +81,35 @@ export const EuiButton = ({ | |
); | ||
} | ||
|
||
return ( | ||
<button | ||
disabled={isDisabled} | ||
className={classes} | ||
{...rest} | ||
> | ||
<span className="euiButton__content"> | ||
{buttonIcon} | ||
<span>{children}</span> | ||
</span> | ||
</button> | ||
); | ||
if (href) { | ||
return ( | ||
<a | ||
disabled={isDisabled} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to googles, |
||
className={classes} | ||
href={href} | ||
{...rest} | ||
> | ||
<span className="euiButton__content"> | ||
{buttonIcon} | ||
<span>{children}</span> | ||
</span> | ||
</a> | ||
); | ||
} else { | ||
return ( | ||
<button | ||
disabled={isDisabled} | ||
className={classes} | ||
onClick={onClick} | ||
{...rest} | ||
> | ||
<span className="euiButton__content"> | ||
{buttonIcon} | ||
<span>{children}</span> | ||
</span> | ||
</button> | ||
); | ||
} | ||
}; | ||
|
||
EuiButton.propTypes = { | ||
|
@@ -92,6 +121,8 @@ EuiButton.propTypes = { | |
color: PropTypes.oneOf(COLORS), | ||
size: PropTypes.oneOf(SIZES), | ||
isDisabled: PropTypes.bool, | ||
href: checkHrefAndOnClick, | ||
onClick: PropTypes.func, | ||
}; | ||
|
||
EuiButton.defaultProps = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import React from 'react'; | |
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
import checkHrefAndOnClick from '../../../services/prop-types/check_href_and_onclick'; | ||
|
||
import { | ||
ICON_TYPES, | ||
EuiIcon, | ||
|
@@ -48,6 +50,8 @@ export const EuiButtonEmpty = ({ | |
size, | ||
flush, | ||
isDisabled, | ||
href, | ||
onClick, | ||
...rest | ||
}) => { | ||
|
||
|
@@ -74,18 +78,35 @@ export const EuiButtonEmpty = ({ | |
); | ||
} | ||
|
||
return ( | ||
<button | ||
disabled={isDisabled} | ||
className={classes} | ||
{...rest} | ||
> | ||
<span className="euiButtonEmpty__content"> | ||
{buttonIcon} | ||
<span>{children}</span> | ||
</span> | ||
</button> | ||
); | ||
if (href) { | ||
return ( | ||
<a | ||
disabled={isDisabled} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too |
||
className={classes} | ||
href={href} | ||
{...rest} | ||
> | ||
<span className="euiButtonEmpty__content"> | ||
{buttonIcon} | ||
<span>{children}</span> | ||
</span> | ||
</a> | ||
); | ||
} else { | ||
return ( | ||
<button | ||
disabled={isDisabled} | ||
className={classes} | ||
onClick={onClick} | ||
{...rest} | ||
> | ||
<span className="euiButtonEmpty__content"> | ||
{buttonIcon} | ||
<span>{children}</span> | ||
</span> | ||
</button> | ||
); | ||
} | ||
}; | ||
|
||
EuiButtonEmpty.propTypes = { | ||
|
@@ -97,6 +118,8 @@ EuiButtonEmpty.propTypes = { | |
size: PropTypes.oneOf(SIZES), | ||
flush: PropTypes.oneOf(FLUSH_TYPES), | ||
isDisabled: PropTypes.bool, | ||
href: checkHrefAndOnClick, | ||
onClick: PropTypes.func, | ||
}; | ||
|
||
EuiButtonEmpty.defaultProps = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import React from 'react'; | |
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
import checkHrefAndOnClick from '../../../services/prop-types/check_href_and_onclick'; | ||
|
||
import { | ||
ICON_TYPES, | ||
EuiIcon, | ||
|
@@ -37,6 +39,8 @@ export const EuiButtonIcon = ({ | |
iconType, | ||
color, | ||
isDisabled, | ||
href, | ||
onClick, | ||
...rest | ||
}) => { | ||
|
||
|
@@ -60,15 +64,29 @@ export const EuiButtonIcon = ({ | |
); | ||
} | ||
|
||
return ( | ||
<button | ||
disabled={isDisabled} | ||
className={classes} | ||
{...rest} | ||
> | ||
{buttonIcon} | ||
</button> | ||
); | ||
if (href) { | ||
return ( | ||
<a | ||
disabled={isDisabled} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too |
||
className={classes} | ||
href={href} | ||
{...rest} | ||
> | ||
{buttonIcon} | ||
</a> | ||
); | ||
} else { | ||
return ( | ||
<button | ||
disabled={isDisabled} | ||
className={classes} | ||
onClick={onClick} | ||
{...rest} | ||
> | ||
{buttonIcon} | ||
</button> | ||
); | ||
} | ||
}; | ||
|
||
EuiButtonIcon.propTypes = { | ||
|
@@ -78,6 +96,8 @@ EuiButtonIcon.propTypes = { | |
color: PropTypes.oneOf(COLORS), | ||
isDisabled: PropTypes.bool, | ||
'aria-label': accessibleButtonIcon, | ||
href: checkHrefAndOnClick, | ||
onClick: PropTypes.func, | ||
}; | ||
|
||
EuiButtonIcon.defaultProps = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function checkHrefAndOnClick(props, propName, componentName) { | ||
if (props.href && props.onClick) { | ||
throw new Error( | ||
`${componentName} must either specify an href property (if it should be a link) ` + | ||
`or an onClick property (if it should be a button), but not both.` | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: can we change "HREF" to be:
(using back ticks for code-formatting)