Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid necessity for overwriting height and scrolling behavior [CFISO-1861] #2859

Merged
merged 25 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
778f12e
docs: show different layout variations
Lelith Sep 3, 2024
3ce00c3
docs: improve storybook examples
Lelith Sep 4, 2024
934fe4a
docs: extend examples
Lelith Sep 5, 2024
ee1b8d3
refactor: layout component html structure and styling
Lelith Sep 5, 2024
b93c678
refactor: use grid instead of flexbox for column arrangement
Lelith Sep 5, 2024
0ddc6f8
refactor: change scroll container for narrow variant
Lelith Sep 6, 2024
07cf52c
refactor: only scroll content, never header
Lelith Sep 6, 2024
ab654d7
chore: optimize code for sidebar
Lelith Sep 9, 2024
101be5a
chore: import sizes from dependent component packages
Lelith Sep 11, 2024
39b95f8
fix: adjust size for border
Lelith Sep 11, 2024
680bb23
style: adjust outer spacing for smaller screens
Lelith Sep 12, 2024
74b22be
chore: fix ci build run
Lelith Sep 12, 2024
f0a8ca0
Update packages/components/layout/src/Layout.styles.ts
Lelith Sep 12, 2024
83ff139
Update packages/components/layout/src/Layout.styles.ts
Lelith Sep 12, 2024
ead0898
Update packages/components/layout/src/Layout.styles.ts
Lelith Sep 12, 2024
cc854fd
feat: forward overwriting styles to main container
Lelith Sep 12, 2024
c607037
Merge remote-tracking branch 'origin/fix/layout_height_and_scrolling_…
Lelith Sep 12, 2024
1b2c0c1
docs: add comment to code
Lelith Sep 12, 2024
6d02120
fix: reset package.json
Lelith Sep 12, 2024
699866c
chore: update package-lock
Lelith Sep 16, 2024
2cdaa74
Merge branch 'next' into fix/layout_height_and_scrolling_CFISO-1861
Lelith Sep 17, 2024
1596028
feat: make offsetTop a overwritable property
Lelith Sep 18, 2024
25a166b
chore: bump to reflect current published version
cf-remylenoir Sep 24, 2024
663dcab
refactor: define default top offset to navbar height
cf-remylenoir Sep 25, 2024
d2a030c
feat: introduce sidebar variants
cf-remylenoir Sep 27, 2024
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
202 changes: 202 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/components/layout/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "@contentful/f36-layout",
"version": "5.0.0-alpha.15",
"version": "5.0.0-alpha.18",
"description": "Forma 36: Layout component",
"scripts": {
"build": "tsup"
},
"dependencies": {
"@contentful/f36-core": "^4.68.1",
"@contentful/f36-header": "^4.69.2",
"@contentful/f36-tokens": "^4.0.5",
"emotion": "^10.0.17"
},
Expand Down
125 changes: 115 additions & 10 deletions packages/components/layout/src/Layout.styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import tokens from '@contentful/f36-tokens';
import { css } from 'emotion';
import type { LayoutProps } from './Layout';
import { HEADER_HEIGHT } from '@contentful/f36-header';
import type { LayoutProps, LayoutSidebarVariant } from './Layout';

const SIDEBAR_WIDTHS: Record<LayoutSidebarVariant, `${number}px`> = {
narrow: '280px',
wide: '340px',
};

//header + offsetTop + 1px border or offsetTop
const getMainOffset = (withHeader: boolean, offsetTop: number) =>
withHeader ? HEADER_HEIGHT + 1 + offsetTop + 'px' : offsetTop + 'px';

