Skip to content

Commit c1dc392

Browse files
committed
Add CardBody Component
1 parent 5fc1f2f commit c1dc392

File tree

6 files changed

+96
-27
lines changed

6 files changed

+96
-27
lines changed

src/components/Card/Body.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createElement as E } from 'react'
2+
import T from 'prop-types'
3+
4+
import { classNames } from '../../utils/'
5+
import { NAMESPACE, BLOCK_TAGS } from '../../constants'
6+
7+
const CardBody = ({ tag, className, children, ...rest }) =>
8+
E(
9+
tag || 'div',
10+
{
11+
className: classNames(`${NAMESPACE}c-card__body`, className),
12+
...rest
13+
},
14+
children
15+
)
16+
17+
CardBody.propTypes = {
18+
tag: T.oneOf(BLOCK_TAGS),
19+
className: T.string,
20+
children: T.node
21+
}
22+
23+
export default CardBody

src/components/Card/Wrapper.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createElement as E } from 'react'
2+
import T from 'prop-types'
3+
4+
import { classNames } from '../../utils/'
5+
import { NAMESPACE, BLOCK_TAGS } from '../../constants'
6+
7+
const CardWrapper = ({ tag, className, children, ...rest }) =>
8+
E(
9+
tag || 'div',
10+
{
11+
className: classNames(`${NAMESPACE}c-card`, className),
12+
...rest
13+
},
14+
children
15+
)
16+
17+
CardWrapper.propTypes = {
18+
tag: T.oneOf(BLOCK_TAGS),
19+
className: T.string,
20+
children: T.node
21+
}
22+
23+
export default CardWrapper
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react'
2+
import { shallow } from 'enzyme'
3+
4+
import { NAMESPACE } from '../../../constants'
5+
import { Card } from '../'
6+
7+
describe('<Card.Body />', () => {
8+
it('passes in an optional className override', () => {
9+
const $ = shallow(<Card.Body className="something else" />)
10+
expect($.hasClass(`${NAMESPACE}c-card__body`)).toBe(true)
11+
expect($.hasClass('something else')).toBe(true)
12+
})
13+
14+
it('renders a defined tag type', () => {
15+
const $ = shallow(<Card.Body tag="article" />)
16+
expect($.type()).toBe('article')
17+
})
18+
19+
it('renders a div by default', () => {
20+
const $ = shallow(<Card.Body />)
21+
expect($.type()).toBe('div')
22+
})
23+
24+
it('renders with attributes', () => {
25+
const $ = shallow(
26+
<Card.Body style={{ position: 'relative' }} ariaHidden />
27+
)
28+
expect($.prop('style')).toEqual({
29+
position: 'relative'
30+
})
31+
expect($.prop('ariaHidden')).toBe(true)
32+
})
33+
34+
it('renders children', () => {
35+
const $ = shallow(<Card.Body>test child</Card.Body>)
36+
expect($.contains('test child')).toBe(true)
37+
})
38+
})
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@ import { shallow } from 'enzyme'
44
import { NAMESPACE } from '../../../constants'
55
import { Card } from '../'
66

7-
describe('<Card />', () => {
7+
describe('<Card.Wrapper />', () => {
88
it('passes in an optional className override', () => {
9-
const $ = shallow(<Card className="something else" />)
9+
const $ = shallow(<Card.Wrapper className="something else" />)
1010
expect($.hasClass(`${NAMESPACE}c-card`)).toBe(true)
1111
expect($.hasClass('something else')).toBe(true)
1212
})
1313

1414
it('renders a defined tag type', () => {
15-
const $ = shallow(<Card tag="article">_</Card>)
15+
const $ = shallow(<Card.Wrapper tag="article" />)
1616
expect($.type()).toBe('article')
1717
})
1818

1919
it('renders a div by default', () => {
20-
const $ = shallow(<Card>-</Card>)
20+
const $ = shallow(<Card.Wrapper />)
2121
expect($.type()).toBe('div')
2222
})
2323

2424
it('renders with attributes', () => {
2525
const $ = shallow(
26-
<Card style={{ position: 'relative' }} ariaHidden>
27-
_
28-
</Card>
26+
<Card.Wrapper style={{ position: 'relative' }} ariaHidden />
2927
)
3028
expect($.prop('style')).toEqual({
3129
position: 'relative'
@@ -34,7 +32,7 @@ describe('<Card />', () => {
3432
})
3533

3634
it('renders children', () => {
37-
const $ = shallow(<Card>test child</Card>)
35+
const $ = shallow(<Card.Wrapper>test child</Card.Wrapper>)
3836
expect($.contains('test child')).toBe(true)
3937
})
4038
})

src/components/Card/index.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
1-
import { createElement as E } from 'react'
2-
import T from 'prop-types'
1+
import Wrapper from './Wrapper'
2+
import Body from './Body'
33

4-
import { classNames } from '../../utils/'
5-
import { NAMESPACE, BLOCK_TAGS } from '../../constants'
6-
7-
const Card = ({ tag, className, children, ...rest }) =>
8-
E(
9-
tag || 'div',
10-
{
11-
className: classNames(`${NAMESPACE}c-card`, className),
12-
...rest
13-
},
14-
children
15-
)
16-
17-
Card.propTypes = {
18-
tag: T.oneOf(BLOCK_TAGS),
19-
className: T.string,
20-
children: T.node
4+
const Card = {
5+
Wrapper,
6+
Body
217
}
228

239
export { Card }

src/components/Toast/Wrapper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ToastWrapper extends Component {
4545
const { toastItems } = this.state
4646
const enhancedChildren = children && React.Children.map(children, (child) => {
4747
if (child.type !== Item) {
48+
// eslint-disable-next-line no-console
4849
return console.warn(`${child} is not a valid child of <Toast.Wrapper />`)
4950
}
5051

0 commit comments

Comments
 (0)