-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathHeader.js
163 lines (136 loc) · 4.04 KB
/
Header.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import _ from 'lodash'
import cx from 'clsx'
import PropTypes from 'prop-types'
import * as React from 'react'
import {
childrenUtils,
customPropTypes,
getComponentType,
getUnhandledProps,
SUI,
getValueAndKey,
getTextAlignProp,
getKeyOrValueAndKey,
getKeyOnly,
} from '../../lib'
import Icon from '../Icon'
import Image from '../Image'
import HeaderSubheader from './HeaderSubheader'
import HeaderContent from './HeaderContent'
/**
* A header provides a short summary of content
*/
const Header = React.forwardRef(function (props, ref) {
const {
attached,
block,
children,
className,
color,
content,
disabled,
dividing,
floated,
icon,
image,
inverted,
size,
sub,
subheader,
textAlign,
} = props
const classes = cx(
'ui',
color,
size,
getKeyOnly(block, 'block'),
getKeyOnly(disabled, 'disabled'),
getKeyOnly(dividing, 'dividing'),
getValueAndKey(floated, 'floated'),
getKeyOnly(icon === true, 'icon'),
getKeyOnly(image === true, 'image'),
getKeyOnly(inverted, 'inverted'),
getKeyOnly(sub, 'sub'),
getKeyOrValueAndKey(attached, 'attached'),
getTextAlignProp(textAlign),
'header',
className,
)
const rest = getUnhandledProps(Header, props)
const ElementType = getComponentType(props)
if (!childrenUtils.isNil(children)) {
return (
<ElementType {...rest} className={classes} ref={ref}>
{children}
</ElementType>
)
}
const iconElement = Icon.create(icon, { autoGenerateKey: false })
const imageElement = Image.create(image, { autoGenerateKey: false })
const subheaderElement = HeaderSubheader.create(subheader, { autoGenerateKey: false })
if (iconElement || imageElement) {
return (
<ElementType {...rest} className={classes} ref={ref}>
{iconElement || imageElement}
{(content || subheaderElement) && (
<HeaderContent>
{content}
{subheaderElement}
</HeaderContent>
)}
</ElementType>
)
}
return (
<ElementType {...rest} className={classes} ref={ref}>
{content}
{subheaderElement}
</ElementType>
)
})
Header.displayName = 'Header'
Header.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
/** Attach header to other content, like a segment. */
attached: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['top', 'bottom'])]),
/** Format header to appear inside a content block. */
block: PropTypes.bool,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** Color of the header. */
color: PropTypes.oneOf(SUI.COLORS),
/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,
/** Show that the header is inactive. */
disabled: PropTypes.bool,
/** Divide header from the content below it. */
dividing: PropTypes.bool,
/** Header can sit to the left or right of other content. */
floated: PropTypes.oneOf(SUI.FLOATS),
/** Add an icon by icon name or pass an Icon. */
icon: customPropTypes.every([
customPropTypes.disallow(['image']),
PropTypes.oneOfType([PropTypes.bool, customPropTypes.itemShorthand]),
]),
/** Add an image by img src or pass an Image. */
image: customPropTypes.every([
customPropTypes.disallow(['icon']),
PropTypes.oneOfType([PropTypes.bool, customPropTypes.itemShorthand]),
]),
/** Inverts the color of the header for dark backgrounds. */
inverted: PropTypes.bool,
/** Content headings are sized with em and are based on the font-size of their container. */
size: PropTypes.oneOf(_.without(SUI.SIZES, 'big', 'massive', 'mini')),
/** Headers may be formatted to label smaller or de-emphasized content. */
sub: PropTypes.bool,
/** Shorthand for Header.Subheader. */
subheader: customPropTypes.itemShorthand,
/** Align header content. */
textAlign: PropTypes.oneOf(SUI.TEXT_ALIGNMENTS),
}
Header.Content = HeaderContent
Header.Subheader = HeaderSubheader
export default Header