diff --git a/src/devtools/views/Components/Badge.css b/src/devtools/views/Components/Badge.css index 370409aeb9..22f749cc5b 100644 --- a/src/devtools/views/Components/Badge.css +++ b/src/devtools/views/Components/Badge.css @@ -9,3 +9,9 @@ font-family: var(--font-family-monospace); font-size: var(--font-size-monospace-small); } + +.ExtraLabel { + font-family: var(--font-family-monospace); + font-size: var(--font-size-monospace-small); + color: var(--color-component-badge-count); +} diff --git a/src/devtools/views/Components/Badge.js b/src/devtools/views/Components/Badge.js index 42ec2d180d..0956f71c03 100644 --- a/src/devtools/views/Components/Badge.js +++ b/src/devtools/views/Components/Badge.js @@ -1,17 +1,47 @@ // @flow -import React from 'react'; +import React, { Fragment } from 'react'; +import { ElementTypeMemo, ElementTypeForwardRef } from 'src/types'; import styles from './Badge.css'; +import type { ElementType } from 'src/types'; + type Props = {| - children: string | null, className?: string, + hocDisplayNames: Array | null, + type: ElementType, |}; -export default function Badge({ children, className }: Props) { - if (children === null) { +export default function Badge({ className, hocDisplayNames, type }: Props) { + 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) { return null; } - return
{children}
; + return ( + +
+ {hocDisplayName || typeLabel} +
+ {totalBadgeCount > 1 && ( +
+{totalBadgeCount}
+ )} +
+ ); } diff --git a/src/devtools/views/Components/Element.css b/src/devtools/views/Components/Element.css index 1c6bc2376f..dd4512be9a 100644 --- a/src/devtools/views/Components/Element.css +++ b/src/devtools/views/Components/Element.css @@ -37,6 +37,7 @@ --color-component-badge-background: var( --color-component-badge-background-inverted ); + --color-component-badge-count: var(--color-component-badge-count-inverted); --color-jsx-arrow-brackets: var(--color-jsx-arrow-brackets-inverted); --color-attribute-name: var(--color-attribute-name-inverted); --color-attribute-value: var(--color-attribute-value-inverted); diff --git a/src/devtools/views/Components/Element.js b/src/devtools/views/Components/Element.js index d0afe8d45c..c07392fb6e 100644 --- a/src/devtools/views/Components/Element.js +++ b/src/devtools/views/Components/Element.js @@ -7,7 +7,6 @@ import React, { useMemo, useState, } from 'react'; -import { ElementTypeMemo, ElementTypeForwardRef } from 'src/types'; import Store from 'src/devtools/store'; import Badge from './Badge'; import ButtonIcon from '../ButtonIcon'; @@ -89,16 +88,6 @@ export default function ElementView({ data, index, style }: Props) { type, } = ((element: any): Element); - // TODO Maybe factor this into a shared util method? - let badge = null; - if (hocDisplayNames !== null) { - badge = hocDisplayNames.length === 1 ? hocDisplayNames[0] : '…'; - } else if (type === ElementTypeMemo) { - badge = 'Memo'; - } else if (type === ElementTypeForwardRef) { - badge = 'ForwardRef'; - } - let className = styles.Element; if (isSelected) { className = treeFocused @@ -139,7 +128,11 @@ export default function ElementView({ data, index, style }: Props) { )} > - {badge} + ); diff --git a/src/devtools/views/Components/HocBadges.css b/src/devtools/views/Components/HocBadges.css index fb1944d8ef..fd44b6227c 100644 --- a/src/devtools/views/Components/HocBadges.css +++ b/src/devtools/views/Components/HocBadges.css @@ -7,3 +7,15 @@ ); user-select: none; } + +.Badge { + display: inline-block; + background-color: var(--color-component-badge-background); + color: var(--color-text); + padding: 0.125rem 0.25rem; + line-height: normal; + border-radius: 0.125rem; + margin-right: 0.25rem; + font-family: var(--font-family-monospace); + font-size: var(--font-size-monospace-small); +} diff --git a/src/devtools/views/Components/HocBadges.js b/src/devtools/views/Components/HocBadges.js index c9e7daff98..5e21f8e27c 100644 --- a/src/devtools/views/Components/HocBadges.js +++ b/src/devtools/views/Components/HocBadges.js @@ -27,10 +27,12 @@ export default function HocBadges({ element }: Props) { return (
- {typeBadge} + {typeBadge !== null &&
{typeBadge}
} {hocDisplayNames !== null && hocDisplayNames.map(hocDisplayName => ( - {hocDisplayName} +
+ {hocDisplayName} +
))}
); diff --git a/src/devtools/views/Components/OwnersStack.css b/src/devtools/views/Components/OwnersStack.css index 8e6fc95c9f..5fed9e61d4 100644 --- a/src/devtools/views/Components/OwnersStack.css +++ b/src/devtools/views/Components/OwnersStack.css @@ -101,4 +101,4 @@ .Badge { margin-left: 0.25rem; -} \ No newline at end of file +} diff --git a/src/devtools/views/Components/OwnersStack.js b/src/devtools/views/Components/OwnersStack.js index f47c93c2cb..90195bb955 100644 --- a/src/devtools/views/Components/OwnersStack.js +++ b/src/devtools/views/Components/OwnersStack.js @@ -18,7 +18,6 @@ import { OwnersListContext } from './OwnersListContext'; import { TreeDispatcherContext, TreeStateContext } from './TreeContext'; import { useIsOverflowing } from '../hooks'; import { StoreContext } from '../context'; -import { ElementTypeMemo, ElementTypeForwardRef } from 'src/types'; import type { Owner } from './types'; @@ -248,16 +247,6 @@ function ElementView({ isSelected, owner, selectOwner }: ElementViewProps) { } }, [isInStore, selectOwner, owner]); - // TODO Maybe factor this into a shared util method? - let badge = null; - if (hocDisplayNames !== null) { - badge = hocDisplayNames.length === 1 ? hocDisplayNames[0] : '…'; - } else if (type === ElementTypeMemo) { - badge = 'Memo'; - } else if (type === ElementTypeForwardRef) { - badge = 'ForwardRef'; - } - return ( {displayName} - {badge} + ); } diff --git a/src/devtools/views/Components/SelectedElement.js b/src/devtools/views/Components/SelectedElement.js index a819ecbb02..e4250fbe03 100644 --- a/src/devtools/views/Components/SelectedElement.js +++ b/src/devtools/views/Components/SelectedElement.js @@ -350,15 +350,6 @@ function OwnerView({ [dispatch, id] ); - let badge = null; - if (hocDisplayNames !== null) { - badge = hocDisplayNames.length === 1 ? hocDisplayNames[0] : '…'; - } else if (type === ElementTypeMemo) { - badge = 'Memo'; - } else if (type === ElementTypeForwardRef) { - badge = 'ForwardRef'; - } - return ( ); } diff --git a/src/devtools/views/Settings/SettingsContext.js b/src/devtools/views/Settings/SettingsContext.js index e4af216522..99f552d67f 100644 --- a/src/devtools/views/Settings/SettingsContext.js +++ b/src/devtools/views/Settings/SettingsContext.js @@ -259,6 +259,12 @@ function updateThemeVariables( 'color-component-badge-background-inverted', documentElements ); + updateStyleHelper(theme, 'color-component-badge-count', documentElements); + updateStyleHelper( + theme, + 'color-component-badge-count-inverted', + documentElements + ); updateStyleHelper(theme, 'color-dim', documentElements); updateStyleHelper(theme, 'color-dimmer', documentElements); updateStyleHelper(theme, 'color-dimmest', documentElements); diff --git a/src/devtools/views/root.css b/src/devtools/views/root.css index f6a187185b..cd9c3ce9eb 100644 --- a/src/devtools/views/root.css +++ b/src/devtools/views/root.css @@ -40,6 +40,8 @@ --light-color-component-name-inverted: #ffffff; --light-color-component-badge-background: rgba(0, 0, 0, 0.15); --light-color-component-badge-background-inverted: rgba(255, 255, 255, 0.25); + --light-color-component-badge-count: #777d88; + --light-color-component-badge-count-inverted: rgba(255, 255, 255, 0.7); --light-color-dim: #777d88; --light-color-dimmer: #cfd1d5; --light-color-dimmest: #eff0f1; @@ -98,9 +100,11 @@ --dark-color-commit-gradient-9: #febc38; --dark-color-commit-gradient-text: #000000; --dark-color-component-name: #61dafb; - --dark-color-component-name-inverted: ##282828; + --dark-color-component-name-inverted: #282828; --dark-color-component-badge-background: rgba(255, 255, 255, 0.25); --dark-color-component-badge-background-inverted: rgba(0, 0, 0, 0.25); + --dark-color-component-badge-count: #8f949d; + --dark-color-component-badge-count-inverted: rgba(255, 255, 255, 0.7); --dark-color-dim: #8f949d; --dark-color-dimmer: #777d88; --dark-color-dimmest: #4f5766;