2019-08-28 01:54:01 +08:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
2019-06-01 23:24:24 +08:00
|
|
|
|
2020-02-22 11:45:20 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
|
import {Fragment} from 'react';
|
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,
|
2020-05-16 01:37:34 +08:00
|
|
|
children: React$Node,
|
2019-06-01 23:24:24 +08:00
|
|
|
|};
|
|
|
|
|
|
2020-05-16 01:37:34 +08:00
|
|
|
export default function Badge({
|
|
|
|
|
className,
|
|
|
|
|
hocDisplayNames,
|
|
|
|
|
type,
|
|
|
|
|
children,
|
|
|
|
|
}: Props) {
|
2019-06-02 09:48:24 +08:00
|
|
|
let totalBadgeCount = 0;
|
|
|
|
|
|
|
|
|
|
if (hocDisplayNames !== null) {
|
|
|
|
|
totalBadgeCount += hocDisplayNames.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Fragment>
|
2020-05-16 01:37:34 +08:00
|
|
|
<div className={`${styles.Badge} ${className || ''}`}>{children}</div>
|
2019-06-02 09:48:24 +08:00
|
|
|
{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
|
|
|
}
|