| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import * as React from 'react'; |
| 11 | |
| 12 | import Badge from './Badge'; |
| 13 | import ForgetBadge from './ForgetBadge'; |
| 14 | import IndexableDisplayName from './IndexableDisplayName'; |
| 15 | |
| 16 | import styles from './IndexableElementBadges.css'; |
| 17 | |
| 18 | type Props = { |
| 19 | hocDisplayNames: Array<string> | null, |
| 20 | compiledWithForget: boolean, |
| 21 | elementID: number, |
| 22 | className?: string, |
| 23 | }; |
| 24 | |
| 25 | export default function IndexableElementBadges({ |
| 26 | compiledWithForget, |
| 27 | hocDisplayNames, |
| 28 | elementID, |
| 29 | className = '', |
| 30 | }: Props): React.Node { |
| 31 | if ( |
| 32 | !compiledWithForget && |
| 33 | (hocDisplayNames == null || hocDisplayNames.length === 0) |
| 34 | ) { |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | return ( |
| 39 | <div className={`${styles.Root} ${className}`}> |
| 40 | {compiledWithForget && ( |
| 41 | <ForgetBadge indexable={true} elementID={elementID} /> |
| 42 | )} |
| 43 | |
| 44 | {hocDisplayNames != null && hocDisplayNames.length > 0 && ( |
| 45 | <Badge> |
| 46 | <IndexableDisplayName |
| 47 | displayName={hocDisplayNames[0]} |
| 48 | id={elementID} |
| 49 | /> |
| 50 | </Badge> |
| 51 | )} |
| 52 | |
| 53 | {hocDisplayNames != null && hocDisplayNames.length > 1 && ( |
| 54 | <div className={styles.ExtraLabel}>+{hocDisplayNames.length - 1}</div> |
| 55 | )} |
| 56 | </div> |
| 57 | ); |
| 58 | } |