From 3b6dc3f3c40a5dd59be40698916ce61382efa294 Mon Sep 17 00:00:00 2001 From: ddcat1115 Date: Thu, 28 Sep 2017 17:28:49 +0800 Subject: [PATCH] revert wrong code removing fd40643c2d53dbf108a4944982a30ef728aa3217 --- components/layout/Sider.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/components/layout/Sider.tsx b/components/layout/Sider.tsx index 49165af58f83..2a9c96056cb5 100644 --- a/components/layout/Sider.tsx +++ b/components/layout/Sider.tsx @@ -1,9 +1,33 @@ +// matchMedia polyfill for +// https://github.com/WickyNilliams/enquire.js/issues/82 +if (typeof window !== 'undefined') { + const matchMediaPolyfill = (mediaQuery: string): MediaQueryList => { + return { + media: mediaQuery, + matches: false, + addListener() { + }, + removeListener() { + }, + }; + }; + window.matchMedia = window.matchMedia || matchMediaPolyfill; +} + import React from 'react'; import classNames from 'classnames'; import omit from 'omit.js'; import PropTypes from 'prop-types'; import Icon from '../icon'; +const dimensionMap = { + xs: '480px', + sm: '768px', + md: '992px', + lg: '1200px', + xl: '1600px', +}; + export interface SiderProps { style?: React.CSSProperties; prefixCls?: string; @@ -40,6 +64,13 @@ export default class Sider extends React.Component { constructor(props) { super(props); + let matchMedia; + if (typeof window !== 'undefined') { + matchMedia = window.matchMedia; + } + if (matchMedia && props.breakpoint && props.breakpoint in dimensionMap) { + this.mql = matchMedia(`(max-width: ${dimensionMap[props.breakpoint]})`); + } let collapsed; if ('collapsed' in props) { collapsed = props.collapsed;