main
js 50 lines 1.12 KB
Raw
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 IndexableDisplayName from './IndexableDisplayName';
14 import Tooltip from './reach-ui/tooltip';
15
16 import styles from './ForgetBadge.css';
17
18 type CommonProps = {
19 className?: string,
20 };
21
22 type PropsForIndexable = CommonProps & {
23 indexable: true,
24 elementID: number,
25 };
26
27 type PropsForNonIndexable = CommonProps & {
28 indexable: false | void,
29 elementID?: number,
30 };
31
32 type Props = PropsForIndexable | PropsForNonIndexable;
33
34 export default function ForgetBadge(props: Props): React.Node {
35 const {className = ''} = props;
36
37 const innerView = props.indexable ? (
38 <IndexableDisplayName displayName="Memo" id={props.elementID} />
39 ) : (
40 'Memo'
41 );
42
43 const title =
44 '✨ This component has been auto-memoized by the React Compiler.';
45 return (
46 <Tooltip label={title}>
47 <Badge className={`${styles.Root} ${className}`}>{innerView}</Badge>
48 </Tooltip>
49 );
50 }