Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
🐲 boss :compatible layout props (#528)
Browse files Browse the repository at this point in the history
* ?? :compatible layout props

* fix test

* bugfix
  • Loading branch information
chenshuai2144 authored Jul 2, 2020
1 parent 6d965c1 commit 4a993e8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/demo/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default () => {
{...defaultProps}
style={{
height: 800,
maxHeight: '100vh',
}}
location={{
pathname,
Expand Down
9 changes: 6 additions & 3 deletions src/BasicLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import PageLoading from './PageLoading';
import MenuCounter from './SiderMenu/Counter';
import WrapContent from './WrapContent';
import { useDocumentTitle } from './utils/hooks';
import compatibleLayout from './utils/compatibleLayout';

export type BasicLayoutProps = Partial<RouterTypes<Route>> &
SiderMenuProps &
Expand Down Expand Up @@ -197,10 +198,10 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
fixSiderbar,
navTheme,
contentStyle,
layout: PropsLayout,
route = {
routes: [],
},
layout: defaultPropsLayout,
style,
disableContentMargin,
siderWidth = 208,
Expand All @@ -210,6 +211,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
loading,
...rest
} = props;
const propsLayout = compatibleLayout(defaultPropsLayout);
const { prefixCls } = rest;
const formatMessage = ({
id,
Expand Down Expand Up @@ -290,7 +292,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {

// If it is a fix menu, calculate padding
// don't need padding in phone mode
const hasLeftPadding = fixSiderbar && PropsLayout !== 'top' && !isMobile;
const hasLeftPadding = fixSiderbar && propsLayout !== 'top' && !isMobile;

const [collapsed, onCollapse] = useMergeValue<boolean>(false, {
value: props.collapsed,
Expand All @@ -303,6 +305,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
...props,
formatMessage,
breadcrumb,
layout: compatibleLayout(props.layout) as 'side',
},
['className', 'style'],
);
Expand Down Expand Up @@ -373,7 +376,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
baseClassName,
{
[`screen-${colSize}`]: colSize,
[`${baseClassName}-top-menu`]: PropsLayout === 'top',
[`${baseClassName}-top-menu`]: propsLayout === 'top',
[`${baseClassName}-is-children`]: isChildrenLayout,
[`${baseClassName}-fix-siderbar`]: fixSiderbar,
[`${baseClassName}-mobile`]: isMobile,
Expand Down
14 changes: 14 additions & 0 deletions src/utils/compatibleLayout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const compatibleLayout = (
layout?: 'side' | 'top' | 'mix' | 'sidemenu' | 'topmenu',
) => {
if (!layout) {
return layout;
}
const layoutEnum = ['sidemenu', 'topmenu'];
if (layoutEnum.includes(layout)) {
return layout.replace('menu', '');
}
return layout;
};

export default compatibleLayout;
12 changes: 6 additions & 6 deletions tests/__tests__/__snapshots__/settingDrawer.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ exports[`settingDrawer.test base user 1`] = `
>
<span
aria-label="down"
class="anticon anticon-down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
Expand Down Expand Up @@ -750,7 +750,7 @@ exports[`settingDrawer.test hideColors = true 1`] = `
>
<span
aria-label="down"
class="anticon anticon-down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
Expand Down Expand Up @@ -1349,7 +1349,7 @@ exports[`settingDrawer.test hideCopyButton = true 1`] = `
>
<span
aria-label="down"
class="anticon anticon-down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
Expand Down Expand Up @@ -1920,7 +1920,7 @@ exports[`settingDrawer.test hideHintAlert = true 1`] = `
>
<span
aria-label="down"
class="anticon anticon-down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
Expand Down Expand Up @@ -2485,7 +2485,7 @@ exports[`settingDrawer.test hideLoading = true 1`] = `
>
<span
aria-label="down"
class="anticon anticon-down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
Expand Down Expand Up @@ -3084,7 +3084,7 @@ exports[`settingDrawer.test settings = undefined 1`] = `
>
<span
aria-label="down"
class="anticon anticon-down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
Expand Down
33 changes: 33 additions & 0 deletions tests/__tests__/compatible.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { mount, render } from 'enzyme';

import React from 'react';
import BasicLayout from '../../src/BasicLayout';
import { waitForComponentToPaint } from './util';

beforeAll(() => {
Object.defineProperty(window, 'matchMedia', {
value: jest.fn(() => ({
matches: false,
addListener() {},
removeListener() {},
})),
});
});

it('🐲 layout=sidemenu', async () => {
// @ts-expect-error
const wrapper = mount(<BasicLayout layout="sidemenu" />);
await waitForComponentToPaint(wrapper);
const menu = wrapper.find('.ant-pro-sider-menu');
expect(menu.exists()).toBe(true);
wrapper.unmount();
});

it('🐲 layout=topmenu', async () => {
// @ts-expect-error
const wrapper = mount(<BasicLayout layout="topmenu" />);
await waitForComponentToPaint(wrapper);
const menu = wrapper.find('.ant-pro-sider-menu');
expect(menu.exists()).toBe(false);
wrapper.unmount();
});

0 comments on commit 4a993e8

Please sign in to comment.