diff --git a/tools/ui-components/src/modal/modal.stories.tsx b/tools/ui-components/src/modal/modal.stories.tsx index e326682c5e0..8d4be0d2b75 100644 --- a/tools/ui-components/src/modal/modal.stories.tsx +++ b/tools/ui-components/src/modal/modal.stories.tsx @@ -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; const story = { title: 'Example/Modal', @@ -28,12 +31,11 @@ const story = { } } satisfies Meta; -type Story = StoryObj; - const Spacer = () =>
; -const DefaultTemplate: StoryFn = ({ +const DefaultTemplate: StoryFn = ({ showCloseButton, + alignment, ...modalProps }) => { const [open, setOpen] = useState(false); @@ -47,7 +49,7 @@ const DefaultTemplate: StoryFn = ({ Lorem ipsum - +

Laboriosam autem non et nisi. Ut voluptatem sit beatae assumenda amet aliquam corporis. @@ -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; diff --git a/tools/ui-components/src/modal/modal.tsx b/tools/ui-components/src/modal/modal.tsx index dca4d5aa0a0..7f551b15248 100644 --- a/tools/ui-components/src/modal/modal.tsx +++ b/tools/ui-components/src/modal/modal.tsx @@ -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 @@ -63,9 +63,11 @@ const Header = ({ ); }; -const Body = ({ children }: { children: ReactNode }) => { +const Body = ({ children, alignment = 'center' }: BodyProps) => { return ( -

+
{children}
); diff --git a/tools/ui-components/src/modal/types.ts b/tools/ui-components/src/modal/types.ts index 4e24d30d013..7cdaf8acdf6 100644 --- a/tools/ui-components/src/modal/types.ts +++ b/tools/ui-components/src/modal/types.ts @@ -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'; +}