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

fix(Dialog): missing granular padding control #2145

Merged
merged 10 commits into from
Jan 6, 2025
5 changes: 5 additions & 0 deletions .changeset/gentle-insects-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frontify/fondue-components": patch
---

fix(`Dialog`): missing granular padding control
150 changes: 140 additions & 10 deletions packages/components/src/components/Dialog/Dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,32 +338,162 @@ export const WithFocusableContent: Story = {
};

export const WithNoPadding: Story = {
args: {
padding: 'none',
render: (args) => {
return (
<Dialog.Root>
<Dialog.Trigger>
<Button>Open dialog</Button>
</Dialog.Trigger>
<Dialog.Content {...args}>
<Dialog.Header padding="none">
<Flex justify="space-between" align="center" width="100%" pr="1rem">
<Dialog.Title>Header</Dialog.Title>
<Button
emphasis="default"
onPress={() => {
alert('Button in the header clicked');
}}
>
Button in the header
</Button>
</Flex>
</Dialog.Header>
<Dialog.Body padding="none">None</Dialog.Body>
<Dialog.Footer padding="none">
<Button emphasis="default">Cancel</Button>
<Button>Submit</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
},
};

export const WithTightPadding: Story = {
args: {
padding: 'tight',
render: (args) => {
return (
<Dialog.Root>
<Dialog.Trigger>
<Button>Open dialog</Button>
</Dialog.Trigger>
<Dialog.Content {...args}>
<Dialog.Header padding="tight">
<Flex justify="space-between" align="center" width="100%" pr="1rem">
<Dialog.Title>Header</Dialog.Title>
<Button
emphasis="default"
onPress={() => {
alert('Button in the header clicked');
}}
>
Button in the header
</Button>
</Flex>
</Dialog.Header>
<Dialog.Body padding="tight">Tight</Dialog.Body>
<Dialog.Footer padding="tight">
<Button emphasis="default">Cancel</Button>
<Button>Submit</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
},
};

export const WithCompactPadding: Story = {
args: {
padding: 'compact',
render: (args) => {
return (
<Dialog.Root>
<Dialog.Trigger>
<Button>Open dialog</Button>
</Dialog.Trigger>
<Dialog.Content {...args}>
<Dialog.Header padding="compact">
<Flex justify="space-between" align="center" width="100%" pr="1rem">
<Dialog.Title>Header</Dialog.Title>
<Button
emphasis="default"
onPress={() => {
alert('Button in the header clicked');
}}
>
Button in the header
</Button>
</Flex>
</Dialog.Header>
<Dialog.Body padding="compact">Compact</Dialog.Body>
<Dialog.Footer padding="compact">
<Button emphasis="default">Cancel</Button>
<Button>Submit</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
},
};

export const WithComfortablePadding: Story = {
args: {
padding: 'comfortable',
render: (args) => {
return (
<Dialog.Root>
<Dialog.Trigger>
<Button>Open dialog</Button>
</Dialog.Trigger>
<Dialog.Content {...args}>
<Dialog.Header padding="comfortable">
<Flex justify="space-between" align="center" width="100%" pr="1rem">
<Dialog.Title>Header</Dialog.Title>
<Button
emphasis="default"
onPress={() => {
alert('Button in the header clicked');
}}
>
Button in the header
</Button>
</Flex>
</Dialog.Header>
<Dialog.Body padding="comfortable">Confortable</Dialog.Body>
<Dialog.Footer padding="comfortable">
<Button emphasis="default">Cancel</Button>
<Button>Submit</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
},
};

export const WithSpaciousPadding: Story = {
args: {
padding: 'spacious',
render: (args) => {
return (
<Dialog.Root>
<Dialog.Trigger>
<Button>Open dialog</Button>
</Dialog.Trigger>
<Dialog.Content {...args}>
<Dialog.Header padding="spacious">
<Flex justify="space-between" align="center" width="100%" pr="1rem">
<Dialog.Title>Header</Dialog.Title>
<Button
emphasis="default"
onPress={() => {
alert('Button in the header clicked');
}}
>
Button in the header
</Button>
</Flex>
</Dialog.Header>
<Dialog.Body padding="spacious">Spacious</Dialog.Body>
<Dialog.Footer padding="spacious">
<Button emphasis="default">Cancel</Button>
<Button>Submit</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
},
};

Expand Down
38 changes: 31 additions & 7 deletions packages/components/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export type DialogTriggerProps = {
};

export type DialogHeaderProps = {
/**
* Define the padding for the dialog header
*/
padding?: 'none' | 'tight' | 'compact' | 'comfortable' | 'spacious';
/**
* Show a border at the bottom of the header
* @default true
Expand All @@ -93,6 +97,10 @@ export type DialogHeaderProps = {
};

export type DialogFooterProps = {
/**
* Define the padding for the dialog footer
*/
padding?: 'none' | 'tight' | 'compact' | 'comfortable' | 'spacious';
/**
* Show a border at the top of the footer
* @default true
Expand All @@ -102,7 +110,14 @@ export type DialogFooterProps = {
'data-test-id'?: string;
};

export type DialogBodyProps = { children?: ReactNode; 'data-test-id'?: string };
export type DialogBodyProps = {
/**
* Define the padding for the dialog body
*/
padding?: 'none' | 'tight' | 'compact' | 'comfortable' | 'spacious';
children?: ReactNode;
'data-test-id'?: string;
};

export type DialogSideContentProps = { children?: ReactNode; 'data-test-id'?: string };

Expand Down Expand Up @@ -170,8 +185,8 @@ export const DialogContent = (
verticalAlign = 'center',
'data-test-id': dataTestId = 'fondue-dialog-content',
showUnderlay = false,
children,
rounded = true,
children,
...props
}: DialogContentProps,
ref: ForwardedRef<HTMLDivElement>,
Expand All @@ -190,8 +205,8 @@ export const DialogContent = (
ref={ref}
className={styles.content}
onFocus={addShowFocusRing}
data-dialog-padding={padding}
data-dialog-rounded={rounded}
data-dialog-spacing={padding}
data-test-id={dataTestId}
data-dialog-vertical-align={verticalAlign}
{...props}
Expand All @@ -206,9 +221,10 @@ DialogContent.displayName = 'Dialog.Content';

export const DialogHeader = (
{
children,
padding,
showBorder = true,
showCloseButton = true,
children,
'data-test-id': dataTestId = 'fondue-dialog-header',
}: DialogHeaderProps,
ref: ForwardedRef<HTMLDivElement>,
Expand All @@ -218,6 +234,7 @@ export const DialogHeader = (
data-test-id={dataTestId}
ref={ref}
className={styles.header}
data-dialog-header-padding={padding}
data-show-border={showBorder}
data-dialog-layout-component
>
Expand All @@ -233,14 +250,15 @@ export const DialogHeader = (
DialogHeader.displayName = 'Dialog.Header';

export const DialogFooter = (
{ showBorder = true, children, 'data-test-id': dataTestId = 'fondue-dialog-footer' }: DialogFooterProps,
{ padding, showBorder = true, children, 'data-test-id': dataTestId = 'fondue-dialog-footer' }: DialogFooterProps,
ref: ForwardedRef<HTMLDivElement>,
) => {
return (
<div
data-test-id={dataTestId}
ref={ref}
className={styles.footer}
data-dialog-footer-padding={padding}
data-show-border={showBorder}
data-dialog-layout-component
>
Expand All @@ -251,11 +269,17 @@ export const DialogFooter = (
DialogFooter.displayName = 'Dialog.Footer';

export const DialogBody = (
{ children, 'data-test-id': dataTestId = 'fondue-dialog-body' }: DialogBodyProps,
{ padding, children, 'data-test-id': dataTestId = 'fondue-dialog-body' }: DialogBodyProps,
ref: ForwardedRef<HTMLDivElement>,
) => {
return (
<div data-test-id={dataTestId} ref={ref} className={styles.body} data-dialog-layout-component>
<div
data-test-id={dataTestId}
ref={ref}
className={styles.body}
data-dialog-body-padding={padding}
data-dialog-layout-component
>
{children}
</div>
);
Expand Down
66 changes: 46 additions & 20 deletions packages/components/src/components/Dialog/__tests__/Dialog.ct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ test('should render no padding', async ({ mount, page }) => {
<Dialog.Trigger data-test-id={DIALOG_TRIGGER_TEST_ID}>
<Button>{DIALOG_TRIGGER_TEXT}</Button>
</Dialog.Trigger>
<Dialog.Content padding="none" data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header data-test-id={DIALOG_HEADER_TEST_ID}>{DIALOG_HEADER_TEXT}</Dialog.Header>
<Dialog.Body data-test-id={DIALOG_BODY_TEST_ID}>{DIALOG_BODY_TEXT}</Dialog.Body>
<Dialog.Footer data-test-id={DIALOG_FOOTER_TEST_ID}>{DIALOG_FOOTER_TEXT}</Dialog.Footer>
<Dialog.Content data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header padding="none" data-test-id={DIALOG_HEADER_TEST_ID}>
{DIALOG_HEADER_TEXT}
</Dialog.Header>
<Dialog.Body padding="none" data-test-id={DIALOG_BODY_TEST_ID}>
{DIALOG_BODY_TEXT}
</Dialog.Body>
<Dialog.Footer padding="none" data-test-id={DIALOG_FOOTER_TEST_ID}>
{DIALOG_FOOTER_TEXT}
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>,
);
Expand All @@ -69,10 +75,16 @@ test('should render tight padding', async ({ mount, page }) => {
<Dialog.Trigger data-test-id={DIALOG_TRIGGER_TEST_ID}>
<Button>{DIALOG_TRIGGER_TEXT}</Button>
</Dialog.Trigger>
<Dialog.Content padding="tight" data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header data-test-id={DIALOG_HEADER_TEST_ID}>{DIALOG_HEADER_TEXT}</Dialog.Header>
<Dialog.Body data-test-id={DIALOG_BODY_TEST_ID}>{DIALOG_BODY_TEXT}</Dialog.Body>
<Dialog.Footer data-test-id={DIALOG_FOOTER_TEST_ID}>{DIALOG_FOOTER_TEXT}</Dialog.Footer>
<Dialog.Content data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header padding="tight" data-test-id={DIALOG_HEADER_TEST_ID}>
{DIALOG_HEADER_TEXT}
</Dialog.Header>
<Dialog.Body padding="tight" data-test-id={DIALOG_BODY_TEST_ID}>
{DIALOG_BODY_TEXT}
</Dialog.Body>
<Dialog.Footer padding="tight" data-test-id={DIALOG_FOOTER_TEST_ID}>
{DIALOG_FOOTER_TEXT}
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>,
);
Expand All @@ -88,10 +100,16 @@ test('should render compact padding', async ({ mount, page }) => {
<Dialog.Trigger data-test-id={DIALOG_TRIGGER_TEST_ID}>
<Button>{DIALOG_TRIGGER_TEXT}</Button>
</Dialog.Trigger>
<Dialog.Content padding="compact" data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header data-test-id={DIALOG_HEADER_TEST_ID}>{DIALOG_HEADER_TEXT}</Dialog.Header>
<Dialog.Body data-test-id={DIALOG_BODY_TEST_ID}>{DIALOG_BODY_TEXT}</Dialog.Body>
<Dialog.Footer data-test-id={DIALOG_FOOTER_TEST_ID}>{DIALOG_FOOTER_TEXT}</Dialog.Footer>
<Dialog.Content data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header padding="compact" data-test-id={DIALOG_HEADER_TEST_ID}>
{DIALOG_HEADER_TEXT}
</Dialog.Header>
<Dialog.Body padding="compact" data-test-id={DIALOG_BODY_TEST_ID}>
{DIALOG_BODY_TEXT}
</Dialog.Body>
<Dialog.Footer padding="compact" data-test-id={DIALOG_FOOTER_TEST_ID}>
{DIALOG_FOOTER_TEXT}
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>,
);
Expand All @@ -107,10 +125,14 @@ test('should render comfortable padding', async ({ mount, page }) => {
<Dialog.Trigger data-test-id={DIALOG_TRIGGER_TEST_ID}>
<Button>{DIALOG_TRIGGER_TEXT}</Button>
</Dialog.Trigger>
<Dialog.Content padding="comfortable" data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header data-test-id={DIALOG_HEADER_TEST_ID}>{DIALOG_HEADER_TEXT}</Dialog.Header>
<Dialog.Body data-test-id={DIALOG_BODY_TEST_ID}>{DIALOG_BODY_TEXT}</Dialog.Body>
<Dialog.Footer data-test-id={DIALOG_FOOTER_TEST_ID}>
<Dialog.Content data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header padding="comfortable" data-test-id={DIALOG_HEADER_TEST_ID}>
{DIALOG_HEADER_TEXT}
</Dialog.Header>
<Dialog.Body padding="comfortable" data-test-id={DIALOG_BODY_TEST_ID}>
{DIALOG_BODY_TEXT}
</Dialog.Body>
<Dialog.Footer padding="comfortable" data-test-id={DIALOG_FOOTER_TEST_ID}>
<Button>{DIALOG_FOOTER_TEXT}</Button>
</Dialog.Footer>
</Dialog.Content>
Expand All @@ -128,10 +150,14 @@ test('should render spacious padding', async ({ mount, page }) => {
<Dialog.Trigger data-test-id={DIALOG_TRIGGER_TEST_ID}>
<Button>{DIALOG_TRIGGER_TEXT}</Button>
</Dialog.Trigger>
<Dialog.Content padding="spacious" data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header data-test-id={DIALOG_HEADER_TEST_ID}>{DIALOG_HEADER_TEXT}</Dialog.Header>
<Dialog.Body data-test-id={DIALOG_BODY_TEST_ID}>{DIALOG_BODY_TEXT}</Dialog.Body>
<Dialog.Footer data-test-id={DIALOG_FOOTER_TEST_ID}>
<Dialog.Content data-test-id={DIALOG_CONTENT_TEST_ID}>
<Dialog.Header padding="spacious" data-test-id={DIALOG_HEADER_TEST_ID}>
{DIALOG_HEADER_TEXT}
</Dialog.Header>
<Dialog.Body padding="spacious" data-test-id={DIALOG_BODY_TEST_ID}>
{DIALOG_BODY_TEXT}
</Dialog.Body>
<Dialog.Footer padding="spacious" data-test-id={DIALOG_FOOTER_TEST_ID}>
<Button>{DIALOG_FOOTER_TEXT}</Button>
</Dialog.Footer>
</Dialog.Content>
Expand Down
Loading
Loading