Skip to content
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

Protect: Refactor AdminSectionHero #40516

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,73 @@ import {
AdminSectionHero as JetpackAdminSectionHero,
H3,
ShieldIcon,
Container,
Col,
} from '@automattic/jetpack-components';
import SeventyFiveLayout from '../seventy-five-layout';
import clsx from 'clsx';
import AdminSectionHeroNotices from './admin-section-hero-notices';
import styles from './styles.module.scss';

interface AdminSectionHeroProps {
main: React.ReactNode;
secondary?: React.ReactNode;
preserveSecondaryOnMobile?: boolean;
spacing?: number;
}

interface AdminSectionHeroComponent extends React.FC< AdminSectionHeroProps > {
Heading: React.FC< {
children: React.ReactNode;
showIcon?: boolean;
variant?: 'default' | 'success' | 'error';
outline?: boolean;
} >;
Subheading: React.FC< { children: React.ReactNode } >;
}

const AdminSectionHero: AdminSectionHeroComponent = ( {
main,
secondary,
preserveSecondaryOnMobile = true,
spacing = 7,
} ) => {
const AdminSectionHero = ( {
children,
...props
}: React.ComponentProps< typeof JetpackAdminSectionHero > ) => {
return (
<JetpackAdminSectionHero>
<JetpackAdminSectionHero { ...props }>
<AdminSectionHeroNotices />
<SeventyFiveLayout
spacing={ spacing }
gap={ 0 }
main={ main }
mainClassName={ styles[ 'header-main' ] }
secondary={ secondary }
secondaryClassName={ styles[ 'header-secondary' ] }
preserveSecondaryOnMobile={ preserveSecondaryOnMobile }
fluid={ false }
/>
<Container horizontalSpacing={ 0 }>
<Col>
<div className={ styles[ 'admin-section-hero' ] }>{ children }</div>
</Col>
</Container>
</JetpackAdminSectionHero>
);
};

AdminSectionHero.Heading = ( {
AdminSectionHero.Main = ( {
children,
variant = 'default',
showIcon = false,
className,
...props
}: {
children: React.ReactNode;
variant?: 'default' | 'success' | 'error';
showIcon?: boolean;
className?: string;
[ key: string ]: unknown;
} ) => {
return (
<div className={ clsx( styles[ 'admin-section-hero__main' ], className ) } { ...props }>
{ children }
</div>
);
};

AdminSectionHero.Aside = ( {
children,
className,
...props
}: React.ComponentProps< 'div' > & {
className?: string;
} ) => {
return (
<H3 className={ styles.heading } mt={ 2 } mb={ 2 }>
<div className={ clsx( styles[ 'admin-section-hero__aside' ], className ) } { ...props }>
{ children }
{ showIcon && (
</div>
);
};

AdminSectionHero.Heading = ( {
children,
icon,
...props
}: React.ComponentProps< typeof H3 > & {
icon?: 'default' | 'success' | 'error';
} ) => {
return (
<H3 mb={ 1 } { ...props }>
{ children }
{ !! icon && (
<ShieldIcon
height={ 38 }
variant={ variant }
variant={ icon }
outline
fill="default"
className={ styles[ 'heading-icon' ] }
Expand All @@ -72,8 +78,4 @@ AdminSectionHero.Heading = ( {
);
};

AdminSectionHero.Subheading = ( { children }: { children: React.ReactNode } ) => {
return <div className={ styles.subheading }>{ children }</div>;
};

export default AdminSectionHero;
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ export default {

export const Default = args => <AdminSectionHero { ...args } />;
Default.args = {
main: (
children: (
<>
<Status status={ 'active' } label={ 'Active' } />
<AdminSectionHero.Heading showIcon variant="success">
{ 'No threats found' }
</AdminSectionHero.Heading>
<AdminSectionHero.Subheading>
<AdminSectionHero.Main>
<Status status={ 'active' } label={ 'Active' } />
<AdminSectionHero.Heading icon="success">{ 'No threats found' }</AdminSectionHero.Heading>
<Text>{ 'Most recent results' }</Text>
</AdminSectionHero.Subheading>
</AdminSectionHero.Main>
<AdminSectionHero.Aside>
<InProgressAnimation />
</AdminSectionHero.Aside>
</>
),
secondary: <InProgressAnimation />,
};
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
.header-main {
.admin-section-hero {
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
gap: calc( var( --spacing-base ) * 6 ); // 48px

max-width: var(--max-container-width);
padding: calc( var( --spacing-base ) * 6 ) 0; // 48px 0
margin: 0 auto;

@media (min-width: 600px) {
padding: calc( var( --spacing-base ) * 7 ) 0; // 56px 0
}

@media (min-width: 600px) {
padding: calc( var( --spacing-base ) * 7 ) 0; // 56px 0
}

@media ( min-width: 1100px ) {
flex-direction: row;
align-items: center;
gap: calc( var( --spacing-base ) * 3 ); // 24px
}
}

.header-secondary {
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-end;
.admin-section-hero__main {
flex: 2;
}

.admin-section-hero__aside {
flex: 1;
flex-shrink: 0;

@media ( min-width: 1200px ) {
display: flex;
justify-content: flex-end;
}
}

.heading-icon {
margin-left: calc( var( --spacing-base ) * 1.5 ); // 12px
margin-bottom: calc( var( --spacing-base ) / 2 * -1 ); // -4px
}

.subheading {
width: fit-content;
}

.connection-error-col {
margin-top: calc( var( --spacing-base ) * 3 + 1px ); // 25px
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Text } from '@automattic/jetpack-components';
import { ShieldIcon, Text } from '@automattic/jetpack-components';
import { __ } from '@wordpress/i18n';
import { Icon, warning } from '@wordpress/icons';
import AdminSectionHero from '../admin-section-hero';
import styles from './styles.module.scss';

Expand All @@ -19,22 +18,17 @@ const ErrorAdminSectionHero: React.FC< ErrorAdminSectionHeroProps > = ( {
displayErrorMessage += ' ' + __( 'Try again in a few minutes.', 'jetpack-protect' );

return (
<AdminSectionHero
main={
<>
<AdminSectionHero.Heading>
<div className={ styles.heading }>
<Icon className={ styles.warning } icon={ warning } size={ 54 } />
{ __( 'An error occurred', 'jetpack-protect' ) }
</div>
</AdminSectionHero.Heading>
<AdminSectionHero.Subheading>
<Text>{ displayErrorMessage }</Text>
</AdminSectionHero.Subheading>
</>
}
preserveSecondaryOnMobile={ false }
/>
<AdminSectionHero>
<AdminSectionHero.Main>
<AdminSectionHero.Heading>
<div className={ styles.heading }>
{ __( 'An error occurred', 'jetpack-protect' ) }
<ShieldIcon className={ styles.warning } variant="error" height={ 38 } outline />
</div>
</AdminSectionHero.Heading>
<Text>{ displayErrorMessage }</Text>
</AdminSectionHero.Main>
</AdminSectionHero>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
}

.warning {
width: 54px;
height: 54px;
fill: var( --jp-red );
margin-left: -8px;
margin-right: var( --spacing-base ); // 8px
margin-left: calc( var( --spacing-base ) * 1.5 ); // 12px
}

.scan-navigation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AdminSectionHero from '../../components/admin-section-hero';
import useWafData from '../../hooks/use-waf-data';
import FirewallStatCards from './firewall-statcards';
import FirewallSubheading from './firewall-subheading';
import styles from './styles.module.scss';

const FirewallAdminSectionHero = () => {
const {
Expand Down Expand Up @@ -84,16 +85,22 @@ const FirewallAdminSectionHero = () => {
}, [ status ] );

return (
<AdminSectionHero
main={
<>
<Status status={ 'on' === status ? 'active' : 'inactive' } label={ statusLabel } />
<AdminSectionHero.Heading>{ heading }</AdminSectionHero.Heading>
<AdminSectionHero.Subheading>{ subheading }</AdminSectionHero.Subheading>
</>
}
secondary={ wafSupported && <FirewallStatCards /> }
/>
<AdminSectionHero>
<AdminSectionHero.Main>
<Status
status={ 'on' === status ? 'active' : 'inactive' }
label={ statusLabel }
className={ styles.status }
/>
<AdminSectionHero.Heading>{ heading }</AdminSectionHero.Heading>
<Text>{ subheading }</Text>
</AdminSectionHero.Main>
{ wafSupported && (
<AdminSectionHero.Aside>
<FirewallStatCards />
</AdminSectionHero.Aside>
) }
</AdminSectionHero>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const FirewallStatCards = () => {
);

return (
<div className={ styles[ 'stat-card-wrapper' ] }>
<div className={ styles[ 'stat-cards-wrapper' ] }>
<StatCard { ...currentDayArgs } />
<StatCard { ...thirtyDaysArgs } />
</div>
Expand Down
49 changes: 21 additions & 28 deletions projects/plugins/protect/src/js/routes/firewall/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
max-width: calc( 744px + ( var( --spacing-base ) * 6 ) ); // 744px + 48px (desired inner width + horizontal padding)
}

.status {
margin-bottom: calc( var( --spacing-base ) * 2 ); // 16px
}

.toggle-section {
display: flex;

Expand Down Expand Up @@ -145,14 +149,10 @@
align-items: center;
}

.stat-card-wrapper {
.stat-cards-wrapper {
display: flex;
margin-left: auto;
flex-wrap: wrap;

>:first-child {
margin-right: calc( var( --spacing-base ) * 3 ); // 24px
}
justify-content: flex-end;
gap: calc( var( --spacing-base ) * 3 ); // 24px

.disabled {
opacity: 0.5;
Expand All @@ -171,27 +171,6 @@
white-space: nowrap;
}

@media ( max-width: 1115px ) {
.stat-card-wrapper {
margin-top: calc( var( --spacing-base ) * 3 ); // 24px
}
}

@media ( max-width: 599px ) {
.stat-card-wrapper {
margin-top: calc( var( --spacing-base ) * 3 ); // 24px

>:first-child {
margin-right: 0;
margin-bottom: var( --spacing-base ); // 8px
}
}

.stat-card-icon {
margin-bottom: 0;
}
}

.footer-checkbox {
display: flex;
align-items: center;
Expand Down Expand Up @@ -231,7 +210,21 @@
}
}

@media ( max-width: 1200px ) {
.stat-cards-wrapper {
justify-content: flex-start;
}
}

@media ( max-width: 599px ) {
.stat-cards-wrapper {
flex-direction: column;
gap: var( --spacing-base ); // 8px
}

.stat-card-icon {
margin-bottom: 0;
}

.share-data-section {
margin-top: 0;
Expand Down
Loading
Loading