Layout 页面布局

如果项目中使用的是 0.x 版本的基础组件(@icedesign/base, @ali/ice, @alife/next),请在左侧导航顶部切换组件版本。

安装方法

  1. 在命令行中执行以下命令npm install @icedesign/layout@1.0.8 -S

提供页面框架性的 Layout 以及基础区块布局,除了 Layout.Main 必须以外, 其它的组件在页面中可以按需自由搭配使用。

Layout

import Layout from '@icedesign/layout';

页面布局,一个页面有且只能有一个 Layout 组件。

参数(props)

参数名说明类型默认值
fixable开启布局模块滚动跟随模式booleanfalse

fixable 一旦设置为 true 则整个页面所有模块都固定高度,内容区域不可滚动。子组件通过 scrollable props 使其可滚动,以此实现主体内容滚动,其余模块 fixed 的效果。

Layout.Section

辅助布局组件,会创建 100% 宽度的一整行。当某一块区域需要两个模块左右排列,则需要使用 Layout.Section 组件包裹。

如:

  1. <Layout.Section>
  2. <Layout.Aside />
  3. <Layout.Main />
  4. </Layout.Section>

参数(props)

参数名说明类型默认值
scrollable区域可滚动 (<Layout fixable={true} /> 下可用)booleanfalse

Layout.Header

顶部布局,默认 flex 布局,并且内部元素垂直居中对齐,可通过 style 属性修改。

参数(props)

参数名说明类型默认值
type配置皮肤色stringnormal
  • type: none(继承父元素的背景色), normal,primary,secondary

Layout.Aside

侧边栏,根据嵌套顺序,可左右布局。

参数(props)

参数名说明类型默认值
type配置Aside 皮肤色string-

Layout.Main

参数(props)

参数名说明类型默认值
scrollable区域可滚动 (<Layout fixable={true} /> 下可用)booleanfalse

主体内容。

页脚布局。

参数(props)

参数名说明类型默认值
type配置Aside 皮肤色string-

代码示例

基本结构

基础组件 Header Main Footer,默认宽度都是 100%。当需要侧边栏 Aside 组件,需要使用辅助布局组件 Section 包裹起来。通过各组件的先后顺序实现多样性布局。

Layout 页面布局 - 图1

