项目作者: ant-design

项目描述 :
🌃 Powerful and easy to use beautiful layout
高级语言: TypeScript
项目地址: git://github.com/ant-design/ant-design-pro-layout.git
创建时间: 2019-04-05T04:17:37Z
项目社区:https://github.com/ant-design/ant-design-pro-layout

开源协议:MIT License

下载


此仓库已废弃

重要: 此仓库后续不再维护,也不再接受更多的特性更新。ant-design/pro-layout 将会迁移至 ant-design/pro-components 仓库进行后续的维护,访问 https://procomponent.ant.design/layout 了解更多。此变更不影响继续使用 @ant-design/pro-layout 这个 npm 包名安装使用此组件。

English | 简体中文 changelog


@ant-design/pro-layout""> @ant-design/pro-layout"">npm package

Ant Design Pro Layout



image

An out-of-box UI solution for enterprise applications as a React boilerplate. This repository is the layout of Ant Design Pro and was developed for quick and easy use of the layout.

Usage

  1. npm i @ant-design/pro-layout --save
  2. // or
  3. yarn add @ant-design/pro-layout

```jsx | pure
import ProLayout from ‘@ant-design/pro-layout’;

render(, document.getElementById(‘root’));

  1. ## Demo
  2. [site](https://ant-design.github.io/ant-design-pro-layout/)
  3. ## API
  4. ### ProLayout
  5. > All methods with the suffix `Render` can prevent rendering by passing in `false`.
  6. | Property | Description | Type | Default Value |
  7. | --- | --- | --- | --- |
  8. | title | layout in the upper left corner title | ReactNode | `'Ant Design Pro'` |
  9. | logo | layout top left logo url | ReactNode \| ()=>ReactNode | - |
  10. | pure | Interface that doesn't require extra ui | boolean | - |
  11. | loading | layout loading status | boolean | - |
  12. | menuHeaderRender | render logo and title | ReactNode \| (logo,title)=>ReactNode | - |
  13. | onMenuHeaderClick | menu header click event | `(e: React.MouseEvent<HTMLDivElement>) => void` | - |
  14. | contentStyle | layout content style | CSSProperties | - |
  15. | layout | layout menu mode, side: right navigation, top: top navigation | 'side' \| 'top' | `'side'` |
  16. | contentWidth | content mode of layout, Fluid: fixed width 1200px, Fixed: adaptive | 'Fluid' \| 'Fixed' | `'Fluid'` |
  17. | navTheme | Navigation menu theme | 'light' \| 'dark' | `'dark'` |
  18. | fixedHeader | whether to fix header to top | boolean | `false` |
  19. | fixSiderbar | Whether to fix navigation menu | boolean | `false` |
  20. | breakpoint | [breakpoints](https://ant.design/components/grid/#api) of the responsive layout | `Enum { 'xs', 'sm', 'md', 'lg', 'xl', 'xxl' }` | `lg` |
  21. | menu | About the configuration of the menu, only locale, locale can turn off the globalization of the menu | { locale: boolean,defaultOpenAll: boolean } | `{ locale: true }` |
  22. | iconfontUrl | Use [IconFont](https://ant.design/components/icon-cn/#components-icon-demo-iconfont) icon configuration | string | - |
  23. | locale | The language setting of the layout | 'zh-CN' \| 'zh-TW' \| 'en-US' | navigator.language |
  24. | settings | layout settings | [`Settings`](#Settings) | [`Settings`](#Settings) | - |
  25. | siderWidth | width of sider menu | number | 256 |
  26. | collapsed | control menu's collapse and expansion | boolean | true |
  27. | onPageChange | Triggered when page switching | (location: Location) => void | - |
  28. | onCollapse | folding collapse event of menu | (collapsed: boolean) => void | - |
  29. | headerRender | custom header render method | (props: BasicLayoutProps) => ReactNode | - |
  30. | headerTitleRender | custom header title render method | (props: BasicLayoutProps) => ReactNode | - |
  31. | headerContentRender | custom header content render method | (props: BasicLayoutProps) => ReactNode | - |
  32. | rightContentRender | header right content render method | (props: HeaderViewProps) => ReactNode | - |
  33. | collapsedButtonRender | custom collapsed button method | (collapsed: boolean) => ReactNode | - |
  34. | footerRender | custom footer render method | (props: BasicLayoutProps) => ReactNode | - |
  35. | pageTitleRender | custom page title render method | (props: BasicLayoutProps) => ReactNode | - |
  36. | menuRender | custom menu render method | (props: HeaderViewProps) => ReactNode | - |
  37. | menuDataRender | The render method of menuData, with the definition of menuData | `(menuData: MenuDataItem[]) => MenuDataItem[]` | - |
  38. | postMenuData | View the menu data before displaying it. Modification will not trigger re-rendering. | `(menuData: MenuDataItem[]) => MenuDataItem[]` | - |
  39. | postMenuData |
  40. | menuItemRender | the render method of a custom menu item | [(itemProps: MenuDataItem) => ReactNode](#MenuDataItem) | - |
  41. | subMenuItemRender | the render method of a custom subMenu item | [(itemProps: MenuDataItem) => ReactNode](#MenuDataItem) | - |
  42. | breadcrumbRender | custom breadcrumbs data | (route)=>route | - |
  43. | route | Used to assist in the generation of menu and bread crumbs. Umi will automatically bring | [route](#Route) | - |
  44. | disableMobile | Disable automatic switch to mobile mode | boolean | false |
  45. | links | Shortcuts displayed in the lower right corner of the menu | ReactNode[] | - |
  46. | menuProps | Props passed to ANTD MENU, SEE (https://ant.design/components/menu-cn/) | MenuProps | undefined |
  47. Layout support for most of [Menu](https://ant.design/components/menu-cn/#Menu) by `menuProps` after 4.5.13.
  48. ### SettingDrawer
  49. ```js | pure
  50. import { SettingDrawer } from '@ant-design/pro-layout';

