Skip to content

Commit

Permalink
feat: #button: pass props along to the button markup
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Jan 30, 2019
1 parent 5581706 commit d3ca2fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
37 changes: 24 additions & 13 deletions packages/dnb-ui-lib/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,42 +133,51 @@ export default class Button extends PureComponent {
class: class_name,
className,
type,
variant,
size,
title,
id,
disabled,
text,
icon,
icon_position,
href,
attributes, // eslint-disable-line
innerRef, // eslint-disable-line
...props
} = this.props

let { variant, size } = props
let usedVariant = variant
let usedSize = size

// let { size } = props

// if only has Icon, then resize it and define it as secondary
const isIconOnly = Boolean(!text && icon)
if (isIconOnly) {
if (!variant) {
variant = 'secondary'
if (!usedVariant) {
usedVariant = 'secondary'
}
if (!size) {
size = 'medium'
if (!usedSize) {
usedSize = 'medium'
}
} else if (text) {
if (!variant) {
variant = 'primary'
if (!usedVariant) {
usedVariant = 'primary'
}
if (!size) {
size = 'default'
if (!usedSize) {
usedSize = 'default'
}
}

const content = Button.getContent(this.props)

const classes = classnames(
'dnb-button',
`dnb-button--${variant}`,
size && size !== 'default' ? `dnb-button--size-${size}` : null,
`dnb-button--${usedVariant}`,
usedSize && usedSize !== 'default'
? `dnb-button--size-${usedSize}`
: null,
icon && icon_position
? `dnb-button--icon-position-${icon_position}`
: null,
Expand All @@ -185,10 +194,12 @@ export default class Button extends PureComponent {
className: classes,
type,
title: title || text,
['aria-label']: title || text,
id,
disabled,
onMouseOut: this.onMouseOutHandler,
onClick: this.onClickHandler
onMouseOut: this.onMouseOutHandler, // for resetting the button to the default state
onClick: this.onClickHandler,
...props
}

// also used for code markup simulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports[`Button component have to match default button snapshot 1`] = `
variant="primary"
>
<button
aria-label="This is a button title"
className="dnb-button dnb-button--primary dnb-button--icon-position-right dnb-button--has-text dnb-button--has-icon id class className"
disabled="disabled"
id="id"
Expand Down Expand Up @@ -122,6 +123,7 @@ exports[`Button component have to match href="..." snapshot 1`] = `
variant="primary"
>
<a
aria-label="This is a button title"
className="dnb-button dnb-button--primary dnb-button--icon-position-right dnb-button--has-text dnb-button--has-icon id class className dnb-no-anchor-underline dnb-no-anchor-hover"
disabled="disabled"
href="https://url"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ exports[`Modal component have to match snapshot 1`] = `
variant="secondary"
>
<button
aria-label="Open Modal"
className="dnb-button dnb-button--secondary dnb-button--size-medium dnb-button--icon-position-right dnb-button--has-icon"
onClick={[Function]}
onMouseOut={[Function]}
Expand Down Expand Up @@ -328,6 +329,7 @@ exports[`Modal component have to match snapshot 1`] = `
variant="secondary"
>
<button
aria-label="Close"
className="dnb-button dnb-button--secondary dnb-button--size-medium dnb-button--icon-position-right dnb-button--has-icon dnb-modal__close-button"
onClick={[Function]}
onMouseOut={[Function]}
Expand Down

0 comments on commit d3ca2fc

Please sign in to comment.