-
Notifications
You must be signed in to change notification settings - Fork 51
/
BenefitWithHeading.jsx
44 lines (35 loc) · 1023 Bytes
/
BenefitWithHeading.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from 'react'
import { componentWithName } from '@tds/util-prop-types'
import Box from '@tds/core-box'
import { safeRest } from '@tds/util-helpers'
import Item from './BenefitWithHeadingItem'
const cloneChild = (icon, child) => {
if (child.props.icon) {
return child
}
return React.cloneElement(child, { icon })
}
/**
* @version ../package.json
*/
const BenefitWithHeading = ({ icon, children, ...rest }) => (
<Box {...safeRest(rest)} tag="ul" between={3}>
{React.Children.map(children, child => cloneChild(icon, child))}
</Box>
)
BenefitWithHeading.propTypes = {
/**
* A `DecorativeIcon`. If set here, it applies to all nested Benefit Items
* except for Items that receive an `icon` prop.
*/
icon: componentWithName('DecorativeIcon', true),
/**
* An Item in the Benefit list.
*/
children: componentWithName('BenefitItem').isRequired,
}
BenefitWithHeading.defaultProps = {
icon: undefined,
}
BenefitWithHeading.Item = Item
export default BenefitWithHeading