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

Provide new prop to add content to left area of form dialog #3587

Merged
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
5 changes: 5 additions & 0 deletions .changeset/nasty-dragons-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/application-components': minor
---

Add a new property `footerContent`to the form dialog. This provides an additional content positioned to the left area of the form dialog footer.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ describe('rendering', () => {
screen.getByText('button icon');
},
}));

it('should show additional content in footer', () =>
validateComponent({
title: 'Lorem ipsus',
extraProps: {
footerContent: <a href="/#">Left aligned content</a>,
},
extraChecks: () => {
screen.getByText('Left aligned content');
},
}));
});

describe('with custom title', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type TFormDialogProps = {
dataAttributesPrimaryButton?: { [key: string]: string };
getParentSelector?: () => HTMLElement;
iconLeftSecondaryButton?: ReactElement;
footerContent?: ReactNode;
};
const defaultProps: Pick<TFormDialogProps, 'labelSecondary' | 'labelPrimary'> =
{
Expand Down Expand Up @@ -59,6 +60,7 @@ const FormDialog = (props: TFormDialogProps) => (
dataAttributesSecondaryButton={props.dataAttributesSecondaryButton}
dataAttributesPrimaryButton={props.dataAttributesPrimaryButton}
iconLeftSecondaryButton={props.iconLeftSecondaryButton}
footerContent={props.footerContent}
/>
</DialogContainer>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactElement, SyntheticEvent } from 'react';
import type { ReactElement, SyntheticEvent, ReactNode } from 'react';
import { css } from '@emotion/react';
import { useIntl, type IntlShape } from 'react-intl';
import { designTokens as uiKitDesignTokens } from '@commercetools-uikit/design-system';
Expand Down Expand Up @@ -26,6 +26,7 @@ type Props = {
dataAttributesSecondaryButton: { [key: string]: string };
children?: never;
iconLeftSecondaryButton?: ReactElement;
footerContent?: ReactNode;
};
const defaultProps: Pick<
Props,
Expand All @@ -49,19 +50,26 @@ const DialogFooter = (props: Props) => {
margin-top: ${uiKitDesignTokens.spacing50};
`}
>
<Spacings.Inline scale="m" alignItems="center" justifyContent="flex-end">
<SecondaryButton
label={getFormattedLabel(props.labelSecondary, intl)}
onClick={props.onCancel}
iconLeft={props.iconLeftSecondaryButton}
{...filterDataAttributes(props.dataAttributesSecondaryButton)}
/>
<PrimaryButton
label={getFormattedLabel(props.labelPrimary, intl)}
onClick={props.onConfirm}
isDisabled={props.isPrimaryButtonDisabled}
{...filterDataAttributes(props.dataAttributesPrimaryButton)}
/>
<Spacings.Inline alignItems="center" justifyContent="space-between">
<div>{props.footerContent}</div>
<Spacings.Inline
scale="m"
alignItems="center"
justifyContent="flex-end"
>
<SecondaryButton
label={getFormattedLabel(props.labelSecondary, intl)}
onClick={props.onCancel}
iconLeft={props.iconLeftSecondaryButton}
{...filterDataAttributes(props.dataAttributesSecondaryButton)}
/>
<PrimaryButton
label={getFormattedLabel(props.labelPrimary, intl)}
onClick={props.onConfirm}
isDisabled={props.isPrimaryButtonDisabled}
{...filterDataAttributes(props.dataAttributesPrimaryButton)}
/>
</Spacings.Inline>
</Spacings.Inline>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const FormDialogExample = (props: ContainerProps) => (
document.querySelector(`#${props.portalId}`) as HTMLElement
}
zIndex={10001}
footerContent={props.footerContent}
>
<Spacings.Stack scale="m">
<TextField
Expand Down Expand Up @@ -109,5 +110,16 @@ export const Component = () => (
portalId="dialog-disabled"
/>
</Spec>
<Spec
label="FormDialog - footerContent provided"
size="l"
contentAlignment="center"
>
<FormDialogExample
size="l"
portalId="dialog-left-aligned-footer-content"
footerContent={<a href="/#">lorem ipsum</a>}
/>
</Spec>
</Suite>
);
1 change: 1 addition & 0 deletions website-components-playground/src/pages/form-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const FormDialogExample = () => (
event as FormEvent<HTMLFormElement>
)
}
footerContent={<a href="/#">Left aligned content</a>}
>
<Spacings.Stack scale="m">
<TextField
Expand Down