查看源码在线预览

  1. import React, { Component } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Layout from '@icedesign/layout';
  4. class App extends Component {
  5. render() {
  6. return (
  7. <div>
  8. <Layout>
  9. <Layout.Header style={{
  10. height: 80,
  11. }} type="secondary">header</Layout.Header>
  12. <Layout.Main style={{height: 200, background: '#fff'}}>Main</Layout.Main>
  13. <Layout.Footer style={{
  14. height: 80,
  15. }} type="secondary">Footer</Layout.Footer>
  16. </Layout>
  17. <div style={{height: 20}}></div>
  18. <Layout>
  19. <Layout.Header style={{
  20. height: 80,
  21. }} type="secondary">header</Layout.Header>
  22. <Layout.Section>
  23. <Layout.Aside style={{
  24. width: 80,
  25. }} type="secondary">Aside</Layout.Aside>
  26. <Layout.Main style={{height: 200, background: '#fff'}}>Main</Layout.Main>
  27. </Layout.Section>
  28. <Layout.Footer style={{
  29. height: 80,
  30. }} type="secondary">Footer</Layout.Footer>
  31. </Layout>
  32. <div style={{height: 20}}></div>
  33. <Layout>
  34. <Layout.Header style={{
  35. height: 80,
  36. }} type="secondary">header</Layout.Header>
  37. <Layout.Section style={{ padding: '20px 40px' }}>
  38. <Layout.Aside style={{
  39. width: 80,
  40. }} type="secondary" >Aside</Layout.Aside>
  41. <Layout.Main style={{height: 200, background: '#fff'}}>Main</Layout.Main>
  42. </Layout.Section>
  43. <Layout.Footer style={{
  44. height: 80,
  45. }} type="secondary">Footer</Layout.Footer>
  46. </Layout>
  47. <div style={{height: 20}}></div>
  48. <Layout>
  49. <Layout.Header style={{
  50. height: 80,
  51. }} type="secondary">header</Layout.Header>
  52. <Layout.Section>
  53. <Layout.Aside style={{
  54. width: 80,
  55. }} type="secondary">Aside</Layout.Aside>
  56. <Layout.Main style={{height: 500, background: '#fff'}}>Main</Layout.Main>
  57. <Layout.Aside style={{
  58. width: 80,
  59. }} type="secondary">Aside</Layout.Aside>
  60. </Layout.Section>
  61. <Layout.Footer style={{
  62. height: 80,
  63. }} type="secondary">Footer</Layout.Footer>
  64. </Layout>
  65. <div style={{height: 20}}></div>
  66. <Layout>
  67. <Layout.Aside style={{
  68. width: 80,
  69. }} type="secondary">Aside</Layout.Aside>
  70. <Layout.Section>
  71. <Layout.Header style={{
  72. height: 80,
  73. }} type="secondary">header</Layout.Header>
  74. <Layout.Main style={{
  75. height: 200, background: '#fff'
  76. }}>Main</Layout.Main>
  77. <Layout.Footer style={{
  78. height: 80,
  79. }} type="secondary">Footer</Layout.Footer>
  80. </Layout.Section>
  81. </Layout>
  82. </div>
  83. );
  84. }
  85. }
  86. ReactDOM.render(<App />, mountNode);
  1. .ice-layout {
  2. color: #fff;
  3. text-align: center;
  4. margin-bottom: 50px;
  5. background-color: #eee;
  6. }
  7. .ice-layout-header {
  8. line-height: 50px;
  9. background-color: rgba(27, 115, 225, 0.5) !important;;
  10. }
  11. .ice-layout-aside {
  12. line-height: 120px;
  13. background-color: rgba(27, 115, 225, 0.7) !important;;
  14. }
  15. .ice-layout-main {
  16. line-height: 120px;
  17. background-color: rgba(27, 115, 225, 1);
  18. }
  19. .ice-layout-footer {
  20. line-height: 50px;
  21. background-color: rgba(27, 115, 225, 0.5);
  22. }

通过 type 定制主题

通过 type 属性可以定制组件的样式,Header/Footer/Aside 支持 type 属性,并且与 Nav 组件保持一致

Layout 页面布局 - 图2

查看源码在线预览

  1. import React, { Component, PropTypes } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Layout from '@icedesign/layout';
  4. import { Icon, Dropdown, Nav, Radio } from '@alifd/next';
  5. class App extends Component {
  6. state = {
  7. type: 'normal'
  8. };
  9. render() {
  10. return (
  11. <Layout style={{ minHeight: '100vh' }}>
  12. <Layout.Aside
  13. type={this.state.type}
  14. >
  15. <Logo />
  16. <Nav type={this.state.type}>
  17. <Nav.Group label="需求">
  18. <Nav.Item icon="account">需求1</Nav.Item>
  19. <Nav.Item icon="account">需求2</Nav.Item>
  20. <Nav.Item icon="account">需求3</Nav.Item>
  21. </Nav.Group>
  22. <Nav.Group label="我的">
  23. <Nav.Item icon="account">资料</Nav.Item>
  24. <Nav.Item icon="account">设置</Nav.Item>
  25. <Nav.Item icon="account">主题</Nav.Item>
  26. </Nav.Group>
  27. </Nav>
  28. </Layout.Aside>
  29. <Layout.Section>
  30. <Layout.Header
  31. style={{
  32. height: '60px',
  33. padding: '0 20px',
  34. justifyContent: 'space-between',
  35. }}
  36. type={this.state.type}
  37. >
  38. <Nav
  39. type={this.state.type}
  40. direction="hoz"
  41. triggerType="hover"
  42. >
  43. <Nav.Item key="home">Home</Nav.Item>
  44. <Nav.SubNav label="Component" selectable>
  45. <Nav.Item key="next">ICE</Nav.Item>
  46. <Nav.Item key="mext">Next</Nav.Item>
  47. </Nav.SubNav>
  48. <Nav.Item key="document">Document</Nav.Item>
  49. </Nav>
  50. <div>ICE</div>
  51. </Layout.Header>
  52. <Layout.Main
  53. style={{
  54. padding: 20,
  55. margin: '0 24px'
  56. }}
  57. >
  58. <Radio.Group
  59. shape="button" size="medium"
  60. value={this.state.type}
  61. onChange={(value) => {
  62. this.setState({
  63. type: value
  64. })
  65. }}
  66. >
  67. <Radio value="normal">type="normal"</Radio>
  68. <Radio value="primary">type="primary"</Radio>
  69. <Radio value="secondary">type="secondary"</Radio>
  70. <Radio value="line">type="line"</Radio>
  71. <Radio value="line">type="none"</Radio>
  72. </Radio.Group>
  73. </Layout.Main>
  74. <Layout.Footer
  75. type={this.state.type}
  76. style={{
  77. textAlign: 'center',
  78. lineHeight: '36px'
  79. }}
  80. >
  81. <p style={{ color: '#999' }}>
  82. © 2017-2018 xxxx团队 版权所有 系统维护者:@xx 如有问题随时联系!
  83. <br />
  84. <a href="https://alibaba.github.io/ice" target="_blank"> ICE </a> 提供技术支持
  85. </p>
  86. </Layout.Footer>
  87. </Layout.Section>
  88. </Layout>
  89. );
  90. }
  91. }
  92. // 项目内敛 Logo 组件
  93. class Logo extends Component {
  94. render() {
  95. return (
  96. <div
  97. className="logo"
  98. style={{
  99. overflow: 'hidden',
  100. height: 60,
  101. color: '#f40',
  102. textAlign: 'center',
  103. ...this.props.style
  104. }}
  105. >
  106. <div
  107. style={{
  108. height: 60,
  109. lineHeight: '60px',
  110. fontSize: 20,
  111. ...this.props.style
  112. }}
  113. >
  114. Your Logo
  115. </div>
  116. </div>
  117. );
  118. }
  119. }
  120. ReactDOM.render(<App />, mountNode);

