-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (21 loc) · 665 Bytes
/
index.js
File metadata and controls
29 lines (21 loc) · 665 Bytes
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
'use strict'
var React = require('react')
function createSeparator (separator, idx) {
if (typeof separator === 'string') {
return separator
}
return React.cloneElement(separator, { key: 'separator-' + idx })
}
module.exports = function WithSeparator (props) {
var children = React.Children.toArray(props.children)
for (var i = 1; i < children.length; i += 2) {
children.splice(i, 0, createSeparator(props.separator, (i - 1) / 2))
}
if (props.leading) {
children.unshift(createSeparator(props.separator, 'leading'))
}
if (props.trailing) {
children.push(createSeparator(props.separator, 'trailing'))
}
return children
}