Skip to content

Commit

Permalink
type check and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
broccolinisoup committed Jun 10, 2024
1 parent ed80257 commit de87b0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
16 changes: 8 additions & 8 deletions packages/react/src/PageHeader/PageHeader.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ export default meta

export const Playground: Story = args => (
<Box sx={{padding: 3}}>
<PageHeader>
<PageHeader.TitleArea
variant={{
narrow: args['Title.variant'],
regular: args['Title.variant'],
wide: args['Title.variant'],
}}
>
<PageHeader
variant={{
narrow: args['Title.variant'],
regular: args['Title.variant'],
wide: args['Title.variant'],
}}
>
<PageHeader.TitleArea>
<PageHeader.LeadingVisual hidden={!args.hasLeadingVisual}>{<args.LeadingVisual />}</PageHeader.LeadingVisual>
<PageHeader.Title as={args['Title.as']} hidden={!args.hasTitle}>
{args.Title}
Expand Down
53 changes: 23 additions & 30 deletions packages/react/src/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,40 +321,33 @@ const ContextAreaActions: React.FC<React.PropsWithChildren<ChildrenPropTypes>> =
</Box>
)
}

type TitleAreaProps = {
// variant?: 'subtitle' | 'medium' | 'large' | ResponsiveValue<'subtitle' | 'medium' | 'large'>
} & ChildrenPropTypes
// PageHeader.TitleArea: The main title area of the page. Visible on all viewports.
// PageHeader.TitleArea Sub Components: PageHeader.LeadingVisual, PageHeader.Title, PageTitle.TrailingVisual
// ---------------------------------------------------------------------

const TitleArea = React.forwardRef<HTMLDivElement, React.PropsWithChildren<TitleAreaProps>>(
({children, sx = {}, hidden = false}, forwardedRef) => {
return (
<Box
ref={forwardedRef}
data-component="TitleArea"
sx={merge<BetterSystemStyleObject>(
{
gridRow: GRID_ROW_ORDER.TitleArea,
gridArea: 'title-area',
display: 'flex',
gap: '0.5rem',
...getBreakpointDeclarations(hidden, 'display', value => {
return value ? 'none' : 'flex'
}),
flexDirection: 'row',
alignItems: 'flex-start',
},
sx,
)}
>
{children}
</Box>
)
},
) as PolymorphicForwardRefComponent<'div', TitleAreaProps>
const TitleArea: React.FC<React.PropsWithChildren<ChildrenPropTypes>> = ({children, sx = {}, hidden = false}) => {
return (
<Box
data-component="TitleArea"
sx={merge<BetterSystemStyleObject>(
{
gridRow: GRID_ROW_ORDER.TitleArea,
gridArea: 'title-area',
display: 'flex',
gap: '0.5rem',
...getBreakpointDeclarations(hidden, 'display', value => {
return value ? 'none' : 'flex'
}),
flexDirection: 'row',
alignItems: 'flex-start',
},
sx,
)}
>
{children}
</Box>
)
}

// PageHeader.LeadingAction and PageHeader.TrailingAction should only be visible on regular viewports.
// So they come as hidden on narrow viewports by default and their visibility can be managed by their `hidden` prop.
Expand Down

0 comments on commit de87b0d

Please sign in to comment.