about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/components/display_name.js
blob: a26cff0492c7b5786e5cd16656ddc38b79852257 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//  Package imports.
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';

//  The component.
export default function DisplayName ({
  account,
  className,
  inline,
  localDomain,
}) {
  const computedClass = classNames('display-name', { inline }, className);

  if (!account) return null;

  let acct = account.get('acct');
  if (acct.indexOf('@') === -1 && localDomain) {
    acct = `${acct}@${localDomain}`;
  }

  //  The result.
  return account ? (
    <span className={computedClass}>
      <bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }} /></bdi>
      {inline ? ' ' : null}
      <span className='display-name__account'>@{acct}</span>
    </span>
  ) : null;
}

//  Props.
DisplayName.propTypes = {
  account: ImmutablePropTypes.map,
  className: PropTypes.string,
  inline: PropTypes.bool,
  localDomain: PropTypes.string,
};