export const getLayoutMaxWidthStyles = ({
variant,
Expand All @@ -12,6 +22,7 @@ export const getLayoutMaxWidthStyles = ({
if (variant === 'fullscreen') {
return css({
maxWidth: '100%',
width: '100%',
});
}

Expand All @@ -20,28 +31,122 @@ export const getLayoutMaxWidthStyles = ({
boxShadow: withBoxShadow
? '0px 6px 16px -2px rgba(25, 37, 50, 0.1), 0px 3px 6px -3px rgba(25, 37, 50, 0.15)'
: 'unset',
borderRadius: `10px 10px 0 0`,
margin: `0 ${tokens.spacingM}`,
borderRadius: '10px 10px 0 0',
margin: `0 auto`,
width: `calc(100% - ${tokens.spacingM} * 2)`, // 100% - desired space to the browser border
});
};

const getContentContainerGridTemplateColumns = ({
variant,
withLeftSidebar,
leftSidebarVariant,
withRightSidebar,
rightSidebarVariant,
}: {
variant: LayoutProps['variant'];
withLeftSidebar?: boolean;
leftSidebarVariant?: LayoutSidebarVariant;
withRightSidebar?: boolean;
rightSidebarVariant?: LayoutSidebarVariant;
}) => {
let gridTemplateColumns = 'auto';

if (withLeftSidebar) {
gridTemplateColumns = `${SIDEBAR_WIDTHS[leftSidebarVariant]} auto`;
}

if (withRightSidebar) {
gridTemplateColumns = `auto ${SIDEBAR_WIDTHS[rightSidebarVariant]}`;
}

if (variant !== 'narrow' && withLeftSidebar && withRightSidebar) {
gridTemplateColumns = `${SIDEBAR_WIDTHS[leftSidebarVariant]} auto ${SIDEBAR_WIDTHS[rightSidebarVariant]}`;
}

return css({
gridTemplateColumns: gridTemplateColumns,
});
};

export const getLayoutStyles = ({
variant,
withBoxShadow,
withLeftSidebar,
leftSidebarVariant,
withRightSidebar,
rightSidebarVariant,
offsetTop,
}: {
variant: LayoutProps['variant'];
withBoxShadow?: boolean;
withLeftSidebar?: boolean;
leftSidebarVariant?: LayoutSidebarVariant;
withRightSidebar?: boolean;
rightSidebarVariant?: LayoutSidebarVariant;
offsetTop: number;
}) => ({
root: css({
layoutMainContainer: css(
getLayoutMaxWidthStyles({ variant, withBoxShadow }),
{
backgroundColor: tokens.colorWhite,
minHeight: `calc(100vh - ${offsetTop}px)`,
},
),
layoutContentContainer: css(
getContentContainerGridTemplateColumns({
variant,
withLeftSidebar,
leftSidebarVariant,
withRightSidebar,
rightSidebarVariant,
}),
{
width: '100%',
display: 'grid',
},
),
});

export const getLayoutBodyStyles = (
withHeader: boolean,
offsetTop: number,
) => ({
layoutBodyContainer: css({
width: '100%',
minHeight: '100%',
padding: `${tokens.spacingL} ${tokens.spacingL} 0`,
overflowY: 'auto',
height: `calc(100vh - ${getMainOffset(withHeader, offsetTop)})`,
}),
mainContainer: css(getLayoutMaxWidthStyles({ variant, withBoxShadow }), {
width: '100%',
backgroundColor: tokens.colorWhite,
layoutBodyInner: css({
maxWidth: '900px',
margin: '0 auto',
}),
});

export const getLayoutSidebarStyles = (
withHeader: boolean,
offsetTop: number,
) => ({
layoutSidebar: css({
padding: `${tokens.spacingL} ${tokens.spacingS} 0`,
overflowY: 'auto',
height: `calc(100vh - ${getMainOffset(withHeader, offsetTop)})`,
'&:first-child': {
borderRight: `1px solid ${tokens.gray200}`,
},
'&:last-child': {
borderLeft: `1px solid ${tokens.gray200}`,
},
}),
contentContainer: css({
});

export const getLayoutHeaderStyles = (variant: LayoutProps['variant']) => ({
layoutHeader: css({
borderBottom: `1px solid ${tokens.gray200}`,
padding: `0 ${tokens.spacingL}`,
width: '100%',
minHeight: '200px',
maxWidth: variant === 'fullscreen' ? '100%' : '1920px',
}),
layoutHeaderInner: css({ width: '100%' }),
});
Loading