28
loading...
This website collects cookies to deliver better user experience
Components should not know where they are being displayed and Layout components should only be concerned with displaying the component.
import React from 'react';
import styled from 'styled-components';
const Container= styled.div`
display:flex;
`
const Panel= styled.div`
flex:${props=>props.width};
`;
export default const SplitScreen=({Left,Right,leftWidth=1,rightWidth=1})
{
return (
<Container>
<Pane width={leftWidth}>
<Right/>
</Pane>
<Pane width={rightWidth}>
<Right/>
</Pane>
</Container>
)
}
import React from 'react'
import styled from 'styled-component'
const LeftComponent=()=>(
<p style={{backgroundColor:'yellow'}}>Left</p>
)
const RightComponent=()=>(
<p style={{backgroundColor:'red'}}>Right</p>
)
function App (){
return (
<SplitScreen
left={LeftComponent}
right={RightComponent}
leftWidth={1}
rightWidth={2}/>
)
}
export default App;
import React from 'react'
import styled from 'styled-component'
const LeftComponent=({title})=><p style={{backgroundColor:'yellow'}}>{title}</p>
const RightComponent=({title})=><p style={{backgroundColor:'red'}}>{title}</p>
function App (){
return (
<SplitScreen
left={LeftComponent}
right={RightComponent}
leftWidth={1}
rightWidth={2}/>
)
}
export default App;
import React from 'react';
import styled from 'styled-components';
const Container= styled.div`
display:flex;
`
const Panel= styled.div`
flex:${props=>props.width};
`;
export default const SplitScreen=({
Left,
Right,
leftWidth=1,
rightWidth=1,
leftTitle='Left',
rightTitle='Right'})
{
return (
<Container>
<Pane width={leftWidth}>
<Right title={leftTitle/>
</Pane>
<Pane width={rightWidth}>
<Right title={rightTitle}/>
</Pane>
</Container>
)
}
import React from 'react'
import styled from 'styled-component'
const LeftComponent=({title='Left'})=>(
<p style={{backgroundColor:'yellow'}}>{title}</p>)
const RightComponent=({title='Right'})=>(
<p style={{backgroundColor:'red'}}>{title}</p>)
function App (){
return (
<SplitScreen
leftWidth={1}
rightWidth={2}
>
<LeftComponent title={'Left Pane'}/>
<RightComponent title={'Right Panel}/>
</SplitScreen>
)
}
export default App;
import React from 'react';
import styled from 'styled-components';
const Container= styled.div`
display:flex;
`
const Panel= styled.div`
flex:${props=>props.width};
`;
export default const SplitScreen=({leftWidth=1,rightWidth=1,children})
{
const [left,right]= children
return (
<Container>
<Pane width={leftWidth}>
{left}
</Pane>
<Pane width={rightWidth}>
{right}
</Pane>
</Container>
)
}