Skip to content

Commit

Permalink
Remove prefix prop from Blockquote
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnblk committed Mar 6, 2016
1 parent 693f9eb commit 5f78c5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 74 deletions.
61 changes: 17 additions & 44 deletions src/Blockquote.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,24 @@ import React from 'react'
import Base from './Base'
import config from './config'

/**
* Stylized blockquote element with citation link
*/

const Blockquote = ({
source,
href,
prefix,
children,
...props
}, { rebass }) => {
const { fontSizes, bold, scale } = { ...config, ...rebass }
const { fontSizes, scale } = { ...config, ...rebass }

const sx = {
root: {
fontSize: fontSizes[3],
fontStyle: 'italic',
display: 'flex',
alignItems: 'flex-start',
margin: 0
},
prefix: {
fontSize: fontSizes[0] * 2,
width: '.75em',
marginLeft: '-.75em',
fontFamily: 'Georgia',
fontWeight: bold,
lineHeight: 1,
flex: 'none',
minWidth: 1
margin: 0,
marginBottom: scale[2]
},
p: {
margin: 0,
Expand All @@ -43,31 +35,21 @@ const Blockquote = ({
}
}

const pfx = typeof prefix === 'string' ? prefix : '“'

return (
<Base
{...props}
tagName='blockquote'
className='Blockquote'
baseStyle={sx.root}>
{prefix && (
<div
className='Blockquote_prefix'
style={sx.prefix}
children={pfx} />
)}
<div>
<p style={sx.p}>
{children}
</p>
<cite style={sx.cite}>
{'— '}
<a href={href}
style={sx.source}
children={source} />
</cite>
</div>
<p style={sx.p}>
{children}
</p>
<cite style={sx.cite}>
{'— '}
<a href={href}
style={sx.source}
children={source} />
</cite>
</Base>
)
}
Expand All @@ -76,16 +58,7 @@ Blockquote.propTypes = {
/** Name of source */
source: React.PropTypes.string,
/** URL link to source */
href: React.PropTypes.string,
/** Decorative prefix - e.g. `“` */
prefix: React.PropTypes.oneOfType([
React.PropTypes.bool,
React.PropTypes.string
])
}

Blockquote.defaultProps = {
prefix: true
href: React.PropTypes.string
}

export default Blockquote
Expand Down
33 changes: 3 additions & 30 deletions test/Blockquote.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { Blockquote, Base } from '../src'
const renderer = TestUtils.createRenderer()

describe('Blockquote', () => {
let tree, prefix, link
let tree, link

beforeEach(() => {
renderer.render(<Blockquote />)
tree = renderer.getRenderOutput()
prefix = tree.props.children[0]
link = tree.props.children[1].props.children[1].props.children[1]
link = tree.props.children[1].props.children[1]
})

it('should render', () => {
Expand All @@ -28,41 +27,15 @@ describe('Blockquote', () => {
expect(tree.props.className).toEqual('Blockquote')
})

it('should have a prefix', () => {
expect(prefix.type).toEqual('div')
})

it('should have a source link', () => {
expect(link.type).toEqual('a')
})

context('when prefix is false', () => {
beforeEach(() => {
renderer.render(<Blockquote prefix={false} />)
tree = renderer.getRenderOutput()
prefix = tree.props.children[0]
})
it('should not have a prefix', () => {
expect(prefix).toEqual(false)
})
})

context('when prefix is a string', () => {
beforeEach(() => {
renderer.render(<Blockquote prefix='»' />)
tree = renderer.getRenderOutput()
prefix = tree.props.children[0]
})
it('should render the string', () => {
expect(prefix.props.children).toEqual('»')
})
})

context('when source and href are set', () => {
beforeEach(() => {
renderer.render(<Blockquote href='#hello' source='Hello' />)
tree = renderer.getRenderOutput()
link = tree.props.children[1].props.children[1].props.children[1]
link = tree.props.children[1].props.children[1]
})
it('should pass href and children to link', () => {
expect(link.props.href).toEqual('#hello')
Expand Down

0 comments on commit 5f78c5d

Please sign in to comment.