Skip to content

Stats-30 - Ensure correct logo and titles are displayed in the new header #102833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eb54b5a
Setup header section for logo and title
Nikschavan Apr 24, 2025
9fbea44
Don't override the config
Nikschavan Apr 24, 2025
d7ac13c
Merge branch 'trunk' into stats-30-ensure-sites-has-the-right-logo
Nikschavan Apr 24, 2025
aa786c3
Set CSS colors using SASS variables
Nikschavan Apr 24, 2025
4ca4ac9
Merge branch 'trunk' into stats-30-ensure-sites-has-the-right-logo
Nikschavan Apr 25, 2025
0380512
Set the font-family
Nikschavan Apr 25, 2025
d83cf73
Merge branch 'trunk' into stats-30-ensure-sites-has-the-right-logo
Nikschavan Apr 25, 2025
22c25bf
Simplify the titleElement default prop by defining it in the component
Nikschavan Apr 25, 2025
af68585
Remove duplicate class for nav header
Nikschavan Apr 25, 2025
d78644f
Remove the duplicate navigation header class
Nikschavan Apr 25, 2025
6d16e67
Merge branch 'trunk' into stats-30-ensure-sites-has-the-right-logo
Nikschavan Apr 28, 2025
70f360f
Allow setting the logo of size 24 in color
Nikschavan Apr 28, 2025
b908c59
Simplify the monochrome condition
Nikschavan Apr 28, 2025
2181bcd
Fix typo
Nikschavan Apr 28, 2025
9b3a9ad
The logo should be displayed for odyssey
Nikschavan Apr 28, 2025
0ee8be3
Make the variable name clear
Nikschavan Apr 28, 2025
9bb3316
Merge branch 'trunk' into stats-30-ensure-sites-has-the-right-logo
Nikschavan Apr 28, 2025
1c04ce2
Hide the right section from this PR
Nikschavan Apr 28, 2025
a35308c
Fix props for the JetpackLogo
Nikschavan Apr 28, 2025
388d76b
Apply padding to the nav heade rbody
Nikschavan Apr 28, 2025
f88d7f9
Match the padding on mobile
Nikschavan Apr 28, 2025
baf967d
Merge branch 'trunk' into stats-30-ensure-sites-has-the-right-logo
Nikschavan Apr 28, 2025
3ca2bc2
try
kangzj Apr 29, 2025
6985be1
Fix lint errors
Nikschavan Apr 29, 2025
2528130
use logo with new props
Nikschavan Apr 29, 2025
db51525
Simplify the monochrome condition
Nikschavan Apr 29, 2025
a9a5730
Update the function doc return statement
Nikschavan Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions client/components/jetpack-logo/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import colorStudio from '@automattic/color-studio';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import React from 'react';
import useAriaProps from 'calypso/lib/a11y/use-aria-props';

