2019-06-01 23:24:24 +08:00
|
|
|
// @flow
|
|
|
|
|
|
2019-08-14 08:58:03 +08:00
|
|
|
import React, {Fragment} from 'react';
|
|
|
|
|
import {
|
|
|
|
|
ElementTypeMemo,
|
|
|
|
|
ElementTypeForwardRef,
|
|
|
|
|
} from 'react-devtools-shared/src/types';
|
2019-06-01 23:24:24 +08:00
|
|
|
import styles from './Badge.css';
|
|
|
|
|
|
2019-08-14 08:58:03 +08:00
|
|
|
import type {ElementType} from 'react-devtools-shared/src/types';
|
2019-06-02 09:48:24 +08:00
|
|
|
|
2019-06-01 23:24:24 +08:00
|
|
|
type Props = {|
|
2019-06-02 00:19:32 +08:00
|
|
|
className?: string,
|
2019-06-02 09:48:24 +08:00
|
|
|
hocDisplayNames: Array<string> | null,
|
|
|
|
|
type: ElementType,
|
2019-06-01 23:24:24 +08:00
|
|
|
|};
|
|
|
|
|
|
2019-08-14 08:58:03 +08:00
|
|
|
export default function Badge({className, hocDisplayNames, type}: Props) {
|
2019-06-02 09:48:24 +08:00
|
|
|
let hocDisplayName = null;
|
|
|
|
|
let totalBadgeCount = 0;
|
|
|
|
|
let typeLabel = null;
|
|
|
|
|
|
|
|
|
|
if (hocDisplayNames !== null) {
|
|
|
|
|
hocDisplayName = hocDisplayNames[0];
|
|
|
|
|
totalBadgeCount += hocDisplayNames.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type === ElementTypeMemo) {
|
|
|
|
|
typeLabel = 'Memo';
|
|
|
|
|
totalBadgeCount++;
|
|
|
|
|
} else if (type === ElementTypeForwardRef) {
|
|
|
|
|
typeLabel = 'ForwardRef';
|
|
|
|
|
totalBadgeCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hocDisplayNames === null && typeLabel === null) {
|
2019-06-01 23:24:24 +08:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-02 09:48:24 +08:00
|
|
|
return (
|
|
|
|
|
<Fragment>
|
|
|
|
|
<div className={`${styles.Badge} ${className || ''}`}>
|
|
|
|
|
{hocDisplayName || typeLabel}
|
|
|
|
|
</div>
|
|
|
|
|
{totalBadgeCount > 1 && (
|
2019-06-03 01:02:22 +08:00
|
|
|
<div className={styles.ExtraLabel}>+{totalBadgeCount - 1}</div>
|
2019-06-02 09:48:24 +08:00
|
|
|
)}
|
|
|
|
|
</Fragment>
|
|
|
|
|
);
|
2019-06-01 23:24:24 +08:00
|
|
|
}
|