-
Notifications
You must be signed in to change notification settings - Fork 235
/
tabs.js
68 lines (64 loc) · 1.38 KB
/
tabs.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* External dependencies.
*/
import cx from 'classnames';
import { forwardRef } from '@wordpress/element';
/**
* Renders the tabs navigation.
*
* @param {Object} props
* @param {Object[]} props.items
* @param {string} props.current
* @param {string} props.layout
* @param {mixed} props.children
* @param {Function} props.onChange
* @param {Object} ref
* @return {void}
*/
function ComplexTabs( {
items,
current,
layout,
children,
onChange
}, ref ) {
return (
<div className={ `cf-complex__tabs cf-complex__tabs--${ layout }` }>
<ul className="cf-complex__tabs-list" ref={ ref }>
{ items.map( ( item, index ) => {
const classes = cx(
'cf-complex__tabs-item',
`cf-complex__tabs-item--${ layout }`,
{
'cf-complex__tabs-item--current': item.id === current
}
);
return (
<li
key={ item.id }
className={ classes }
onClick={ () => onChange( item.id ) }
>
{
item.label
? (
<span
className="cf-complex__tabs-title"
dangerouslySetInnerHTML={ { __html: item.label } }
></span>
)
: (
<span className="cf-complex__tabs-index">
{ index + 1 }
</span>
)
}
</li>
);
} ) }
</ul>
{ children }
</div>
);
}
export default forwardRef( ComplexTabs );