-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathListItem.jsx
243 lines (214 loc) · 6.06 KB
/
ListItem.jsx
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/**
* @component
*/
import classnames from 'clsx';
import PropTypes from 'prop-types';
import React from 'react';
import ListItemHeader from './ListItemHeader';
/**
* The items in a list to display related data in a structured format. Should be
* used inside of a `List` component.
*/
const ListItem = ({
title,
subtitle,
image,
images,
icon,
className,
onClick,
right,
style,
circle = false,
headerProps,
hoverItem,
onLongPress,
onMouseDown,
onMouseUp,
onTouchStart,
onTouchEnd,
onTouchCancel,
longPressTimeout = 450,
noContentClass,
onOpen,
imageBorderColor = 'rgba(var(--chayns-color-rgb--009), .08)',
left,
headMultiline = false,
// eslint-disable-next-line react/prop-types
notExpandable,
openImageOnClick = false,
...props
}) => (
<div
className={classnames('list-item', className, {
'list-item--clickable': onClick,
})}
style={style}
{...props}
>
<ListItemHeader
title={title}
subtitle={subtitle}
onClick={onClick}
image={image}
images={images}
icon={icon}
className={className}
right={right}
style={style && style.head ? style.head : null}
circle={circle}
hoverItem={hoverItem}
longPressTimeout={longPressTimeout}
onLongPress={onLongPress}
onKeyDown={onMouseDown}
onKeyUp={onMouseUp}
onTouchStart={onTouchStart}
onTouchEnd={onTouchEnd}
onTouchCancel={onTouchCancel}
imageBorderColor={imageBorderColor}
left={left}
openImageOnClick={openImageOnClick}
{...headerProps}
/>
</div>
);
ListItem.propTypes = {
/**
* A string or `ReactNode` that will be rendered as the title of the list
* item.
*/
title: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]).isRequired,
/**
* A string or `ReactNode` that will be rendered as the subtitle of the list
* item.
*/
subtitle: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
/**
* The URL to an image that will be shown on the left of the list item.
*/
image: PropTypes.string,
/**
* An array of URLs for creating a puzzle of images on the left hand of the
* image item.
*/
images: PropTypes.arrayOf(PropTypes.string),
/**
* Whether the image/images should be opened at full size when clicked
* only works if either image or images is defined
*/
openImageOnClick: PropTypes.bool,
/**
* An icon to show on the left side of the list item.
*/
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
/**
* A classname string that will be applied ot the outer-most `<div>`-element
* of the list item.
*/
className: PropTypes.string,
/**
* An `onClick`-listener for the list item header.
*/
onClick: PropTypes.func,
/**
* A `ReactNode` that should be displayed on the right side of the list
* item.
*/
right: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
/**
* A React style object that will be applied to the outer-most
* `<div>`-element of the list item.
*
* `style.body` and `style.head` will be applied to the body and head parts
* of the list item accordingly.
*/
style: PropTypes.shape({
head: PropTypes.objectOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.number])
),
body: PropTypes.objectOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.number])
),
}),
/**
* Any additional props that will be applied to the head of the list item.
*/
headerProps: PropTypes.object, // eslint-disable-line react/forbid-prop-types
/**
* Wether the image should be in a circular shape rather than a rectangle.
*/
circle: PropTypes.bool,
/**
* A ReactNode that is shown on the right side of the list item on hover.
*/
hoverItem: PropTypes.node,
/**
* This function will be called when the user long-presses on the list item
* header.
*/
onLongPress: PropTypes.func,
/**
* A callback for the `mousedown`-event on the list item header.
*/
onMouseDown: PropTypes.func,
/**
* A callback for the `mousemove`-event on the list item header.
*/
onMouseMove: PropTypes.func,
/**
* A callback for the `mouseup`-event on the list item header.
*/
onMouseUp: PropTypes.func,
/**
* A callback for the `touchstart`-event on the list item header.
*/
onTouchStart: PropTypes.func,
/**
* A callback for the `touchmove`-event on the list item header.
*/
onTouchMove: PropTypes.func,
/**
* A callback for the `touchend`-event on the list item header.
*/
onTouchEnd: PropTypes.func,
/**
* A callback for the `touchcancel`-event on the list item header.
*/
onTouchCancel: PropTypes.func,
/**
* Control the time after which a press is considered a long press.
*/
longPressTimeout: PropTypes.number,
/**
* Whether the default classname for the children container should be
* removed, which removes the padding around the list item content.
*/
noContentClass: PropTypes.bool,
/**
* This function will be called when the list item is opening.
*/
onOpen: PropTypes.func,
/**
* A CSS color that will be applied to the border of the image.
*/
imageBorderColor: PropTypes.string,
left: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
/**
* Whether the head of the list item should be multiline or ellipsis in expanded state
*/
headMultiline: PropTypes.bool,
};
ListItem.displayName = 'ListItem';
export default ListItem;