-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathList.js
More file actions
173 lines (146 loc) · 4.27 KB
/
List.js
File metadata and controls
173 lines (146 loc) · 4.27 KB
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
164
165
166
167
168
169
170
171
172
173
import cx from 'clsx'
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'
import {
childrenUtils,
customPropTypes,
getElementType,
getUnhandledProps,
SUI,
useKeyOnly,
useKeyOrValueAndKey,
useValueAndKey,
useVerticalAlignProp,
} from '../../lib'
import ListContent from './ListContent'
import ListDescription from './ListDescription'
import ListHeader from './ListHeader'
import ListIcon from './ListIcon'
import ListItem from './ListItem'
import ListList from './ListList'
/**
* A list groups related content.
*/
const List = React.forwardRef(function (props, ref) {
const {
animated,
bulleted,
celled,
children,
className,
content,
divided,
floated,
horizontal,
inverted,
items,
link,
ordered,
relaxed,
selection,
size,
verticalAlign,
} = props
const classes = cx(
'ui',
size,
useKeyOnly(animated, 'animated'),
useKeyOnly(bulleted, 'bulleted'),
useKeyOnly(celled, 'celled'),
useKeyOnly(divided, 'divided'),
useKeyOnly(horizontal, 'horizontal'),
useKeyOnly(inverted, 'inverted'),
useKeyOnly(link, 'link'),
useKeyOnly(ordered, 'ordered'),
useKeyOnly(selection, 'selection'),
useKeyOrValueAndKey(relaxed, 'relaxed'),
useValueAndKey(floated, 'floated'),
useVerticalAlignProp(verticalAlign),
'list',
className,
)
const rest = getUnhandledProps(List, props)
const ElementType = getElementType(List, props)
if (!childrenUtils.isNil(children)) {
return (
<ElementType role='list' {...rest} className={classes} ref={ref}>
{children}
</ElementType>
)
}
if (!childrenUtils.isNil(content)) {
return (
<ElementType role='list' {...rest} className={classes} ref={ref}>
{content}
</ElementType>
)
}
return (
<ElementType role='list' {...rest} className={classes} ref={ref}>
{_.map(items, (item) =>
ListItem.create(item, {
overrideProps: (predefinedProps) => ({
onClick: (e, itemProps) => {
predefinedProps.onClick?.(e, itemProps)
props.onItemClick?.(e, itemProps)
},
}),
}),
)}
</ElementType>
)
})
List.displayName = 'List'
List.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
/** A list can animate to set the current item apart from the list. */
animated: PropTypes.bool,
/** A list can mark items with a bullet. */
bulleted: PropTypes.bool,
/** A list can divide its items into cells. */
celled: PropTypes.bool,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,
/** A list can show divisions between content. */
divided: PropTypes.bool,
/** An list can be floated left or right. */
floated: PropTypes.oneOf(SUI.FLOATS),
/** A list can be formatted to have items appear horizontally. */
horizontal: PropTypes.bool,
/** A list can be inverted to appear on a dark background. */
inverted: PropTypes.bool,
/** Shorthand array of props for ListItem. */
items: customPropTypes.collectionShorthand,
/** A list can be specially formatted for navigation links. */
link: PropTypes.bool,
/**
* onClick handler for ListItem. Mutually exclusive with children.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All item props.
*/
onItemClick: customPropTypes.every([customPropTypes.disallow(['children']), PropTypes.func]),
/** A list can be ordered numerically. */
ordered: PropTypes.bool,
/** A list can relax its padding to provide more negative space. */
relaxed: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['very'])]),
/** A selection list formats list items as possible choices. */
selection: PropTypes.bool,
/** A list can vary in size. */
size: PropTypes.oneOf(SUI.SIZES),
/** An element inside a list can be vertically aligned. */
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
}
List.Content = ListContent
List.Description = ListDescription
List.Header = ListHeader
List.Icon = ListIcon
List.Item = ListItem
List.List = ListList
export default List