From 1b00672bc7c68c78bcdcdd306b52feb1bf2e9d4a Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 23 Jan 2019 15:46:05 +0100 Subject: [PATCH] feat: do not hide icons if a button is a icon button only --- .../src/components/button/Button.js | 32 +++++++++++++++---- .../src/components/button/Example.js | 4 +-- .../__snapshots__/Button.test.js.snap | 2 ++ .../__snapshots__/Modal.test.js.snap | 8 ++--- .../src/patterns/range-slider/description.md | 2 +- .../src/patterns/summary-table/description.md | 2 +- 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/packages/dnb-ui-lib/src/components/button/Button.js b/packages/dnb-ui-lib/src/components/button/Button.js index 3f50c56a331..dac005bda53 100644 --- a/packages/dnb-ui-lib/src/components/button/Button.js +++ b/packages/dnb-ui-lib/src/components/button/Button.js @@ -146,7 +146,8 @@ export default class Button extends PureComponent { let { variant, size } = props // if only has Icon, then resize it and define it as secondary - if (!text && icon) { + const isIconOnly = Boolean(!text && icon) + if (isIconOnly) { if (!variant) { variant = 'secondary' } @@ -195,11 +196,19 @@ export default class Button extends PureComponent { return href ? ( - + ) : ( ) } @@ -215,17 +224,26 @@ class Content extends PureComponent { PropTypes.node, PropTypes.func ]), - icon_size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) + icon_size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + isIconOnly: PropTypes.bool } static defaultProps = { text: null, title: null, content: null, icon: null, - icon_size: null + icon_size: null, + isIconOnly: null } render() { - const { text, title, content, icon, icon_size } = this.props + const { + text, + title, + content, + icon, + icon_size, + isIconOnly + } = this.props const ret = [] @@ -250,7 +268,7 @@ class Content extends PureComponent { icon={icon} size={icon_size} alt={alt} - area_hidden={Boolean(alt)} + area_hidden={isIconOnly ? false : Boolean(alt)} /> ) } diff --git a/packages/dnb-ui-lib/src/components/button/Example.js b/packages/dnb-ui-lib/src/components/button/Example.js index cbc142867e7..8492e86c7f4 100644 --- a/packages/dnb-ui-lib/src/components/button/Example.js +++ b/packages/dnb-ui-lib/src/components/button/Example.js @@ -98,10 +98,10 @@ class Example extends PureComponent { />