-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathFeed.js
76 lines (62 loc) · 2.02 KB
/
Feed.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
import cx from 'clsx'
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'
import { childrenUtils, customPropTypes, getElementType, getUnhandledProps, SUI } from '../../lib'
import FeedContent from './FeedContent'
import FeedDate from './FeedDate'
import FeedEvent from './FeedEvent'
import FeedExtra from './FeedExtra'
import FeedLabel from './FeedLabel'
import FeedLike from './FeedLike'
import FeedMeta from './FeedMeta'
import FeedSummary from './FeedSummary'
import FeedUser from './FeedUser'
/**
* A feed presents user activity chronologically.
*/
function Feed(props) {
const { children, className, events, size } = props
const classes = cx('ui', size, 'feed', className)
const rest = getUnhandledProps(Feed, props)
const ElementType = getElementType(Feed, props)
if (!childrenUtils.isNil(children)) {
return (
<ElementType {...rest} className={classes}>
{children}
</ElementType>
)
}
const eventElements = _.map(events, (eventProps) => {
const { childKey, date, meta, summary, ...eventData } = eventProps
const finalKey = childKey || [date, meta, summary].join('-')
return <FeedEvent date={date} key={finalKey} meta={meta} summary={summary} {...eventData} />
})
return (
<ElementType {...rest} className={classes}>
{eventElements}
</ElementType>
)
}
Feed.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** Shorthand array of props for FeedEvent. */
events: customPropTypes.collectionShorthand,
/** A feed can have different sizes. */
size: PropTypes.oneOf(_.without(SUI.SIZES, 'mini', 'tiny', 'medium', 'big', 'huge', 'massive')),
}
Feed.Content = FeedContent
Feed.Date = FeedDate
Feed.Event = FeedEvent
Feed.Extra = FeedExtra
Feed.Label = FeedLabel
Feed.Like = FeedLike
Feed.Meta = FeedMeta
Feed.Summary = FeedSummary
Feed.User = FeedUser
export default Feed