2019-12-06 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2023-11-01 10:40:29 +00:00
|
|
|
import Title from '../title';
|
2019-12-06 13:18:55 +00:00
|
|
|
|
2021-11-26 17:03:12 +00:00
|
|
|
interface StepHeadingProps {
|
|
|
|
title: string;
|
|
|
|
stepHeadingContent?: JSX.Element;
|
|
|
|
}
|
|
|
|
|
|
|
|
const StepHeading = ( { title, stepHeadingContent }: StepHeadingProps ) => (
|
2020-06-17 09:53:42 +00:00
|
|
|
<div className="wc-block-components-checkout-step__heading">
|
2020-06-05 10:00:19 +00:00
|
|
|
<Title
|
|
|
|
aria-hidden="true"
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-components-checkout-step__title"
|
2020-06-05 10:00:19 +00:00
|
|
|
headingLevel="2"
|
|
|
|
>
|
2020-01-13 15:21:20 +00:00
|
|
|
{ title }
|
2020-06-05 10:00:19 +00:00
|
|
|
</Title>
|
2020-05-27 14:48:23 +00:00
|
|
|
{ !! stepHeadingContent && (
|
2020-06-17 09:53:42 +00:00
|
|
|
<span className="wc-block-components-checkout-step__heading-content">
|
2020-05-27 14:48:23 +00:00
|
|
|
{ stepHeadingContent }
|
|
|
|
</span>
|
|
|
|
) }
|
2019-12-06 13:18:55 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2023-11-10 17:20:20 +00:00
|
|
|
export interface FormStepProps {
|
2021-11-26 17:03:12 +00:00
|
|
|
id?: string;
|
|
|
|
className?: string;
|
|
|
|
title?: string;
|
|
|
|
legend?: string;
|
|
|
|
description?: string;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
disabled?: boolean;
|
|
|
|
showStepNumber?: boolean;
|
|
|
|
stepHeadingContent?: () => JSX.Element | undefined;
|
|
|
|
}
|
|
|
|
|
2019-12-06 13:18:55 +00:00
|
|
|
const FormStep = ( {
|
|
|
|
id,
|
|
|
|
className,
|
|
|
|
title,
|
2020-01-13 15:21:20 +00:00
|
|
|
legend,
|
2019-12-06 13:18:55 +00:00
|
|
|
description,
|
|
|
|
children,
|
2020-04-15 16:09:15 +00:00
|
|
|
disabled = false,
|
2020-07-31 15:17:01 +00:00
|
|
|
showStepNumber = true,
|
2021-11-26 17:03:12 +00:00
|
|
|
stepHeadingContent = () => undefined,
|
|
|
|
}: FormStepProps ): JSX.Element => {
|
2020-07-31 15:17:01 +00:00
|
|
|
// If the form step doesn't have a legend or title, render a <div> instead
|
|
|
|
// of a <fieldset>.
|
|
|
|
const Element = legend || title ? 'fieldset' : 'div';
|
|
|
|
|
2019-12-06 13:18:55 +00:00
|
|
|
return (
|
2020-07-31 15:17:01 +00:00
|
|
|
<Element
|
2020-06-17 09:53:42 +00:00
|
|
|
className={ classnames(
|
|
|
|
className,
|
2020-07-31 15:17:01 +00:00
|
|
|
'wc-block-components-checkout-step',
|
|
|
|
{
|
2022-06-15 09:56:52 +00:00
|
|
|
'wc-block-components-checkout-step--with-step-number':
|
|
|
|
showStepNumber,
|
2020-11-20 10:48:26 +00:00
|
|
|
'wc-block-components-checkout-step--disabled': disabled,
|
2020-07-31 15:17:01 +00:00
|
|
|
}
|
2020-06-17 09:53:42 +00:00
|
|
|
) }
|
2019-12-06 13:18:55 +00:00
|
|
|
id={ id }
|
2020-04-15 16:09:15 +00:00
|
|
|
disabled={ disabled }
|
2019-12-06 13:18:55 +00:00
|
|
|
>
|
2020-07-31 15:17:01 +00:00
|
|
|
{ !! ( legend || title ) && (
|
|
|
|
<legend className="screen-reader-text">
|
|
|
|
{ legend || title }
|
|
|
|
</legend>
|
|
|
|
) }
|
|
|
|
{ !! title && (
|
|
|
|
<StepHeading
|
|
|
|
title={ title }
|
|
|
|
stepHeadingContent={ stepHeadingContent() }
|
|
|
|
/>
|
|
|
|
) }
|
2020-06-17 09:53:42 +00:00
|
|
|
<div className="wc-block-components-checkout-step__container">
|
2020-06-08 11:13:34 +00:00
|
|
|
{ !! description && (
|
2020-06-17 09:53:42 +00:00
|
|
|
<p className="wc-block-components-checkout-step__description">
|
2020-06-08 11:13:34 +00:00
|
|
|
{ description }
|
|
|
|
</p>
|
|
|
|
) }
|
2020-06-17 09:53:42 +00:00
|
|
|
<div className="wc-block-components-checkout-step__content">
|
2020-06-08 11:13:34 +00:00
|
|
|
{ children }
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-07-31 15:17:01 +00:00
|
|
|
</Element>
|
2019-12-06 13:18:55 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FormStep;
|