diff --git a/.changeset/selfish-walls-visit.md b/.changeset/selfish-walls-visit.md new file mode 100644 index 0000000000..8748b3717e --- /dev/null +++ b/.changeset/selfish-walls-visit.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-components': patch +--- + +Add a fullHeightFixedContent variant of the GaugeCard, and a small size version. Fixed content will vertically align the gauge in the cards, even when the card titles span across multiple lines. diff --git a/packages/core-components/api-report.md b/packages/core-components/api-report.md index 7fd706db43..1e5c1b892f 100644 --- a/packages/core-components/api-report.md +++ b/packages/core-components/api-report.md @@ -448,6 +448,7 @@ export type GaugeProps = { inverse?: boolean; unit?: string; max?: number; + size?: 'normal' | 'small'; description?: ReactNode; getColor?: GaugePropsGetColor; }; @@ -609,7 +610,11 @@ export type InfoCardClassKey = | 'headerContent'; // @public (undocumented) -export type InfoCardVariants = 'flex' | 'fullHeight' | 'gridItem'; +export type InfoCardVariants = + | 'flex' + | 'fullHeight' + | 'fullHeightFixedContent' + | 'gridItem'; // Warning: (ae-forgotten-export) The symbol "ItemCardProps" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "ItemCard" is part of the package's API, 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 088e369e62..87d2bf4f58 100644 --- a/packages/core-components/src/components/ProgressBars/Gauge.tsx +++ b/packages/core-components/src/components/ProgressBars/Gauge.tsx @@ -19,6 +19,7 @@ import { makeStyles, useTheme } from '@material-ui/core/styles'; import { Circle } from 'rc-progress'; import React, { ReactNode, useEffect, useState } from 'react'; import Box from '@material-ui/core/Box'; +import classNames from 'classnames'; /** @public */ export type GaugeClassKey = @@ -43,6 +44,9 @@ const useStyles = makeStyles( fontWeight: theme.typography.fontWeightBold, color: theme.palette.textContrast, }, + overlaySmall: { + fontSize: theme.typography.pxToRem(25), + }, description: { fontSize: '100%', top: '50%', @@ -68,6 +72,7 @@ export type GaugeProps = { inverse?: boolean; unit?: string; max?: number; + size?: 'normal' | 'small'; description?: ReactNode; getColor?: GaugePropsGetColor; }; @@ -121,7 +126,7 @@ export const getProgressColor: GaugePropsGetColor = ({ export function Gauge(props: GaugeProps) { const [hoverRef, setHoverRef] = useState(null); - const { getColor = getProgressColor } = props; + const { getColor = getProgressColor, size = 'normal' } = props; const classes = useStyles(props); const { palette } = useTheme(); const { value, fractional, inverse, unit, max, description } = { @@ -165,7 +170,12 @@ export function Gauge(props: GaugeProps) { {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 a0b6faea60..21d023999e 100644 --- a/packages/core-components/src/components/ProgressBars/GaugeCard.stories.tsx +++ b/packages/core-components/src/components/ProgressBars/GaugeCard.stories.tsx @@ -175,6 +175,82 @@ export const InfoMessage = () => ( ); +export const AlignedBottom = () => ( + + + + + + + + + + + + + + +); + +export const Small = () => ( + + + + + + + + + + + + + + +); + export const HoverMessage = () => ( diff --git a/packages/core-components/src/components/ProgressBars/GaugeCard.tsx b/packages/core-components/src/components/ProgressBars/GaugeCard.tsx index 3442395380..bbb870141b 100644 --- a/packages/core-components/src/components/ProgressBars/GaugeCard.tsx +++ b/packages/core-components/src/components/ProgressBars/GaugeCard.tsx @@ -27,6 +27,7 @@ type Props = { variant?: InfoCardVariants; /** Progress in % specified as decimal, e.g. "0.23" */ progress: number; + size?: 'normal' | 'small'; description?: ReactNode; icon?: ReactNode; inverse?: boolean; @@ -43,6 +44,10 @@ const useStyles = makeStyles( height: '100%', width: 250, }, + rootSmall: { + height: '100%', + width: 160, + }, }, { name: 'BackstageGaugeCard' }, ); @@ -64,6 +69,7 @@ export function GaugeCard(props: Props) { description, icon, variant, + size = 'normal', getColor, } = props; @@ -75,15 +81,22 @@ export function GaugeCard(props: Props) { }; return ( - + - + ); diff --git a/packages/core-components/src/layout/InfoCard/InfoCard.tsx b/packages/core-components/src/layout/InfoCard/InfoCard.tsx index c80e71b609..9fd72e50b6 100644 --- a/packages/core-components/src/layout/InfoCard/InfoCard.tsx +++ b/packages/core-components/src/layout/InfoCard/InfoCard.tsx @@ -46,6 +46,10 @@ const useStyles = makeStyles( header: { padding: theme.spacing(2, 2, 2, 2.5), }, + headerFixedContent: { + flexGrow: 1, + alignItems: 'flex-start', + }, headerTitle: { fontWeight: theme.typography.fontWeightBold, }, @@ -87,6 +91,11 @@ const VARIANT_STYLES = { flexDirection: 'column', height: '100%', }, + fullHeightFixedContent: { + display: 'flex', + flexDirection: 'column', + height: '100%', + }, gridItem: { display: 'flex', flexDirection: 'column', @@ -102,6 +111,9 @@ const VARIANT_STYLES = { fullHeight: { flex: 1, }, + fullHeightFixedContent: { + flex: '0 1 0%', + }, gridItem: { flex: 1, }, @@ -109,7 +121,11 @@ const VARIANT_STYLES = { }; /** @public */ -export type InfoCardVariants = 'flex' | 'fullHeight' | 'gridItem'; +export type InfoCardVariants = + | 'flex' + | 'fullHeight' + | 'fullHeightFixedContent' + | 'gridItem'; /** * InfoCard is used to display a paper-styled block on the screen, similar to a panel. @@ -228,7 +244,12 @@ export function InfoCard(props: Props): JSX.Element { {title && (