-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Drawer): make drawer configurable
- Loading branch information
Showing
13 changed files
with
644 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
<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); | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Oops, something went wrong.