Skip to content

Dashboard v2: Add SummaryButtonList and SectionHeader components #103555

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 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
102 changes: 102 additions & 0 deletions client/dashboard/components/summary-button-list/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { SummaryButton } from '@automattic/components';
import { Meta, StoryObj } from '@storybook/react';
import { Icon } from '@wordpress/components';
import { brush, home, seen } from '@wordpress/icons';
import { SummaryButtonList } from './';

const meta: Meta< typeof SummaryButtonList > = {
title: 'client/dashboard/SummaryButtonList',
component: SummaryButtonList,
tags: [ 'autodocs' ],
parameters: {
actions: { argTypesRegex: '^on.*' },
},
decorators: [
( Story ) => (
<div style={ { maxWidth: '600px', margin: '0 auto' } }>
<Story />
</div>
),
],
};

export default meta;
type Story = StoryObj< typeof SummaryButtonList >;

export const Default: Story = {
args: {
title: 'General Settings',
children: [
<SummaryButton
key="visibility"
title="Site visibility"
decoration={ <Icon icon={ seen } /> }
badges={ [ { text: 'Public', intent: 'success' } ] }
/>,
<SummaryButton
key="theme"
title="Theme"
decoration={ <Icon icon={ brush } /> }
badges={ [ { text: 'Twenty Twenty-Four' } ] }
/>,
<SummaryButton
key="home"
title="Homepage settings"
decoration={ <Icon icon={ home } /> }
badges={ [ { text: 'Latest posts' } ] }
/>,
],
},
};

export const WithDescription: Story = {
args: {
...Default.args,
description: 'Configure the basic settings for your site',
},
};

export const LowDensity: Story = {
args: {
...Default.args,
density: 'low',
},
};

export const WithDescriptionsInButtons: Story = {
args: {
title: 'General Settings',
density: 'low',
children: [
<SummaryButton
key="visibility"
title="Site visibility"
description="Control who can see your site"
decoration={ <Icon icon={ seen } /> }
badges={ [ { text: 'Public', intent: 'success' } ] }
/>,
<SummaryButton
key="theme"
title="Theme"
description="Change the look and feel of your site"
decoration={ <Icon icon={ brush } /> }
badges={ [ { text: 'Twenty Twenty-Four' } ] }
/>,
<SummaryButton
key="home"
title="Homepage settings"
description="Choose what appears on your homepage"
decoration={ <Icon icon={ home } /> }
badges={ [ { text: 'Latest posts' } ] }
/>,
],
},
};

export const Empty: Story = {
args: {
title: 'Empty Section',
description: 'This section has no buttons',
children: [],
},
};
65 changes: 65 additions & 0 deletions client/dashboard/components/summary-button-list/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
Card,
CardHeader,
__experimentalVStack as VStack,
__experimentalText as Text,
} from '@wordpress/components';
import clsx from 'clsx';
import { isValidElement, cloneElement, Children, ReactElement } from 'react';
import { SummaryButtonListProps } from './types';
import './style.scss';

/**
* The SummaryButtonList is a utility component that wraps multiple SummaryButton instances
* along with an optional section header. It provides consistent layout, spacing, and
* grouping behavior for presenting a collection of summary actions or options.
*
* This component ensures visual coherence and structural alignment when multiple
* SummaryButton elements are displayed together. It is intended for use in contexts
* where a list of summarised items or actions needs to be grouped under a shared
* label or heading.
*/
export function SummaryButtonList( {
title,
description,
density = 'medium',
children,
}: SummaryButtonListProps ) {
const isMediumDensity = density === 'medium';
// Clone children and override their density prop.
const clonedChildren = Children.map( children, ( child ) => {
if ( isValidElement( child ) ) {
return cloneElement( child as ReactElement< { density?: string } >, { density } );
}
return child;
} );
const header = (
<VStack spacing={ 4 }>
<h3 className="client-dashboard-components-summary-button-list__heading">{ title }</h3>
{ description && <Text variant="muted">{ description }</Text> }
</VStack>
);
const className = clsx(
'client-dashboard-components-summary-button-list',
`has-density-${ density }`
);
if ( isMediumDensity ) {
return (
<Card className={ className }>
<CardHeader>{ header }</CardHeader>
<VStack
spacing="1px"
className="client-dashboard-components-summary-button-list__children-container"
Copy link
Member

Choose a reason for hiding this comment

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

Those long classnames are giving me headaches 😅 Is this some remnant of abiding wpcalypso/jsx-classname-namespace? Should we keep them shorter?

>
{ clonedChildren }
</VStack>
</Card>
);
}
return (
<VStack className={ className } spacing={ 4 }>
{ header }
{ clonedChildren }
</VStack>
);
}
31 changes: 31 additions & 0 deletions client/dashboard/components/summary-button-list/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@import "@wordpress/base-styles/variables";

