Coder Social home page Coder Social logo

ant-design / ant-design-pro-layout Goto Github PK

View Code? Open in Web Editor NEW
998.0 26.0 238.0 15.73 MB

🌃 Powerful and easy to use beautiful layout

Home Page: https://prolayout.ant.design/

License: MIT License

JavaScript 3.71% TypeScript 85.96% CSS 8.32% HTML 2.01%
umi ant-design ant-design-pro react admin layout

ant-design-pro-layout's Introduction

此仓库已废弃

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

English | 简体中文 changelog

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

npm i @ant-design/pro-layout --save
// or
yarn add @ant-design/pro-layout
import ProLayout from '@ant-design/pro-layout';

render(<ProLayout />, document.getElementById('root'));

Demo

site

API

ProLayout

All methods with the suffix Render can prevent rendering by passing in false.

Property Description Type Default Value
title layout in the upper left corner title ReactNode 'Ant Design Pro'
logo layout top left logo url ReactNode | ()=>ReactNode -
pure Interface that doesn't require extra ui boolean -
loading layout loading status boolean -
menuHeaderRender render logo and title ReactNode | (logo,title)=>ReactNode -
onMenuHeaderClick menu header click event (e: React.MouseEvent<HTMLDivElement>) => void -
contentStyle layout content style CSSProperties -
layout layout menu mode, side: right navigation, top: top navigation 'side' | 'top' 'side'
contentWidth content mode of layout, Fluid: fixed width 1200px, Fixed: adaptive 'Fluid' | 'Fixed' 'Fluid'
navTheme Navigation menu theme 'light' | 'dark' 'dark'
fixedHeader whether to fix header to top boolean false
fixSiderbar Whether to fix navigation menu boolean false
breakpoint breakpoints of the responsive layout Enum { 'xs', 'sm', 'md', 'lg', 'xl', 'xxl' } lg
menu About the configuration of the menu, only locale, locale can turn off the globalization of the menu { locale: boolean,defaultOpenAll: boolean } { locale: true }
iconfontUrl Use IconFont icon configuration string -
locale The language setting of the layout 'zh-CN' | 'zh-TW' | 'en-US' navigator.language
settings layout settings Settings Settings
siderWidth width of sider menu number 256
collapsed control menu's collapse and expansion boolean true
onPageChange Triggered when page switching (location: Location) => void -
onCollapse folding collapse event of menu (collapsed: boolean) => void -
headerRender custom header render method (props: BasicLayoutProps) => ReactNode -
headerTitleRender custom header title render method (props: BasicLayoutProps) => ReactNode -
headerContentRender custom header content render method (props: BasicLayoutProps) => ReactNode -
rightContentRender header right content render method (props: HeaderViewProps) => ReactNode -
collapsedButtonRender custom collapsed button method (collapsed: boolean) => ReactNode -
footerRender custom footer render method (props: BasicLayoutProps) => ReactNode -
pageTitleRender custom page title render method (props: BasicLayoutProps) => ReactNode -
menuRender custom menu render method (props: HeaderViewProps) => ReactNode -
menuDataRender The render method of menuData, with the definition of menuData (menuData: MenuDataItem[]) => MenuDataItem[] -
postMenuData View the menu data before displaying it. Modification will not trigger re-rendering. (menuData: MenuDataItem[]) => MenuDataItem[] -
postMenuData
menuItemRender the render method of a custom menu item (itemProps: MenuDataItem) => ReactNode -
subMenuItemRender the render method of a custom subMenu item (itemProps: MenuDataItem) => ReactNode -
breadcrumbRender custom breadcrumbs data (route)=>route -
route Used to assist in the generation of menu and bread crumbs. Umi will automatically bring route -
disableMobile Disable automatic switch to mobile mode boolean false
links Shortcuts displayed in the lower right corner of the menu ReactNode[] -
menuProps Props passed to ANTD MENU, SEE (https://ant.design/components/menu-cn/) MenuProps undefined

Layout support for most of Menu by menuProps after 4.5.13.

SettingDrawer

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.

import { RouteContext, RouteContextType } from '../index';

const Page = () => (
  <RouteContext.Consumer>
    {(value: RouteContextType) => {
      return value.title;
    }}
  </RouteContext.Consumer>
);

GridContent

GridContent encapsulates equal width and streaming The logic of analysis?layout=top). You can see the preview in preview.

Property Description Type Default Value
contentWidth Content mode 'Fluid' | 'Fixed' -

getMenuData

Generate menuData and breadcrumb based on the router information.

import { getMenuData } from '@ant-design/pro-layout';

const { breadcrumb, menuData } = getMenuData(
  routes,
  menu,
  formatMessage,
  menuDataRender,
);
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

import { getPageTitle } from '@ant-design/pro-layout';

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

getPageTitle encapsulates the logic based on the title generated on menuData.

