From 2a3f792f9e7dbba618b90bbf67654b8b6416e920 Mon Sep 17 00:00:00 2001 From: Elizabeth Stranack Date: Thu, 20 Jan 2022 14:01:39 -0800 Subject: [PATCH] Updating Commit Changes Signed-off-by: Elizabeth Stranack --- packages/core-components/api-report.md | 23 +++++----- .../src/components/ProgressBars/Gauge.tsx | 45 ++++++++++++++----- .../ProgressBars/GaugeCard.stories.tsx | 42 ++++++++++------- .../src/components/ProgressBars/GaugeCard.tsx | 12 ++--- packages/core-components/src/hooks/index.ts | 1 - .../core-components/src/hooks/useHover.ts | 41 ----------------- .../src/layout/InfoCard/InfoCard.tsx | 22 ++------- 7 files changed, 80 insertions(+), 106 deletions(-) delete mode 100644 packages/core-components/src/hooks/useHover.ts diff --git a/packages/core-components/api-report.md b/packages/core-components/api-report.md index efdbddb979..3743c1d16d 100644 --- a/packages/core-components/api-report.md +++ b/packages/core-components/api-report.md @@ -37,7 +37,6 @@ import { default as React_2 } from 'react'; import * as React_3 from 'react'; import { ReactElement } from 'react'; import { ReactNode } from 'react'; -import { RefObject } from 'react'; import { SessionApi } from '@backstage/core-plugin-api'; import { SignInPageProps } from '@backstage/core-plugin-api'; import { SparklinesLineProps } from 'react-sparklines'; @@ -384,7 +383,12 @@ export function GaugeCard(props: Props_10): JSX.Element; export type GaugeCardClassKey = 'root'; // @public (undocumented) -export type GaugeClassKey = 'root' | 'overlay' | 'circle' | 'colorUnknown'; +export type GaugeClassKey = + | 'root' + | 'overlay' + | 'description' + | 'circle' + | 'colorUnknown'; // @public (undocumented) export type GaugeProps = { @@ -393,7 +397,7 @@ export type GaugeProps = { inverse?: boolean; unit?: string; max?: number; - hoverMessage?: ReactNode; + description?: ReactNode; getColor?: GaugePropsGetColor; }; @@ -924,6 +928,7 @@ export const SidebarDivider: React_2.ComponentType< | 'contentEditable' | 'inputMode' | 'tabIndex' + | 'onError' | 'defaultChecked' | 'defaultValue' | 'suppressContentEditableWarning' @@ -1031,7 +1036,6 @@ export const SidebarDivider: React_2.ComponentType< | 'onInvalidCapture' | 'onLoad' | 'onLoadCapture' - | 'onError' | 'onErrorCapture' | 'onKeyDown' | 'onKeyDownCapture' @@ -1286,6 +1290,7 @@ export const SidebarScrollWrapper: React_2.ComponentType< | 'contentEditable' | 'inputMode' | 'tabIndex' + | 'onError' | 'defaultChecked' | 'defaultValue' | 'suppressContentEditableWarning' @@ -1393,7 +1398,6 @@ export const SidebarScrollWrapper: React_2.ComponentType< | 'onInvalidCapture' | 'onLoad' | 'onLoadCapture' - | 'onError' | 'onErrorCapture' | 'onKeyDown' | 'onKeyDownCapture' @@ -1561,6 +1565,7 @@ export const SidebarSpace: React_2.ComponentType< | 'contentEditable' | 'inputMode' | 'tabIndex' + | 'onError' | 'defaultChecked' | 'defaultValue' | 'suppressContentEditableWarning' @@ -1668,7 +1673,6 @@ export const SidebarSpace: React_2.ComponentType< | 'onInvalidCapture' | 'onLoad' | 'onLoadCapture' - | 'onError' | 'onErrorCapture' | 'onKeyDown' | 'onKeyDownCapture' @@ -1835,6 +1839,7 @@ export const SidebarSpacer: React_2.ComponentType< | 'contentEditable' | 'inputMode' | 'tabIndex' + | 'onError' | 'defaultChecked' | 'defaultValue' | 'suppressContentEditableWarning' @@ -1942,7 +1947,6 @@ export const SidebarSpacer: React_2.ComponentType< | 'onInvalidCapture' | 'onLoad' | 'onLoadCapture' - | 'onError' | 'onErrorCapture' | 'onKeyDown' | 'onKeyDownCapture' @@ -2411,11 +2415,6 @@ export function useContent(): { contentRef: React_2.MutableRefObject | undefined; }; -// Warning: (ae-missing-release-tag) "useHover" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const useHover: (ref: RefObject) => boolean; - // Warning: (ae-forgotten-export) The symbol "SetQueryParams" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "useQueryParamState" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // diff --git a/packages/core-components/src/components/ProgressBars/Gauge.tsx b/packages/core-components/src/components/ProgressBars/Gauge.tsx index a2f725ecf0..f71756f946 100644 --- a/packages/core-components/src/components/ProgressBars/Gauge.tsx +++ b/packages/core-components/src/components/ProgressBars/Gauge.tsx @@ -17,11 +17,15 @@ import { BackstagePalette, BackstageTheme } from '@backstage/theme'; import { makeStyles, useTheme } from '@material-ui/core/styles'; import { Circle } from 'rc-progress'; -import { useHover } from '../../hooks'; -import React, { ReactNode, RefObject, useRef } from 'react'; +import React, { ReactNode, useEffect, useRef, useState } from 'react'; /** @public */ -export type GaugeClassKey = 'root' | 'overlay' | 'circle' | 'colorUnknown'; +export type GaugeClassKey = + | 'root' + | 'overlay' + | 'description' + | 'circle' + | 'colorUnknown'; const useStyles = makeStyles( theme => ({ @@ -38,8 +42,8 @@ const useStyles = makeStyles( fontWeight: 'bold', color: theme.palette.textContrast, }, - hoveringMessage: { - fontSize: 13, + description: { + fontSize: '100%', top: '50%', left: '50%', transform: 'translate(-55%, -50%)', @@ -63,7 +67,7 @@ export type GaugeProps = { inverse?: boolean; unit?: string; max?: number; - hoverMessage?: ReactNode; + description?: ReactNode; getColor?: GaugePropsGetColor; }; @@ -115,12 +119,11 @@ export const getProgressColor: GaugePropsGetColor = ({ */ export function Gauge(props: GaugeProps) { - const hoverRef = useRef() as RefObject; - const isHovering = useHover(hoverRef); + const hoverRef = useRef(null); const { getColor = getProgressColor } = props; const classes = useStyles(props); const { palette } = useTheme(); - const { value, fractional, inverse, unit, max, hoverMessage } = { + const { value, fractional, inverse, unit, max, description } = { ...defaultGaugeProps, ...props, }; @@ -128,6 +131,26 @@ export function Gauge(props: GaugeProps) { const asPercentage = fractional ? Math.round(value * max) : value; const asActual = max !== 100 ? Math.round(value) : asPercentage; + const [isHovering, setValue] = useState(false); + const handleMouseOver = () => setValue(true); + const handleMouseOut = () => setValue(false); + + useEffect(() => { + const node = hoverRef.current; + if (node) { + node.addEventListener('mouseenter', handleMouseOver); + node.addEventListener('mouseleave', handleMouseOut); + + return () => { + node.removeEventListener('mouseenter', handleMouseOver); + node.removeEventListener('mouseleave', handleMouseOut); + }; + } + return () => { + setValue(false); + }; + }); + return (
- {hoverMessage && isHovering ? ( -
{hoverMessage}
+ {description && isHovering ? ( +
{description}
) : (
{isNaN(value) ? 'N/A' : `${asActual}${unit}`} diff --git a/packages/core-components/src/components/ProgressBars/GaugeCard.stories.tsx b/packages/core-components/src/components/ProgressBars/GaugeCard.stories.tsx index 5ce96310b1..08c7813643 100644 --- a/packages/core-components/src/components/ProgressBars/GaugeCard.stories.tsx +++ b/packages/core-components/src/components/ProgressBars/GaugeCard.stories.tsx @@ -18,6 +18,8 @@ import React, { PropsWithChildren } from 'react'; import { GaugeCard } from './GaugeCard'; import Grid from '@material-ui/core/Grid'; import { MemoryRouter } from 'react-router'; +import Tooltip from '@material-ui/core/Tooltip'; +import Info from '@material-ui/icons/Info'; const linkInfo = { title: 'Go to XYZ Location', link: '#' }; @@ -126,7 +128,11 @@ export const InfoMessage = () => ( title="Progress" subheader="With a subheader" progress={0.3} - iconInfoMessage="Info Message" + icon={ + + + + } /> @@ -134,7 +140,11 @@ export const InfoMessage = () => ( title="Progress" subheader="With a subheader" progress={0.57} - iconInfoMessage="Info Message" + icon={ + + + + } /> @@ -142,7 +152,11 @@ export const InfoMessage = () => ( title="Progress" subheader="With a subheader" progress={0.89} - iconInfoMessage="Info Message" + icon={ + + + + } /> @@ -151,7 +165,11 @@ export const InfoMessage = () => ( subheader="With a subheader" inverse progress={0.2} - iconInfoMessage="Info Message" + icon={ + + + + } /> @@ -160,28 +178,20 @@ export const InfoMessage = () => ( export const HoverMessage = () => ( - + - + - + diff --git a/packages/core-components/src/components/ProgressBars/GaugeCard.tsx b/packages/core-components/src/components/ProgressBars/GaugeCard.tsx index 745c37d480..1114890523 100644 --- a/packages/core-components/src/components/ProgressBars/GaugeCard.tsx +++ b/packages/core-components/src/components/ProgressBars/GaugeCard.tsx @@ -26,8 +26,8 @@ type Props = { variant?: InfoCardVariants; /** Progress in % specified as decimal, e.g. "0.23" */ progress: number; - hoverMessage?: ReactNode; - iconInfoMessage?: string; + description?: ReactNode; + icon?: ReactNode; inverse?: boolean; deepLink?: BottomLinkProps; getColor?: GaugePropsGetColor; @@ -60,15 +60,15 @@ export function GaugeCard(props: Props) { progress, inverse, deepLink, - hoverMessage, - iconInfoMessage, + description, + icon, variant, getColor, } = props; const gaugeProps = { inverse, - hoverMessage, + description, getColor, value: progress, }; @@ -80,7 +80,7 @@ export function GaugeCard(props: Props) { subheader={subheader} deepLink={deepLink} variant={variant} - iconInfoMessage={iconInfoMessage} + icon={icon} > diff --git a/packages/core-components/src/hooks/index.ts b/packages/core-components/src/hooks/index.ts index afaf68e7d9..07e585bf27 100644 --- a/packages/core-components/src/hooks/index.ts +++ b/packages/core-components/src/hooks/index.ts @@ -16,7 +16,6 @@ export { useQueryParamState } from './useQueryParamState'; export { useSupportConfig } from './useSupportConfig'; -export { useHover } from './useHover'; export type { SupportConfig, SupportItem, diff --git a/packages/core-components/src/hooks/useHover.ts b/packages/core-components/src/hooks/useHover.ts deleted file mode 100644 index 4c5602c77c..0000000000 --- a/packages/core-components/src/hooks/useHover.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2022 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { useEffect, RefObject, useState } from 'react'; - -export const useHover = (ref: RefObject) => { - const [value, setValue] = useState(false); - - const handleMouseOver = () => setValue(true); - const handleMouseOut = () => setValue(false); - - useEffect(() => { - const node = ref.current as any; - if (node) { - node.addEventListener('mouseenter', handleMouseOver) as any; - node.addEventListener('mouseleave', handleMouseOut) as any; - - return () => { - node.removeEventListener('mouseenter', handleMouseOver); - node.removeEventListener('mouseleave', handleMouseOut); - }; - } - return () => { - setValue(false); - }; - }, [ref]); - - return value; -}; diff --git a/packages/core-components/src/layout/InfoCard/InfoCard.tsx b/packages/core-components/src/layout/InfoCard/InfoCard.tsx index 70ffd2e0cd..5c52e28543 100644 --- a/packages/core-components/src/layout/InfoCard/InfoCard.tsx +++ b/packages/core-components/src/layout/InfoCard/InfoCard.tsx @@ -24,8 +24,6 @@ import classNames from 'classnames'; import React, { ReactNode } from 'react'; import { BottomLink, BottomLinkProps } from '../BottomLink'; import { ErrorBoundary, ErrorBoundaryProps } from '../ErrorBoundary'; -import Info from '@material-ui/icons/Info'; -import Tooltip from '@material-ui/core/Tooltip'; /** @public */ export type InfoCardClassKey = @@ -57,12 +55,6 @@ const useStyles = makeStyles( headerAvatar: {}, headerAction: {}, headerContent: {}, - leftIcon: { - float: 'right', - }, - tooltip: { - fontSize: 14, - }, subheader: { float: 'left', }, @@ -145,7 +137,7 @@ type Props = { children?: ReactNode; headerStyle?: object; headerProps?: CardHeaderProps; - iconInfoMessage?: ReactNode; + icon?: ReactNode; action?: ReactNode; actionsClassName?: string; actions?: ReactNode; @@ -174,7 +166,7 @@ export function InfoCard(props: Props): JSX.Element { children, headerStyle, headerProps, - iconInfoMessage, + icon, action, actionsClassName, actions, @@ -211,15 +203,7 @@ export function InfoCard(props: Props): JSX.Element { return (
{subheader &&
{subheader}
} - {iconInfoMessage && ( - - - - )} + {icon && icon}
); };