| 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351 |
70x
70x
70x
70x
68x
1x
67x
1x
66x
1x
65x
1x
64x
70x
70x
70x
70x
70x
18x
18x
18x
14x
70x
52x
52x
52x
9x
70x
70x
70x
89x
89x
89x
| import React from 'react';
import PropTypes from 'prop-types';
import { uniqueId } from 'lodash';
import {
Avatar,
Icon,
ListItem,
ListItemSection
} from '@collab-ui/react';
/**
* @category containers
* @component list-item
* @variations collab-ui-react
*/
class SpaceListItem extends React.PureComponent {
state = {
id: this.props.id || uniqueId('cui-space-list-item-')
};
render() {
const {
attachments,
className,
childrenLeft,
childrenRight,
header,
headerSecondary,
highlightColor,
isAlertOn,
isBold,
isDecrypting,
isMentioned,
isMuted,
isOverview,
isUnread,
resultRight,
searchTerm,
subheader,
title,
type,
...props
} = this.props;
const { id } = this.state;
const getTitle =
(!title && typeof header === 'string')
? header
: title;
const getIcon = () => {
if (isMuted) {
return <Icon color="$white-60" name="alert-muted_12" />;
} else if (isUnread) {
return (
<i
style={{ fontSize: '12px', color: '#07C1E4' }}
className="icon icon-unread-badge_16"
/>
);
} else if (isMentioned) {
return <Icon color="blue" name="mention_12" />;
} else if (isAlertOn) {
return <Icon color="$white-60" name="alert_12" />;
}
return null;
};
const leftSection = isOverview
? (
<Avatar isOverview icon={<Icon name="handset_24" />} />
) : (
childrenLeft
);
const rightSection = (
<ListItemSection key="child-2" position="right">
{childrenRight ? childrenRight : getIcon()}
</ListItemSection>
);
const addEscapes = text =>
text && text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") || '';
const highlightSubheader = () => {
const escapedTerm = addEscapes(searchTerm);
const re = new RegExp(`(${escapedTerm})`, 'gi');
return searchTerm && typeof subheader === 'string'
? subheader.split(re)
.map((ele, idx) =>
ele.match(re)
? (
<span
key={`subheader-${idx}`}
className="cui-list-item__subheader--highlight"
style={{ color: highlightColor }}
>
{ele}
</span>
) : ele
)
: subheader;
};
const highlightHeader = () => {
const escapedTerm = addEscapes(searchTerm);
const re = new RegExp(`(${escapedTerm})`, 'gi');
return searchTerm && typeof header === 'string'
? header.split(re)
.map((ele, idx) =>
ele.match(re)
? (
<span
key={`header-${idx}`}
className="cui-list-item__header--highlight"
style={{ color: highlightColor }}
>
{ele}
</span>
) : ele
)
: header;
};
const getHeader = ['search', 'filter', 'flag', 'filter-search'].includes(type)
? [
<span key="header-0" className="cui-list-item__header-main">{header}</span>,
headerSecondary && (
<span className="cui-list-item__header-secondary" key="header-1">
{headerSecondary}
</span>
)
]
: highlightHeader();
const children = [
<ListItemSection key="child-0" position="left">
{leftSection || <Avatar title="NA" />}
</ListItemSection>,
<ListItemSection key="child-1" position="center">
<div
className={
'cui-list-item__header' +
`${((searchTerm || isOverview) && ` cui-list-item__header--overview`) || ''}` +
`${(isDecrypting && ` cui-decrypting`) || ''}`
}
>
{getHeader}
</div>
{['search', 'filter', 'flag', 'filter-search'].includes(type)
? (
<ListItemSection
position="center"
className="cui-list-item__result-container"
>
{['flag'].includes(type)
? (
<ListItemSection
position="center"
key="attachment-line-1"
className="cui-list-item__attachment"
>
<div className="cui-list-item__attachment--top">
<ListItemSection
position="center"
className="cui-list-item__attachment--top-left">
{highlightSubheader(subheader)}
</ListItemSection>
{resultRight && (
<ListItemSection
position="right"
className="cui-list-item__attachment--top-right">
{resultRight}
</ListItemSection>
)}
</div>
{attachments &&
attachments.length && (
<div className="cui-list-item__attachment--bottom">
{attachments[0]}
</div>
)}
</ListItemSection>
) : (
<div className="cui-list-item__result">
{highlightSubheader(subheader)}
</div>
)
}
</ListItemSection>
) : (
<div
className={
"cui-list-item__subheader" +
`${(isDecrypting && ` cui-decrypting`) || ''}`
}
>
{subheader}
</div>
)
}
</ListItemSection>,
...(!type ? [rightSection] : [])
];
return (
<ListItem
className={
`${(isBold && ` cui-list-item--unread`) || ''}` +
`${(type && ` cui-list-item--space-${type}`) || ''}` +
`${(className && ` ${className}`) || ''}`
}
id={id}
title={getTitle}
type="space"
{...props}
>
{children}
</ListItem>
);
}
}
SpaceListItem.propTypes = {
/** @prop SpaceListItem Attachment Array | null */
attachments: PropTypes.arrayOf(PropTypes.node),
/** @prop Children nodes to render for left section | null */
childrenLeft: PropTypes.node,
/** @prop Children nodes to render for right section | null */
childrenRight: PropTypes.node,
/** @prop Optional HTML class string | '' */
className: PropTypes.string,
/** @prop ListItem header node */
header: PropTypes.node.isRequired,
/** @prop Secondary header for center section | '' */
headerSecondary: PropTypes.string,
/** @prop Highlight Color for Regex | '' */
highlightColor: PropTypes.string,
/** @prop HTML ID for SpaceListItem | '' */
id: PropTypes.string,
/** @prop Determines if SpaceListItem's Alert is on | false */
isAlertOn: PropTypes.bool,
/** @prop Determines if SpaceListItem is Bolded | false */
isBold: PropTypes.bool,
/** @prop Determines if SpaceListItem decrypting | false */
isDecrypting: PropTypes.bool,
/** @prop Determines if SpaceListItem has been mentioned | false */
isMentioned: PropTypes.bool,
/** @prop Determines if SpaceListItem has been muted | false */
isMuted: PropTypes.bool,
/** @prop Determines if SpaceListItem is an Overview item | false */
isOverview: PropTypes.bool,
/** @prop Determines if SpaceListItem is unread | false */
isUnread: PropTypes.bool,
/** @prop Children node for result right section | null */
resultRight: PropTypes.node,
/** @prop Word used for search | '' */
searchTerm: PropTypes.string,
/** @prop SpaceListItem subheader node | ''s */
subheader: PropTypes.node,
/** @prop SpaceListItem title | '' */
title: PropTypes.string,
/** @prop SpaceListItem type | '' */
type: PropTypes.oneOf([
'',
'filter',
'filter-search',
'filter-summary',
'flag',
'search',
])
};
SpaceListItem.defaultProps = {
attachments: null,
childrenLeft: null,
childrenRight: null,
className: '',
headerSecondary: '',
highlightColor: '',
id: '',
isAlertOn: false,
isBold: false,
isDecrypting: false,
isMentioned: false,
isMuted: false,
isOverview: false,
isUnread: false,
resultRight: null,
searchTerm: '',
subheader: '',
title: '',
type: ''
};
SpaceListItem.displayName = 'SpaceListItem';
export default SpaceListItem;
/**
* @component space-list
* @section default
* @react
*
import {
Icon,
List,
ListItemHeader,
SpaceListItem,
} from '@collab-ui/react';
import { NavLink } from 'react-router-dom';
export default class ListItemDefault extends React.PureComponent {
render() {
const anchorNode = <NavLink to='/containers/list-item' />;
return(
<div className="medium-4 columns">
<List style={{backgroundColor: 'black'}}>
<SpaceListItem isOverview header='Overview Item' />
<SpaceListItem header='Header Only'/>
<SpaceListItem header='Bold Unread' isBold isUnread/>
<SpaceListItem header='Bold Mentioned' isBold isMentioned/>
<SpaceListItem header='isAlertOn' isAlertOn/>
<SpaceListItem header='isMuted' isMuted/>
<SpaceListItem header='Disabled' subheader='subheader' disabled/>
<SpaceListItem header='Subheader as Node' subheader={<span style={{color: '#98D5CA'}}>Marketing</span>}/>
<ListItemHeader header='List Header-Type(space)' children={<a>More</a>} type='space'/>
<SpaceListItem header='Header with SearchTerm' searchTerm='search'/>
<SpaceListItem header='Both Headers w/ SearchTerm' subheader='Searchable subheader' searchTerm='search'/>
<SpaceListItem header='Subheader(node)-searchTerm' subheader={<span style={{color: '#D7ABE1'}}>Searching</span>} searchTerm='search'/>
<SpaceListItem header='Type(search)' headerSecondary='16:00' subheader='HighlightColor changes search color' searchTerm='search' type='search' highlightColor='white'/>
<SpaceListItem header='Type(filter)' headerSecondary='12/03/2018' subheader='headerSecondary=string' searchTerm='Barbara' type='filter' />
<SpaceListItem header='Type(filter-search)' headerSecondary='12/03/2018' subheader='For search after a (filter)' type='filter-search' searchTerm='(filter)'/>
<SpaceListItem header='Type(filter-summary) (8)' type='filter-summary' childrenLeft={<Icon name='alert_12' />}/>
<SpaceListItem header='Type(flag)-attachments' attachments={[<span><Icon name='document_12' /> <span>Ideas.pdf</span></span>]} subheader='resultRight=node, attachments=[node]' headerSecondary='12/03/2018' type='flag' resultRight={<Icon name='flag-active_12'/>}/>
<SpaceListItem header='Type(flag)' subheader='header&subheader=node' headerSecondary='08/03/2018' type='flag' resultRight={<Icon name='flag-active_12'/>}/>
</List>
</div>
);
}
}
**/
|