简体   繁体   English

material-ui抽屉位置

[英]material-ui Drawer position

just recently I got involved in a new project that required me to put my hands on JS, React and Material-UI so apologies in advance if my question won't be precise enough. 就在最近,我参与了一个新项目,该项目要求我亲自处理JS,React和Material-UI,因此如果我的问题不够精确,请提前道歉。

I want to replace a module done with jquery that is handling a "drawer" that is opened from the footer with a tabber, once clicked on the items in the tabber the drawer go up from the footer and it gives to the user that specific react component rendered into the drawer. 我想替换一个用jquery完成的模块,该模块处理的是用Tabber从页脚中打开的“抽屉”,一旦单击Taber中的项目,抽屉就会从页脚上移,它给用户特定的反应组件渲染到抽屉中。

I would like to replace this element with a react component and thought about using material-ui for this, http://www.material-ui.com/#/components/drawer , so I would like to modify the drawer to came out from the bottom and not from the left. 我想用react组件替换此元素,并考虑使用为此的material-ui http://www.material-ui.com/#/components/drawer ,所以我想修改抽屉以使其出来从底部而不是从左侧开始。 Can someone more expert suggest how would you approach this? 有人可以建议您如何处理吗?

Thanks! 谢谢!

PS: I already know I can surf the web and find a component with a similar behaviour, this task is more a way to get familiar with JS and react. PS:我已经知道我可以在网上冲浪并找到具有类似行为的组件,此任务更多是一种熟悉JS并做出反应的方法。

PPS: Currently the project relies on material-ui v0.20.0, I already saw that there is an example in the v1.+ beta release as suggested by eskers PPS:当前该项目依赖于Material-ui v0.20.0,我已经看到eskers建议在v1。+ beta版本中有一个示例

Edit 编辑

After have spent a bit of time I created my own component, in case someone will need this, below my code. 花了一段时间后,我创建了自己的组件,以防万一有人在我的代码下面需要它。

 define(function (require) { var React = require('react'); var DrawerButton = require('./DrawerButton'); require('./TabbedDrawer.less'); class TabbedDrawer extends React.Component { constructor(props) { super(props); this.state = { drawerOpened: false, buttonSelected: null, drawerHeight: 0 } this.openDrawer = this.openDrawer.bind(this); this.renderMyLabels = this.renderMyLabels.bind(this); } renderMyLabels() { var renderedLabels = this.props.labels.map(function(label, _key) { return ( <DrawerButton functionDrawer={this.openDrawer} labelKey={_key} buttonSelected={this.state.buttonSelected} drawerOpened={this.state.drawerOpened}> {label} </DrawerButton> ); }, this); return renderedLabels; } openDrawer(buttonClicked) { if(this.state.drawerOpened && (buttonClicked == this.state.buttonSelected)) { this.setState({buttonSelected: null, drawerOpened: !this.state.drawerOpened}); } else if(this.state.drawerOpened && (buttonClicked != this.state.buttonSelected)) { this.setState({buttonSelected: buttonClicked}); } else { this.setState({buttonSelected: buttonClicked, drawerOpened: !this.state.drawerOpened}); } } render() { const ElementToRender = (this.state.buttonSelected !== null) ? this.props.children[this.state.buttonSelected] : null; const myElement = (ElementToRender !== null) ? <ElementToRender /> : ""; const drawerStyle = this.state.drawerOpened ? {display: 'block'} : {display: 'none'}; const tabStyle = this.state.drawerOpened ? {bottom: '250px'} : {bottom: '0px'}; return ( <div id="geppettoDrawer"> <span id="tabber" style={tabStyle}> {this.renderMyLabels()} </span> <div id="drawer" style={drawerStyle}> <div className="topLine" > </div> {myElement} </div> </div> ); } } return TabbedDrawer; }); 
 @import "./../../../../style/less/components/colors"; @-webkit-keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } #geppettoDrawer { display: inline-block; } #tabber { -webkit-animation: fadeIn 1s; animation: fadeIn 1s; border-bottom: 0.5px solid rgb(252, 99, 32); width: 100%; display: block; margin-top: 0px; text-decoration: none; left: 0; bottom: 0; position: absolute; background: transparent; } #tabButton { color: @primary_color; margin: 0 auto; margin-bottom: 26px; position: relative; border-color: rgb(252, 99, 32); border: 0.5px; border-bottom: 0px; border-style: solid; box-shadow: none; text-shadow: none; width: 140px; height: 35px; padding: 7px 20px; text-align: center; display: inline-block; cursor: pointer!important; background: rgba(50, 50, 53, 0.8); } #drawer { -webkit-animation: fadeIn 1s; animation: fadeIn 1s; height: 250px; width: 100%; background-color: black; color: white; position: fixed; bottom: 0px; left: 0px; display: none; transition: opacity 1s ease-out; -webkit-animation: fadeIn 1s; animation: fadeIn 1s; background: rgba(50, 50, 53, 0.8); } #drawer.topLine { border-top: solid rgb(243, 250, 247); /* 1px for the "border" size */ cursor: n-resize; resize: horizontal; } 

 define(function (require) { var React = require('react'); require('./TabbedDrawer.less'); class DrawerButton extends React.Component { constructor(props) { super(props); this.state = { mouseOver: false, buttonActived: false} this.activeButton = this.activeButton.bind(this); this.overButton = this.overButton.bind(this); this.outButton = this.outButton.bind(this); } activeButton() { if((this.props.labelKey === this.props.buttonSelected) && this.props.drawerOpened) this.setState({buttonActived: true, mouseOver: false}); else this.setState({buttonActived: false, mouseOver: false}); this.props.functionDrawer(this.props.labelKey); } overButton() { if((this.state.buttonActived === false)) this.setState({mouseOver: true}); } outButton() { if(!this.props.drawerOpened) this.setState({buttonActived: false}); if((this.state.buttonActived === false)) this.setState({mouseOver: false}); } render() { if(this.props.labelKey === this.props.buttonSelected) { var buttonStyle = {background: 'rgba(252, 99, 32, 0.8)', color: 'rgba(50, 50, 53)'}; } else { var buttonStyle = (this.state.mouseOver) ? {background: 'rgba(252, 99, 32, 0.8)', color: 'rgba(50, 50, 53)'} : {background: 'rgba(50, 50, 53, 0.8)', color: 'rgba(252, 99, 32)'}; } return ( <span id="tabButton" onClick={this.activeButton} onMouseOver={this.overButton} onMouseOut={this.outButton} style={buttonStyle}> {this.props.children} </span> ); } } return DrawerButton; }) 

If the goal is to get more familiar with JS and React, I would just build a bunch of different things with it, no better way to learn imo. 如果目标是更加熟悉JS和React,我将用它构建许多不同的东西,没有更好的学习imo的方法。 Are you locked into using an older version of Material-UI? 您是否被锁定使用旧版本的Material-UI? In v1.+ there is an example that will do just that for you. 在v1。+中,有一个示例可以为您完成此操作。 Please see the following link https://material-ui-next.com/demos/drawers/ 请查看以下链接https://material-ui-next.com/demos/drawers/

best of luck 祝你好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM