Sha256: 2b79c233ee5adbd3ce439616bc51bfd452e0983fc13de325baff45c13ea79bd3

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

import React from 'react';

import {
  Body,
  Caption,
  Avatar,
} from '../'

type MessageProps = {
  avatarName?: String,
  avatarStatus?: String,
  avatarUrl?: String,
  label?: String,
  message: String,
  timestamp?: String,
}

const print_label = (label) => {
  if ( label != null ) {
    return (
      <Caption>{`${label}`}</Caption>
    )
  }
}

const print_timestamp = (timestamp) => {
  if ( timestamp != null ) {
    return(
      <Caption size='xs'>{`${timestamp}`}</Caption>
    )
  }
}

const Message = (props: MessageProps) => {
  const {
    avatarName='',
    avatarUrl='',
    label='',
    message='',
    timestamp='',
    avatarStatus=null
  } = props
  
  const print_avatar = (avatarName, avatarUrl, avatarStatus) => {
    if ( avatarUrl !== '' && avatarName !== '' ) {
      return (
        <Avatar name={avatarName} size='sm' imageUrl={avatarUrl} status={avatarStatus}/>
      )
    }
    if ( avatarUrl === '' && avatarName !== '' ) {
      return (
        <Avatar name={avatarName} size='sm' status={avatarStatus}/>
      )
    }
  }

  const messageCSS = ( avatarUrl, avatarName ) => {
    if (avatarUrl != '' || avatarName != '') {
      return 'pb_message_kit_avatar'
    }
    else {
      return 'pb_message_kit'
    }
  }

  return (
    <div className={messageCSS(avatarName, avatarUrl)}>
      {print_avatar(avatarName, avatarUrl, avatarStatus)}
      <div class="content_wrapper">
        {print_label(label)}
        <Body>{message}</Body>
        {print_timestamp(timestamp)}
      </div>
    </div>
  )
}

export default Message;

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
playbook_ui-3.1.0 app/pb_kits/playbook/pb_message/_message.jsx
playbook_ui-3.0.1 app/pb_kits/playbook/pb_message/_message.jsx
playbook_ui-3.0.0 app/pb_kits/playbook/pb_message/_message.jsx