Skip to content

Commit

Permalink
Provide new prop to add content to left area of form dialog (#3587)
Browse files Browse the repository at this point in the history
* feat(form dialog): provide new prop to add content to left area of form dialog footer

* feat(form dialog): fix position issue when additional content is not provided

* feat(form dialog): add new prop to docs example

* feat(form dialog): update prop name

* feat(form dialog): remove unnecessary spacing inline

---------

Co-authored-by: Ddouglasz <[email protected]>
  • Loading branch information
ddouglasz and Ddouglasz authored Aug 9, 2024
1 parent d976e65 commit d37e74e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
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

0 comments on commit d37e74e

Please sign in to comment.