-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Container.js
62 lines (51 loc) · 1.43 KB
/
Container.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
import cx from 'clsx'
import PropTypes from 'prop-types'
import * as React from 'react'
import {
childrenUtils,
customPropTypes,
getComponentType,
getUnhandledProps,
SUI,
useKeyOnly,
useTextAlignProp,
} from '../../lib'
/**
* A container limits content to a maximum width.
*/
const Container = React.forwardRef(function (props, ref) {
const { children, className, content, fluid, text, textAlign } = props
const classes = cx(
'ui',
useKeyOnly(text, 'text'),
useKeyOnly(fluid, 'fluid'),
useTextAlignProp(textAlign),
'container',
className,
)
const rest = getUnhandledProps(Container, props)
const ElementType = getComponentType(props)
return (
<ElementType {...rest} className={classes} ref={ref}>
{childrenUtils.isNil(children) ? content : children}
</ElementType>
)
})
Container.displayName = 'Container'
Container.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,
/** Container has no maximum width. */
fluid: PropTypes.bool,
/** Reduce maximum width to more naturally accommodate text. */
text: PropTypes.bool,
/** Align container text. */
textAlign: PropTypes.oneOf(SUI.TEXT_ALIGNMENTS),
}
export default Container