Aside 收起展开模式

Layout 页面布局 - 图3

查看源码在线预览

  1. import React, { Component, PropTypes } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Layout from '@icedesign/layout';
  4. import { Icon, Nav } from '@alifd/next';
  5. class App extends Component {
  6. state = {
  7. collapse: false,
  8. };
  9. render() {
  10. const { collapse } = this.state;
  11. return (
  12. <Layout style={{ minHeight: '100vh' }}>
  13. <Layout.Aside
  14. type="primary"
  15. style={{
  16. width: collapse ? 60 : 200
  17. }}
  18. >
  19. <Logo text={collapse ? 'go' : 'your-logo'} />
  20. <div style={{
  21. display: 'flex',
  22. justifyContent: 'center',
  23. margin: '20px 0'
  24. }}>
  25. <Icon
  26. type={collapse ? 'arrow-right' : 'arrow-left'}
  27. onClick={() => {
  28. this.setState({
  29. collapse: !this.state.collapse
  30. })
  31. }}
  32. />
  33. </div>
  34. <Nav type="primary" iconOnly={this.state.collapse} hasTooltip={true}>
  35. <Nav.SubNav icon="account" label="需求">
  36. <Nav.Item icon="account">需求1</Nav.Item>
  37. <Nav.Item icon="account">需求2</Nav.Item>
  38. <Nav.Item icon="account">需求3</Nav.Item>
  39. </Nav.SubNav>
  40. <Nav.SubNav icon="account" label="我的">
  41. <Nav.Item icon="account">资料</Nav.Item>
  42. <Nav.Item icon="account">设置</Nav.Item>
  43. <Nav.Item icon="account">主题</Nav.Item>
  44. </Nav.SubNav>
  45. </Nav>
  46. </Layout.Aside>
  47. <Layout.Section>
  48. <Layout.Header
  49. style={{
  50. height: '60px',
  51. padding: '0 20px',
  52. justifyContent: 'space-between',
  53. }}
  54. type="primary"
  55. >
  56. <Nav
  57. type="primary"
  58. direction="hoz"
  59. triggerType="hover"
  60. >
  61. <Nav.Item key="home">Home</Nav.Item>
  62. <Nav.SubNav label="Component" selectable>
  63. <Nav.Item key="next">ICE</Nav.Item>
  64. <Nav.Item key="mext">Next</Nav.Item>
  65. </Nav.SubNav>
  66. <Nav.Item key="document">Document</Nav.Item>
  67. </Nav>
  68. </Layout.Header>
  69. <Layout.Main
  70. style={{
  71. padding: 20,
  72. height: 500,
  73. margin: '0 24px'
  74. }}
  75. >
  76. Main
  77. </Layout.Main>
  78. <Layout.Footer
  79. type="primary"
  80. style={{
  81. textAlign: 'center',
  82. lineHeight: '36px'
  83. }}
  84. >
  85. <p style={{ color: '#999' }}>
  86. © 2017-2018 xxxx团队 版权所有 系统维护者:@xx 如有问题随时联系!
  87. <br />
  88. <a href="https://alibaba.github.io/ice" target="_blank"> ICE </a> 提供技术支持
  89. </p>
  90. </Layout.Footer>
  91. </Layout.Section>
  92. </Layout>
  93. );
  94. }
  95. }
  96. // 项目内敛 Logo 组件
  97. class Logo extends Component {
  98. render() {
  99. const { text } = this.props;
  100. return (
  101. <div
  102. className="logo"
  103. style={{
  104. overflow: 'hidden',
  105. height: 60,
  106. color: '#f40',
  107. textAlign: 'center',
  108. ...this.props.style
  109. }}
  110. >
  111. <div
  112. style={{
  113. height: 60,
  114. lineHeight: '60px',
  115. fontSize: 20,
  116. ...this.props.style
  117. }}
  118. >
  119. {text}
  120. </div>
  121. </div>
  122. );
  123. }
  124. }
  125. ReactDOM.render(<App />, mountNode);