.client-dashboard-components-summary-button-list {

.client-dashboard-components-summary-button-list__heading {
margin: 0;
font-weight: $font-weight-medium;
}

&.has-density-low {
.client-dashboard-components-summary-button-list__heading {
font-size: $font-size-x-large;
line-height: $font-line-height-x-large;
}
}

&.has-density-medium {
.client-dashboard-components-summary-button-list__heading {
font-size: $font-size-large;
line-height: $font-line-height-large;
}

.client-dashboard-components-summary-button-list__children-container {
> *:last-child {
/* stylelint-disable-next-line scales/radii */
border-radius: 7px;
}

}
}
}
40 changes: 40 additions & 0 deletions client/dashboard/components/summary-button-list/test/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @jest-environment jsdom
*/
import '@testing-library/jest-dom';
import { SummaryButton } from '@automattic/components';
import { Density } from '@automattic/components/src/summary-button/types';
import { render, screen } from '@testing-library/react';
import * as React from 'react';
import { SummaryButtonList } from '../index';

describe( 'SummaryButtonList', () => {
it( 'renders a title and description', () => {
render(
<SummaryButtonList title="My Settings" description="Configure your settings">
<SummaryButton title="Setting One" />
</SummaryButtonList>
);
const heading = screen.getByRole( 'heading', { name: 'My Settings' } );
expect( heading ).toBeVisible();
expect( screen.getByText( 'Configure your settings' ) ).toBeVisible();
} );
it( 'passes the density prop to children', () => {
interface TestChildProps {
density?: Density;
}
const TestChild = ( props: TestChildProps ) => (
<button aria-label="Test Child" data-density={ props.density }>
Child
</button>
);
render(
<SummaryButtonList title="My Settings" density="low">
<TestChild />
</SummaryButtonList>
);
const testChild = screen.getByRole( 'button', { name: 'Test Child' } );
expect( testChild ).toBeVisible();
expect( testChild ).toHaveAttribute( 'data-density', 'low' );
} );
} );
26 changes: 26 additions & 0 deletions client/dashboard/components/summary-button-list/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ReactNode } from 'react';
import type { Density } from '@automattic/components/src/summary-button/types';

export interface SummaryButtonListProps {
/**
* The main label that identifies the section.
*/
title: string;
/**
* Optional supporting text that provides additional context or detail about the section.
*/
description?: string;
/**
* The density of the component. This affects both the container styling
* and the density of child SummaryButton components. It should be one of the `Density` values
* from the SummaryButton component ('low|medium').
* @default 'medium'
*/
density?: Density;
/**
* The child components should be either SummaryButton instances or components that
* wrap SummaryButton internally and pass the `density` prop to them. This is because
* the component will override the 'density' prop of these children to match the parent's density.
*/
children: ReactNode;
}
11 changes: 9 additions & 2 deletions client/dashboard/sites/settings-site-visibility/summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import { __ } from '@wordpress/i18n';
import { seen } from '@wordpress/icons';
import RouterLinkSummaryButton from '../../components/router-link-summary-button';
import type { Site } from '../../data/types';
import type { Density } from '@automattic/components/src/summary-button/types';

