Layout 页面布局

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

安装方法

  1. 在命令行中执行以下命令npm install @icedesign/layout@0.1.7 -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

顶部布局,默认内部元素居中对其。

参数(props)

参数名说明类型默认值
alignItems内部元素垂直对其方式stringcenter
theme配置 Header 皮肤色string-
  • alignItems:flex-start flex-end center baseline stretch

  • theme:dark, light

Layout.Aside

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

参数(props)

参数名说明类型默认值
width展开状态下的宽度number/string200
theme配置 Aside 皮肤色string-
  • theme:dark, light

Layout.Main

参数(props)

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

主体内容。

页脚布局。

代码示例

基本结构

基础组件 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>&nbsp;&nbsp;&nbsp;&nbsp;header</Layout.Header>
  10. <Layout.Main>Main</Layout.Main>
  11. <Layout.Footer>Footer</Layout.Footer>
  12. </Layout>
  13. <Layout>
  14. <Layout.Header>&nbsp;&nbsp;&nbsp;&nbsp;header</Layout.Header>
  15. <Layout.Section>
  16. <Layout.Aside>Aside</Layout.Aside>
  17. <Layout.Main>Main</Layout.Main>
  18. </Layout.Section>
  19. <Layout.Footer>Footer</Layout.Footer>
  20. </Layout>
  21. <Layout>
  22. <Layout.Header>&nbsp;&nbsp;&nbsp;&nbsp;header</Layout.Header>
  23. <Layout.Section style={{ padding: '20px 40px' }}>
  24. <Layout.Aside>Aside</Layout.Aside>
  25. <Layout.Main>Main</Layout.Main>
  26. </Layout.Section>
  27. <Layout.Footer>Footer</Layout.Footer>
  28. </Layout>
  29. <Layout>
  30. <Layout.Header>&nbsp;&nbsp;&nbsp;&nbsp;header</Layout.Header>
  31. <Layout.Section>
  32. <Layout.Aside>Aside</Layout.Aside>
  33. <Layout.Main>Main</Layout.Main>
  34. <Layout.Aside>Aside</Layout.Aside>
  35. </Layout.Section>
  36. <Layout.Footer>Footer</Layout.Footer>
  37. </Layout>
  38. <Layout>
  39. <Layout.Aside>Aside</Layout.Aside>
  40. <Layout.Section>
  41. <Layout.Header>&nbsp;&nbsp;&nbsp;&nbsp;header</Layout.Header>
  42. <Layout.Main>Main</Layout.Main>
  43. <Layout.Footer>Footer</Layout.Footer>
  44. </Layout.Section>
  45. </Layout>
  46. </div>
  47. );
  48. }
  49. }
  50. 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. }

Aside 吸顶

Aside Header Footer 固定位置布局。

Layout 页面布局 - 图2

查看源码在线预览

  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.Aside>
  9. <br />
  10. Aside
  11. </Layout.Aside>
  12. <Layout.Section scrollable={true}>
  13. <Layout.Header>&nbsp;&nbsp;&nbsp;&nbsp;Header</Layout.Header>
  14. <Layout.Main>
  15. <p style={{ height: 200 }}>内容可滚动</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. <p style={{ height: 200 }}>内容可滚动</p>
  23. </Layout.Main>
  24. <Layout.Footer>Footer</Layout.Footer>
  25. </Layout.Section>
  26. </Layout>
  27. );
  28. }
  29. }
  30. ReactDOM.render(<App />, mountNode);
  1. .ice-layout {
  2. color: #fff;
  3. text-align: center;
  4. background-color: #eee;
  5. }
  6. .ice-layout-header {
  7. line-height: 50px;
  8. background-color: #84B0E7 !important;;
  9. }
  10. .ice-layout-aside {
  11. background-color: rgba(27, 115, 225, 0.7) !important;;
  12. }
  13. .ice-layout-main {
  14. line-height: 120px;
  15. background-color: rgba(27, 115, 225, 1);
  16. }
  17. .ice-layout-footer {
  18. line-height: 50px;
  19. background-color: #84B0E7;
  20. }

Aside Header 吸顶

Aside Header 固定位置布局。

将 Footer 放在 Main 里一同滚动。

Layout 页面布局 - 图3

