Skip to content

Commit

Permalink
fix(Header): Fix height when wrapper is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbals committed Jun 11, 2024
1 parent a6d7ed9 commit e87180c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/components/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { StoryFn, Meta } from '@storybook/react';
import { Header } from '.';
import { Box } from '@chakra-ui/react';

export default {
title: 'components/Header',
Expand Down Expand Up @@ -43,7 +44,11 @@ export default {
},
} as Meta<typeof Header>;

const Template: StoryFn<typeof Header> = (args) => <Header {...args} />;
const Template: StoryFn<typeof Header> = (args) => (
<Box height="20" backgroundColor="primary.50">
<Header {...args} />
</Box>
);

export const DefaultProps = Template.bind({});
DefaultProps.args = {};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('The Header component', () => {
it('renders the wrapper if the showWrapper prop is true', () => {
setup({ showWrapper: true });

expect(screen.getByTestId('wrapper')).toBeInTheDocument();
expect(screen.getByText('center')).toBeInTheDocument();
});

it('renders the left prop', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ReactNode } from 'react';
import { Flex } from '@chakra-ui/react';
import { Wrapper } from '../Wrapper';

export interface HeaderProps {
left: ReactNode;
Expand All @@ -17,13 +16,15 @@ export const Header: React.FC<HeaderProps> = ({
hideCenter = false,
showWrapper = false,
}) => {
const Content = (
return (
<Flex
mx={['6', null, null, '8']}
height="100%"
height="full"
flexDir="row"
alignItems="center"
justifyContent="space-between"
maxWidth={showWrapper ? '7xl' : 'full'}
marginX={showWrapper ? 'auto' : ['6', null, null, '8']}
paddingX={showWrapper ? ['6', null, '8'] : undefined}
>
<Flex
width={hideCenter ? '50%' : ['76%', null, null, '24%']}
Expand All @@ -48,5 +49,4 @@ export const Header: React.FC<HeaderProps> = ({
</Flex>
</Flex>
);
return showWrapper ? <Wrapper>{Content}</Wrapper> : Content;
};
8 changes: 1 addition & 7 deletions src/components/Wrapper/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ interface WrapperProps {
children: JSX.Element | JSX.Element[];
}
export const Wrapper: React.FC<WrapperProps> = ({ children }: WrapperProps) => (
<Box
maxWidth="7xl"
marginX="auto"
paddingX={['6', null, '8']}
position="relative"
data-testid="wrapper"
>
<Box maxWidth="7xl" marginX="auto" paddingX={['6', null, '8']} position="relative">
{children}
</Box>
);

0 comments on commit e87180c

Please sign in to comment.