bpk-component-button
Advanced tools
Comparing version 0.0.5 to 0.0.6-alpha.d2203521
{ | ||
"name": "bpk-component-button", | ||
"version": "0.0.5", | ||
"version": "0.0.6-alpha.d2203521", | ||
"description": "Backpack button component.", | ||
"main": "src/index.js", | ||
"main": "index.js", | ||
"author": "Backpack Design System <backpack@skyscanner.net>", | ||
@@ -7,0 +7,0 @@ "license": "Apache-2.0", |
@@ -14,2 +14,9 @@ jest.unmock('./BpkButton') | ||
it('should render the correct element if an href is provided', () => { | ||
const wrapper = shallow(<BpkButton href='#'>My button</BpkButton>) | ||
expect(wrapper.children().length).toEqual(1) | ||
expect(wrapper.name()).toEqual('a') | ||
expect(wrapper.prop('href')).toEqual('#') | ||
}) | ||
it('should render the correct class by default', () => { | ||
@@ -16,0 +23,0 @@ const wrapper = shallow(<BpkButton>My button</BpkButton>) |
import React, { PropTypes } from 'react' | ||
import './bpk-button.scss' | ||
const BpkButton = ({ secondary, selected, large, link, ...rest }) => { | ||
const BpkButton = ({ href, submit, secondary, selected, large, link, ...rest }) => { | ||
const classNames = [ 'bpk-button' ] | ||
@@ -12,6 +12,14 @@ | ||
return <button type='button' className={classNames.join(' ')} {...rest} /> | ||
const className = classNames.join(' ') | ||
if (href) { | ||
return <a href={href} className={className} {...rest} /> | ||
} | ||
return <button type={submit ? 'submit' : 'button'} className={className} {...rest} /> | ||
} | ||
BpkButton.propTypes = { | ||
href: PropTypes.string, | ||
submit: PropTypes.bool, | ||
secondary: PropTypes.bool, | ||
@@ -24,2 +32,3 @@ selected: PropTypes.bool, | ||
BpkButton.defaultProps = { | ||
submit: false, | ||
secondary: false, | ||
@@ -26,0 +35,0 @@ selected: false, |
4301
78