Skip to content

Commit

Permalink
Ab 219 support right components in sectionheader (#322)
Browse files Browse the repository at this point in the history
* allow for a right element in section header

* add story for right header

* fix import order

* apply review feedback
  • Loading branch information
SirCotare authored Oct 29, 2024
1 parent d530d19 commit 0b9ed01
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/components/section/SectionHeader/SectionHeader.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs'
import { SectionHeader } from './SectionHeader'
import { Button } from "../../button";

<Meta title="Components/Section/SectionHeader" component={SectionHeader} />

# SectionHeader

This component can be used to create a section header swiftly.

It leverages the components [SectionHeaderArea](/docs/components-section-sectionheaderara--docs) and [SectionHeaderTitle](/docs/components-section-sectionheadertitle--docs).
It leverages the components [SectionHeaderArea](/docs/components-section-sectionheaderara--docs), [SectionHeaderRow](/docs/components-section-sectionheaderrow--docs) and [SectionHeaderTitle](/docs/components-section-sectionheadertitle--docs).

export const Template = ({ ...args }) => <SectionHeader {...args} />

Expand All @@ -17,6 +18,24 @@ export const Template = ({ ...args }) => <SectionHeader {...args} />
</Story>
</Canvas>

<Canvas>
<Story name="With right element" args={{ title: 'Header Title', rightArea: <Button>Right</Button> }}>
{Template.bind({})}
</Story>
</Canvas>

<Canvas>
<Story name="With multiple right elements" args={{ title: 'Header Title', rightArea: <><Button>Right 1</Button><Button>Right 2</Button></> }}>
{Template.bind({})}
</Story>
</Canvas>

<Canvas>
<Story name="Long title with right element" args={{ title: 'Very Long Title: lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet', rightArea: <Button>Right</Button> }}>
{Template.bind({})}
</Story>
</Canvas>

### Props

<ArgsTable story="Default" />
<ArgsTable story="With right element" />
13 changes: 11 additions & 2 deletions src/components/section/SectionHeader/SectionHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { ReactNode } from 'react'
import { SectionHeaderArea } from './SectionHeaderArea'
import { SectionHeaderRow, SectionHeaderRowLayout } from './SectionHeaderRow'
import { SectionHeaderTitle } from './SectionHeaderTitle'

export type SectionHeaderProps = {
title: ReactNode
className?: string
rightArea?: ReactNode
}

export function SectionHeader({ className, title }: SectionHeaderProps) {
export function SectionHeader({
className,
title,
rightArea,
}: SectionHeaderProps) {
return (
<SectionHeaderArea className={className}>
<SectionHeaderTitle>{title}</SectionHeaderTitle>
<SectionHeaderRow layout={SectionHeaderRowLayout.SpaceBetween}>
<SectionHeaderTitle>{title}</SectionHeaderTitle>
<div>{rightArea}</div>
</SectionHeaderRow>
</SectionHeaderArea>
)
}

0 comments on commit 0b9ed01

Please sign in to comment.