查看源码在线预览

  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.Aside>
  9. <br />
  10. Aside
  11. </Layout.Aside>
  12. <Layout.Section>
  13. <Layout.Header>&nbsp;&nbsp;&nbsp;&nbsp;Header</Layout.Header>
  14. <Layout.Main scrollable={true}>
  15. <p style={{ height: 200 }}>内容可滚动</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. <p style={{ height: 200 }}>内容可滚动</p>
  23. <Layout.Footer>Footer</Layout.Footer>
  24. </Layout.Main>
  25. </Layout.Section>
  26. </Layout>
  27. );
  28. }
  29. }
  30. ReactDOM.render(<App />, mountNode);
  1. .ice-layout {
  2. color: #fff;
  3. text-align: center;
  4. background-color: #eee;
  5. }
  6. .ice-layout-header {
  7. line-height: 50px;
  8. background-color: #84B0E7 !important;;
  9. }
  10. .ice-layout-aside {
  11. background-color: rgba(27, 115, 225, 0.7) !important;;
  12. }
  13. .ice-layout-main {
  14. line-height: 120px;
  15. background-color: rgba(27, 115, 225, 1);
  16. }
  17. .ice-layout-footer {
  18. line-height: 50px;
  19. background-color: #84B0E7;
  20. }

Header 吸顶

Header Aside Footer 固定位置布局。

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>&nbsp;&nbsp;&nbsp;&nbsp;Header</Layout.Header>
  9. <Layout.Section scrollable={true}>
  10. <Layout.Aside>
  11. <br />
  12. Aside
  13. </Layout.Aside>
  14. <Layout.Main>
  15. <p style={{ height: 200 }}>内容可滚动</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. <p style={{ height: 200 }}>内容可滚动 end</p>
  23. <Layout.Footer>Footer</Layout.Footer>
  24. </Layout.Main>
  25. </Layout.Section>
  26. </Layout>
  27. );
  28. }
  29. }
  30. ReactDOM.render(<App />, mountNode);
  1. .ice-layout {
  2. color: #fff;
  3. text-align: center;
  4. background-color: #eee;
  5. }
  6. .ice-layout-header {
  7. line-height: 50px;
  8. background-color: #84B0E7 !important;;
  9. }
  10. .ice-layout-aside {
  11. background-color: rgba(27, 115, 225, 0.7) !important;;
  12. }
  13. .ice-layout-main {
  14. line-height: 120px;
  15. background-color: rgba(27, 115, 225, 1);
  16. }
  17. .ice-layout-footer {
  18. line-height: 50px;
  19. background-color: #84B0E7;
  20. }

Header Aside 吸顶

Header Aside 固定位置布局。

将 Footer 放在 Main 里一同滚动。

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>&nbsp;&nbsp;&nbsp;&nbsp;Header</Layout.Header>
  9. <Layout.Section>
  10. <Layout.Aside scrollable={true}>
  11. <p style={{ height: 200 }}>内容可滚动</p>
  12. <p style={{ height: 200 }}>内容可滚动</p>
  13. <p style={{ height: 200 }}>内容可滚动</p>
  14. <p style={{ height: 200 }}>内容可滚动</p>
  15. <p style={{ height: 200 }}>内容可滚动</p>
  16. <p style={{ height: 200 }}>内容可滚动</p>
  17. </Layout.Aside>
  18. <Layout.Main scrollable={true}>
  19. <p style={{ height: 200 }}>内容可滚动</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 }}>内容可滚动 end</p>
  27. <Layout.Footer>Footer</Layout.Footer>
  28. </Layout.Main>
  29. </Layout.Section>
  30. </Layout>
  31. );
  32. }
  33. }
  34. ReactDOM.render(<App />, mountNode);
  1. .ice-layout {
  2. color: #fff;
  3. text-align: center;
  4. background-color: #eee;
  5. }
  6. .ice-layout-header {
  7. line-height: 50px;
  8. background-color: #84B0E7 !important;
  9. }
  10. .ice-layout-aside {
  11. background-color: rgba(27, 115, 225, 0.7) !important;;
  12. }
  13. .ice-layout-main {
  14. line-height: 120px;
  15. background-color: rgba(27, 115, 225, 1);
  16. }
  17. .ice-layout-footer {
  18. line-height: 50px;
  19. background-color: #84B0E7;
  20. }

Aside 应用示例

Layout 页面布局 - 图6

查看源码在线预览

  1. import React, { Component, PropTypes } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Layout from '@icedesign/layout';
  4. import { Breadcrumb, Icon, Button, Dropdown, Select } from '@icedesign/base';
  5. import Img from '@icedesign/img';
  6. import StyledMenu, {
  7. SubMenu,
  8. ItemGroup as MenuItemGroup,
  9. Item as MenuItem
  10. } from '@icedesign/styled-menu';
  11. class App extends Component {
  12. state = {
  13. current: 'setting:1',
  14. mode: 'inline',
  15. headerTheme: 'light',
  16. headerColor: '',
  17. asideTheme: 'dark',
  18. asideColor: '',
  19. };
  20. handleClick = e => {
  21. this.setState({
  22. current: e.key
  23. });
  24. };
  25. headerThemeChange = value => {
  26. this.setState({ headerTheme: value });
  27. };
  28. headerColorChange = value => {
  29. this.setState({ headerColor: value });
  30. };
  31. asideThemeChange = value => {
  32. this.setState({ asideTheme: value });
  33. };
  34. asideColorChange = value => {
  35. this.setState({ asideColor: value });
  36. };
  37. render() {
  38. return (
  39. <Layout style={{ minHeight: '100vh' }}>
  40. <Layout.Aside theme={this.state.asideTheme} color={this.state.asideColor}>
  41. <Logo {...getDefaultFontColor(this.state.asideTheme)} />
  42. <StyledMenu theme={this.state.asideTheme} color={this.state.asideColor} mode={this.state.mode}>
  43. <SubMenu
  44. key="sub1"
  45. title={
  46. <span>
  47. <Icon size="xs" type="similar-product" /><span>侧边菜单一</span>
  48. </span>
  49. }
  50. >
  51. <MenuItemGroup title="Item 1">
  52. <MenuItem key="1">子菜单一</MenuItem>
  53. <MenuItem key="2">子菜单二</MenuItem>
  54. </MenuItemGroup>
  55. <MenuItemGroup title="Iteom 2">
  56. <MenuItem key="3">子菜单三</MenuItem>
  57. <MenuItem key="4">子菜单四</MenuItem>
  58. </MenuItemGroup>
  59. </SubMenu>
  60. <SubMenu
  61. key="sub2"
  62. title={
  63. <span>
  64. <Icon size="xs" type="bags" /><span>侧边菜单二</span>
  65. </span>
  66. }
  67. >
  68. <MenuItem key="5">子菜单一</MenuItem>
  69. <MenuItem key="6">子菜单二</MenuItem>
  70. <SubMenu key="sub3" title="Submenu">
  71. <MenuItem key="7">子菜单三</MenuItem>
  72. <MenuItem key="8">子菜单四</MenuItem>
  73. </SubMenu>
  74. </SubMenu>
  75. <SubMenu
  76. key="sub4"
  77. title={
  78. <span>
  79. <Icon size="xs" type="history" /><span>侧边菜单三</span>
  80. </span>
  81. }
  82. >
  83. <MenuItem key="9">子菜单一</MenuItem>
  84. <MenuItem key="10">子菜单二</MenuItem>
  85. <MenuItem key="11">子菜单三</MenuItem>
  86. <MenuItem key="12">子菜单四</MenuItem>
  87. </SubMenu>
  88. </StyledMenu>
  89. </Layout.Aside>
  90. <Layout.Section>
  91. <Layout.Header
  92. theme={this.state.headerTheme}
  93. color={this.state.headerColor}
  94. style={{
  95. height: '56px',
  96. padding: '0 24px 0 0',
  97. justifyContent: 'space-between'
  98. }}
  99. >
  100. <StyledMenu
  101. theme={this.state.headerTheme}
  102. color={this.state.headerColor}
  103. onClick={this.handleClick}
  104. selectedKeys={[this.state.current]}
  105. mode="horizontal"
  106. >
  107. <MenuItem key="mail">
  108. <Icon type="service" />首页
  109. </MenuItem>
  110. <MenuItem key="app" disabled>
  111. <Icon type="training" />分类
  112. </MenuItem>
  113. <SubMenu key="favorite" title={<span><Icon type="favorite" />收藏</span>}>
  114. <MenuItemGroup title="购买清单">
  115. <MenuItem key="setting:1">家电</MenuItem>
  116. <MenuItem key="setting:2">床品</MenuItem>
  117. </MenuItemGroup>
  118. <MenuItemGroup title="心愿单">
  119. <MenuItem key="setting:3">童装</MenuItem>
  120. <MenuItem key="setting:4">女装</MenuItem>
  121. </MenuItemGroup>
  122. </SubMenu>
  123. <MenuItem key="ice">
  124. <a
  125. href="http://ice.alibaba-inc.com/"
  126. target="_blank"
  127. rel="noopener noreferrer"
  128. >
  129. ICE 官网
  130. </a>
  131. </MenuItem>
  132. </StyledMenu>
  133. <div className="ice-layout-header-right" {...getDefaultFontColor(this.state.headerTheme)}>
  134. <span style={{ paddingRight: 12 }}>
  135. 下午好,内容管理后台。
  136. </span>
  137. <UserPanel
  138. offset={[0, 11]}
  139. size={36}
  140. shape="circle"
  141. userName="Jack Ma"
  142. avatar="//img.alicdn.com/tfs/TB1JLbBQXXXXXcUapXXXXXXXXXX-215-185.png"
  143. >
  144. <div>
  145. <StyledMenu
  146. style={{
  147. minWidth: 120,
  148. boxShadow: '0 0 2px #ccc'
  149. }}
  150. >
  151. <MenuItem>
  152. <a href="/">信息中心</a>
  153. </MenuItem>
  154. <MenuItem>
  155. <a href="/">设置</a>
  156. </MenuItem>
  157. <MenuItem>
  158. <a href="/">退出</a>
  159. </MenuItem>
  160. </StyledMenu>
  161. </div>
  162. </UserPanel>
  163. </div>
  164. </Layout.Header>
  165. <Breadcrumb style={{ margin: '12px 24px' }}>
  166. <Breadcrumb.Item link="javascript:void(0);">
  167. 首页
  168. </Breadcrumb.Item>
  169. <Breadcrumb.Item link="javascript:void(0);">
  170. 分类
  171. </Breadcrumb.Item>
  172. <Breadcrumb.Item link="javascript:void(0);">
  173. 收藏
  174. </Breadcrumb.Item>
  175. </Breadcrumb>
  176. <Layout.Main
  177. style={{
  178. padding: 20,
  179. margin: '0 24px',
  180. backgroundColor: '#fff'
  181. }}
  182. >
  183. <table>
  184. <thead>
  185. <tr>
  186. <td colSpan="4">
  187. <p>
  188. 通过配置 Layout.HeaderLayout.Aside 以及 IceMenu theme color props 实现组合配色
  189. </p>
  190. <p>
  191. 为了达到视觉美观,推荐 Layout.HeaderLayout.Aside 与内部 IceMenu 使用统一的配色配置。
  192. </p>
  193. </td>
  194. </tr>
  195. <tr>
  196. <td>
  197. <br />
  198. </td>
  199. </tr>
  200. </thead>
  201. <tbody style={{ color: '#999' }}>
  202. <tr>
  203. <td>切换 Header theme:</td>
  204. <td>
  205. <Select
  206. style={{width: 200}}
  207. onChange={this.headerThemeChange}
  208. defaultValue={this.state.headerTheme}
  209. >
  210. <Select.Option value="dark">
  211. dark
  212. </Select.Option>
  213. <Select.Option value="light">
  214. light
  215. </Select.Option>
  216. </Select>
  217. </td>
  218. </tr>
  219. <tr>
  220. <td>
  221. 切换 Aside theme
  222. </td>
  223. <td>
  224. <Select
  225. style={{width: 200}}
  226. onChange={this.asideThemeChange}
  227. defaultValue={this.state.asideTheme}
  228. >
  229. <Select.Option value="dark">
  230. dark
  231. </Select.Option>
  232. <Select.Option value="light">
  233. light
  234. </Select.Option>
  235. </Select>
  236. </td>
  237. </tr>
  238. </tbody>
  239. </table>
  240. {this.props.children}
  241. </Layout.Main>
  242. <Layout.Footer
  243. style={{
  244. textAlign: 'center',
  245. lineHeight: '36px'
  246. }}
  247. >
  248. <p style={{ color: '#999' }}>
  249. © 2017-2018 xxxx团队 版权所有 系统维护者:@xx 如有问题随时联系!
  250. <br />
  251. <a href="//ice.alibaba-inc.com" target="_blank"> ICE </a> 提供技术支持
  252. </p>
  253. </Layout.Footer>
  254. </Layout.Section>
  255. </Layout>
  256. );
  257. }
  258. }
  259. // 项目内敛 Logo 组件
  260. class Logo extends Component {
  261. render() {
  262. return (
  263. <div
  264. className="logo"
  265. style={{
  266. overflow: 'hidden',
  267. height: 60,
  268. color: '#f40',
  269. textAlign: 'center',
  270. ...this.props.style
  271. }}
  272. >
  273. <a href="/">
  274. <div
  275. style={{
  276. height: 60,
  277. lineHeight: '60px',
  278. fontSize: 20,
  279. ...this.props.style
  280. }}
  281. >
  282. Your Logo
  283. </div>
  284. </a>
  285. </div>
  286. );
  287. }
  288. }
  289. // 项目内敛 用户面板 组件
  290. class UserPanel extends Component {
  291. static displayName = 'UserPanel';
  292. static propTypes = {};
  293. static defaultProps = {
  294. size: 50,
  295. shape: 'sharp',
  296. type: 'cover',
  297. avatar: ''
  298. };
  299. constructor(props) {
  300. super(props);
  301. this.state = {
  302. dropdownVisible: false
  303. };
  304. }
  305. handleDropChange = value => {
  306. this.setState({
  307. dropdownVisible: value
  308. });
  309. };
  310. render() {
  311. const {
  312. offset,
  313. size,
  314. shape,
  315. type,
  316. avatar,
  317. style,
  318. children,
  319. className = ''
  320. } = this.props;
  321. const hasChildren = React.Children.count(children) > 0;
  322. const trigger = (
  323. <div
  324. className={`ice-user-panel ${className}`}
  325. style={{
  326. ...style,
  327. overflow: 'hidden',
  328. cursor: hasChildren ? 'pointer' : 'default'
  329. }}
  330. >
  331. <div className="avatar" style={{ float: 'left' }}>
  332. <Img
  333. height={size}
  334. width={size}
  335. type={type}
  336. shape={shape}
  337. src={avatar}
  338. />
  339. </div>
  340. <div
  341. className="user-name"
  342. style={{
  343. float: 'left',
  344. height: size,
  345. lineHeight: `${size}px`
  346. }}
  347. >
  348. <span style={{ padding: '10px' }}>
  349. {this.props.userName}
  350. </span>
  351. <Icon
  352. type={this.state.dropdownVisible ? 'arrow-up' : 'arrow-down'}
  353. size="xxs"
  354. />
  355. </div>
  356. </div>
  357. );
  358. if (hasChildren) {
  359. return (
  360. <Dropdown
  361. offset={offset}
  362. align="tr br"
  363. trigger={trigger}
  364. onVisibleChange={this.handleDropChange}
  365. >
  366. {this.props.children}
  367. </Dropdown>
  368. );
  369. } else {
  370. return trigger;
  371. }
  372. }
  373. }
  374. function getDefaultFontColor(theme) {
  375. let result = {
  376. style: {
  377. color: '#fff',
  378. }
  379. };
  380. if (theme.indexOf('light') > -1) {
  381. result = {
  382. style: {
  383. color: '#000',
  384. }
  385. };
  386. }
  387. return result;
  388. }
  389. ReactDOM.render(<App />, mountNode);

