Skip to content

Commit

Permalink
feat: do not hide icons if a button is a icon button only
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Jan 23, 2019
1 parent 59743d6 commit 1b00672
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
32 changes: 25 additions & 7 deletions packages/dnb-ui-lib/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -195,11 +196,19 @@ export default class Button extends PureComponent {

return href ? (
<a href={href} ref={this._ref} {...params}>
<Content {...this.props} content={content} />
<Content
{...this.props}
content={content}
isIconOnly={isIconOnly}
/>
</a>
) : (
<button ref={this._ref} {...params}>
<Content {...this.props} content={content} />
<Content
{...this.props}
content={content}
isIconOnly={isIconOnly}
/>
</button>
)
}
Expand All @@ -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 = []

Expand All @@ -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)}
/>
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dnb-ui-lib/src/components/button/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ class Example extends PureComponent {
/>
<Button title="Button with Icon only" icon="calendar" />
<Button
title="Medium Button with Icon only"
title="Default sized Button with medium Icon"
icon="calendar"
icon_size="medium"
size="medium"
size="default"
/>
<Button
title="Button with custom, Secondary Icon only"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exports[`Button component have to match default button snapshot 1`] = `
icon_size="icon_size"
id="id"
innerRef={Object {}}
isIconOnly={false}
on_click="on_click"
size={null}
text="text"
Expand Down Expand Up @@ -143,6 +144,7 @@ exports[`Button component have to match href="..." snapshot 1`] = `
icon_size="icon_size"
id="id"
innerRef={Object {}}
isIconOnly={false}
on_click="on_click"
size={null}
text="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ exports[`Modal component have to match snapshot 1`] = `
icon_size={null}
id={null}
innerRef={null}
isIconOnly={true}
on_click={[Function]}
size={null}
text={null}
Expand All @@ -120,7 +121,7 @@ exports[`Modal component have to match snapshot 1`] = `
>
<IconPrimary
alt="Open Modal"
area_hidden={true}
area_hidden={false}
attributes={null}
class={null}
className="dnb-button__icon"
Expand All @@ -133,7 +134,6 @@ exports[`Modal component have to match snapshot 1`] = `
width={null}
>
<span
aria-hidden={true}
aria-label="Open Modal"
className="dnb-icon dnb-icon--default dnb-button__icon"
role="img"
Expand Down Expand Up @@ -349,6 +349,7 @@ exports[`Modal component have to match snapshot 1`] = `
icon_size={null}
id={null}
innerRef={null}
isIconOnly={true}
on_click={[Function]}
size={null}
text={null}
Expand All @@ -358,7 +359,7 @@ exports[`Modal component have to match snapshot 1`] = `
>
<IconPrimary
alt="Close"
area_hidden={true}
area_hidden={false}
attributes={null}
class={null}
className="dnb-button__icon"
Expand All @@ -371,7 +372,6 @@ exports[`Modal component have to match snapshot 1`] = `
width={null}
>
<span
aria-hidden={true}
aria-label="Close"
className="dnb-icon dnb-icon--default dnb-button__icon"
role="img"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
status: 'wip'
status: 'dep'
---

## Description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
status: 'wip'
status: 'dep'
---

## Description
Expand Down

0 comments on commit 1b00672

Please sign in to comment.