export default function SiteVisibilitySettingsSummary( { site }: { site: Site } ) {
export default function SiteVisibilitySettingsSummary( {
site,
density,
}: {
site: Site;
density?: Density;
} ) {
let badges = [];
if ( site.launch_status === 'unlaunched' || site.is_coming_soon ) {
badges = [ { text: __( 'Coming soon' ), intent: 'warning' as const } ];
Expand All @@ -18,7 +25,7 @@ export default function SiteVisibilitySettingsSummary( { site }: { site: Site }
<RouterLinkSummaryButton
to={ `/sites/${ site.slug }/settings/site-visibility` }
title={ __( 'Site visibility' ) }
density="medium"
density={ density }
decoration={ <Icon icon={ seen } /> }
badges={ badges }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { heading } from '@wordpress/icons';
import RouterLinkSummaryButton from '../../components/router-link-summary-button';
import { hasSubscriptionGiftingFeature } from './utils';
import type { Site, SiteSettings } from '../../data/types';
import type { Density } from '@automattic/components/src/summary-button/types';

export default function SubscriptionGiftingSettingsSummary( {
site,
settings,
density,
}: {
site: Site;
settings: SiteSettings;
density?: Density;
} ) {
if ( ! hasSubscriptionGiftingFeature( site ) ) {
return null;
Expand All @@ -19,7 +22,7 @@ export default function SubscriptionGiftingSettingsSummary( {
<RouterLinkSummaryButton
to={ `/sites/${ site.slug }/settings/subscription-gifting` }
title={ __( 'Accept a gift subscription' ) }
density="medium"
density={ density }
decoration={ <Icon icon={ heading } /> }
badges={
settings.wpcom_gifting_subscription
Expand Down
26 changes: 8 additions & 18 deletions client/dashboard/sites/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { useQuery } from '@tanstack/react-query';
import {
__experimentalHeading as Heading,
__experimentalVStack as VStack,
Card,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { siteQuery, siteSettingsQuery } from '../../app/queries';
import { PageHeader } from '../../components/page-header';
import PageLayout from '../../components/page-layout';
import { SummaryButtonList } from '../../components/summary-button-list';
import SiteVisibilitySettingsSummary from '../settings-site-visibility/summary';
import SubscriptionGiftingSettingsSummary from '../settings-subscription-gifting/summary';
import WordPressSettingsSummary from '../settings-wordpress/summary';
Expand All @@ -24,19 +20,13 @@ export default function SiteSettings( { siteSlug }: { siteSlug: string } ) {

return (
<PageLayout size="small" header={ <PageHeader title={ __( 'Settings' ) } /> }>
<Heading>{ __( 'General' ) }</Heading>
<Card>
<VStack>
<SiteVisibilitySettingsSummary site={ site } />
<SubscriptionGiftingSettingsSummary site={ site } settings={ settings } />
</VStack>
</Card>
<Heading>{ __( 'Server' ) }</Heading>
<Card>
<VStack>
<WordPressSettingsSummary site={ site } />
</VStack>
</Card>
<SummaryButtonList title={ __( 'General' ) }>
<SiteVisibilitySettingsSummary site={ site } />
<SubscriptionGiftingSettingsSummary site={ site } settings={ settings } />
</SummaryButtonList>
<SummaryButtonList title={ __( 'Server' ) }>
<WordPressSettingsSummary site={ site } />
</SummaryButtonList>
<SiteActions site={ site } />
<DangerZone site={ site } />
</PageLayout>
Expand Down
7 changes: 0 additions & 7 deletions packages/components/src/summary-button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@
padding: $grid-unit-15;
box-shadow: 0 2px 1px -1px $gray-100;

// TODO: this should be handled better in `SummaryButtonList` component.
// @see: https://github.com/Automattic/wp-calypso/pull/103233#issuecomment-2862541935
&:focus-visible, &:hover:not(:disabled, [aria-disabled="true"]) {
/* stylelint-disable-next-line scales/radii */
border-radius: 7px;
}

.summary-button-title {
@include body-medium;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/summary-button/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Density = 'low' | 'medium';
export type Density = 'low' | 'medium';

/**
* `badges` property of `SummaryButton` component is used to display `CoreBadge`
Expand Down