Sha256: 372505587a05bf2256ecc76e24aa90da9619a96903e567fb8b2aeb7a69a4402e

Contents?: true

Size: 1.05 KB

Versions: 38

Compression:

Stored size: 1.05 KB

Contents

/* @flow */

import React from 'react'
import classnames from 'classnames'
import { map } from 'lodash'

import { Image } from '../'

type AvatarProps = {
  className?: String,
  name: String,
  imageUrl: String,
  size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl',
  status: 'online' | 'away',
}

const firstTwoInitials = (name) => (
  map(name.split(/\s/), (name) => name[0])
    .join('')
    .substring(0, 2)
)

const Avatar = ({
  className,
  name = null,
  imageUrl,
  size = 'md',
  status = null,
}: AvatarProps) => {
  const classes = classnames(['pb_avatar_kit', `avatar_${size}`, className])
  const initials = name && firstTwoInitials(name)

  return (
    <div className={classes}>
      <div
          className="avatar_wrapper"
          data-initials={initials}
      >
        <If condition={imageUrl}>
          <Image
              alt={name}
              url={imageUrl}
          />
        </If>
      </div>
      <If condition={status}>
        <div className={`pb_online_status_kit_${status} size_${size}`} />
      </If>
    </div>
  )
}

export default Avatar

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
playbook_ui-4.17.0.pre.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.16.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.15.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.14.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.15.1.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.13.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.13.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.12.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.11.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.11.0.pre.alpha3 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.11.0.pre.alpha.pre.2 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.10.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.10.0.pre.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.9.0.pre.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.9.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.8.2 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.8.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.7.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.7.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-4.6.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx