Skip to content

Commit

Permalink
feat: add new property to enable a larger bounding box to a #button -…
Browse files Browse the repository at this point in the history
… currently used in #date-picker
  • Loading branch information
tujoworker committed May 5, 2019
1 parent 5c58b07 commit 645d95e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/dnb-ui-lib/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const propTypes = {
class: PropTypes.string,
attributes: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
href: PropTypes.string,
bounding: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
disabled: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),

// React props
Expand Down Expand Up @@ -69,6 +70,7 @@ export const defaultProps = {
id: null,
class: null,
attributes: null,
bounding: false,
disabled: false,

// React props
Expand Down Expand Up @@ -146,6 +148,7 @@ export default class Button extends PureComponent {
icon,
icon_position,
href,
bounding, // eslint-disable-line
attributes, // eslint-disable-line
innerRef, // eslint-disable-line
...props
Expand Down Expand Up @@ -242,6 +245,7 @@ class Content extends PureComponent {
PropTypes.func
]),
icon_size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
bounding: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
isIconOnly: PropTypes.bool
}
static defaultProps = {
Expand All @@ -250,6 +254,7 @@ class Content extends PureComponent {
content: null,
icon: null,
icon_size: 'default',
bounding: false,
isIconOnly: null
}
render() {
Expand All @@ -259,11 +264,18 @@ class Content extends PureComponent {
content,
icon,
icon_size,
bounding,
isIconOnly
} = this.props

const ret = []

if (bounding) {
ret.push(
<span key="button-bounding" className="dnb-button__bounding" />
)
}

if (content) {
ret.push(content)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ describe('Button component', () => {
expect(Comp.find('.dnb-button--has-text').exists()).toBe(false)
})

it('has to have a bounding tag if property is set', () => {
const Comp = mount(<Component bounding={true} />)
expect(Comp.find('.dnb-button__bounding').exists()).toBe(true)
})

it('has a button tag', () => {
const Comp = mount(<Component {...props} href="https://url" />)
expect(Comp.find('a').exists()).toBe(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`Button component have to match default button snapshot 1`] = `
<Button
attributes="attributes"
bounding="bounding"
class="class"
className="className"
custom_element={Object {}}
Expand Down Expand Up @@ -34,6 +35,7 @@ exports[`Button component have to match default button snapshot 1`] = `
>
<Content
attributes="attributes"
bounding="bounding"
class="class"
className="className"
content="children"
Expand All @@ -55,6 +57,10 @@ exports[`Button component have to match default button snapshot 1`] = `
type="type"
variant="primary"
>
<span
className="dnb-button__bounding"
key="button-bounding"
/>
children
<span
className="dnb-button__text"
Expand Down Expand Up @@ -108,6 +114,7 @@ exports[`Button component have to match default button snapshot 1`] = `
exports[`Button component have to match href="..." snapshot 1`] = `
<Button
attributes="attributes"
bounding="bounding"
class="class"
className="className"
custom_element={Object {}}
Expand Down Expand Up @@ -140,6 +147,7 @@ exports[`Button component have to match href="..." snapshot 1`] = `
>
<Content
attributes="attributes"
bounding="bounding"
class="class"
className="className"
content="children"
Expand All @@ -161,6 +169,10 @@ exports[`Button component have to match href="..." snapshot 1`] = `
type="type"
variant="primary"
>
<span
className="dnb-button__bounding"
key="button-bounding"
/>
children
<span
className="dnb-button__text"
Expand Down Expand Up @@ -572,6 +584,13 @@ exports[`Button scss have to match snapshot 1`] = `
@supports not (-ms-ime-align: auto) {
.dnb-button__text {
transform: translateY(calc(1px - var(--button-border-width))); } }
.dnb-button__bounding {
position: absolute;
background-color: transparent;
width: var(--button-width);
height: var(--button-height);
border-radius: var(--button-border-radius);
transform: scale(1.2); }
.dnb-button--size-small {
width: var(--button-width--small);
height: var(--button-height--small);
Expand Down
9 changes: 9 additions & 0 deletions packages/dnb-ui-lib/src/components/button/style/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@
}
}

&__bounding {
position: absolute;
background-color: transparent;
width: var(--button-width);
height: var(--button-height);
border-radius: var(--button-border-radius);
transform: scale(1.2);
}

// size small
&--size-small {
width: var(--button-width--small);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ exports[`Modal component have to match snapshot 1`] = `
>
<Button
attributes={null}
bounding={false}
class={null}
className="dnb-modal__trigger"
custom_element={null}
Expand Down Expand Up @@ -125,6 +126,7 @@ exports[`Modal component have to match snapshot 1`] = `
>
<Content
attributes={null}
bounding={false}
class={null}
className="dnb-modal__trigger"
content={null}
Expand Down Expand Up @@ -384,6 +386,7 @@ exports[`Modal component have to match snapshot 1`] = `
>
<Button
attributes={null}
bounding={false}
class={null}
className="dnb-modal__close-button"
custom_element={null}
Expand Down Expand Up @@ -413,6 +416,7 @@ exports[`Modal component have to match snapshot 1`] = `
>
<Content
attributes={null}
bounding={false}
class={null}
className="dnb-modal__close-button"
content={null}
Expand Down Expand Up @@ -665,6 +669,13 @@ exports[`Modal scss have to match snapshot 1`] = `
@supports not (-ms-ime-align: auto) {
.dnb-button__text {
transform: translateY(calc(1px - var(--button-border-width))); } }
.dnb-button__bounding {
position: absolute;
background-color: transparent;
width: var(--button-width);
height: var(--button-height);
border-radius: var(--button-border-radius);
transform: scale(1.2); }
.dnb-button--size-small {
width: var(--button-width--small);
height: var(--button-height--small);
Expand Down

0 comments on commit 645d95e

Please sign in to comment.