/**
Expand Down Expand Up @@ -48,7 +49,17 @@ const LogoPathSize32Monochrome = () => (
</>
);

const JetpackLogo = ( { full = false, monochrome = false, size = 32, className, aria } ) => {
/**
* JetpackLogo component renders the Jetpack logo with optional monochrome styling.
* @param {Object} props - Component properties.
* @param {boolean} [props.full] - Whether to show the full logo with text.
* @param {boolean|undefined} [props.monochrome] - If true, renders the logo in monochrome. If undefined, uses a default based on size.
* @param {number} [props.size] - The size of the logo.
* @param {string} [props.className] - Additional class names.
* @param {Object} [props.aria] - ARIA attributes.
* @returns The rendered Jetpack logo component
*/
const JetpackLogo = ( { full = false, monochrome, size = 32, className, aria } ) => {
const classes = clsx( 'jetpack-logo', className );
const ariaProps = useAriaProps( aria );

Expand All @@ -65,7 +76,9 @@ const JetpackLogo = ( { full = false, monochrome = false, size = 32, className,
);
}

if ( 24 === size ) {
// If size=24 and monochrome is true or undefined, return a monochrome logo - This is to ensure legacy behavior of the component.
// Return a non-monochrome logo if monochrome=false is explicitly passed with size 24.
if ( 24 === size && ( monochrome || monochrome === undefined ) ) {
return (
// eslint-disable-next-line wpcalypso/jsx-classname-namespace
<svg className={ classes } height="24" width="24" viewBox="0 0 24 24" { ...ariaProps }>
Expand Down
32 changes: 25 additions & 7 deletions client/components/navigation-header/navigation-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
.calypso-navigation-header {
background-color: var(--wp-components-color-background, #fff);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
width: 100%;
padding: 24px 0;

&__head {
Expand All @@ -17,12 +16,18 @@
display: flex;
align-items: center;
justify-content: space-between;
height: 32px;
padding-bottom: 24px;
}

&__left-section {
display: flex;
align-items: center;
gap: $grid-unit-20;
}

&__right-section {
display: flex;
align-items: center;
}

&__back-link {
Expand All @@ -34,7 +39,7 @@
transition: color 0.2s ease;

&:hover {
color: var(--wp-components-color-gray-900, #333);
color: var(--wp-components-color-gray-900, $gray-900);
}

svg {
Expand All @@ -43,19 +48,32 @@
}

&__title {
margin: 0;
font-size: 24px;
font-size: 20px;
font-weight: 500;
color: var(--wp-components-color-gray-900, #333);
font-family: "SF Pro Display", $sans;
color: var(--wp-components-color-gray-900, $gray-900);
display: flex;
align-items: center;
gap: 10px;
line-height: 1;
height: 32px;

@media (max-width: $break-small) {
font-size: 20px;
}
}

&__right-section {
&__title-logo {
padding: 4px;
display: flex;
align-items: center;
height: 24px;
width: 24px;

img, svg {
max-height: 100%;
width: auto;
}
}

// Add extra space when there is a classic/non classic option tab at the top on mobile that collides with cta's
Expand Down
40 changes: 32 additions & 8 deletions client/components/navigation-header/navigation-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,35 @@ interface BackLinkProps {

interface HeaderProps extends React.HTMLAttributes< HTMLElement > {
title?: string;
titleLogo?: ReactNode;
backLinkProps?: BackLinkProps;
titleElement?: ReactNode;
headElement?: ReactNode;
children?: ReactNode;
rightSection?: ReactNode;
hasScreenOptionsTab?: boolean;
titleProps?: {
title?: string;
titleLogo?: ReactNode;
};
}

/**
* Header component that can be used in various contexts
* @param props - Component props
* @param props.className - Additional CSS class name for the component
* @param props.title - Header title text
* @param props.titleProps - Header title props
* @param props.backLinkProps - Object containing back link properties (backLink URL, backLinkText, and onBackClick handler)
* @param props.titleElement - Custom element to override default title rendering
* @param props.headElement - Custom element to override default head section rendering
* @param props.children - Child elements to render in the right section
* @param props.rightSection - Child elements to render in the right section
* @param props.hasScreenOptionsTab - Indicates whether the screen options tab should be added
* @returns The rendered NavigationHeader component
*/
const NavigationHeader: React.FC< HeaderProps > = ( {
className,
title,
titleProps,
backLinkProps,
titleElement = <h1 className="calypso-navigation-header__title">{ title }</h1>,
titleElement,
headElement = backLinkProps?.url && (
<a
className="calypso-navigation-header__back-link"
Expand All @@ -50,10 +55,27 @@ const NavigationHeader: React.FC< HeaderProps > = ( {
{ backLinkProps?.text ?? translate( 'Back' ) }
</a>
),
children,
rightSection,
hasScreenOptionsTab,
...rest
} ) => {
const defaultTitleElement = (
<h1 className="calypso-navigation-header__title">
{ titleProps?.titleLogo && (
<span className="calypso-navigation-header__title-logo" aria-hidden="true">
{ titleProps.titleLogo }
</span>
) }
{ titleProps?.title && titleProps?.titleLogo ? (
<span className="calypso-navigation-header__title-text">{ titleProps?.title }</span>
) : (
titleProps?.title
) }
</h1>
);

const finalTitleElement = titleElement ?? defaultTitleElement;

return (
<header
className={ clsx( 'calypso-navigation-header', className, {
Expand All @@ -63,8 +85,10 @@ const NavigationHeader: React.FC< HeaderProps > = ( {
>
<div className="calypso-navigation-header__head">{ headElement }</div>
<div className="calypso-navigation-header__body">
<div className="calypso-navigation-header__left-section">{ titleElement }</div>
<div className="calypso-navigation-header__right-section">{ children }</div>
<div className="calypso-navigation-header__left-section">{ finalTitleElement }</div>
{ rightSection && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is introducing this rightSection a kind of YAP-ing mentioned by @kangzj in the task STATS-6 of creating the component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rightSection still takes in the whole component as to what is to be displayed in that section. IMO, the wrapper for the right section is required in the component itself, as it acts as a slot and places the content in the correct location. Let me know your thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the original component design, I feel like the children property was introduced to represent the right section here. 🤔 @kangzj What do you think?

<div className="calypso-navigation-header__right-section">{ rightSection }</div>
) }
</div>
</header>
);
Expand Down
31 changes: 31 additions & 0 deletions client/my-sites/stats/components/headers/page-header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import config from '@automattic/calypso-config';
import JetpackLogo from 'calypso/components/jetpack-logo';
import NavigationHeaderImpr from 'calypso/components/navigation-header/navigation-header';
import { STATS_PRODUCT_NAME, STATS_PRODUCT_NAME_IMPR } from '../../constants';

function PageHeader() {
const isOdysseyStats = config.isEnabled( 'is_running_in_jetpack_site' );

if ( isOdysseyStats ) {
return (
<NavigationHeaderImpr
className="stats__section-header modernized-header"
titleProps={ {
title: STATS_PRODUCT_NAME,
titleLogo: <JetpackLogo size={ 24 } monochrome={ false } />,
} }
/>
);
}

return (
<NavigationHeaderImpr
className="stats__section-header modernized-header"
titleProps={ {
title: STATS_PRODUCT_NAME_IMPR,
} }
/>
);
}

export default PageHeader;
18 changes: 12 additions & 6 deletions client/my-sites/stats/modernized-layout-styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $sidebar-appearance-break-point: $break-medium;
> * {
padding: 0 max(calc(50% - #{math.div($stats-sections-max-width, 2)}), 32px);

&:not(.navigation-header) {
&:not(.calypso-navigation-header, .navigation-header) {
@media (max-width: $break-small) {
padding-left: 0;
padding-right: 0;
Expand All @@ -50,17 +50,23 @@ $sidebar-appearance-break-point: $break-medium;
}

.navigation-header {
margin-bottom: 0;
padding-bottom: 24px;

@media (max-width: $break-small) {
padding-bottom: 24px;
}
}

.calypso-navigation-header,
.navigation-header {
margin-bottom: 0;
padding-left: max(calc(50% - #{math.div($stats-sections-max-width, 2)}), 32px);
padding-right: max(calc(50% - #{math.div($stats-sections-max-width, 2)}), 32px);
background-color: var(--studio-white);

@media (max-width: $break-small) {
// Restore padding to 16px on mobile as per the `.navigation-header` style.
padding: 16px;
// Reduce gap to the following section on mobile.
padding-bottom: 24px;
padding-top: 16px;
padding-inline: 16px;
}

@media (max-width: $break-mobile) {
Expand Down
8 changes: 2 additions & 6 deletions client/my-sites/stats/site.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import EmptyContent from 'calypso/components/empty-content';
import InlineSupportLink from 'calypso/components/inline-support-link';
import JetpackColophon from 'calypso/components/jetpack-colophon';
import NavigationHeader from 'calypso/components/navigation-header';
import NavigationHeaderImpr from 'calypso/components/navigation-header/navigation-header';
import StickyPanel from 'calypso/components/sticky-panel';
import memoizeLast from 'calypso/lib/memoize-last';
import Main from 'calypso/my-sites/stats/components/stats-main';
Expand All @@ -33,7 +32,6 @@ import {
STATS_FEATURE_PAGE_TRAFFIC,
STATS_FEATURE_INTERVAL_DROPDOWN_WEEK,
STATS_PRODUCT_NAME,
STATS_PRODUCT_NAME_IMPR,
} from 'calypso/my-sites/stats/constants';
import { getMomentSiteZone } from 'calypso/my-sites/stats/hooks/use-moment-site-zone';
import { getChartRangeParams } from 'calypso/my-sites/stats/utils';
Expand All @@ -54,6 +52,7 @@ import { isJetpackSite } from 'calypso/state/sites/selectors';
import getEnvStatsFeatureSupportChecks from 'calypso/state/sites/selectors/get-env-stats-feature-supports';
import { getModuleToggles } from 'calypso/state/stats/module-toggles/selectors';
import { getSelectedSiteId, getSelectedSiteSlug } from 'calypso/state/ui/selectors';
import PageHeader from './components/headers/page-header';
import StatsModuleAuthors from './features/modules/stats-authors';
import StatsModuleClicks from './features/modules/stats-clicks';
import StatsModuleCountries from './features/modules/stats-countries';
Expand Down Expand Up @@ -531,10 +530,7 @@ function StatsBody( { siteId, chartTab = 'views', date, context, isInternal, ...
</div>
) }
{ isStatsNavigationImprovementEnabled ? (
<NavigationHeaderImpr
className="stats__section-header modernized-header"
title={ STATS_PRODUCT_NAME_IMPR }
/>
<PageHeader />
) : (
<NavigationHeader
className="stats__section-header modernized-header"
Expand Down