1
0
puyopuyotetr.is/app/javascript/flavours/glitch/components/display_name.js

40 lines
1012 B
JavaScript
Raw Normal View History

2018-01-06 13:04:13 +09:00
// Package imports.
2017-12-30 07:55:06 +09:00
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
2016-09-01 21:12:11 +09:00
import ImmutablePropTypes from 'react-immutable-proptypes';
2018-01-06 13:04:13 +09:00
// The component.
export default function DisplayName ({
account,
className,
inline,
localDomain,
2018-01-06 13:04:13 +09:00
}) {
const computedClass = classNames('display-name', { inline }, className);
2016-09-01 21:12:11 +09:00
if (!account) return null;
let acct = account.get('acct');
if (acct.indexOf('@') === -1 && localDomain) {
acct = `${acct}@${localDomain}`;
}
2018-01-06 13:04:13 +09:00
// The result.
return account ? (
<span className={computedClass}>
<bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }} /></bdi>
2018-01-06 13:04:13 +09:00
{inline ? ' ' : null}
<span className='display-name__account'>@{acct}</span>
2018-01-06 13:04:13 +09:00
</span>
) : null;
}
2018-01-06 13:04:13 +09:00
// Props.
DisplayName.propTypes = {
account: ImmutablePropTypes.map,
className: PropTypes.string,
inline: PropTypes.bool,
localDomain: PropTypes.string,
2018-01-06 13:04:13 +09:00
};