Overview
Layout: Layout containers. You can nestHeaderSiderContentFooterorLayoutitself inside.Header: Head component, can only be used insideLayout.Sider: Sidebar, can only be used insideLayout.Content: Content component, can only be used insideLayout.Footer: Footer component, can only be used insideLayout.
Demos
How to import
import { Layout } from '@fibrous/semi-ui-react';
Three-section Layout
Code
import { Layout } from '@fibrous/semi-ui-react';
export default function LayoutDemo() {
const { Header, Footer, Content } = Layout;
const commonStyle = {
height: 64,
lineHeight: '64px',
background: 'var(--semi-color-fill-0)',
};
return (
<Layout className="components-layout-demo">
<Header style={commonStyle}>Header</Header>
<Content style={{ height: 300, lineHeight: '300px' }}>Content</Content>
<Footer style={commonStyle}>Footer</Footer>
</Layout>
);
}Left-sidebar Layout
Code
import { Layout } from '@fibrous/semi-ui-react';
export default function LayoutDemo() {
const { Header, Footer, Sider, Content } = Layout;
const commonStyle = {
height: 64,
lineHeight: '64px',
background: 'var(--semi-color-fill-0)',
};
return (
<Layout className="components-layout-demo">
<Header style={commonStyle}>Header</Header>
<Layout>
<Sider style={{ width: '120px', background: 'var(--semi-color-fill-2)' }}>Sider</Sider>
<Content style={{ height: 300, lineHeight: '300px' }}>Content</Content>
</Layout>
<Footer style={commonStyle}>Footer</Footer>
</Layout>
);
}Right-sidebar Layout
Code
import { Layout } from '@fibrous/semi-ui-react';
export default function LayoutDemo() {
const { Header, Footer, Sider, Content } = Layout;
const commonStyle = {
height: 64,
lineHeight: '64px',
background: 'var(--semi-color-fill-0)',
};
return (
<Layout className="components-layout-demo">
<Header style={commonStyle}>Header</Header>
<Layout>
<Content style={{ height: 300, lineHeight: '300px' }}>Content</Content>
<Sider style={{ width: '120px', background: 'var(--semi-color-fill-2)' }}>Sider</Sider>
</Layout>
<Footer style={commonStyle}>Footer</Footer>
</Layout>
);
}Sidebar Layout
Code
import { Layout } from '@fibrous/semi-ui-react';
export default function LayoutDemo() {
const { Header, Footer, Sider, Content } = Layout;
const commonStyle = {
height: 64,
lineHeight: '64px',
background: 'var(--semi-color-fill-0)',
};
return (
<Layout className="components-layout-demo">
<Sider style={{ width: '120px', background: 'var(--semi-color-fill-2)' }}>Sider</Sider>
<Layout>
<Header style={commonStyle}>Header</Header>
<Content style={{ height: 300, lineHeight: '300px' }}>Content</Content>
<Footer style={commonStyle}>Footer</Footer>
</Layout>
</Layout>
);
}Responsive Layout
Six response sizes are preset in the sidebar: xs,sm,md,lg,xl,xxl. You can use breakpoint to set breakpoints.
Use onBreakpoint to call callback functions.
Code
import { Layout, type SiderProps } from '@fibrous/semi-ui-react';
export default function LayoutDemo() {
const onbreakpoint: SiderProps['onBreakpoint'] = (screen, bool) => {
console.log(screen, bool);
};
const commonStyle = {
height: 64,
lineHeight: '64px',
background: 'var(--semi-color-fill-0)',
};
const { Header, Footer, Sider, Content } = Layout;
return (
<Layout className="components-layout-demo">
<Header style={commonStyle}>Header</Header>
<Layout>
<Sider style={{ width: '120px', background: 'var(--semi-color-fill-2)' }} breakpoint={['md']} onBreakpoint={onbreakpoint}>
Sider
</Sider>
<Content style={{ height: 300, lineHeight: '300px' }}>Content</Content>
</Layout>
<Footer style={commonStyle}>Footer</Footer>
</Layout>
);
}Layout Examples
Top-nav Layout
Top-Nav SideBar Layout
SideBar Navigation
API Reference
Layout
Props
| Property | Description | Type | Default |
|---|---|---|---|
| children | Content of the layout: Layout.Header, Layout.Sider, Layout.Content, Layout.Footer or a nested Layout. | React.ReactNode | - |
| className | Class name of the root element. | string | - |
| hasSider | Indicates that a Sider is inside; usually not needed. A direct child Sider is detected during render; a Sider nested deeper registers after mount, so pass true during SSR to avoid a style flash. Passing false cannot remove the has-sider class that a Sider adds. | boolean | - |
| prefixCls | Class name prefix. | string | "semi-layout" |
| ref | Reference to the root element, whose tag is set by tagName. | TypeReact.Ref<HTMLElement> | - |
| style | Style of the root element. | CSSProperties | - |
| tagName | Tag name of the root element. | keyof HTMLElementTagNameMap | "section" |
Native attributes not listed above (including role and aria-*) fall through to the root element.
Layout.Header,Layout.Footer,Layout.Contentuse same API asLayout, except that they have nohasSiderand have an extratypefor internal use
| Property | Description | Type | Default |
|---|---|---|---|
| className | Class name of the root element. | string | - |
| prefixCls | Class name prefix. | string | semi-layout |
| style | Style of the root element. | CSSProperties | - |
| tagName | Tag name of the root element. | keyof HTMLElementTagNameMap | header, footer and main for Header, Footer and Content |
ref and native attributes not listed above (including role and aria-*) fall through to each root element.
Layout.Sider
Props
| Property | Description | Type | Default |
|---|---|---|---|
| aria-label | Accessible name of the sider, describing what it is for. | React.AriaAttributes['aria-label'] | - |
| breakpoint | Breakpoints that trigger the responsive layout: xs, sm, md, lg, xl or xxl. Read once at mount. | TypeArray<keyof ResponsiveMap> | - |
| children | Sider content, rendered inside a div wrapped by the root element. | React.ReactNode | - |
| className | Class name of the root element. | string | - |
| onBreakpoint | Called with the breakpoint name and whether it matches: once for each breakpoint in breakpoint at mount with the current viewport, then whenever a match starts or stops. | Type(screen: keyof ResponsiveMap, match: boolean) => void | - |
| prefixCls | Class name prefix. | string | "semi-layout" |
| ref | Reference to the root aside element. | TypeReact.Ref<HTMLElement> | - |
| role | role of the root aside element. | React.AriaRole | - |
| style | Style of the root element. | CSSProperties | - |
Native attributes not listed above (including aria-* and onClick) fall through to the root aside element.
responsive map
{
xs: '(max-width: 575px)',
sm: '(min-width: 576px)',
md: '(min-width: 768px)',
lg: '(min-width: 992px)',
xl: '(min-width: 1200px)',
xxl: '(min-width: 1600px)',
}
Accessibility
ARIA
- Sider renders an
aside; passaria-labelto describe what this Sider is for. - Header and Footer render
headerandfooterby default. Inside thesectionof a Layout they are not banner or contentinfo landmarks; passrole="banner"orrole="contentinfo"when they are the header or footer of the whole page. - Content renders
mainby default, and a page should have only onemain; when nesting, usetagNameto switch to another tag. - Header, Content and Footer accept
roleandaria-labelto describe the corresponding element.