Skip to content

Commit

Permalink
highlight matched hoc name
Browse files Browse the repository at this point in the history
  • Loading branch information
bl00mber committed May 1, 2020
1 parent 3b654cd commit 6ceac4d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
5 changes: 0 additions & 5 deletions packages/react-devtools-shared/src/devtools/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
* @flow
*/

import {
ElementTypeForwardRef,
ElementTypeMemo,
} from 'react-devtools-shared/src/types';

import type {Element} from './views/Components/types';
import type Store from './store';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

import * as React from 'react';
import {Fragment} from 'react';
import {
ElementTypeMemo,
ElementTypeForwardRef,
} from 'react-devtools-shared/src/types';
import styles from './Badge.css';

import type {ElementType} from 'react-devtools-shared/src/types';
Expand All @@ -21,27 +17,24 @@ type Props = {|
className?: string,
hocDisplayNames: Array<string> | null,
type: ElementType,
children: React$Node,
|};

export default function Badge({className, hocDisplayNames, type}: Props) {
let hocDisplayName = null;
export default function Badge({
className,
hocDisplayNames,
type,
children,
}: Props) {
let totalBadgeCount = 0;
let typeLabel = null;

if (hocDisplayNames !== null) {
hocDisplayName = hocDisplayNames[0];
totalBadgeCount += hocDisplayNames.length;
}

if (hocDisplayNames === null && typeLabel === null) {
return null;
}

return (
<Fragment>
<div className={`${styles.Badge} ${className || ''}`}>
{hocDisplayName || typeLabel}
</div>
<div className={`${styles.Badge} ${className || ''}`}>{children}</div>
{totalBadgeCount > 1 && (
<div className={styles.ExtraLabel}>+{totalBadgeCount - 1}</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,17 @@ export default function ElementView({data, index, style}: Props) {
"
</Fragment>
)}
<Badge
className={styles.Badge}
hocDisplayNames={hocDisplayNames}
type={type}
/>
{hocDisplayNames !== null ? (
<Badge
className={styles.Badge}
hocDisplayNames={hocDisplayNames}
type={type}>
<DisplayName
displayName={hocDisplayNames[0]}
id={((id: any): number)}
/>
</Badge>
) : null}
</div>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ export function separateDisplayNameAndHOCs(
}
break;
case ElementTypeForwardRef:
hocDisplayNames = ['ForwardRef']
break;
hocDisplayNames = ['ForwardRef'];
break;
case ElementTypeMemo:
hocDisplayNames = ['Memo']
hocDisplayNames = ['Memo'];
break;
default:
break;
Expand Down

0 comments on commit 6ceac4d

Please sign in to comment.