Skip to content

Commit 4ef6ad3

Browse files
committed
fix(layout): fix sidebar trigger position and add collapsible demo
Sidebar was missing position:relative so the absolute-positioned collapse trigger rendered relative to the wrong ancestor.
1 parent 19ff93c commit 4ef6ad3

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

components/layout/demo/sidebar.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<demo>
2+
3+
### Collapsible Sidebar
4+
5+
Use `collapsible` to enable a built-in toggle trigger on the sidebar. Control the collapsed state with `collapsed` and `onCollapse`.
6+
7+
```jsx live
8+
() => {
9+
const { Sidebar, Header, Content } = Layout;
10+
const [collapsed, setCollapsed] = React.useState(false);
11+
12+
const sidebarStyle = {
13+
background: 'rgba(110, 65, 191, 0.84)',
14+
color: '#fff',
15+
textAlign: 'center',
16+
};
17+
18+
const headerStyle = {
19+
background: 'rgba(110, 65, 191, 0.7)',
20+
color: '#fff',
21+
height: '64px',
22+
lineHeight: '64px',
23+
textAlign: 'center',
24+
};
25+
26+
const contentStyle = {
27+
background: 'rgba(110, 65, 191, 0.98)',
28+
color: '#fff',
29+
minHeight: '200px',
30+
lineHeight: '200px',
31+
textAlign: 'center',
32+
};
33+
34+
return (
35+
<Layout>
36+
<Sidebar
37+
style={sidebarStyle}
38+
collapsible
39+
collapsed={collapsed}
40+
onCollapse={setCollapsed}
41+
width={200}
42+
collapsedWidth={60}
43+
>
44+
<div style={{ padding: '16px 0' }}>
45+
{collapsed ? '' : 'Sidebar'}
46+
</div>
47+
</Sidebar>
48+
<Layout>
49+
<Header style={headerStyle}>Header</Header>
50+
<Content style={contentStyle}>Content</Content>
51+
</Layout>
52+
</Layout>
53+
);
54+
}
55+
```
56+
57+
</demo>

components/layout/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Basic from './demo/basic.md'
2+
import Sidebar from './demo/sidebar.md'
23

34
# Layout
45

@@ -23,6 +24,7 @@ const { Header, Footer, Content, Sidebar } = Layout;
2324
## Examples
2425

2526
<Basic />
27+
<Sidebar />
2628

2729

2830
## API

components/layout/style/_index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
box-sizing: border-box;
3434
display: flex;
3535
flex-direction: column;
36+
position: relative;
3637
transition: all 200ms;
3738
background: var(--ty-layout-sidebar-bg);
3839
color: #fff;

0 commit comments

Comments
 (0)