From 7d5ace49776b26fc8467c64d935dce0f29150c52 Mon Sep 17 00:00:00 2001 From: Jeremy Neal Date: Wed, 7 Jun 2023 11:25:52 -0400 Subject: [PATCH 1/7] Remove position prop and reorganize PageLayout stories to match previous layout. --- .../PageLayout.features.stories.tsx | 46 +- src/PageLayout/PageLayout.stories.tsx | 34 -- src/PageLayout/PageLayout.tsx | 80 ++-- .../__snapshots__/PageLayout.test.tsx.snap | 413 ++++++++++-------- src/SplitPageLayout/SplitPageLayout.tsx | 3 +- .../SplitPageLayout.test.tsx.snap | 23 +- 6 files changed, 298 insertions(+), 301 deletions(-) diff --git a/src/PageLayout/PageLayout.features.stories.tsx b/src/PageLayout/PageLayout.features.stories.tsx index 9a168985c56..458f97eb246 100644 --- a/src/PageLayout/PageLayout.features.stories.tsx +++ b/src/PageLayout/PageLayout.features.stories.tsx @@ -83,49 +83,42 @@ export const StickyPane: Story = args => ( - + - {Array.from({length: args.numParagraphsInContent}).map((_, i) => { - const testId = `content${i}` + {Array.from({length: args.numParagraphsInPane}).map((_, i) => { + const testId = `paragraph${i}` return ( Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at enim id lorem tempus egestas a non ipsum. Maecenas imperdiet ante quam, at varius lorem molestie vel. Sed at eros consequat, varius tellus et, auctor felis. Donec pulvinar lacinia urna nec commodo. Phasellus at imperdiet risus. Donec sit amet - massa purus. Nunc sem lectus, bibendum a sapien nec, tristique tempus felis. Ut porttitor auctor tellus - in imperdiet. Ut blandit tincidunt augue, quis fringilla nunc tincidunt sed. Vestibulum auctor euismod - nisi. Nullam tincidunt est in mi tincidunt dictum. Sed consectetur aliquet velit ut ornare. + massa purus. ) })} - - + + - {Array.from({length: args.numParagraphsInPane}).map((_, i) => { - const testId = `paragraph${i}` + {Array.from({length: args.numParagraphsInContent}).map((_, i) => { + const testId = `content${i}` return ( Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at enim id lorem tempus egestas a non ipsum. Maecenas imperdiet ante quam, at varius lorem molestie vel. Sed at eros consequat, varius tellus et, auctor felis. Donec pulvinar lacinia urna nec commodo. Phasellus at imperdiet risus. Donec sit amet - massa purus. + massa purus. Nunc sem lectus, bibendum a sapien nec, tristique tempus felis. Ut porttitor auctor tellus + in imperdiet. Ut blandit tincidunt augue, quis fringilla nunc tincidunt sed. Vestibulum auctor euismod + nisi. Nullam tincidunt est in mi tincidunt dictum. Sed consectetur aliquet velit ut ornare. ) })} - + @@ -172,7 +165,7 @@ export const NestedScrollContainer: Story = args => ( ))} - + {Array.from({length: args.numParagraphsInPane}).map((_, i) => ( @@ -248,14 +241,7 @@ export const CustomStickyHeader: Story = args => ( })} - + {Array.from({length: args.numParagraphsInPane}).map((_, i) => { const testId = `paragraph${i}` @@ -306,7 +292,7 @@ export const ResizablePane: Story = () => ( - + @@ -323,7 +309,7 @@ export const ScrollContainerWithinPageLayoutPane: Story = () => ( - + diff --git a/src/PageLayout/PageLayout.stories.tsx b/src/PageLayout/PageLayout.stories.tsx index 2ec2aaa0f56..7b8a5d7ffd0 100644 --- a/src/PageLayout/PageLayout.stories.tsx +++ b/src/PageLayout/PageLayout.stories.tsx @@ -34,9 +34,6 @@ const meta: Meta = { 'Content.hidden.regular': false, 'Content.hidden.narrow': false, 'Content.hidden.wide': false, - 'Pane.position.regular': 'end', - 'Pane.position.narrow': 'end', - 'Pane.position.wide': 'end', 'Pane.width': 'medium', 'Pane.sticky': false, 'Pane.resizable': false, @@ -204,32 +201,6 @@ const meta: Meta = { type: 'boolean', table: {category: 'Content props'}, }, - - // Pane prop controls - 'Pane.position.regular': { - type: { - name: 'enum', - value: ['start', 'end'], - }, - control: {type: 'radio'}, - table: {category: 'Pane props'}, - }, - 'Pane.position.narrow': { - type: { - name: 'enum', - value: ['start', 'end'], - }, - control: {type: 'radio'}, - table: {category: 'Pane props'}, - }, - 'Pane.position.wide': { - type: { - name: 'enum', - value: ['start', 'end'], - }, - control: {type: 'radio'}, - table: {category: 'Pane props'}, - }, 'Pane.width': { type: { name: 'enum', @@ -382,11 +353,6 @@ const Template: Story = args => ( {args['Render pane?'] ? ( > = ({ }} > {slots.header} - {rest} + ({ + display: 'flex', + flex: '1 1 100%', + flexWrap: 'wrap', + maxWidth: '100%', + [`@media screen and (min-width: ${theme.breakpoints[1]})`]: {columnGap: SPACING_MAP[columnGap]}, + })} + > + {rest} + {slots.footer} @@ -417,27 +427,32 @@ const Content: React.FC> = ({ sx = {}, }) => { const isHidden = useResponsiveValue(hidden, false) - const {contentTopRef, contentBottomRef} = React.useContext(PageLayoutContext) + const {contentTopRef, contentBottomRef, columnGap} = React.useContext(PageLayoutContext) return ( ( - { - display: isHidden ? 'none' : 'flex', - flexDirection: 'column', - order: REGION_ORDER.content, - // Set flex-basis to 0% to allow flex-grow to control the width of the content region. - // Without this, the content region could wrap onto a different line - // than the pane region on wide viewports if its contents are too wide. - flexBasis: 0, - flexGrow: 1, - flexShrink: 1, - minWidth: 1, // Hack to prevent overflowing content from pushing the pane region to the next line - }, - sx, - )} + sx={(theme: any) => + merge( + { + display: isHidden ? 'none' : 'flex', + flexDirection: 'column', + // Set flex-basis to 0% to allow flex-grow to control the width of the content region. + // Without this, the content region could wrap onto a different line + // than the pane region on wide viewports if its contents are too wide. + flexBasis: 0, + flexGrow: 1, + flexShrink: 1, + minWidth: 1, // Hack to prevent overflowing content from pushing the pane region to the next line + [`@media screen and (min-width: ${theme.breakpoints[1]})`]: { + width: 'auto', + marginY: '0 !important', + }, + }, + sx, + ) + } > {/* Track the top of the content region so we can calculate the height of the pane region */} @@ -466,7 +481,6 @@ Content.displayName = 'PageLayout.Content' // PageLayout.Pane export type PageLayoutPaneProps = { - position?: keyof typeof panePositions | ResponsiveValue /** * @deprecated Use the `position` prop with a responsive value instead. * @@ -529,8 +543,6 @@ const Pane = React.forwardRef { - // Combine position and positionWhenNarrow for backwards compatibility - const positionProp = - !isResponsiveValue(responsivePosition) && positionWhenNarrow !== 'inherit' - ? {regular: responsivePosition, narrow: positionWhenNarrow} - : responsivePosition - - const position = useResponsiveValue(positionProp, 'end') - // Combine divider and dividerWhenNarrow for backwards compatibility const dividerProp = !isResponsiveValue(responsiveDivider) && dividerWhenNarrow !== 'inherit' @@ -677,12 +681,11 @@ const Pane = React.forwardRef {/* Show a horizontal divider when viewport is narrow. Otherwise, show a vertical divider. */} - + { // Get the number of pixels the divider was dragged - const deltaWithDirection = position === 'end' ? -delta : delta + const deltaWithDirection = delta updatePaneWidth(paneWidth + deltaWithDirection) }} // Ensure `paneWidth` state and actual pane width are in sync when the drag ends diff --git a/src/PageLayout/__snapshots__/PageLayout.test.tsx.snap b/src/PageLayout/__snapshots__/PageLayout.test.tsx.snap index 30144461b0c..3b714ba8748 100644 --- a/src/PageLayout/__snapshots__/PageLayout.test.tsx.snap +++ b/src/PageLayout/__snapshots__/PageLayout.test.tsx.snap @@ -18,20 +18,6 @@ exports[`PageLayout renders condensed layout 1`] = ` padding: 0; } -.c5 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-flex: 1 1 100%; - -ms-flex: 1 1 100%; - flex: 1 1 100%; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; - flex-wrap: wrap; - max-width: 100%; -} - .c6 { display: -webkit-box; display: -webkit-flex; @@ -40,9 +26,6 @@ exports[`PageLayout renders condensed layout 1`] = ` -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; - -webkit-order: 2; - -ms-flex-order: 2; - order: 2; -webkit-flex-basis: 0; -ms-flex-preferred-size: 0; flex-basis: 0; @@ -68,7 +51,7 @@ exports[`PageLayout renders condensed layout 1`] = ` padding: 0; } -.c11 { +.c10 { --pane-min-width: 256px; --pane-max-width-diff: 511px; --pane-max-width: calc(100vw - var(--pane-max-width-diff)); @@ -92,38 +75,43 @@ exports[`PageLayout renders condensed layout 1`] = ` margin-top: 16px; } +.c5 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex: 1 1 100%; + -ms-flex: 1 1 100%; + flex: 1 1 100%; + -webkit-flex-wrap: wrap; + -ms-flex-wrap: wrap; + flex-wrap: wrap; + max-width: 100%; +} + .c8 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; - -webkit-order: 3; - -ms-flex-order: 3; - order: 3; width: 100%; margin-left: 0; margin-right: 0; - -webkit-flex-direction: column; - -ms-flex-direction: column; - flex-direction: column; + -webkit-flex-direction: column-reverse; + -ms-flex-direction: column-reverse; + flex-direction: column-reverse; + margin-bottom: 16px; margin-top: 16px; } .c9 { - margin-left: -16px; - margin-right: -16px; - display: none; - margin-bottom: 16px; -} - -.c10 { height: 100%; position: relative; display: none; - margin-right: 16px; + margin-left: 16px; } -.c12 { +.c11 { -webkit-order: 4; -ms-flex-order: 4; order: 4; @@ -131,21 +119,36 @@ exports[`PageLayout renders condensed layout 1`] = ` margin-top: 16px; } +.c12 { + margin-left: -16px; + margin-right: -16px; + display: none; + margin-bottom: 16px; +} + @media screen and (min-width:768px) { - .c11 { + .c6 { + width: auto; + margin-top: 0 !important; + margin-bottom: 0 !important; + } +} + +@media screen and (min-width:768px) { + .c10 { width: 256px; overflow: auto; } } @media screen and (min-width:1012px) { - .c11 { + .c10 { width: 296px; } } @media screen and (min-width:1280px) { - .c11 { + .c10 { --pane-max-width-diff: 959px; } } @@ -157,20 +160,26 @@ exports[`PageLayout renders condensed layout 1`] = ` } } +@media screen and (min-width:768px) { + .c5 { + -webkit-column-gap: 16px; + column-gap: 16px; + } +} + @media screen and (min-width:768px) { .c8 { width: auto; margin-top: 0 !important; margin-bottom: 0 !important; - -webkit-flex-direction: row; - -ms-flex-direction: row; - flex-direction: row; - margin-left: 16px; + -webkit-flex-direction: row-reverse; + -ms-flex-direction: row-reverse; + flex-direction: row-reverse; } } @media screen and (min-width:768px) { - .c9 { + .c12 { margin-left: 0 !important; margin-right: 0 !important; } @@ -218,13 +227,13 @@ exports[`PageLayout renders condensed layout 1`] = ` class="c8" >
Pane @@ -232,10 +241,10 @@ exports[`PageLayout renders condensed layout 1`] = `