SettingDrawer provides a graphical interface to set the layout configuration. Not recommended for use in a product environment.

Property Description Type Default Value
settings layout settings Settings Settings -
onSettingChange The setting changes event (settings: Settings) => void -
hideHintAlert remove hint info boolean -

PageContainer

PageContainer encapsulates the PageHeader component of ant design, adds tabList, and content. Fill in the title and breadcrumb based on the current route. It depends on the route property of the Layout. Of course you can pass in parameters to override the default values. PageContainer supports all the attributes of Tabs and PageHeader.

Property Description Type Default Value
content Content area ReactNode -
extraContent Extra content area, on the right side of content ReactNode -
tabList Tabs title list Array<{key: string, tab: ReactNode}> -
tabActiveKey The currently highlighted tab item string -
onTabChange Switch panel callback (key) => void -
tabBarExtraContent Extra elements on the tab bar React.ReactNode -

PageLoading

a simple loading page

Property Description Type Default Value
tip loading tip ReactNode -

RouteContext

RouteContext can provide built-in data for Layout. For example, isMobile and collapsed, you can consume this data to customize some behavior.

```tsx | pure
import { RouteContext, RouteContextType } from ‘../index’;

const Page = () => (

{(value: RouteContextType) => {
return value.title;
}}

);

  1. ### GridContent
  2. GridContent encapsulates [equal width](https://preview.pro.ant.design/dashboard/analysis?layout=top&contentWidth=Fixed) and [streaming](https://preview.pro.ant.design/dashboard/) The logic of analysis?layout=top). You can see the preview in [preview](https://preview.pro.ant.design/dashboard/analysis).
  3. | Property | Description | Type | Default Value |
  4. | ------------ | ------------ | ------------------ | ------------- |
  5. | contentWidth | Content mode | 'Fluid' \| 'Fixed' | - |
  6. ### getMenuData
  7. Generate menuData and breadcrumb based on the router information.
  8. ```js | pure
  9. import { getMenuData } from '@ant-design/pro-layout';
  10. const { breadcrumb, menuData } = getMenuData(
  11. routes,
  12. menu,
  13. formatMessage,
  14. menuDataRender,
  15. );
