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

[7.x] [Enterprise Search] Add flag to restrict width of layout (#77539) #77552

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';
import { shallow } from 'enzyme';
import { EuiPageSideBar, EuiButton } from '@elastic/eui';
import { EuiPageSideBar, EuiButton, EuiPageBody } from '@elastic/eui';

import { Layout, INavContext } from './layout';

Expand All @@ -15,6 +15,13 @@ describe('Layout', () => {
const wrapper = shallow(<Layout navigation={null} />);

expect(wrapper.find('.enterpriseSearchLayout')).toHaveLength(1);
expect(wrapper.find(EuiPageBody).prop('restrictWidth')).toBeFalsy();
});

it('passes the restrictWidth prop', () => {
const wrapper = shallow(<Layout navigation={null} restrictWidth />);

expect(wrapper.find(EuiPageBody).prop('restrictWidth')).toEqual(true);
});

it('renders navigation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import './layout.scss';

interface ILayoutProps {
navigation: React.ReactNode;
restrictWidth?: boolean;
}

export interface INavContext {
closeNavigation(): void;
}
export const NavContext = React.createContext({});

export const Layout: React.FC<ILayoutProps> = ({ children, navigation }) => {
export const Layout: React.FC<ILayoutProps> = ({ children, navigation, restrictWidth }) => {
const [isNavOpen, setIsNavOpen] = useState(false);
const toggleNavigation = () => setIsNavOpen(!isNavOpen);
const closeNavigation = () => setIsNavOpen(false);
Expand Down Expand Up @@ -54,7 +55,9 @@ export const Layout: React.FC<ILayoutProps> = ({ children, navigation }) => {
</div>
<NavContext.Provider value={{ closeNavigation }}>{navigation}</NavContext.Provider>
</EuiPageSideBar>
<EuiPageBody className="enterpriseSearchLayout__body">{children}</EuiPageBody>
<EuiPageBody className="enterpriseSearchLayout__body" restrictWidth={restrictWidth}>
{children}
</EuiPageBody>
</EuiPage>
);
};