Header 吸顶

Header 固定(吸顶),其他区域滚动。

Layout 页面布局 - 图4

查看源码在线预览

  1. import React, { Component } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Layout from '@icedesign/layout';
  4. class App extends Component {
  5. render() {
  6. return (
  7. <Layout fixable={true}>
  8. <Layout.Header style={{
  9. height: 80,
  10. }} type="primary">Header</Layout.Header>
  11. <Layout.Section scrollable={true}>
  12. <Layout.Aside style={{
  13. width: 200,
  14. }} type="primary">
  15. <br />
  16. Aside
  17. </Layout.Aside>
  18. <Layout.Main>
  19. <p>Main</p>
  20. <p style={{ height: 200 }}>内容可滚动</p>
  21. <p style={{ height: 200 }}>内容可滚动</p>
  22. <p style={{ height: 200 }}>内容可滚动</p>
  23. <p style={{ height: 200 }}>内容可滚动</p>
  24. <p style={{ height: 200 }}>内容可滚动</p>
  25. <p style={{ height: 200 }}>内容可滚动</p>
  26. <p style={{ height: 200 }}>内容可滚动</p>
  27. <p style={{ height: 200 }}>内容可滚动 end</p>
  28. <Layout.Footer>Footer</Layout.Footer>
  29. </Layout.Main>
  30. </Layout.Section>
  31. </Layout>
  32. );
  33. }
  34. }
  35. ReactDOM.render(<App />, mountNode);

Header&Aside 固定,Aside 内容可滚动

Layout 页面布局 - 图5

查看源码在线预览

  1. import React, { Component } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Layout from '@icedesign/layout';
  4. class App extends Component {
  5. render() {
  6. return (
  7. <Layout fixable={true}>
  8. <Layout.Header style={{
  9. height: 80,
  10. }} type="primary">&nbsp;&nbsp;&nbsp;&nbsp;Header</Layout.Header>
  11. <Layout.Section>
  12. <Layout.Aside style={{
  13. width: 150,
  14. }} type="primary" scrollable={true}>
  15. <p>Aside</p>
  16. <p style={{ height: 200 }}>内容可滚动</p>
  17. <p style={{ height: 200 }}>内容可滚动</p>
  18. <p style={{ height: 200 }}>内容可滚动</p>
  19. <p style={{ height: 200 }}>内容可滚动</p>
  20. <p style={{ height: 200 }}>内容可滚动</p>
  21. <p style={{ height: 200 }}>内容可滚动</p>
  22. </Layout.Aside>
  23. <Layout.Main scrollable={true}>
  24. <p>Main</p>
  25. <p style={{ height: 200 }}>内容可滚动</p>
  26. <p style={{ height: 200 }}>内容可滚动</p>
  27. <p style={{ height: 200 }}>内容可滚动</p>
  28. <p style={{ height: 200 }}>内容可滚动</p>
  29. <p style={{ height: 200 }}>内容可滚动</p>
  30. <p style={{ height: 200 }}>内容可滚动</p>
  31. <p style={{ height: 200 }}>内容可滚动</p>
  32. <p style={{ height: 200 }}>内容可滚动 end</p>
  33. <Layout.Footer style={{
  34. height: 80,
  35. }} type="primary">Footer</Layout.Footer>
  36. </Layout.Main>
  37. </Layout.Section>
  38. </Layout>
  39. );
  40. }
  41. }
  42. ReactDOM.render(<App />, mountNode);

