Skip to content

Commit

Permalink
Merge pull request #829 from equinor/feat/dialog-content-height
Browse files Browse the repository at this point in the history
✨ Added contentMaxHeight prop to Dialog
  • Loading branch information
mariush2 authored Oct 22, 2024
2 parents 075fb00 + 89e2f64 commit a58b6e0
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/amplify-component-lib",
"version": "8.10.2",
"version": "8.10.3",
"description": "Frontend Typescript components for the Amplify team",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
49 changes: 49 additions & 0 deletions src/molecules/Dialog/Dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,52 @@ export const ColorVariations: Story = {
],
},
};

export const LongDialogWithContentMaxHeight: Story = {
args: {
title: 'Long dialog with content max height',
children: (
<div
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
}}
>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p>十一</p>
<p>十二</p>
<p>十三</p>
<p>十四</p>
<p>十五</p>
<p>十六</p>
<p>十七</p>
<p>十八</p>
<p>十九</p>
<p>ニ十</p>
</div>
),
contentMaxHeight: '400px',
actions: [
{
text: 'Cancel',
onClick: () => console.log('clicked'),
variant: 'ghost',
},
{
text: 'Okay',
onClick: () => console.log('clicked'),
variant: 'contained',
},
],
},
};
1 change: 1 addition & 0 deletions src/molecules/Dialog/Dialog.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const DialogContent = styled(
EDSDialog.CustomContent
)<DialogContentProps>`
min-height: unset;
overflow: auto;
${({ $withContentPadding }) => {
if ($withContentPadding) {
return css`
Expand Down
21 changes: 21 additions & 0 deletions src/molecules/Dialog/Dialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,24 @@ test('Custom children works as expected', () => {
expect(element).toBeInTheDocument();
expect(element).toHaveTextContent(description);
});

test('Content max height prop works as expected', () => {
const handleOnClose = vi.fn();
const title = faker.airline.airplane().name;
const description = faker.lorem.paragraph();
const contentMaxHeight = `${faker.number.int({ min: 10, max: 1000 })}px`;

render(
<Dialog
open
title={title}
onClose={handleOnClose}
contentMaxHeight={contentMaxHeight}
>
{description}
</Dialog>
);

const contentWrapper = screen.getByText(description).parentElement;
expect(contentWrapper).toHaveStyle(`max-height: ${contentMaxHeight}`);
});
8 changes: 7 additions & 1 deletion src/molecules/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface DialogProps extends Omit<EDSDialogProps, 'title'> {
actions?: DialogAction[];
withContentPadding?: boolean;
withBorders?: boolean;
contentMaxHeight?: string;
}

/**
Expand All @@ -54,6 +55,7 @@ export interface DialogProps extends Omit<EDSDialogProps, 'title'> {
* @param actions - Dialog actions, { position: "right" is default }
* @param withContentPadding - Defaults to true
* @param withBorders - Defaults to false
* @param contentMaxHeight - Defaults to '60vh'
* Also inherits props from EDS dialog
*/
export const Dialog = forwardRef<HTMLDivElement, DialogProps>(
Expand All @@ -65,6 +67,7 @@ export const Dialog = forwardRef<HTMLDivElement, DialogProps>(
actions,
withContentPadding = true,
withBorders = false,
contentMaxHeight = '60vh',
...otherProps
},
ref
Expand Down Expand Up @@ -108,7 +111,10 @@ export const Dialog = forwardRef<HTMLDivElement, DialogProps>(
</DialogTitle>
<DialogContent
$withContentPadding={withContentPadding}
style={{ width: width ? `${width}px` : undefined }}
style={{
width: width ? `${width}px` : undefined,
maxHeight: contentMaxHeight,
}}
>
{childrenElements}
</DialogContent>
Expand Down

0 comments on commit a58b6e0

Please sign in to comment.