Header Aside 应用示例

Layout 页面布局 - 图7

查看源码在线预览

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Layout from '@icedesign/layout';
import { Breadcrumb, Icon } from '@icedesign/base';
import Img from '@icedesign/img';

import StyledMenu, {
  SubMenu,
  ItemGroup as MenuItemGroup,
  Item as MenuItem
} from '@icedesign/styled-menu';

class App extends Component {
  state = {
    current: 'mail'
  };

  handleNavClick = e => {
    this.setState({
      current: e.key
    });
  };

  render() {
    return (
      <Layout style={{ minHeight: '100vh' }}>
        <Layout.Header style={{ padding: '12px 50px' }} theme="dark">
          <Logo />
          <StyledMenu
            theme="dark"
            onClick={this.handleNavClick}
            selectedKeys={[this.state.current]}
            mode="horizontal"
          >
            <MenuItem key="mail">
              <Icon type="service" />首页
            </MenuItem>
            <MenuItem key="app" disabled>
              <Icon type="training" />分类
            </MenuItem>
            <SubMenu title={<span><Icon type="favorite" />收藏</span>}>
              <MenuItemGroup title="购买清单">
                <MenuItem key="setting:1">家电</MenuItem>
                <MenuItem key="setting:2">床品</MenuItem>
              </MenuItemGroup>
              <MenuItemGroup title="心愿单">
                <MenuItem key="setting:3">童装</MenuItem>
                <MenuItem key="setting:4">女装</MenuItem>
              </MenuItemGroup>
            </SubMenu>
            <MenuItem key="ice">
              <a
                href="http://ice.alibaba-inc.com/"
                target="_blank"
                rel="noopener noreferrer"
              >
                ICE 官网
              </a>
            </MenuItem>
          </StyledMenu>
        </Layout.Header>
        <Layout.Section style={{ padding: '0 50px' }}>
          <Breadcrumb style={{ margin: '12px 0' }}>
            <Breadcrumb.Item link="javascript:void(0);">
              首页
            </Breadcrumb.Item>
            <Breadcrumb.Item link="javascript:void(0);">
              分类
            </Breadcrumb.Item>
            <Breadcrumb.Item link="javascript:void(0);">
              收藏
            </Breadcrumb.Item>
          </Breadcrumb>
          <Layout.Section style={{ background: '#fff', minHeight: 280 }}>
            <Layout.Aside theme="light">
              <StyledMenu
                mode="inline"
                defaultSelectedKeys={['1']}
                defaultOpenKeys={['sub1']}
              >
                <SubMenu
                  key="sub1"
                  title={
                    <span>
                      <Icon type="mail" />
                      <span>侧边菜单一</span>
                    </span>
                  }
                >
                  <MenuItemGroup title="Item 1">
                    <MenuItem key="1">子菜单一</MenuItem>
                    <MenuItem key="2">子菜单二</MenuItem>
                  </MenuItemGroup>
                  <MenuItemGroup title="Iteom 2">
                    <MenuItem key="3">子菜单三</MenuItem>
                    <MenuItem key="4">子菜单四</MenuItem>
                  </MenuItemGroup>
                </SubMenu>
                <SubMenu
                  key="sub2"
                  title={
                    <span>
                      <Icon type="appstore" />
                      <span>侧边菜单二</span>
                    </span>
                  }
                >
                  <MenuItem key="5">子菜单一</MenuItem>
                  <MenuItem key="6">子菜单二</MenuItem>
                  <SubMenu key="sub3" title="Submenu">
                    <MenuItem key="7">子菜单三</MenuItem>
                    <MenuItem key="8">子菜单四</MenuItem>
                  </SubMenu>
                </SubMenu>
                <SubMenu
                  key="sub4"
                  title={
                    <span>
                      <icon type="setting" />
                      <span>侧边菜单三</span>
                    </span>
                  }
                >
                  <MenuItem key="9">子菜单一</MenuItem>
                  <MenuItem key="10">子菜单二</MenuItem>
                  <MenuItem key="11">子菜单三</MenuItem>
                  <MenuItem key="12">子菜单四</MenuItem>
                </SubMenu>
              </StyledMenu>
            </Layout.Aside>
            <Layout.Main style={{ padding: 24 }}>
              Main
            </Layout.Main>
          </Layout.Section>
        </Layout.Section>
        <Layout.Footer
          style={{
            textAlign: 'center',
            lineHeight: '36px'
          }}
        >
          <p style={{ color: '#999' }}>
            © 2017-2018 xxxx团队 版权所有 系统维护者:@xx 如有问题随时联系!
            <br />
            由
            {' '}
            <a href="//ice.alibaba-inc.com" target="_blank">ICE</a>
            {' '}
            提供技术支持
          </p>
        </Layout.Footer>
      </Layout>
    );
  }
}