Property Description Type Default Value
pathname Current pathname location.pathname -
breadcrumb Collection of MenuDataItem { [path: string]: MenuDataItem } -
menu Menu configuration item, default {locale: true} { locale: boolean } -
title Type of title string 'Ant Design Pro'
formatMessage The formatMessage method of react-intl (data: { id: any; defaultMessage?: string }) => string; -

Data Structure

For ease of viewing and use, Typescript is used here to write.

Settings

// can be done via import { Settings } from '@ant-design/pro-layout/defaultSettings' to get this type

export interface Settings {
  /**
   * theme for nav menu
   */
  navTheme: 'light' | 'dark';
  /**
   * primary color of ant design
   */
  primaryColor: string;
  /**
   * nav menu position: `side` or `top`
   */
  layout: 'side' | 'top';
  /**
   * layout of content: `Fluid` or `Fixed`, only works when layout is top
   */
  contentWidth: 'Fluid' | 'Fixed';
  /**
   * sticky header
   */
  fixedHeader: boolean;
  /**
   * sticky siderbar
   */
  fixSiderbar: boolean;
  menu: { locale: boolean };
  title: string;
  pwa: boolean;
  // Your custom iconfont Symbol script Url
  // eg://at.alicdn.com/t/font_1039637_btcrd5co4w.js
  // Usage: https://github.com/ant-design/ant-design-pro/pull/3517
  iconfontUrl: string;
  colorWeak: boolean;
}

MenuDataItem

// 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;
  [key: string]: any;
}

Route

// can be imported { RouterTypes } from '@ant-design/pro-layout/typings'  to get this type
export interface Route {
  path: string;
  routes: Array<{
    exact?: boolean;
    icon: string;
    name: string;
    path: string;
    // optional secondary menu
    children?: Route['routes'];
  }>;
}

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.

ant-design-pro-layout's People

Contributors

afc163 avatar anderson-liu avatar andriijas avatar chenshuai2144 avatar ddcat1115 avatar dependabot-preview[bot] avatar depfu[bot] avatar flutterbest avatar guowenfh avatar happier2 avatar imhele avatar jaredleechn avatar kaoding avatar kennylbj avatar kjlmfe avatar m4jing avatar michelemilani91 avatar nikogu avatar puuuudding avatar qjekingstar avatar rayronvictor avatar sorrycc avatar valleykid avatar wadezhan avatar whatakitty avatar xiaohuoni avatar yesmeck avatar yoyo837 avatar yutingzhao1991 avatar zhongjiewu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ant-design-pro-layout's Issues

页脚版权文字和连接不能改

定义了 footerRender 也不能修改页脚 copyright 和 links 的值,请问要怎么才能修改?
难道只能设置 footerRender 为 false,原后自己在 layout 中自定义页脚?

ProLayout组件的 props: location 是必须的,文档没有标出来

背景:

我是直接ant-design-pro-layout搭架子.没有用 umi 那一套...
路由配置渲染从 umi 的 renderRoutes修改来的(当然这些和 bug无关)

现象:

面包屑不出现和侧边菜单的二级菜单一直不选中...

最后来了源码 SiderMenu.tsx

const { location = { pathname: '/' }, flatMenuKeys = [] } = props;

如果不传..使用默认值..那么菜单选中的值就一直是错误的.
面包屑也是如此 utils/getBreadcrumbProps.tsx

breadcrumbRender issues

版本:"@ant-design/pro-layout": "^4.5.0"

  1. breadcrumbRender这个配置主要是用来干吗的,
  2. 这个版本怎么添加面包屑

手机模式没法关闭

环境:

 "@ant-design/pro-layout": "^4.5.10",
    "@babel/plugin-proposal-decorators": "^7.4.4",
    "antd": "^3.20.3",
    "babel-plugin-import": "^1.12.0",
    "customize-cra": "^0.2.14",
    "less": "^3.9.0",
    "less-loader": "^5.0.0",
    "mobx": "^4.3.0",
    "mobx-react": "^5.2.5",
    "mockjs": "^1.0.1-beta3",
    "moment": "^2.24.0",
    "react": "^16.8.6",
    "react-app-rewired": "^2.1.3",
    "react-dom": "^16.8.6",
    "react-intl": "^2.9.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.0.1"

image

isUrl的判断和 HashRouter 不兼容,导致菜单渲染错误

4.5.8版本

export function isUrl(path: string): boolean {
  return reg.test(path) || path.indexOf('/') === 0;
}

认为 /开头的也是外部地址.使用 a 链接,
那么 /demo/a的hashrouter 的地址是 /#/demo/a, 直接a 链接跳转就是错误地址.

自定义的话,defaultDom始终包含 a 链接,和 Link嵌套有问题

menuItemRender={(menuItemProps, defaultDom) => (
        <Link to={menuItemProps.path}>{defaultDom}</Link>
 )}

