Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4609667
fix(PageLayoutPane): heading is consumable
agreenberry Apr 10, 2023
68377a2
doce(SplitPageLayout): updated to reflect Pane heading
agreenberry Apr 10, 2023
ac0e806
docs(SplitPageLayout.Pane): demo Heading
agreenberry Apr 10, 2023
86db7cc
Merge branch 'main' into 1885-bug-splitpagelayoutpane-needs-to-be-abl…
agreenberry Apr 10, 2023
830f952
chore: added changeset
agreenberry Apr 10, 2023
297b9fe
Merge branch '1885-bug-splitpagelayoutpane-needs-to-be-able-to-consum…
agreenberry Apr 10, 2023
051719c
Merge remote-tracking branch 'origin/main' into 1885-bug-splitpagelay…
agreenberry May 2, 2023
a05f5cc
fix(SplitPageLayout): ability to consume custom level header
agreenberry May 2, 2023
6047711
docs(SplitPageLayout.Pane): updated with heading and headingLevel
agreenberry May 2, 2023
99431fa
Update generated/components.json
green6erry May 2, 2023
5cbaeb3
Merge remote-tracking branch 'origin/main' into 1885-bug-splitpagelay…
Aug 31, 2023
f963fe7
moved heading to around PageLayout.Pane
Sep 1, 2023
6b0123c
Merge branch 'main' into 1885-bug-splitpagelayoutpane-needs-to-be-abl…
TylerJDev Nov 7, 2023
2151877
Utilize `useSlots` to render heading
TylerJDev Nov 7, 2023
45b59f1
Update `SplitPageLayout`
TylerJDev Nov 8, 2023
eb26f54
Update name
TylerJDev Nov 8, 2023
8dabe2f
Adjust `SplitPageLayout` further
TylerJDev Nov 8, 2023
f87d940
Add snapshot test
TylerJDev Nov 8, 2023
8dbe325
Adjust paneheading usage
TylerJDev Nov 13, 2023
cda5fc7
Clean up further
TylerJDev Nov 13, 2023
7c2cf79
Remove unused heading import
TylerJDev Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-gifts-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

Added Heading to SplitPageLayout.Pane
15 changes: 15 additions & 0 deletions docs/content/SplitPageLayout.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ If you need a more flexible layout component, consider using the [PageLayout](/P
</Box>
```

### With pane heading

```jsx live drafts
<Box sx={{height: 320, overflowY: 'auto', border: '1px solid', borderColor: 'border.default'}}>
<SplitPageLayout>
<SplitPageLayout.Pane>
<Placeholder label="Pane" height={120} heading="Pane Heading" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component interface should support accepting a heading level, and in my opinion should make it a required argument.

In this case I believe we were wanting the heading to be a level 2, for instance, but I could imagine circumstances it might be a level 1 or a level 3.

I can see by the tests that it is a level 2, but I'm thinking here in terms of component design.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell this is still choosing h2 by default, and I propose we require user to provide heading level.

</SplitPageLayout.Pane>
<SplitPageLayout.Content>
<Placeholder label="Content" height={480} />
</SplitPageLayout.Content>
</SplitPageLayout>
</Box>
```

### With non-sticky pane

```jsx live drafts
Expand Down
11 changes: 11 additions & 0 deletions generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -3777,6 +3777,17 @@
{
"name": "sx",
"type": "SystemStyleObject"
},
{
"name": "heading",
"type": "string",
"description": "Provide a heading for the SplitPageLayout Pane."
},
{
"name": "headingLevel",
"type": "| 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'",
"defaultValue": "\"h2\"",
"description": "Which heading level is applied to SplitPageLayout Pane heading."
}
]
},
Expand Down
6 changes: 6 additions & 0 deletions src/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import {createGlobalStyle} from 'styled-components'
import Box from '../Box'
import Heading from '../Heading'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import Heading from '../Heading'

