diff --git a/projects/packages/premium-analytics/AGENTS.md b/projects/packages/premium-analytics/AGENTS.md index cad7ff3635a2..3e4d7f351c0f 100644 --- a/projects/packages/premium-analytics/AGENTS.md +++ b/projects/packages/premium-analytics/AGENTS.md @@ -660,7 +660,7 @@ area. Notes: - `isFetching` draws nothing — it only marks the widget `aria-busy`. A revalidation of unchanged params leaves the right numbers on screen, and blanking them reports a refresh nobody asked for (WOOA7S-1934). Nothing unmounts, so children keep their own state and keyboard focus. -- Every other branch *does* unmount the children, and a drill-down reaches the skeleton by +- Every other branch _does_ unmount the children, and a drill-down reaches the skeleton by definition (it changes the params). `` catches the focus that would otherwise fall to `` and parks it on its own root, so the next Tab continues from the widget instead of the top of the page. Widgets need do nothing for this, but drill-down rows must be real @@ -759,10 +759,10 @@ wire a handler in `routeStatsReport()` inside `register-report-mocks.ts`. See add a second in-widget ` }>` title for framed Stats widgets. - View count format: `dataFormat={ { type: 'number', options: { useMultipliers: true, decimals: 0 } } }` -- Leaderboard row height: custom labels should produce a stable 36px row height. For the common - `` label case, `padding: var(--wpds-dimension-padding-sm)` is enough when the text - line-height plus vertical padding yields 36px. Use `min-height: 36px` when the label content - or typography does not naturally produce that height. +- Leaderboard rows: prefer `LeaderboardRow` / `buildLeaderboardRow` / `LeaderboardPostLabel` over + a hand-written label — they carry the shared row box, and a copy drifts from it. A label that + must be custom should match `.row` in `chart-leaderboard/leaderboard-label.module.scss`; + several widgets predate that and have not been migrated yet. - Loading / error / empty state: render through `` (see "Loading / error / empty state" above), not `LeaderboardChart`'s `emptyStateText` or a hand-rolled `data.length === 0` branch. Empty uses a neutral glyph distinct from the error icon. diff --git a/projects/packages/premium-analytics/changelog/wooa7s-1989-leaderboard-row-consolidation b/projects/packages/premium-analytics/changelog/wooa7s-1989-leaderboard-row-consolidation new file mode 100644 index 000000000000..7c2921355666 --- /dev/null +++ b/projects/packages/premium-analytics/changelog/wooa7s-1989-leaderboard-row-consolidation @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Leaderboards: Give shared rows one row height, bar radius, and link hover. diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/README.md b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/README.md index 05c72ecce185..4094c0b2151b 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/README.md +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/README.md @@ -168,22 +168,8 @@ It applies the shared precedence: drill-down for rows with children, external li childless rows, and static content otherwise. Use `LeaderboardLabel` directly for media plus truncating text outside chart rows, such as a -DataViews table cell. It deliberately does not add the chart row's 36px minimum block size. - -### Row layout - -`LeaderboardRow` takes two optional layout props. `LeaderboardPostLabel` accepts both and -forwards them. - -| Prop | Default | Description | -| ----------- | ----------- | ----------------------------------------------------------------------------------------------------------- | -| `variant` | `'compact'` | `'compact'` is the standard 36px row. `'overlay'` drops that floor and takes its height from block padding. | -| `className` | - | Extra class on the row, for per-widget spacing. | - -Pick `variant` to match the sibling rows in the same widget, not the chart's `withOverlayLabel` -prop. That prop only tints the bar fill; it sets no row height. Use `'overlay'` where the -neighbouring rows also take their height from block padding, and `'compact'` where they come -from `buildLeaderboardRow`. +DataViews table cell. It deliberately does not add the chart row's 36px minimum block size or its +inline padding. ## Props diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/index.ts b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/index.ts index e49713c292ff..f93ecbe7a572 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/index.ts +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/index.ts @@ -19,5 +19,4 @@ export type { LeaderboardRowActionOptions, LeaderboardRowChartProps, LeaderboardRowProps, - LeaderboardRowVariant, } from './leaderboard-row'; diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-label.module.scss b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-label.module.scss index cc9db3fe17bf..ca09fea316f8 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-label.module.scss +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-label.module.scss @@ -61,7 +61,7 @@ min-block-size: 36px; min-inline-size: 0; max-inline-size: 100%; - padding-inline: var(--wpds-dimension-padding-sm); + padding-inline: var(--wpds-dimension-padding-md); overflow: hidden; color: inherit; text-decoration: none; @@ -72,13 +72,11 @@ gap: var(--wpds-dimension-gap-xs); } -/* Block padding sets the bar height when the label sits on top of the bar, so - the 36px floor is dropped. Doubled with the base class to beat it on - specificity rather than on stylesheet order. */ -.overlay.row, -.overlay.rowLink { - min-block-size: 0; - padding-block: var(--wpds-dimension-padding-md); +/* The design system renders the external-link arrow as a sibling of the + label, so the colour has to go on the anchor to reach it. */ +.rowLink:hover, +.rowLink:focus { + color: var(--wpds-color-foreground-interactive-brand); } .rowLink:hover .label, diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-row.tsx b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-row.tsx index 1d2afcfa0b1b..59f237556128 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-row.tsx +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-row.tsx @@ -2,7 +2,6 @@ * External dependencies */ import { Link } from '@jetpack-premium-analytics/externals'; -import clsx from 'clsx'; /** * Internal dependencies */ @@ -34,13 +33,6 @@ export type LeaderboardRowAction = } | { kind: 'static' }; -/** - * How tall the row sits. `compact` is the standard 36px row. `overlay` suits - * leaderboards that draw the label on top of the bar, where block padding sets - * the bar height because the row has no image to size it. - */ -export type LeaderboardRowVariant = 'compact' | 'overlay'; - export type LeaderboardRowActionOptions = { /** An external destination used only when the row has no children. */ href?: string; @@ -57,10 +49,6 @@ export type LeaderboardRowProps = { media: LeaderboardRowMedia; /** The mutually exclusive action applied to this chart row. */ action: LeaderboardRowAction; - /** Row height. Defaults to `compact`. */ - variant?: LeaderboardRowVariant; - /** Extra class for the row, for per-widget spacing. */ - className?: string; }; export type LeaderboardRowChartProps = @@ -105,17 +93,7 @@ export function resolveLeaderboardRowAction( * * @return A single label element accepted by `LeaderboardEntry.label`. */ -export function LeaderboardRow( { - label, - media, - action, - variant = 'compact', - className, -}: LeaderboardRowProps ): ReactElement { - const variantClass = variant === 'overlay' ? styles.overlay : undefined; - const rowClassName = clsx( styles.row, variantClass, className ); - const linkClassName = clsx( styles.rowLink, variantClass, className ); - +export function LeaderboardRow( { label, media, action }: LeaderboardRowProps ): ReactElement { // Post rows carry no media, so the row chrome goes on the anchor itself. if ( action.kind === 'postLink' ) { return ( @@ -126,9 +104,9 @@ export function LeaderboardRow( { search={ action.search } title={ label } classNames={ { - internal: linkClassName, - external: linkClassName, - plain: rowClassName, + internal: styles.rowLink, + external: styles.rowLink, + plain: styles.row, text: styles.label, } } /> @@ -142,7 +120,7 @@ export function LeaderboardRow( { if ( action.kind === 'link' ) { return ( + { content } ); diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/index.ts b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/index.ts index 6df056fe3483..a5cd54ce9bff 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/index.ts +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/index.ts @@ -54,7 +54,6 @@ export { type LeaderboardRowChartProps, type LeaderboardRowMedia, type LeaderboardRowProps, - type LeaderboardRowVariant, } from './chart-leaderboard'; export { BarChart, @@ -86,11 +85,7 @@ export { WidgetFooter, type WidgetFooterProps } from './widget-footer'; export { ReportLink, type ReportLinkProps } from './report-link'; export { PostTitleLink, POST_URL_SEARCH_PARAM, type PostTitleLinkProps } from './post-title-link'; export { PostDetailLink, type PostDetailLinkProps } from './post-detail-link'; -export { - LeaderboardPostLabel, - type LeaderboardPostLabelProps, - type LeaderboardPostLabelVariant, -} from './leaderboard-post-label'; +export { LeaderboardPostLabel, type LeaderboardPostLabelProps } from './leaderboard-post-label'; export { PostHighlightCard, PostHighlightCardSkeleton, diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/index.ts b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/index.ts index 397012593a4c..33e8184b83d2 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/index.ts +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/index.ts @@ -1,5 +1 @@ -export { - LeaderboardPostLabel, - type LeaderboardPostLabelProps, - type LeaderboardPostLabelVariant, -} from './leaderboard-post-label'; +export { LeaderboardPostLabel, type LeaderboardPostLabelProps } from './leaderboard-post-label'; diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/leaderboard-post-label.tsx b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/leaderboard-post-label.tsx index d0e685e1ccdc..b7d9c507935b 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/leaderboard-post-label.tsx +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/leaderboard-post-label.tsx @@ -2,12 +2,9 @@ * Internal dependencies */ import { useWidgetNavigationSearch } from '../../hooks/use-widget-navigation-search'; -import { LeaderboardRow, type LeaderboardRowVariant } from '../chart-leaderboard/leaderboard-row'; +import { LeaderboardRow } from '../chart-leaderboard/leaderboard-row'; import type { ReactElement } from 'react'; -/** How tall the row sits. */ -export type LeaderboardPostLabelVariant = LeaderboardRowVariant; - export type LeaderboardPostLabelProps = { /** * Post or page ID. Rows carrying one link to the internal detail route. @@ -22,14 +19,6 @@ export type LeaderboardPostLabelProps = { * Optional detail-page tab to open, e.g. `email-opens`. */ section?: string; - /** - * Row height. Defaults to `compact`. - */ - variant?: LeaderboardPostLabelVariant; - /** - * Extra class for the row, for per-widget spacing. - */ - className?: string; }; /** @@ -42,8 +31,6 @@ export function LeaderboardPostLabel( { label, link, section, - variant = 'compact', - className, }: LeaderboardPostLabelProps ): ReactElement { const search = useWidgetNavigationSearch( section ); @@ -52,8 +39,6 @@ export function LeaderboardPostLabel( { label={ label } media={ { kind: 'none' } } action={ { kind: 'postLink', id, href: link, search } } - variant={ variant } - className={ className } /> ); } diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/hooks/use-chart-theme.ts b/projects/packages/premium-analytics/packages/widgets-toolkit/src/hooks/use-chart-theme.ts index 3f250dfc8ef8..cc5da87a28f6 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/hooks/use-chart-theme.ts +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/hooks/use-chart-theme.ts @@ -70,7 +70,7 @@ export function useChartTheme(): WooChartTheme { rowGap: 4, columnGap: 4, labelSpacing: 'xs', - barBorderRadius: 'var(--wpds-border-radius-md)', + barBorderRadius: 'var(--wpds-border-radius-lg)', deltaColors: [ 'var(--wpds-color-stroke-surface-error-strong)', 'var(--wpds-color-foreground-content-neutral-weak)', diff --git a/projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts b/projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts index 04dfe3010dbd..5c55391a8111 100644 --- a/projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts +++ b/projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts @@ -51,7 +51,6 @@ export { type LeaderboardRowChartProps, type LeaderboardRowMedia, type LeaderboardRowProps, - type LeaderboardRowVariant, BarChart, BarChartSkeleton, type BarChartProps, @@ -85,7 +84,6 @@ export { type PostDetailLinkProps, LeaderboardPostLabel, type LeaderboardPostLabelProps, - type LeaderboardPostLabelVariant, PostHighlightCard, PostHighlightCardSkeleton, type PostHighlightCardMetric, diff --git a/projects/packages/premium-analytics/widgets/utm-insights/render.tsx b/projects/packages/premium-analytics/widgets/utm-insights/render.tsx index db4126cbdaf2..35fc257e10fd 100644 --- a/projects/packages/premium-analytics/widgets/utm-insights/render.tsx +++ b/projects/packages/premium-analytics/widgets/utm-insights/render.tsx @@ -137,12 +137,12 @@ function UtmInsightsInner( { utmDimension, showReportLink }: UtmInsightsInnerPro id={ postRow.postId } label={ postRow.label } link={ postRow.href } - variant="overlay" - className={ styles.itemLabelInset } /> ) : ( - { item.label } + + { item.label } + ), currentValue: item.value, diff --git a/projects/packages/premium-analytics/widgets/utm-insights/style.module.css b/projects/packages/premium-analytics/widgets/utm-insights/style.module.css index 5859a2c01fff..61d3a7f3cf76 100644 --- a/projects/packages/premium-analytics/widgets/utm-insights/style.module.css +++ b/projects/packages/premium-analytics/widgets/utm-insights/style.module.css @@ -20,22 +20,14 @@ margin-block-end: 0; } -/* The UTM value rows. Post rows use `LeaderboardPostLabel` instead and take - only the inline-end inset below. */ +/* Matches the shared leaderboard row so these sit level with the post rows, + which render through `LeaderboardPostLabel`. */ .itemLabel { display: flex; align-items: center; + min-block-size: 36px; min-inline-size: 0; - padding-block: var(--wpds-dimension-padding-md); - padding-inline-start: var(--wpds-dimension-padding-sm); - padding-inline-end: var(--wpds-dimension-padding-lg); -} - -/* Keeps post-row text short of the value column, like `.itemLabel`. Doubled to - outrank the shared row's own `padding-inline` on specificity, because the two - are single classes in different CSS modules and would tie on order. */ -.itemLabelInset.itemLabelInset { - padding-inline-end: var(--wpds-dimension-padding-lg); + padding-inline: var(--wpds-dimension-padding-md); } .itemLabelText { diff --git a/projects/plugins/jetpack/changelog/wooa7s-1989-leaderboard-row-consolidation b/projects/plugins/jetpack/changelog/wooa7s-1989-leaderboard-row-consolidation new file mode 100644 index 000000000000..d6e0fbbe7b0b --- /dev/null +++ b/projects/plugins/jetpack/changelog/wooa7s-1989-leaderboard-row-consolidation @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Premium Analytics: Give shared leaderboard rows one row height, bar radius, and link hover. diff --git a/projects/plugins/premium-analytics/changelog/wooa7s-1989-leaderboard-row-consolidation b/projects/plugins/premium-analytics/changelog/wooa7s-1989-leaderboard-row-consolidation new file mode 100644 index 000000000000..7c2921355666 --- /dev/null +++ b/projects/plugins/premium-analytics/changelog/wooa7s-1989-leaderboard-row-consolidation @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Leaderboards: Give shared rows one row height, bar radius, and link hover.