Aside&Header 固定

Aside Header 固定位置布局,将 Footer 放在 Main 里一同滚动。

Layout 页面布局 - 图6

查看源码在线预览

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Layout from '@icedesign/layout';

class App extends Component {
  render() {
    return (
      <Layout fixable={true}>
        <Layout.Aside style={{
          width: 80,
        }} type="primary">
          <br />
          Aside
        </Layout.Aside>
        <Layout.Section>
          <Layout.Header style={{
            height: 80,
          }} type="primary">&nbsp;&nbsp;&nbsp;&nbsp;Header</Layout.Header>
          <Layout.Main scrollable={true}>
            <p>Main</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <Layout.Footer style={{
              height: 80,
            }} type="primary">Footer</Layout.Footer>
          </Layout.Main>
        </Layout.Section>
      </Layout>
    );
  }
}

ReactDOM.render(<App />, mountNode);

Aside 固定

Aside 固定,其他区域滚动

Layout 页面布局 - 图7

查看源码在线预览

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Layout from '@icedesign/layout';

class App extends Component {
  render() {
    return (
      <Layout fixable={true}>
        <Layout.Aside style={{
          width: 200,
        }} type="primary">
          <br />
          Aside
        </Layout.Aside>
        <Layout.Section scrollable={true}>
          <Layout.Header type="primary" style={{
            height: 80
          }}>&nbsp;&nbsp;&nbsp;&nbsp;Header</Layout.Header>
          <Layout.Main>
            <p>Main</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
            <p style={{ height: 200 }}>内容可滚动</p>
          </Layout.Main>
          <Layout.Footer style={{
            height: 200
          }}>Footer</Layout.Footer>
        </Layout.Section>
      </Layout>
    );
  }
}

ReactDOM.render(<App />, mountNode);

上中下应用示例

Layout 页面布局 - 图8

查看源码在线预览

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Layout from '@icedesign/layout';
import { Nav } from '@alifd/next';

class App extends Component {
  render() {
    return (
      <Layout>
        <Layout.Header style={{ padding: '12px 50px' }} type="primary">
          <Nav
            type="primary"
            direction="hoz"
            triggerType="hover"
          >
            <Nav.Item key="home">Home</Nav.Item>
            <Nav.SubNav label="Component" selectable>
              <Nav.Item key="next">ICE</Nav.Item>
              <Nav.Item key="mext">Next</Nav.Item>
            </Nav.SubNav>
            <Nav.Item key="document">Document</Nav.Item>
          </Nav>
        </Layout.Header>
        <Layout.Section style={{ padding: '0 50px' }}>
          <Layout.Main
            style={{
              background: '#fff',
              padding: 24,
              minHeight: 280
            }}
          >
            Main
          </Layout.Main>
        </Layout.Section>
        <Layout.Footer
          type="secondary"
          style={{
            textAlign: 'center',
            lineHeight: '36px'
          }}
        >
          <p>
            © 2017-2018 xxxx团队 版权所有 系统维护者:@xx 如有问题随时联系!
            <br />
            由
            {' '}
            <a href="//ice.alibaba-inc.com" target="_blank">ICE</a>
            {' '}
            提供技术支持
          </p>
        </Layout.Footer>
      </Layout>
    );
  }
}

ReactDOM.render(<App />, mountNode);

相关区块

Layout 页面布局 - 图9

暂无相关区块