Sha256: 22fdae00ebfb1787d8022bb33c931f32b3a0c7914a018326adbd76d83f5b0626

Contents?: true

Size: 1.59 KB

Versions: 15

Compression:

Stored size: 1.59 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, OnlineStatus } from '../'

type AvatarProps = {
  aria?: object,
  className?: string,
  data?: object,
  dark?: boolean,
  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, dark = false } = 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}>
        <OnlineStatus
            className={`size_${size}`}
            dark={dark}
            status={status}
        />
      </If>
    </div>
  )
}

export default Avatar

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
playbook_ui-7.3.0.pre.alpha2 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.7.0.pre.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-6.7.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha12 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha11 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha10 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha9 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha8 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha7 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha6 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha5 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha4 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha3 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha2 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.0.1.pre.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx