diff --git a/docs/component-adapter/component-inventory.md b/docs/component-adapter/component-inventory.md index 78da81e85..dffdf6024 100644 --- a/docs/component-adapter/component-inventory.md +++ b/docs/component-adapter/component-inventory.md @@ -100,6 +100,7 @@ | Prop | Type | Required | Description | | ------------- | ----------------- | -------- | ------------------------------------------------------------------------- | | **children** | `React.ReactNode` | Yes | Content to be displayed inside the box | +| **header** | `React.ReactNode` | No | Content rendered at the top of the box with an edge-to-edge bottom border | | **footer** | `React.ReactNode` | No | Content rendered at the bottom of the box with an edge-to-edge top border | | **className** | `string` | No | CSS className to be applied | diff --git a/src/components/Common/UI/Box/Box.module.scss b/src/components/Common/UI/Box/Box.module.scss index d79954f4b..b0de4143d 100644 --- a/src/components/Common/UI/Box/Box.module.scss +++ b/src/components/Common/UI/Box/Box.module.scss @@ -6,6 +6,11 @@ border: 1px solid var(--g-colorBorderSecondary); } +.boxHeader { + padding: toRem(20); + border-bottom: 1px solid var(--g-colorBorderSecondary); +} + .boxBody { padding: toRem(20); } diff --git a/src/components/Common/UI/Box/Box.stories.tsx b/src/components/Common/UI/Box/Box.stories.tsx index f74d03fa0..c852338f7 100644 --- a/src/components/Common/UI/Box/Box.stories.tsx +++ b/src/components/Common/UI/Box/Box.stories.tsx @@ -22,6 +22,17 @@ export const Default: Story = { args: {}, } +export const WithHeader: Story = { + render: () => { + const Components = useComponentContext() + return ( + Section Title}> + This is the main content area with padding. + + ) + }, +} + export const WithFooter: Story = { render: () => { const Components = useComponentContext() @@ -39,6 +50,24 @@ export const WithFooter: Story = { }, } +export const WithHeaderAndFooter: Story = { + render: () => { + const Components = useComponentContext() + return ( + Section Title} + footer={ + {}}> + Save + + } + > + This is the main content area with padding. + + ) + }, +} + export const WithCustomClassName: Story = { decorators: [ Story => ( diff --git a/src/components/Common/UI/Box/Box.test.tsx b/src/components/Common/UI/Box/Box.test.tsx index 62d77da1c..21875386a 100644 --- a/src/components/Common/UI/Box/Box.test.tsx +++ b/src/components/Common/UI/Box/Box.test.tsx @@ -10,6 +10,18 @@ describe('Box Component', () => { expect(screen.getByText('Test Content')).toBeInTheDocument() }) + test('renders header when provided', () => { + renderWithProviders(Title}>Content) + + expect(screen.getByText('Title')).toBeInTheDocument() + }) + + test('does not render header when omitted', () => { + renderWithProviders(Content) + + expect(screen.queryByRole('heading')).not.toBeInTheDocument() + }) + test('renders footer when provided', () => { renderWithProviders(Save}>Content) @@ -50,6 +62,13 @@ describe('Box Component', () => { ), }, }, + { + name: 'box with header', + props: { + children: 'Main content', + header:

Title

, + }, + }, { name: 'box with footer', props: { @@ -57,6 +76,14 @@ describe('Box Component', () => { footer: , }, }, + { + name: 'box with header and footer', + props: { + children: 'Main content', + header:

Title

, + footer: , + }, + }, ] it.each(testCases)( diff --git a/src/components/Common/UI/Box/Box.tsx b/src/components/Common/UI/Box/Box.tsx index 9fe625473..0a0b7397c 100644 --- a/src/components/Common/UI/Box/Box.tsx +++ b/src/components/Common/UI/Box/Box.tsx @@ -2,9 +2,10 @@ import cn from 'classnames' import styles from './Box.module.scss' import { type BoxProps } from '@/components/Common/UI/Box/BoxTypes' -export function Box({ children, footer, className }: BoxProps) { +export function Box({ children, header, footer, className }: BoxProps) { return (
+ {header &&
{header}
}
{children}
{footer &&
{footer}
}
diff --git a/src/components/Common/UI/Box/BoxTypes.ts b/src/components/Common/UI/Box/BoxTypes.ts index 13e3a17f6..29c460f8d 100644 --- a/src/components/Common/UI/Box/BoxTypes.ts +++ b/src/components/Common/UI/Box/BoxTypes.ts @@ -5,6 +5,10 @@ export interface BoxProps { * Content to be displayed inside the box */ children: ReactNode + /** + * Content rendered at the top of the box with an edge-to-edge bottom border + */ + header?: ReactNode /** * Content rendered at the bottom of the box with an edge-to-edge top border */