menuDataRender 命名不好

改为 getMenuData,因为这个返回的是纯粹的数据结构,不是 ReactNode,所以不应该是一个 render。

优化建议

  • logo 和 renderLogo 职责重复,不如让 logo 多支持一个 function 的用法就够了。
  • lang 改成 locale
  • onChangeSetting 改成 onSettingsChange,其他 API 类似,Change 要放在最后。
  • API 文档直接写到 README 里来吧,把原来 pro 的部分去掉。
  • onLogoClick 可以用 logo 的 render 方法取代,感觉没啥用。
  • breadcrumbNameMap 这个 API 有点看不懂,不知道解决什么问题,建议改成更好懂的 API。
  • renderHeader 最好把左上角和右上角要加的区别开。
  • settings 直接解构打平和其他 props 放在一起好了,感觉区别不大。
  • logo 的话,也应该有 favicon
  • SettingsDrawer 变成一个独立组件

PageHeaderWrapper 当中缺少 extra 的属性的定义

创建最新的 Pro , PageHeaderWrapper 的代码如下, 还是报错。

<PageHeaderWrapper
        title={<FormattedMessage id="page.title" />}
        extra={
          <Fragment>
            <Authorized authority="category.base_category.recycle">
              <Button type="primary" href="/category/base-category/recycle">
                <FormattedMessage id="application.list.operate.recycle.label" />
              </Button>
            </Authorized>
          </Fragment>
        }
      >

image

roadmap

  • 💪 add test and ui test
  • 👀better api doc
  • 👀have a site
  • 💪add create-react-app use doc
  • 💪add old project use doc
    Maybe with and without umi

DefaultFooter doesn't change copyright

Hi,
when I try to change the DefaultFooter copyright within in the UserLayout.tsx of my ant pro app, by using
<DefaultFooter copyright="xyz" /> nothing changes. How can it be changed?

Best,
Nico

自定义菜单的问题

自定义菜单,当菜单的层级关系与路由的层级关系不一至时,菜单选中没有问题,但是菜单不展开。

BasicLayout 不展示logo,title怎样加链接

<ProLayoutComponents
      title={<Link to="/">标题</Link>}
      logo={false}
      onCollapse={false}
      collapsed={false}
      menuItemRender={(menuItemProps, defaultDom) => {
        return <Link to={menuItemProps.path.replace(/:id/, id)}>{defaultDom}</Link>;
      }}
      breadcrumbRender={false}
      footerRender={false}
      menuDataRender={menuDataRender}
      formatMessage={formatMessage}
      rightContentRender={rightProps => <RightContent {...rightProps} />}
      {...props}
      {...settings}
    >
      {children}
</ProLayoutComponents>

其中根路径‘/’是个dashboard,这样写从dashboard进入具体某个业务之后,PageTitle.split('-')[0]这个地方会报错,请问下怎样给title加链接?

问题反馈

1:右侧删除不必要的组件后,不向面对齐。
image

2:当窗口变小以后,Logo显示不正确。
image

3:当窗口变小以后,菜单显示不正确。 抽屉的关闭按钮被挡住一半,另外菜单感觉也是显示一半。
image

Add Badges

  • deps
  • devDeps
  • build
  • coverage
  • npm version
  • npm downloads

like antd and rc-components.

MenuData uses item.path for key

Hi,

BaseMenu always uses 'item.path' for key, if there are multiple menu items to the same path React will complain about duplicate key. Maybe it's possible to use a custom key property on the MenuItem?

For example change from key: item.path to key: item.key || item.path

support Footer

现在是通过下面两种方式提供 footer:

import ProLayout, { DefaultFooter } from '@ant-design/pro-layout';

<DefaultFooter />
<ProLayout
  footerRender={((_, defaultDom) => {
    return defaultDom;
  }
/>

问题

方案

直接把 https://github.com/ant-design/ant-design-pro-layout/blob/master/src/GlobalFooter/index.tsx 对外暴露,default 内容移出。

import ProLayout, { Footer } from '@ant-design/pro-layout';

<Footer
  links={[...]}
  copyright={...}
/>

<ProLayout
  footerRender={(() => {
    return (
      <Footer
        links={[...]}
        copyright={...}
      />
    );
  }
/>

兼容性

会是一个 break change,需要升级 pro-layout 大版本,并补齐相关 API 文档和 changelog。

vscode 中 BasicLayoutProps 类型报错

接口“BasicLayoutProps”不能同时扩展类型“BasicLayoutProps”和“Pick<ConnectProps<{}>, "history" | "match" | "staticContext" | "computedMatch" | "route" | "dispatch">”。
“BasicLayoutProps”和“Pick<ConnectProps<{}>, "history" | "match" | "staticContext" | "computedMatch" | "route" | "dispatch">”类型的命名属性“computedMatch”不完全相同

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.