Skip to content
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
37 changes: 25 additions & 12 deletions assets/js/components/Stepper/Step.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,43 @@ import PropTypes from 'prop-types';
import Typography from '@/js/components/Typography';
import { STEP_STATUS } from './constants';

export default function Step( { children, title, stepStatus } ) {
export default function Step( { children, title, stepStatus, variant } ) {
const isActive = stepStatus === STEP_STATUS.ACTIVE;
const isRail = variant === 'rail';

const railTitleSize = isActive ? 'large' : 'medium';
const railTitleType = isActive ? 'label' : 'body';

const titleAs = isRail ? 'div' : 'h2';
const titleSize = isRail ? railTitleSize : 'medium';
const titleType = isRail ? railTitleType : 'title';

return (
<div className="googlesitekit-stepper__step-info">
<Typography
as="h2"
as={ titleAs }
className="googlesitekit-stepper__step-title"
size="medium"
type="title"
size={ titleSize }
type={ titleType }
>
{ title }
</Typography>
<div className="googlesitekit-stepper__step-content-container">
{ stepStatus === STEP_STATUS.ACTIVE && (
<div className="googlesitekit-stepper__step-content">
{ children }
</div>
) }
</div>
{ ! isRail && (
<div className="googlesitekit-stepper__step-content-container">
{ children && stepStatus === STEP_STATUS.ACTIVE && (
<div className="googlesitekit-stepper__step-content">
{ children }
</div>
) }
</div>
) }
</div>
);
}

Step.propTypes = {
children: PropTypes.node.isRequired,
children: PropTypes.node,
title: PropTypes.string.isRequired,
stepStatus: PropTypes.oneOf( Object.values( STEP_STATUS ) ),
variant: PropTypes.string,
};
10 changes: 10 additions & 0 deletions assets/js/components/Stepper/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`Stepper should render all steps as completed when activeStep is greater
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 1 of 2 (completed)."
class="googlesitekit-stepper__step-number"
title="Step 1 of 2 (completed)."
>
Expand Down Expand Up @@ -41,6 +42,7 @@ exports[`Stepper should render all steps as completed when activeStep is greater
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 2 of 2 (completed)."
class="googlesitekit-stepper__step-number"
title="Step 2 of 2 (completed)."
>
Expand Down Expand Up @@ -76,6 +78,7 @@ exports[`Stepper should render all steps as upcoming when activeStep is negative
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 1 of 2 (upcoming)."
class="googlesitekit-stepper__step-number"
title="Step 1 of 2 (upcoming)."
>
Expand Down Expand Up @@ -105,6 +108,7 @@ exports[`Stepper should render all steps as upcoming when activeStep is negative
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 2 of 2 (upcoming)."
class="googlesitekit-stepper__step-number"
title="Step 2 of 2 (upcoming)."
>
Expand Down Expand Up @@ -140,6 +144,7 @@ exports[`Stepper should render all steps as upcoming when activeStep is not prov
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 1 of 2 (upcoming)."
class="googlesitekit-stepper__step-number"
title="Step 1 of 2 (upcoming)."
>
Expand Down Expand Up @@ -169,6 +174,7 @@ exports[`Stepper should render all steps as upcoming when activeStep is not prov
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 2 of 2 (upcoming)."
class="googlesitekit-stepper__step-number"
title="Step 2 of 2 (upcoming)."
>
Expand Down Expand Up @@ -204,6 +210,7 @@ exports[`Stepper should render the active step as active and display its content
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 1 of 2 (active)."
class="googlesitekit-stepper__step-number"
title="Step 1 of 2 (active)."
>
Expand Down Expand Up @@ -239,6 +246,7 @@ exports[`Stepper should render the active step as active and display its content
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 2 of 2 (upcoming)."
class="googlesitekit-stepper__step-number"
title="Step 2 of 2 (upcoming)."
>
Expand Down Expand Up @@ -274,6 +282,7 @@ exports[`Stepper should render the active step as active and display its content
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 1 of 2 (completed)."
class="googlesitekit-stepper__step-number"
title="Step 1 of 2 (completed)."
>
Expand Down Expand Up @@ -303,6 +312,7 @@ exports[`Stepper should render the active step as active and display its content
class="googlesitekit-stepper__step-progress"
>
<span
aria-label="Step 2 of 2 (active)."
class="googlesitekit-stepper__step-number"
title="Step 2 of 2 (active)."
>
Expand Down
32 changes: 23 additions & 9 deletions assets/js/components/Stepper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ import { __, sprintf } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import CheckMark from '@/svg/icons/check-2.svg';
import Tick from '@/svg/icons/tick.svg';
import { STEP_STATUS } from './constants';

export default function Stepper( { children, activeStep, className } ) {
export default function Stepper( {
children,
activeStep,
className,
variant,
} ) {
const childCount = Children.count( children );

const Icon = variant === 'rail' ? CheckMark : Tick;

function getStepStatus( index = -1 ) {
if ( index < activeStep ) {
return STEP_STATUS.COMPLETED;
Expand Down Expand Up @@ -78,11 +86,18 @@ export default function Stepper( { children, activeStep, className } ) {
}

return (
<ol className={ classnames( 'googlesitekit-stepper', className ) }>
<ol
className={ classnames(
'googlesitekit-stepper',
variant && `googlesitekit-stepper--${ variant }`,
className
) }
>
{ Children.map( children, ( child, childIndex ) => {
const stepStatus = getStepStatus( childIndex, activeStep );

const childNumber = childIndex + 1;
const numberTitle = getNumberTitle( childNumber, stepStatus );

return (
<li
Expand All @@ -94,23 +109,21 @@ export default function Stepper( { children, activeStep, className } ) {
>
<div className="googlesitekit-stepper__step-progress">
<span
aria-label={ numberTitle }
className="googlesitekit-stepper__step-number"
title={ getNumberTitle(
childNumber,
stepStatus
) }
title={ numberTitle }
>
{ stepStatus === STEP_STATUS.COMPLETED ? (
<Tick />
<Icon />
) : (
childNumber
variant !== 'rail' && childNumber
) }
</span>
{ childNumber < childCount && (
<div className="googlesitekit-stepper__step-progress-line"></div>
) }
</div>
{ cloneElement( child, { stepStatus } ) }
{ cloneElement( child, { stepStatus, variant } ) }
</li>
);
} ) }
Expand All @@ -123,4 +136,5 @@ Stepper.propTypes = {
// The zero-based index of the active step. If omitted or negative, all steps are in the upcoming state. If greater than the number of steps - 1, all steps are complete.
activeStep: PropTypes.number,
className: PropTypes.string,
variant: PropTypes.string,
};
38 changes: 37 additions & 1 deletion assets/js/components/Stepper/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@ import { Button } from 'googlesitekit-components';
import Step from './Step';
import Stepper from '.';

function Template( { activeStep: initialActiveStep } ) {
function Template( { activeStep: initialActiveStep, variant } ) {
const [ activeStep, setActiveStep ] = useState( initialActiveStep );

if ( variant === 'rail' ) {
return (
<Stepper activeStep={ activeStep } variant={ variant }>
<Step title="Connect publication" />
<Step title="Add publication policies" />
<Step title="Set up a sign-up form" />
<Step title="Setup complete" />
</Stepper>
);
}

return (
<Stepper activeStep={ activeStep }>
<Step title="First Step">
Expand Down Expand Up @@ -75,6 +86,31 @@ Complete.storyName = 'Complete';
Complete.args = { activeStep: 3 };
Complete.scenario = {};

export const RailInactive = Template.bind( {} );
RailInactive.storyName = 'Rail Inactive';
RailInactive.args = { variant: 'rail' };
RailInactive.scenario = {};

export const RailFirstStepActive = Template.bind( {} );
RailFirstStepActive.storyName = 'Rail First Step Active';
RailFirstStepActive.args = { activeStep: 0, variant: 'rail' };
RailFirstStepActive.scenario = {};

export const RailMiddleStepActive = Template.bind( {} );
RailMiddleStepActive.storyName = 'Rail Middle Step Active';
RailMiddleStepActive.args = { activeStep: 1, variant: 'rail' };
RailMiddleStepActive.scenario = {};

export const RailLastStepActive = Template.bind( {} );
RailLastStepActive.storyName = 'Rail Last Step Active';
RailLastStepActive.args = { activeStep: 3, variant: 'rail' };
RailLastStepActive.scenario = {};

export const RailComplete = Template.bind( {} );
RailComplete.storyName = 'Rail Complete';
RailComplete.args = { activeStep: 4, variant: 'rail' };
RailComplete.scenario = {};

export default {
title: 'Components/Stepper',
component: Stepper,
Expand Down
117 changes: 117 additions & 0 deletions assets/sass/components/global/_googlesitekit-stepper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,121 @@
margin-bottom: 0;
}
}

.googlesitekit-stepper--rail {
Comment thread
nfmohit marked this conversation as resolved.
--googlesitekit-stepper-row-gap: 12px;
--googlesitekit-stepper-size: 18px;

@JakePT JakePT Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In Figma these are 16.5px, but the active step renders poorly at this size even on 2x displays because the full layout would require padding with quarter-pixels.

18px worked the best across resolutions, matched the layout size in the design, doesn't require special handling for 2x displays, and kept the inner and inactive circle sizes consistent as per the design.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @JakePT. I think this is correct anyway, as the full size of the vector appears to be 18px in Figma designs too.

Image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@nfmohit If you zoom in you'll see some white space though. The green circle itself is 16.5px.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You're right. I think we can disregard that. LGTM 👍

--googlesitekit-stepper-small-size: 10px;

align-items: center;
box-sizing: content-box;
display: flex;

@media (min-width: $bp-desktop) {
align-items: stretch;
display: grid;
gap: var(--googlesitekit-stepper-row-gap);
grid-auto-rows: 1fr;
}

.googlesitekit-stepper__step {
display: block;
flex: 2 1 0;

@media (min-width: $bp-desktop) {
display: grid;
flex-grow: 1;
gap: 14px;
grid-template-columns: var(--googlesitekit-stepper-size) auto;
min-block-size: 36px;
}
}

.googlesitekit-stepper__step:first-child,
.googlesitekit-stepper__step:last-child {
flex-grow: 1;
}

.googlesitekit-stepper__step-info {
display: none;

@media (min-width: $bp-desktop) {
align-self: center;
display: block;
}
}

.googlesitekit-stepper__step-title {
block-size: auto;
}

.googlesitekit-stepper__step-progress {
display: flex;
flex-direction: row;
place-items: center;

@media (min-width: $bp-desktop) {
flex-direction: column;
position: relative;
}

&::after,
&::before {
background-color: $c-surfaces-surface-2;
block-size: 1px;
content: "";
display: block;
flex: 1 1 0;

@media (min-width: $bp-desktop) {
block-size: auto;
inline-size: 1px;
}
}
}

.googlesitekit-stepper__step:first-child .googlesitekit-stepper__step-progress::before,
.googlesitekit-stepper__step:last-child .googlesitekit-stepper__step-progress::after {
display: none;

@media (min-width: $bp-desktop) {
display: block;
visibility: hidden;
}
}

.googlesitekit-stepper__step-number {
aspect-ratio: 1 / 1;
background-color: $c-site-kit-sk-600;
block-size: auto;
inline-size: var(--googlesitekit-stepper-size);
}

.googlesitekit-stepper__step--active {

.googlesitekit-stepper__step-number {
background-clip: content-box;
box-shadow: inset 0 0 0 1px $c-site-kit-sk-600;
padding: calc((var(--googlesitekit-stepper-size) - var(--googlesitekit-stepper-small-size)) / 2);
}
}

.googlesitekit-stepper__step--upcoming .googlesitekit-stepper__step-number {
background-color: $c-site-kit-sk-200;
inline-size: var(--googlesitekit-stepper-small-size);
}

.googlesitekit-stepper__step-progress-line {
display: none;

@media (min-width: $bp-desktop) {
block-size: var(--googlesitekit-stepper-row-gap);
display: block;
inset-block-start: 100%;
margin: 0;
min-block-size: 0;
position: absolute;
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.