简体   繁体   English

如何水平折叠react-bootstrap手风琴面板?

[英]How to collapse react-bootstrap accordion panel horizontally?

I am working with the Panel component from React-Bootstrap page here - https://react-bootstrap.github.io/components/panel/ - and i would like to use their accordion feature with the caveat that the panel body's (Panel.Body) opens horizontally (open to the right of the Panel.Headings that are shown). -我从阵营,引导页面在这里面板组件工作https://react-bootstrap.github.io/components/panel/ -我想用自己的手风琴功能需要提醒的是面板主体的(面板。主体)水平打开(在面板右侧打开。显示标题)。

Here is one of the examples from their page: 这是他们页面中的示例之一:

 const PanelGroup = ReactBootstrap.PanelGroup; const Panel = ReactBootstrap.Panel; class App extends React.Component { constructor(props) { super(props); } render() { return ( <PanelGroup accordion id="accordion-uncontrolled-example"> <Panel style={{ display: 'flex' }} eventKey="1"> <Panel.Heading style={{ margin: '0 2% 0 0' }}> <Panel.Title toggle>Panel heading 1</Panel.Title> </Panel.Heading> <Panel.Body collapsible> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </Panel.Body> </Panel> <Panel style={{ display: 'flex' }} eventKey="2"> <Panel.Heading style={{ margin: '0 2% 0 0' }}> <Panel.Title toggle>Panel heading 2</Panel.Title> </Panel.Heading> <Panel.Body collapsible> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </Panel.Body> </Panel> <Panel style={{ display: 'flex' }} eventKey="3"> <Panel.Heading style={{ margin: '0 2% 0 0' }}> <Panel.Title toggle>Panel heading 3</Panel.Title> </Panel.Heading> <Panel.Body collapsible> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </Panel.Body> </Panel> </PanelGroup> ) } } ReactDOM.render( < App / > , document.getElementById('root') ); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.32.1/react-bootstrap.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <div id='root'> Come On Work! </div> 

I have added display: flex to wrap the panels, although I am not getting the desired layout here. 我添加了display: flex来包裹面板,尽管我在这里没有得到想要的布局。 Rather than extending inline, with the body having the same vertical flush as its own heading, I would like it if the panel was always vertically flush with Panel Heading 1, regardless of which panel it was that was clicked open. 不是延伸的在线,与具有相同的垂直齐平作为它自己的标题中的身体,我想它如果面板总是垂直齐平面板标题1,无论哪个面板是那一个被点击打开。

Additionally, I would like for the Panel Heading to remain the same width, rather than crunch up to a very small width, when the panel is opened. 另外,我希望面板标题在打开面板时保持相同的宽度,而不是缩小到非常小的宽度。

Clearly I'm not sure if react-bootstrap Panel component is the right tool for this, or if i should create my own custom horizontal accordion tool (not quite sure how to do that though). 显然,我不确定React-Bootstrap面板组件是否适合此工具,或者我是否应该创建自己的自定义水平手风琴工具(虽然不太确定该怎么做)。 That is part of what I am asking as well! 这也是我要问的一部分!

Thanks as always for any help. 与往常一样感谢您的帮助。

well created this working snippet where the panels work like in react-bootstrap examples. 很好地创建了这个工作片段,其中面板的工作方式类似于react-bootstrap示例。

But not sure if I understand what exactly you look for visually? 但是不确定我是否能理解您在视觉上的确切需求?

you want instead of slide down effect when toggling to have a slide right? 您想要在切换幻灯片时获得滑倒效果而不是滑倒效果吗?

how exactly? 到底如何 you have the panel title as a block so where the content will fit in? 您将面板标题作为一个块,以便将内容放在哪里?

 const PanelGroup = ReactBootstrap.PanelGroup; const Panel = ReactBootstrap.Panel; class PanelHorizontal extends React.Component { constructor(props) { super(props); this.state = { visible: false } } render() { const classesNames = ['panelHorizontal']; if (this.state.visible){ classesNames.push('slideIn'); } else { classesNames.push('slideOut'); } return ( <div> <h1 className="title" onClick={()=>this.setState({visible: !this.state.visible})} >click to toggle</h1> <div className={classesNames.join(' ')}> content here </div> </div> ); }; } class App extends React.Component { constructor(props) { super(props); } render() { return ( <PanelHorizontal /> ) } } ReactDOM.render( < App / > , document.getElementById('root') ); 
 .panelHorizontal { width: 220px; transform: translateX(-220px); transition: transform 400ms ease-in; } .panelHorizontal.slideIn { transform: translateX(0); } .panelHorizontal.slideOut { transform: translateX(-220px); } .title { cursor: pointer; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.32.1/react-bootstrap.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <div id='root'> Come On Work! </div> 

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

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