BETA

Form Modal Page

Description

Form Modal pages are controlled components used to render a page with a form or something that requires user input, similar to InfoModalPage but semantically with a different role. The header includes buttons to control the submission or cancellation of the form. These buttons can be overwritten with custom controls by using the <CustomFormModalPage> component.

Usage

import { FormModalPage } from '@commercetools-frontend/application-components';
<FormModalPage
title="Lorem ipsum"
isOpen={true}
onClose={handleClose}
subtitle={<Text.Body>{'Lorem ipsum ...'}</Text.Body>}
topBarCurrentPathLabel="Lorem ipsum"
topBarPreviousPathLabel="Back"
onSecondaryButtonClick={handleCancel}
onPrimaryButtonClick={handleSubmit}
>
<TextField {...textFieldFormProps} />
</FormModalPage>;

Properties

PropsTypeRequiredDefaultDescription
isOpenboolean-Indicates whether the page is open or closed. The parent component needs to manage this state.
titlestring-The title of the page.
subtitlenode or string--The subtitle of the page, usually a React component. If a string is passed, it's rendered as a paragraph.
onClosefunction--Called when the page closes click on overlay, click on close button, press ESC. If the function is not provided, the page cannot be closed by any of the listed options.
levelnumber1The level indicates the stack position of the modal page, progressively increasing the z-index position (combined with the baseZIndex) as well as the spacing from the left side of the page.
baseZIndexnumber1000The base z-index value to be applied to the overlay container, incremented by 1 according to the level prop.
zIndexnumber-The z-index value to be applied to the overlay container. This value overrides the normal z-index value calculated from the baseZIndex and level props. If you provide this value, you would need to take care of providing a proper z-index based on the stacked level.
topBarCurrentPathLabelstringThe title propLabel to appear as the current path of the top bar of the modal.
topBarPreviousPathLabelstring"Go Back" (translated)Label to appear as the previous path of the top bar of the modal.
childrennode-Content rendered within the page. If the content is long in height (depending on the screen size) a scrollbar will appear.
labelSecondaryButtonstring | Intl message-Cancel
labelPrimaryButtonstring | Intl message-Confirm
onSecondaryButtonClickfunction-Called when the secondary button is clicked.
onPrimaryButtonClickfunction-Called when the primary button is clicked.
isPrimaryButtonDisabledboolean-falseIndicates whether the primary button is disabled or not.
dataAttributesSecondaryButtonobject--Use this prop to pass data- attributes to the secondary button.
dataAttributesPrimaryButtonobject--Use this prop to pass data- attributes to the primary button.
getParentSelectorfunction--The function should return an HTML element that will be used as the parent container to hold the modal DOM tree. If no function is provided, it's expected that an HTML element with the id="parent-container" is present in the DOM. In the NODE_ENV=test environment, the default HTML element is body.
shouldDelayOnClosebool-trueSets whether the ModalPage should delay calling its onClose function to allow the closing animation time to finish. This can be turned off if the developer is controlling the ModalPage only through the isOpen prop, and not abruptly mounting/unmounting it or one of its parent elements. You might also want to turn this off if you need to display a Prompt (for example to save changes) on the ModalPage before navigating out of it, as this option makes the Modal close itself before onClose is called.

Static properties

FormModalPage.Intl

This is a convenience proxy export to expose pre-defined Intl messages defined in the @commercetools-frontend/i18n package. The Intl messages can be used for button labels.

<FormModalPage
// other props...
labelSecondaryButton={FormModalPage.Intl.revert}
/>