Skip to content

Commit

Permalink
fix(ui-components): modal body alignment (#54161)
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenltnguyen committed Mar 22, 2024
1 parent 6870cf5 commit 623d691
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
26 changes: 21 additions & 5 deletions tools/ui-components/src/modal/modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { StoryObj, StoryFn, Meta } from '@storybook/react';

import { Button } from '../button';
import { Modal } from './modal';
import { type ModalProps, type HeaderProps } from './types';
import { type ModalProps, type HeaderProps, type BodyProps } from './types';

type StoryProps = ModalProps & HeaderProps & BodyProps;
type Story = StoryObj<StoryProps>;

const story = {
title: 'Example/Modal',
Expand All @@ -28,12 +31,11 @@ const story = {
}
} satisfies Meta<typeof Modal>;

type Story = StoryObj<ModalProps & HeaderProps>;

const Spacer = () => <div style={{ height: '5px', width: '100%' }} />;

const DefaultTemplate: StoryFn<ModalProps & HeaderProps> = ({
const DefaultTemplate: StoryFn<StoryProps> = ({
showCloseButton,
alignment,
...modalProps
}) => {
const [open, setOpen] = useState(false);
Expand All @@ -47,7 +49,7 @@ const DefaultTemplate: StoryFn<ModalProps & HeaderProps> = ({
<Modal.Header showCloseButton={showCloseButton}>
Lorem ipsum
</Modal.Header>
<Modal.Body>
<Modal.Body alignment={alignment}>
<p>
Laboriosam autem non et nisi. Ut voluptatem sit beatae assumenda
amet aliquam corporis.
Expand Down Expand Up @@ -152,4 +154,18 @@ export const WithoutCloseButton: Story = {
}
};

export const LeftAlignedBody: Story = {
render: DefaultTemplate,
args: {
alignment: 'left'
}
};

export const StartAlignedBody: Story = {
render: DefaultTemplate,
args: {
alignment: 'start'
}
};

export default story;
8 changes: 5 additions & 3 deletions tools/ui-components/src/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, {
import { Dialog, Transition } from '@headlessui/react';

import { CloseButton } from '../close-button';
import { type ModalProps, type HeaderProps } from './types';
import { type ModalProps, type HeaderProps, BodyProps } from './types';

// There is a close button on the right side of the modal title.
// Some extra padding needs to be added to the left of the title text
Expand Down Expand Up @@ -63,9 +63,11 @@ const Header = ({
);
};

const Body = ({ children }: { children: ReactNode }) => {
const Body = ({ children, alignment = 'center' }: BodyProps) => {
return (
<div className='p-[15px] border-b-1 border-solid border-foreground-secondary'>
<div
className={`p-[15px] border-b-1 border-solid border-foreground-secondary text-${alignment}`}
>
{children}
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions tools/ui-components/src/modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ export interface HeaderProps {
*/
closeButtonClassNames?: string;
}

export interface BodyProps {
children: ReactNode;

/**
* Use `start` for better right-to-left support.
* Use `left` if the modal body contains code blocks.
*/
alignment?: 'center' | 'left' | 'start';
}

0 comments on commit 623d691

Please sign in to comment.