2019-06-01 23:24:24 +08:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
2019-08-14 06:59:43 +08:00
|
|
|
import { ElementTypeForwardRef, ElementTypeMemo } from 'react-devtools-shared/src/types';
|
2019-06-01 23:24:24 +08:00
|
|
|
import styles from './HocBadges.css';
|
|
|
|
|
|
|
|
|
|
import type { Element } from './types';
|
|
|
|
|
|
|
|
|
|
type Props = {|
|
|
|
|
|
element: Element,
|
|
|
|
|
|};
|
|
|
|
|
|
|
|
|
|
export default function HocBadges({ element }: Props) {
|
|
|
|
|
const { hocDisplayNames, type } = ((element: any): Element);
|
|
|
|
|
|
|
|
|
|
let typeBadge = null;
|
|
|
|
|
if (type === ElementTypeMemo) {
|
|
|
|
|
typeBadge = 'Memo';
|
|
|
|
|
} else if (type === ElementTypeForwardRef) {
|
|
|
|
|
typeBadge = 'ForwardRef';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hocDisplayNames === null && typeBadge === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.HocBadges}>
|
2019-06-02 09:48:24 +08:00
|
|
|
{typeBadge !== null && <div className={styles.Badge}>{typeBadge}</div>}
|
2019-06-01 23:24:24 +08:00
|
|
|
{hocDisplayNames !== null &&
|
|
|
|
|
hocDisplayNames.map(hocDisplayName => (
|
2019-06-02 09:48:24 +08:00
|
|
|
<div key={hocDisplayName} className={styles.Badge}>
|
|
|
|
|
{hocDisplayName}
|
|
|
|
|
</div>
|
2019-06-01 23:24:24 +08:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|