Sha256: 26809b82b823cdc84b9b38b0ae3969040b2d4104b1584487d1d8ce00ea0f2509

Contents?: true

Size: 1.6 KB

Versions: 18

Compression:

Stored size: 1.6 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 = '', imageUrl, size = 'md', status = null, dark = false } = props
  const dataProps = buildDataProps(data)
  const ariaProps = buildAriaProps(aria)
  const classes = classnames(
    buildCss('pb_avatar_kit', size),
    globalProps(props),
    className
  )

  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

18 entries across 18 versions & 1 rubygems

Version Path
playbook_ui-7.14.0.pre.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.15.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.15.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.14.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.13.0.pre.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.13.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.12.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.12.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.11.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.11.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.11.0.pre.alpha1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.10.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.9.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.8.4 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.8.3 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.8.2 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.8.1 app/pb_kits/playbook/pb_avatar/_avatar.jsx
playbook_ui-7.8.0 app/pb_kits/playbook/pb_avatar/_avatar.jsx