Skip to content

Commit

Permalink
feat(Drawer): make drawer configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
youluna committed Aug 14, 2019
1 parent 407dc5b commit fbc4ad2
Show file tree
Hide file tree
Showing 13 changed files with 644 additions and 48 deletions.
25 changes: 7 additions & 18 deletions docs/drawer/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Radio, Button, Drawer } from '@alifd/next';
class Demo extends React.Component {
state = {
visible: false,
placement: 'right'
};

onOpen = () => {
Expand All @@ -28,33 +27,23 @@ class Demo extends React.Component {
});
};

onVisibleChange = (visible, reason, e) => {
console.log(reason, visible);

this.setState({
visible
});
};

onPlacementChange = dir => {
onClose = (reason, e) => {
console.log(reason, e);
this.setState({
placement: dir
visible: false
});
}

render() {
return (
<div>
<Radio.Group
dataSource={['right', 'bottom', 'left', 'top']}
defaultValue={'right'}
onChange={this.onPlacementChange}
/> &nbsp;&nbsp;&nbsp;&nbsp;
<Button type="primary" onClick={this.onOpen}> open </Button>
<Drawer
title="标题"
placement="right"
visible={this.state.visible}
placement={this.state.placement}
onVisibleChange={this.onVisibleChange}>
closeable
onClose={this.onClose}>
Start your business here by searching a popular product
</Drawer>
</div>
Expand Down
103 changes: 103 additions & 0 deletions docs/drawer/demo/double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# 双层抽屉

- order: 2

双层抽屉,抽屉内打开新的抽屉

:::lang=en-us
# Basic

- order: 2

Double drawer
:::
---

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

class App extends React.Component {
state = { visible: false, childrenDrawer: false };

showDrawer = () => {
this.setState({
visible: true,
});
};

onClose = () => {
this.setState({
visible: false,
});
};

showChildrenDrawer = () => {
this.setState({
childrenDrawer: true,
});
};

onChildrenDrawerClose = () => {
this.setState({
childrenDrawer: false,
});
};

render() {
return (
<div>
<Button type="primary" onClick={this.showDrawer}>
Open drawer
</Button>
<Drawer
title="Multi-level drawer"
width={520}
closeable={'mask'}
onClose={this.onClose}
visible={this.state.visible}
>
<Button type="primary" onClick={this.showChildrenDrawer}>
Two-level drawer
</Button>
<Drawer
title="Two-level Drawer"
width={320}
closeable={'mask'}
onClose={this.onChildrenDrawerClose}
visible={this.state.childrenDrawer}
>
This is two-level drawer
</Drawer>
<div
style={{
position: 'absolute',
bottom: 0,
width: '100%',
borderTop: '1px solid #e8e8e8',
padding: '10px 16px',
textAlign: 'right',
left: 0,
background: '#fff',
borderRadius: '0 0 4px 4px',
}}
>
<Button
style={{
marginRight: 8,
}}
onClick={this.onClose}
>
Cancel
</Button>
<Button onClick={this.onClose} type="primary">
Submit
</Button>
</div>
</Drawer>
</div>
);
}
}

ReactDOM.render(<App />, mountNode);
````
66 changes: 66 additions & 0 deletions docs/drawer/demo/placement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 自定义弹出方向

- order: 1

自定义弹出方向

:::lang=en-us
# Basic

- order: 1

Diffrent placement
:::
---

````jsx
import { Radio, Button, Drawer } from '@alifd/next';

class Demo extends React.Component {
state = {
visible: false,
placement: 'right'
};

onOpen = () => {
this.setState({
visible: true
});
};

onClose = (reason) => {

this.setState({
visible: false
});
};

onPlacementChange = dir => {
this.setState({
placement: dir
});
}

render() {
return (
<div>
<Radio.Group
dataSource={['right', 'bottom', 'left', 'top']}
defaultValue={'right'}
onChange={this.onPlacementChange}
/> &nbsp;&nbsp;&nbsp;&nbsp;
<Button type="primary" onClick={this.onOpen}> open </Button>
<Drawer
title="标题"
visible={this.state.visible}
placement={this.state.placement}
onClose={this.onClose}>
Start your business here by searching a popular product
</Drawer>
</div>
);
}
}

ReactDOM.render(<Demo />, mountNode);
````
7 changes: 6 additions & 1 deletion docs/drawer/demo/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class Demo extends React.Component {
}

render() {
const drawerProps = {
placement: this.state.placement,
closeable: 'mask',
bodyStyle: {padding: 0}
};
return (
<div>
<Radio.Group
Expand All @@ -49,7 +54,7 @@ class Demo extends React.Component {
onChange={this.onPlacementChange}
/> &nbsp;&nbsp;&nbsp;&nbsp;

<Select id="basic-demo" popupComponent={Drawer} popupProps={{placement: this.state.placement}} autoWidth={false} onChange={onChange} onBlur={onBlur} onToggleHighlightItem={onToggleHighlightItem} defaultValue="jack" aria-label="name is" hasClear>
<Select id="basic-demo" popupComponent={Drawer} popupProps={drawerProps} autoWidth={false} onChange={onChange} onBlur={onBlur} onToggleHighlightItem={onToggleHighlightItem} defaultValue="jack" aria-label="name is" hasClear>
<Option value="jack">Jack</Option>
<Option value="frank">Frank</Option>
<Option value="hugo">Hugo</Option>
Expand Down
8 changes: 5 additions & 3 deletions docs/drawer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@

| 参数 | 说明 | 类型 | 默认值 |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ------- |
| trigger | 触发弹层显示或隐藏的元素 | ReactElement | null |
| triggerType | 触发弹层显示或隐藏的操作类型,可以是 'click','hover','focus',或者它们组成的数组,如 ['hover', 'focus'] | String/Array | 'click' |
| width | 宽度,仅在 placement是 left right 的时候生效 | Number/String | - |
| height | 高度,仅在 placement是 top bottom 的时候生效 | Number/String | - |
| visible | 是否显示 | Boolean | - |
| hasMask | 是否显示遮罩 | Boolean | true |
| closeable | 控制对话框关闭的方式,值可以为字符串或者布尔值,其中字符串是由以下值组成:<br>**mask** 表示点击遮罩区域可以关闭对话框<br>**esc** 表示按下 esc 键可以关闭对话框<br>如 'mask' 或 'esc,mask'<br>如果设置为 true,则以上关闭方式全部生效<br>如果设置为 false,则以上关闭方式全部失效 | String/Boolean | true |
| closeable | 控制对话框关闭的方式,值可以为字符串或者布尔值,其中字符串是由以下值组成:<br>**close** 表示点击关闭按钮可以关闭对话框<br>**mask** 表示点击遮罩区域可以关闭对话框<br>**esc** 表示按下 esc 键可以关闭对话框<br>如 'close' 或 'close,esc,mask'<br>如果设置为 true,则以上关闭方式全部生效<br>如果设置为 false,则以上关闭方式全部失效 | String/Boolean | true |
| placement | 位于页面的位置<br><br>**可选值**:<br>'top', 'right', 'bottom', 'left' | Enum | 'right' |
| title | 标题 | ReactNode | - |
| onVisibleChange | 弹层显示或隐藏时触发的回调<br><br>**签名**:<br>Function(visible: Boolean, type: String) => void<br>**参数**:<br>_visible_: {Boolean} 弹层是否显示<br>_type_: {String} 触发弹层显示或隐藏的来源 fromContent 表示由Dropdown内容触发; fromTrigger 表示由trigger的点击触发; docClick 表示由document的点击触发 | Function | - |
| animation | 显示隐藏时动画的播放方式 | Object/Boolean | - |
| bodyStyle | body上的样式 | Object | - |

## ARIA and Keyboard

Expand Down
129 changes: 129 additions & 0 deletions docs/drawer/theme/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import '../../../src/demo-helper/style.js';
import '../../../src/drawer/style.js';
import { Demo, DemoGroup, initDemo } from '../../../src/demo-helper';
import Drawer from '../../../src/drawer';

import zhCN from '../../../src/locale/zh-cn';
import enUS from '../../../src/locale/en-us';

const i18nMaps = {
'en-us': {
title: 'Title Here',
content: 'Start your business here by searching a popular product',
},

'zh-cn': {
title: '这里是标题',
content: '开启您的贸易生活从 Alibaba.com 开始',
}
};

class FunctionDemo extends Component {
state = {
demoFunction: {
hasTitle: {
label: '标题',
value: 'true',
enum: [{
label: '显示',
value: 'true'
}, {
label: '隐藏',
value: 'false'
}]
},
hasCloseIcon: {
label: '有无关闭按钮',
value: 'true',
enum: [{
label: '有',
value: 'true'
}, {
label: '无',
value: 'false'
}]
},
placement: {
label: '方向',
value: 'right',
enum: [{
label: '上',
value: 'top'
}, {
label: '下',
value: 'bottom'
}, {
label: '左',
value: 'left'
}, {
label: '右',
value: 'right'
}]
},
}
}
onFunctionChange = demoFunction => {
this.setState({
demoFunction
});
}

renderMask(hasMask, content) {
return hasMask ? (
<div className="next-overlay-wrapper opened" style={{ position: 'relative', width: 440, height: 300 }}>
<div className="next-overlay-backdrop" style={{ position: 'relative' }} />
{content}
</div>
) : content;
}

render() {
// eslint-disable-next-line
const { lang, i18n } = this.props;
const locale = (lang === 'en-us' ? enUS : zhCN).Drawer;
const hasTitle = this.state.demoFunction.hasTitle.value === 'true';
const hasCloseIcon = this.state.demoFunction.hasCloseIcon.value === 'true';

const placement = this.state.demoFunction.placement.value;
const style = {
position: 'absolute',
top: placement === 'bottom' ? 'auto' : 0,
[placement]: 0,
};

const normalContent = (
<Drawer.Inner
style={style}
placement={placement}
closeable={hasCloseIcon}
title={hasTitle ? i18n.title : null}
locale={locale}>
{i18n.content}
</Drawer.Inner>
);

return (
<div className="demo-container">
<Demo title="Drawer" demoFunction={this.state.demoFunction} onFunctionChange={this.onFunctionChange}>
<Demo title="Normal">
<DemoGroup label="Align">
{this.renderMask(true, normalContent)}
</DemoGroup>
</Demo>
</Demo>
</div>
);
}
}


const render = (lang = 'en-us') => {
const i18n = i18nMaps[lang];
ReactDOM.render(<FunctionDemo lang={lang} i18n={i18n} />, document.getElementById('container'));
};

window.renderDemo = render;
window.renderDemo('en-us');
initDemo('drawer');
Loading

0 comments on commit fbc4ad2

Please sign in to comment.