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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | 23x 23x 23x 5x 5x 23x 23x 1x 22x 11x 11x 10x 1x 1x 23x 89x 89x 89x | import React from 'react'; import PropTypes from 'prop-types'; import ChatContentItem from '@collab-ui/react/ContentItem/ChatContent'; import FileContentItem from '@collab-ui/react/ContentItem/FileContent'; import IconContent from '@collab-ui/react/ContentItem/IconContent'; import { omit } from 'lodash'; class ContentItem extends React.PureComponent { render() { const { actionNode, aspect, className, content, failedText, fileSize, height, icon, isProtected, loading, loadingText, style, subtitle, title, type, width, ...props } = this.props; const otherProps = omit({...props}, ['gifIcon']); const findAspect = (width, height) => { Iif(width && height){ const aspectRatioObj = { 1 : 'oneOne', .75 : 'threeFour', .66 : 'twoThree', .4 : 'tall', 4.35 : 'wide', 1.33 : 'fourThree', 1.5 : 'threeTwo', 1.78 : 'sixteenNine' }; const providedAspectRatio = width/height; const closestAspectRatio = Object.keys(aspectRatioObj).reduce((prev, curr) => Math.abs(curr - providedAspectRatio) < Math.abs(prev - providedAspectRatio) ? curr : prev ); return aspectRatioObj[closestAspectRatio]; } return type === 'chat' ? 'sixteenNine' : 'threeTwo'; }; const chosenItem = () => { if(failedText && type==='chat') { return ( <div className={ 'cui-content cui-content--failed' + `${(className && ` ${className}`) || ''}` }> <div className='cui-content--failed-container'> <i className='icon icon-warning_28 cui-content--failed-warning'/> <p className='cui-content--failed-message'>{failedText}</p> </div> </div> ); } else if (type==='chat'){ return ( <ChatContentItem actionNode={actionNode} aspect={aspect ? aspect : findAspect(width,height)} className={className} content={content} fileSize={fileSize} height={height} isProtected={isProtected} loading={loading} style={style} title={title} type={type} width={width} {...props} /> ); } else if (type==='file' && !icon){ return ( <FileContentItem actionNode={actionNode} aspect={aspect ? aspect : findAspect(width,height)} className={className} content={content} height={height} icon={icon} isProtected={isProtected} loading={loading} loadingText={loadingText} subtitle={subtitle} title={title} type={type} width={width} {...props} /> ); } else Eif (icon){ return ( <IconContent actionNode={actionNode} className={className} icon={icon} isProtected={isProtected} loading={loading} subtitle={subtitle} title={title} {...otherProps} /> ); } }; return ( <div> {chosenItem()} </div> ); } } ContentItem.displayName = 'ContentItem'; ContentItem.defaultProps = { actionNode: null, aspect: null, className: '', content: null, failedText: '', fileSize: '', icon: '', isProtected: false, loading: false, loadingText: 'Loading', style: null, subtitle: '', title: '', type: 'chat', }; ContentItem.propTypes = { /** @prop Node to render buttons inside Content Item | null */ actionNode: PropTypes.node, /** @prop Set the Content Item's aspect size | null */ aspect: PropTypes.oneOf(['fourThree', 'nineSixteen', 'oneOne', 'sixteenNine', 'tall', 'threeFour', 'threeTwo', 'twoThree', 'wide']), /** @prop Optional css class string | '' */ className: PropTypes.string, /** @prop Set the image/gif of the Content Item | '' */ content: PropTypes.string, /** @prop Set the failed text to show when content fails to load | '' */ failedText: PropTypes.string, /** @prop Show the size of the file | '' */ fileSize: PropTypes.string, /** @prop Show icon at top right corner of Content Item */ gifIcon: PropTypes.string, /** @prop Height of the image in px */ height: PropTypes.number, /** @prop Set the type of icon to show | '' */ icon: PropTypes.string, /** @prop Show visibility of action node buttons | false */ isProtected: PropTypes.bool, /** @prop Show loading spinner | false */ loading: PropTypes.bool, /** @prop Change loading text */ loadingText: PropTypes.string, /** @prop Additional css styling applied to the button | null */ style: PropTypes.object, /** @prop Set the subtitle of the Content Item | '' */ subtitle: PropTypes.string, /** @prop Set the title of the Content Item | '' */ title: PropTypes.string, /** @prop Set the type of Content Item to display */ type: PropTypes.oneOf(['chat', 'file']), /** @prop Width of the image in px */ width: PropTypes.number }; export default ContentItem; /** * @name Content Item with and without isProtected prop * * @category containers * @component content-item * @section default * * @js * import { Button, ContentItem, Icon, } from '@collab-ui/react'; export default class ChatContentItem extends React.PureComponent { render() { const actionNode = ( <div> <Button ariaLabel='For the Win' style={{backgroundColor:'black'}} circle size={32} > <Icon name='open-in-folder_14' color='white' /> </Button> <Button ariaLabel='For the Win' style={{backgroundColor:'black'}} circle size={32} > <Icon name='icon-arrow-tail-down_14' color='white' /> </Button> </div> ) const handleClick = () => { alert('Image onClick') } return( <div className='columns large'> <div className= 'docs-example docs-example--spacing'> <ContentItem actionNode={actionNode} aspect='sixteenNine' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' fileSize='24 KB' onClick={handleClick} type='chat' title='Screen Shot 208-11-07 at 10.30.02 AM.png' /> </div> <div className= 'docs-example docs-example--spacing'> <ContentItem aspect='sixteenNine' content= 'https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' fileSize='24 KB' isProtected={true} onClick={handleClick} title='Nice seating.png' type='chat' /> </div> <div className= 'docs-example docs-example--spacing'> <ContentItem aspect='sixteenNine' content= 'http://upload.wikimedia.org/wikipedia/commons/d/dd/Muybridge_race_horse_animated.gif' fileSize='50 KB' gifIcon='icon icon-gif_24' isProtected={true} title='Race Horse.gif' type='chat' /> </div> </div> ); } } **/ /** * @name Content Item in File View with and without isProtected Prop * * @category containers * @component content-item * @section file * * @js * import { Button, ContentItem, Icon, } from '@collab-ui/react'; export default class FileContentItem extends React.PureComponent { render() { const actionNode = ( <div> <Button ariaLabel='For the Win' style={{backgroundColor:'black'}} circle size={32} > <Icon name='chat_12' color='white' /> </Button> <Button ariaLabel='For the Win' style={{backgroundColor:'black'}} circle size={32} > <Icon name='open-in-folder_12' color='white' /> </Button> <Button ariaLabel='For the Win' style={{backgroundColor:'black'}} circle size={32} > <Icon name='icon-arrow-tail-down_12' color='white' /> </Button> </div> ) const handleClick = () => { alert('Image onClick'); } return( <div className='columns large'> <div className= 'docs-example docs-example--spacing'> <ContentItem actionNode={actionNode} aspect='threeTwo' content='https://vmcdn.ca/f/files/sudbury/uploadedImages/news/localNews/2015/06/090615_IKEA_sized.jpg;w=630' onClick={handleClick} subtitle='Barbara German, 4 days' title='Logo.pdf' type='file' /> </div> <div className= 'docs-example docs-example--spacing'> <ContentItem aspect='threeTwo' content='https://vmcdn.ca/f/files/sudbury/uploadedImages/news/localNews/2015/06/090615_IKEA_sized.jpg;w=630' isProtected={true} subtitle='Barbara German, 4 days' title='Screen Shot 2018-10-11 at 5.22.32 PM.png' type='file' /> </div> <div className= 'docs-example docs-example--spacing'> <ContentItem actionNode={actionNode} aspect='threeTwo' content='http://upload.wikimedia.org/wikipedia/commons/d/dd/Muybridge_race_horse_animated.gif' gifIcon='icon icon-gif_20' onClick={handleClick} subtitle='Barbara German, 4 days' title='Race Horse.gif' type='file' /> </div> </div> ); } } **/ /** * @name Content Item with different size * * @category containers * @component content-item * @section size * * @js * import { Button, ContentItem, Icon, } from '@collab-ui/react'; export default class ContentItemSizes extends React.PureComponent { render() { const actionNode = ( <div> <Button ariaLabel='For the Win' style={{backgroundColor:'black'}} circle size={32} > <Icon name='chat_12' color='white' /> </Button> <Button ariaLabel='For the Win' style={{backgroundColor:'black'}} circle size={32} > <Icon name='open-in-folder_12' color='white' /> </Button> <Button ariaLabel='For the Win' style={{backgroundColor:'black'}} circle size={32} > <Icon name='icon-arrow-tail-down_12' color='white' /> </Button> </div> ) const handleClick = () => { alert('Image onClick'); } return( <div> <ContentItem aspect='twoThree' content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg' subtitle='Barbara German, 4 days' type='file' actionNode={actionNode} onClick={handleClick} title='2:3' /> <ContentItem aspect='threeFour' content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg' subtitle='Barbara German, 4 days' onClick={handleClick} type='file' title='3:4' /> <ContentItem aspect='sixteenNine' content='http://panoramicvisions.com/images/banner-img11.jpg' subtitle='Barbara German, 4 days' type='file' title='16:9' /> <ContentItem aspect='nineSixteen' content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg' subtitle='Barbara German, 4 days' type='file' title='9:16' /> <ContentItem aspect='oneOne' content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg' subtitle='Barbara German, 4 days' type='file' title='1:1' /> <ContentItem aspect='fourThree' content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg' subtitle='Barbara German, 4 days' type='file' title='4:3' /> <ContentItem aspect='threeTwo' content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg' subtitle='Barbara German, 4 days' type='file' title='3:2' /> <ContentItem aspect='oneOne' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' subtitle='Barbara German, 4 days' type='chat' onClick={handleClick} title='1:1, 3:2 Container' /> <ContentItem aspect='threeFour' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' subtitle='Barbara German, 4 days' type='chat' title='3:4, 3:2 container' /> <ContentItem aspect='twoThree' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' subtitle='Barbara German, 4 days' type='chat' title='2:3, 3:2 container' /> <ContentItem aspect='tall' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' subtitle='Barbara German, 4 days' type='chat' title='Tall, 3:2 container' /> <ContentItem aspect='wide' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' subtitle='Barbara German, 4 days' type='chat' title='Wide, 16:9 container' /> <ContentItem aspect='fourThree' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' subtitle='Barbara German, 4 days' type='chat' title='4:3' /> <ContentItem aspect='threeTwo' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' subtitle='Barbara German, 4 days' type='chat' title='3:2' /> <ContentItem aspect='sixteenNine' content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' subtitle='Barbara German, 4 days' type='chat' title='16:9' /> </div> ); } } **/ /** * @name Content Item Loading * * @category containers * @component content-item * @section spinner * * @js * import { ContentItem } from '@collab-ui/react'; export default class ContentItemLoading extends React.PureComponent { render() { return( <div className='columns large'> <div className= 'docs-example docs-example--spacing'> <ContentItem aspect='threeTwo' content= 'https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' loading={true} loadingText='Loading' subtitle='Barbara German, 4 days' type='file' title='Logo.pdf' /> </div> <div className= 'docs-example docs-example--spacing'> <ContentItem aspect='sixteenNine' content= 'https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' loading={true} subtitle='Barbara German, 4 days' type='chat' title='Logo.pdf' /> </div> <div className= 'docs-example docs-example--spacing'> <ContentItem aspect='sixteenNine' loading={true} subtitle='Barbara German, 4 days' type='chat' title='Logo.pdf' /> </div> </div> ); } } **/ /** * @name Finding aspect with image Width and Height Prop * * @category containers * @component content-item * @section aspect * * @js * import { ContentItem } from '@collab-ui/react'; export default class ContentItemWidthHeight extends React.PureComponent { render() { return( <div className='columns large'> <ContentItem content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg' fileSize='24 KB' height={400} title='Nice seating.png' type='chat' width={300} /> </div> ); } } **/ /** * @name Failed to Load Content * * @category containers * @component content-item * @section failed * * @js * import { ContentItem } from '@collab-ui/react'; export default class ContentItemFailed extends React.PureComponent { render() { return( <div className='columns large'> <ContentItem failedText='Failed to load preview. Tap to download the file.' fileSize='24 KB' onDownload={this.alertSomething} title='Nice seating.png' type='chat' showInFolder={this.showInFolder} /> </div> ); } } **/ /** * @name Icon File View * * @category containers * @component content-item * @section icon * * @js * import { Button, ContentItem, Icon, } from '@collab-ui/react'; export default class ContentItemIcon extends React.PureComponent { render() { const handleClick = () => { alert('file onClick'); } const folderClick = e => { alert('folder clicked'); e.stopPropagation(); } const downloadClick = e => { alert('download clicked'); e.stopPropagation(); } const actionNode = ( <div> <Button ariaLabel='For the Win' circle onClick={folderClick} style={{backgroundColor:'black'}} size={32} > <Icon name='open-in-folder_14' color='white' /> </Button> <Button ariaLabel='For the Win' circle onClick={downloadClick} style={{backgroundColor:'black'}} size={32} > <Icon name='icon-arrow-tail-down_14' color='white' /> </Button> </div> ) return( <div className='columns large'> <ContentItem actionNode={actionNode} fileSize='24 KB' icon='icon-pdf_72' onClick={handleClick} subtitle='Barbara German, 12/05/18' title='Ideas.pdf' type='file'/> </div> ); } } **/ |