-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathTabPane.js
61 lines (47 loc) · 1.55 KB
/
TabPane.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
import cx from 'clsx'
import PropTypes from 'prop-types'
import * as React from 'react'
import {
childrenUtils,
createShorthandFactory,
customPropTypes,
getComponentType,
getUnhandledProps,
getKeyOnly,
} from '../../lib'
import Segment from '../../elements/Segment/Segment'
/**
* A tab pane holds the content of a tab.
*/
const TabPane = React.forwardRef(function (props, ref) {
const { active = true, children, className, content, loading } = props
const classes = cx(getKeyOnly(active, 'active'), getKeyOnly(loading, 'loading'), 'tab', className)
const rest = getUnhandledProps(TabPane, props)
const ElementType = getComponentType(props, { defaultAs: Segment })
const calculatedDefaultProps = {}
if (ElementType === Segment) {
calculatedDefaultProps.attached = 'bottom'
}
return (
<ElementType {...calculatedDefaultProps} {...rest} className={classes} ref={ref}>
{childrenUtils.isNil(children) ? content : children}
</ElementType>
)
})
TabPane.displayName = 'TabPane'
TabPane.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
/** A tab pane can be active. */
active: PropTypes.bool,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,
/** A Tab.Pane can display a loading indicator. */
loading: PropTypes.bool,
}
TabPane.create = createShorthandFactory(TabPane, (content) => ({ content }))
export default TabPane