Skip to content

Commit

Permalink
feat(Overlay): v2 fix #3070,#3054,#2797,#2689,#2606,#2598,#2533,#2500,#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bindoon committed Oct 20, 2021
1 parent 79397c4 commit 1c80409
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 39 deletions.
7 changes: 5 additions & 2 deletions docs/overlay/demo/backdrop.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# 遮罩层

- order: 1

- debug: true

带有遮罩的弹层。

:::lang=en-us
Expand Down Expand Up @@ -47,7 +48,9 @@ class Demo extends React.Component {
}}>
Open
</Button>
<Overlay visible={this.state.visible}
<Overlay
v2
visible={this.state.visible}
safeNode={() => this.btn}
align="cc cc"
hasMask
Expand Down
4 changes: 3 additions & 1 deletion docs/overlay/demo/baisc.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class Demo extends React.Component {
}}>
Toggle visible
</Button>
<Overlay visible={this.state.visible}
<Overlay
v2
visible={this.state.visible}
target={() => this.btn}
safeNode={() => this.btn}
onRequestClose={this.onClose}>
Expand Down
12 changes: 9 additions & 3 deletions docs/overlay/demo/controlled.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class Demo extends React.Component {
return (
<div>
<div>
<Popup trigger={<Button>Open</Button>}
<Popup
v2
trigger={<Button>Open</Button>}
triggerType="click"
visible={this.state.visible}
onVisibleChange={this.onVisibleChange}>
Expand All @@ -55,7 +57,9 @@ class Demo extends React.Component {
</div>
<br />
<div>
<Popup trigger={<Button style={{"marginRight": "50px"}} ref={ref => {this.btn1 = ref;}}>Paired Popup 1</Button>}
<Popup
v2
trigger={<Button style={{"marginRight": "50px"}} ref={ref => {this.btn1 = ref;}}>Paired Popup 1</Button>}
triggerType="click"
visible={this.state.groupVisible}
safeNode={[() => this.btn2, () => this.overlay2]}
Expand All @@ -64,7 +68,9 @@ class Demo extends React.Component {
Hello World From Popup!
</span>
</Popup>
<Popup trigger={<Button ref={ref => {this.btn2 = ref;}}>Paired Popup 2</Button>}
<Popup
v2
trigger={<Button ref={ref => {this.btn2 = ref;}}>Paired Popup 2</Button>}
triggerType="click"
visible={this.state.groupVisible}
safeNode={[() => this.btn1, () => this.overlay1]}
Expand Down
4 changes: 2 additions & 2 deletions docs/overlay/demo/nested.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import { Overlay, Button } from '@alifd/next';
const { Popup } = Overlay;

ReactDOM.render(
<Popup trigger={<Button>Open first overlay</Button>}
<Popup v2 trigger={<button>Open first overlay</button>}
triggerType="click">
<div className="overlay-demo">
<Popup trigger={<Button>Open second overlay</Button>}
<Popup v2 trigger={<button>Open second overlay</button>}
triggerType="click"
container={trigger => trigger.parentNode}>
<div className="overlay-demo">
Expand Down
4 changes: 2 additions & 2 deletions docs/overlay/demo/popup.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const { Popup } = Overlay;

ReactDOM.render(
<div>
<Popup trigger={<Button>Open</Button>} triggerType="click">
<Popup v2 trigger={<Button>Open</Button>} triggerType="click">
<span className="overlay-demo">
Hello World From Popup!
</span>
</Popup>
<br />
<br />
<Popup trigger={<Input placeholder="Use Down Arrow to open" />} triggerType="click" triggerClickKeycode={40}>
<Popup v2 trigger={<Input placeholder="Use Down Arrow to open" />} triggerType="click" triggerClickKeycode={40}>
<span className="overlay-demo">
Hello World From Popup!
</span>
Expand Down
70 changes: 70 additions & 0 deletions docs/overlay/demo/scroll-position.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 弹层自动跟随滚动

- order: 7

如果弹层显示隐藏的触发元素所在容器有滚动条,弹窗会自动更新自己的位置跟随滚动。但是实时更新会消耗较大的计算,可以通过更好挂载容器到父节点获得更好性能

:::lang=en-us
# Overlay follows the container scroll

- order: 7

The overlay defaults to absolute positioning with reference to document.body. If the overlay trigger element's container (usually the parent node) has a scrollbar, then when the container is scrolled, the trigger element can be scroll autoly
:::


---

````jsx
import { useState } from 'react';
import { Overlay, Button } from '@alifd/next';

const { Popup } = Overlay;

const style = {
width: 400,
height: 100,
padding: 10,
background: '#fff',
borderRadius: 2,
boxShadow: '2px 2px 20px rgba(0, 0, 0, 0.15)'
};

const App = () => {
const [position, setPosition] = useState({});
const [position2, setPosition2] = useState({});

return <div style={{
position: 'relative',
height: 150,
padding: 50,
border: '1px solid #eee',
overflow: 'auto',
}}>
<Popup
v2 cache
overlay={<div style={style}>transform: {JSON.stringify(position)}</div>}
onPosition={(result) => {
const {style} = result;
console.log(result);
setPosition(style);
}}
>
<button style={{marginTop: 10}}>Open1</button>
</Popup>
<br/>
<Popup
v2
overlay={<div style={style}>transform: {JSON.stringify(position2)}</div>}
onPosition={({style}) => {
setPosition2(style);
}}
>
<button style={{marginTop: 200}}>Open2</button>
</Popup>
<div style={{ height: 300, width: 1200 }} />
</div>
}

ReactDOM.render( <App/>, mountNode);
````
8 changes: 5 additions & 3 deletions docs/overlay/demo/scroll.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# 弹层跟随滚动
# 更换弹窗挂载容器

- order: 7

弹层默认参照 `document.body` 绝对定位,如果弹层显示隐藏的触发元素所在容器(一般为父节点)有滚动条,那么当容器滚动时,会发生触发元素与弹层相分离的情况,解决的办法是将弹层渲染到触发元素所在的容器中。(触发元素所在的容器,必须设置 `position` 样式,以完成弹层的绝对定位。)
遇到有父元素有 overflow 滚动的情况,可以通过更换弹窗的挂载容器到父节点,获得更好性能。



:::lang=en-us
# Overlay follows the container scroll
Expand Down Expand Up @@ -36,7 +38,7 @@ ReactDOM.render(

````css
.overlay-demo {
width: 300px;
width: 400px;
height: 100px;
padding: 10px;
border: 1px solid #eee;
Expand Down
12 changes: 5 additions & 7 deletions docs/overlay/demo/trigger-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ Use `triggerType` prop.
---

````jsx
import { Overlay, Button, Input } from '@alifd/next';
import { Overlay } from '@alifd/next';

const { Popup } = Overlay;

const style ={ marginLeft: 10}
ReactDOM.render(
<div>
<Popup trigger={<Button>click</Button>} triggerType="click">
<Popup v2 trigger={<button style={style}>click</button>} triggerType="click">
<span className="overlay-demo">
Click to open Popup!
</span>
</Popup>
<Popup trigger={<Button>hover</Button>} triggerType="hover">
<Popup v2 trigger={<button style={style}>hover</button>} triggerType="hover">
<span className="overlay-demo">
Hover to open Popup!
</span>
</Popup>
<Popup trigger={<Button>focus</Button>} triggerType="focus">
<Popup v2 trigger={<button style={style}>focus</button>} triggerType="focus" autoFocus={false}>
<span className="overlay-demo">
Focus to open Popup!
</span>
Expand All @@ -49,7 +50,4 @@ ReactDOM.render(
background: #FFFFFF;
box-shadow: 2px 2px 20px rgba(0,0,0,0.15);
}
.next-btn:not(last-child) {
margin-right: 20px;
}
````
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@alifd/doc-parser": "^1.0.0",
"@alifd/dts-generator": "^1.0.3",
"@alifd/eslint-config-next": "^2.0.0",
"@alifd/overlay": "^0.1.7",
"@alifd/sass-mapper": "^2.0.2",
"@alifd/sass-tracker": "^0.1.0",
"@alifd/sassdoc-parser": "^2.0.0",
Expand Down Expand Up @@ -217,8 +218,8 @@
"react-dev-utils": "^4.2.1",
"react-dnd": "^7.0.0",
"react-dnd-html5-backend": "^7.0.0",
"react-draggable": "^4.4.4",
"react-dom": "^16.0.0",
"react-draggable": "^4.4.4",
"react-live": "^2.2.3",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
Expand Down
24 changes: 14 additions & 10 deletions src/animate/overlay-animate.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState } from 'react';
import { Transition } from 'react-transition-group';
import classNames from '_classnames@2.3.1@classnames';

const OverlayAnimate = props => {
const OverlayAnimate = React.forwardRef((props, ref) => {
const { animation, visible, children, timeout = 300, ...others } = props;

const animationMap = typeof animation === 'string' ? { in: animation, out: animation } : animation;
Expand All @@ -19,17 +20,20 @@ const OverlayAnimate = props => {
return (
<Transition {...others} in={visible} timeout={animation ? timeout : 0} appear>
{state => {
if (state in animateClsMap && animateClsMap[state]) {
let cls = animateClsMap[state];
if (children.props && children.props.className) {
cls = children.props.className + ' ' + animateClsMap[state];
}
return React.cloneElement(children, { className: cls });
}
return children;
const cls = classNames({
[children.props.className]: !!children.props.className,
[animateClsMap[state]]: state in animateClsMap && animateClsMap[state],
});

const childProps = {
className: cls,
ref,
};

return React.cloneElement(children, childProps);
}}
</Transition>
);
};
});

export default OverlayAnimate;
32 changes: 30 additions & 2 deletions src/overlay/index.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
import React from 'react';
import ConfigProvider from '../config-provider';
import Overlay from './overlay';

import Overlay1 from './overlay';
import Overlay2 from './overlay-v2';

import Gateway from './gateway';
import Position from './position';
import Popup from './popup';

import Popup1 from './popup';
import Popup2 from './popup-v2';

class Overlay extends React.Component {
render() {
const { v2, ...others } = this.props;
if (v2) {
return <Overlay2 {...others} />;
} else {
return <Overlay1 {...others} />;
}
}
}
// eslint-disable-next-line
class Popup extends React.Component {
render() {
const { v2, ...others } = this.props;
if (v2) {
return <Popup2 {...others} />;
} else {
return <Popup1 {...others} />;
}
}
}

Overlay.Gateway = Gateway;
Overlay.Position = Position;
Expand Down

0 comments on commit 1c80409

Please sign in to comment.