import {useId} from '../hooks/useId'
import {useRefObjectAsForwardedRef} from '../hooks/useRefObjectAsForwardedRef'
import {isResponsiveValue, ResponsiveValue, useResponsiveValue} from '../hooks/useResponsiveValue'
Expand Down Expand Up @@ -490,6 +491,8 @@ export type PageLayoutPaneProps = {
resizable?: boolean
widthStorageKey?: string
padding?: keyof typeof SPACING_MAP
heading?: string
headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
divider?: 'none' | 'line' | ResponsiveValue<'none' | 'line', 'none' | 'line' | 'filled'>
/**
* @deprecated Use the `divider` prop with a responsive value instead.
Expand Down Expand Up @@ -542,6 +545,8 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
sticky = false,
offsetHeader = 0,
hidden: responsiveHidden = false,
heading,
headingLevel = 'h2',
children,
id,
sx = {},
Expand Down Expand Up @@ -760,6 +765,7 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
{...labelProp}
{...(id && {id: paneId})}
>
{heading && <Heading as={headingLevel}>{heading}</Heading>}
Copy link
Contributor

@kendallgassner kendallgassner Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just expose this as a subComponent:

PageLayout.Pane.Heading = Heading

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted this in my most recent commit. There's now a new slot for a heading component that's tied to PageLayout. This should allow someone to use PageLayout.PaneHeading to place a heading component within the pane, above everything else (pending feedback).

{resizable && (
<VisuallyHidden>
<form onSubmit={handleWidthFormSubmit}>
Expand Down
11 changes: 11 additions & 0 deletions src/SplitPageLayout/SplitPageLayout.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@
{
"name": "sx",
"type": "SystemStyleObject"
},
{
"name": "heading",
"type": "string",
"description": "Provide a heading for the SplitPageLayout Pane."
},
{
"name": "headingLevel",
"type": "| 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'",
"defaultValue": "\"h2\"",
"description": "Which heading level is applied to SplitPageLayout Pane heading."
}
]
},
Expand Down
6 changes: 6 additions & 0 deletions src/SplitPageLayout/SplitPageLayout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ export default {
defaultValue: 'customId',
table: {category: 'Pane props'},
},
'Pane.heading': {
type: 'string',
defaultValue: '',
table: {category: 'Pane props'},
},
'Pane.position.narrow': {
type: {
name: 'enum',
Expand Down Expand Up @@ -340,6 +345,7 @@ const Template: Story = args => (
</SplitPageLayout.Content>
{args['Render pane?'] ? (
<SplitPageLayout.Pane
heading={args['Pane.heading']}
resizable={args['Pane.resizable']}
position={{
narrow: args['Pane.position.narrow'],
Expand Down
26 changes: 26 additions & 0 deletions src/SplitPageLayout/SplitPageLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,30 @@ describe('SplitPageLayout', () => {

expect(pane.getAttribute('id')).toBe('customId')
})

it('renders Pane with a heading', () => {
const {getByText} = render(
<ThemeProvider>
<SplitPageLayout>
<SplitPageLayout.Pane heading="Custom heading" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if it makes more sense to make the heading a component itself rather then passing it in as a prop:

          <SplitPageLayout.Pane.heading as='h3'>Custom heading"</SplitPageLayout.Pane.heading >

^ this would make it easier for people to add attributes in the future.

</SplitPageLayout>
</ThemeProvider>,
)
const heading = getByText('Custom heading')

expect(heading.tagName).toBe('H2')
})

it('renders Pane with a custom level heading', () => {
const {getByText} = render(
<ThemeProvider>
<SplitPageLayout>
<SplitPageLayout.Pane heading="Custom heading" headingLevel="h3" />
</SplitPageLayout>
</ThemeProvider>,
)
const heading = getByText('Custom heading')

expect(heading.tagName).toBe('H3')
})
})
10 changes: 9 additions & 1 deletion src/SplitPageLayout/SplitPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ export const Pane: React.FC<React.PropsWithChildren<SplitPageLayoutPaneProps>> =
divider = 'line',
...props
}) => {
return <PageLayout.Pane position={position} sticky={sticky} padding={padding} divider={divider} {...props} />
return (
<PageLayout.Pane
position={position}
sticky={sticky}
padding={padding}
divider={divider}
{...props}
></PageLayout.Pane>
)
}
Pane.displayName = 'SplitPageLayout.Pane'

Expand Down