class Logo extends Component {
  render() {
    return (
      <div
        className="logo"
        style={{
          overflow: 'hidden',
          height: 35,
          margin: 10,
          color: '#f40',
          textAlign: 'left',
          minWidth: 200
        }}
      >
        <a href="/">
          <Img
            style={{ display: 'inline-block' }}
            height={35}
            width={129}
            src="https://img.alicdn.com/tps/TB1k.vjNpXXXXc6XXXXXXXXXXXX-258-70.png"
            type="contain"
          />
        </a>
      </div>
    );
  }
}

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

上中下应用示例

Layout 页面布局 - 图8

查看源码在线预览

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Layout from '@icedesign/layout';
import { Breadcrumb, Icon } from '@icedesign/base';
import Img from '@icedesign/img';

import StyledMenu, {
  SubMenu,
  ItemGroup as MenuItemGroup,
  Item as MenuItem
} from '@icedesign/styled-menu';

class App extends Component {
  state = {
    current: 'mail'
  };

  handleClick = e => {
    console.log('click ', e);
    this.setState({
      current: e.key
    });
  };

  render() {
    return (
      <Layout>
        <Layout.Header style={{ padding: '12px 50px' }} theme="dark">
          <Logo />
          <StyledMenu
            theme="dark"
            onClick={this.handleClick}
            selectedKeys={[this.state.current]}
            mode="horizontal"
          >
            <MenuItem key="mail">
              <Icon type="service" />首页
            </MenuItem>
            <MenuItem key="app" disabled>
              <Icon type="training" />分类
            </MenuItem>
            <SubMenu title={<span><Icon type="favorite" />收藏</span>}>
              <MenuItemGroup title="购买清单">
                <MenuItem key="setting:1">家电</MenuItem>
                <MenuItem key="setting:2">床品</MenuItem>
              </MenuItemGroup>
              <MenuItemGroup title="心愿单">
                <MenuItem key="setting:3">童装</MenuItem>
                <MenuItem key="setting:4">女装</MenuItem>
              </MenuItemGroup>
            </SubMenu>
            <MenuItem key="ice">
              <a
                href="http://ice.alibaba-inc.com/"
                target="_blank"
                rel="noopener noreferrer"
              >
                ICE 官网
              </a>
            </MenuItem>
          </StyledMenu>
        </Layout.Header>
        <Layout.Section style={{ padding: '0 50px' }}>
          <Breadcrumb style={{ margin: '12px 0' }}>
            <Breadcrumb.Item link="javascript:void(0);">
              首页
            </Breadcrumb.Item>
            <Breadcrumb.Item link="javascript:void(0);">
              分类
            </Breadcrumb.Item>
            <Breadcrumb.Item link="javascript:void(0);">
              收藏
            </Breadcrumb.Item>
          </Breadcrumb>
          <Layout.Main
            style={{
              background: '#fff',
              padding: 24,
              minHeight: 280
            }}
          >
            Main
          </Layout.Main>
        </Layout.Section>
        <Layout.Footer
          style={{
            textAlign: 'center',
            lineHeight: '36px'
          }}
        >
          <p style={{ color: '#999' }}>
            © 2017-2018 xxxx团队 版权所有 系统维护者:@xx 如有问题随时联系!
            <br />
            由
            {' '}
            <a href="//ice.alibaba-inc.com" target="_blank">ICE</a>
            {' '}
            提供技术支持
          </p>
        </Layout.Footer>
      </Layout>
    );
  }
}

class Logo extends Component {
  render() {
    return (
      <div
        className="logo"
        style={{
          overflow: 'hidden',
          height: 35,
          margin: 10,
          color: '#f40',
          textAlign: 'left',
          minWidth: 200
        }}
      >
        <a href="/">
          <Img
            style={{ display: 'inline-block' }}
            height={35}
            width={129}
            src="https://img.alicdn.com/tps/TB1k.vjNpXXXXc6XXXXXXXXXXXX-258-70.png"
            type="contain"
          />
        </a>
      </div>
    );
  }
}

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

相关区块

Layout 页面布局 - 图9

暂无相关区块