Property Description Type Default Value
routes Routing configuration information route[] -
menu Menu configuration item, default {locale: true} { locale: boolean } -
menuDataRender The render method of menuData, with the definition of menuData (menuData: MenuDataItem[]) => MenuDataItem[] -
formatMessage The formatMessage method of react-intl (data: { id: any; defaultMessage?: string }) => string; -

getPageTitle

```js | pure
import { getPageTitle } from ‘@ant-design/pro-layout’;

const title = getPageTitle({
pathname,
breadcrumb,
menu,
title,
formatMessage,
});

  1. getPageTitle encapsulates the logic based on the title generated on menuData.
  2. | Property | Description | Type | Default Value |
  3. | --- | --- | --- | --- |
  4. | pathname | Current pathname | location.pathname | - |
  5. | breadcrumb | Collection of MenuDataItem | `{ [path: string]: MenuDataItem }` | - |
  6. | menu | Menu configuration item, default `{locale: true}` | `{ locale: boolean }` | - |
  7. | title | Type of title | string | 'Ant Design Pro' |
  8. | formatMessage | The formatMessage method of react-intl | `(data: { id: any; defaultMessage?: string }) => string;` | - |
  9. ## Data Structure
  10. > For ease of viewing and use, Typescript is used here to write.
  11. ### Settings
  12. ```ts | pure
  13. // can be done via import { Settings } from '@ant-design/pro-layout/defaultSettings' to get this type
  14. export interface Settings {
  15. /**
  16. * theme for nav menu
  17. */
  18. navTheme: 'light' | 'dark';
  19. /**
  20. * primary color of ant design
  21. */
  22. primaryColor: string;
  23. /**
  24. * nav menu position: `side` or `top`
  25. */
  26. layout: 'side' | 'top';
  27. /**
  28. * layout of content: `Fluid` or `Fixed`, only works when layout is top
  29. */
  30. contentWidth: 'Fluid' | 'Fixed';
  31. /**
  32. * sticky header
  33. */
  34. fixedHeader: boolean;
  35. /**
  36. * sticky siderbar
  37. */
  38. fixSiderbar: boolean;
  39. menu: { locale: boolean };
  40. title: string;
  41. pwa: boolean;
  42. // Your custom iconfont Symbol script Url
  43. // eg://at.alicdn.com/t/font_1039637_btcrd5co4w.js
  44. // Usage: https://github.com/ant-design/ant-design-pro/pull/3517
  45. iconfontUrl: string;
  46. colorWeak: boolean;
  47. }

MenuDataItem

```ts | pure
// can be imported { MenuDataItem } from ‘@ant-design/pro-layout/typings’ to get this type

export interface MenuDataItem {
authority?: string[] | string;
children?: MenuDataItem[];
hideChildrenInMenu?: boolean;
hideInMenu?: boolean;
icon?: string;
locale?: string;
name?: string;
path: string;

}

  1. ### Route
  2. ```ts | pure
  3. // can be imported { RouterTypes } from '@ant-design/pro-layout/typings' to get this type
  4. export interface Route {
  5. path: string;
  6. routes: Array<{
  7. exact?: boolean;
  8. icon: string;
  9. name: string;
  10. path: string;
  11. // optional secondary menu
  12. children?: Route['routes'];
  13. }>;
  14. }

Contributing

Any type of contribution is welcome, here are some examples of how you may contribute to this project:

  • Use Ant Design Pro in your daily work.
  • Submit issues to report bugs or ask questions.
  • Propose pull requests to improve our code.