Sha256: 5480aa5c600c4a02f77f8ea9f39639362f928185495c8d9d535b808ec79a2292

Contents?: true

Size: 1.49 KB

Versions: 22

Compression:

Stored size: 1.49 KB

Contents

/* @flow */

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

import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
import { globalProps } from '../utilities/globalProps.js'

import { Image } from '../'

type AvatarProps = {
  aria?: object,
  className?: string,
  data?: object,
  id?: string,
  imageUrl: string,
  name: string,
  size?: "md" | "lg" | "sm" | "xl" | "xs",
  status: "away" | "offline" | "online",
}

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

const Avatar = (props: AvatarProps) => {
  const { aria = {}, className, data = {}, name = null, id = id, imageUrl, size = 'md', status = null } = props
  const dataProps = buildDataProps(data)
  const ariaProps = buildAriaProps(aria)
  const classes = classnames(buildCss('pb_avatar_kit', size), className, globalProps(props))

  const initials = name && firstTwoInitials(name)
  dataProps['data-initials'] = initials

  return (
    <div
        {...ariaProps}
        {...dataProps}
        className={classes}
        id={id}
    >
      <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

22 entries across 22 versions & 1 rubygems

Version Path
playbook_ui-6.6.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha10 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.6.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.5.2 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.5.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.5.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.4.2 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha9 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha8 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha7 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.4.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha6 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha5 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.4.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.3.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha4 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha3 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.0.pre.alpha2 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.3.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.2.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx