semantic-ui-react
Version:
The official Semantic-UI-React integration.
66 lines (52 loc) • 1.44 kB
JavaScript
import cx from 'classnames'
import PropTypes from 'prop-types'
import React from 'react'
import {
childrenUtils,
createShorthandFactory,
customPropTypes,
getElementType,
getUnhandledProps,
META,
} from '../../lib'
import Icon from '../../elements/Icon'
/**
* A dropdown menu can contain a header.
*/
function DropdownHeader(props) {
const {
children,
className,
content,
icon,
} = props
const classes = cx('header', className)
const rest = getUnhandledProps(DropdownHeader, props)
const ElementType = getElementType(DropdownHeader, props)
if (!childrenUtils.isNil(children)) return <ElementType {...rest} className={classes}>{children}</ElementType>
return (
<ElementType {...rest} className={classes}>
{Icon.create(icon)}
{content}
</ElementType>
)
}
DropdownHeader._meta = {
name: 'DropdownHeader',
parent: 'Dropdown',
type: META.TYPES.MODULE,
}
DropdownHeader.propTypes = {
/** An element type to render as (string or function) */
as: customPropTypes.as,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,
/** Shorthand for Icon. */
icon: customPropTypes.itemShorthand,
}
DropdownHeader.create = createShorthandFactory(DropdownHeader, content => ({ content }))
export default DropdownHeader