1.1.0 • Published 4 years ago

header-sider-layout v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Header Sider Layout

A custom layout for Ant-design-pro, based on ant-design-pro-layout. Add the both layout type and some API for Header Nav.

npm.io

Usage

npm i header-sider-layout --save
// or
yarn add header-sider-layout
import ProLayout from 'header-sider-layout';

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

New API

PropertyDescriptionTypeDefault Value
headerMenuPropsProps passed to ANTD MENU (for HeaderMenu), SEE (https://ant.design/components/menu-cn/)MenuPropssame to origin menuProps
headerMenuDataThe menuData of header menuMenuDataItem[]same to origin MenuDataItem[] get from routes
layoutlayout menu mode, sidemenu: right navigation, topmenu: top navigation, both: header navigation and sider navigation'sidemenu' | 'topmenu' | 'both''sidemenu'

English | 简体中文 changelog

npm.io npm package npm.io Dependencies DevDependencies Build Status

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.

PropertyDescriptionTypeDefault Value
titlelayout in the upper left corner titleReactNode'Ant Design Pro'
logolayout top left logo urlReactNode | ()=>ReactNode-
menuHeaderRenderrender logo and titleReactNode | (logo,title)=>ReactNode-
onMenuHeaderClickmenu header click event(e: React.MouseEvent) => void-
layoutlayout menu mode, sidemenu: right navigation, topmenu: top navigation'sidemenu' | 'topmenu''sidemenu'
contentWidthcontent mode of layout, Fluid: fixed width 1200px, Fixed: adaptive'Fluid' | 'Fixed''Fluid'
navThemeNavigation menu theme'light' | 'dark''dark'
fixedHeaderwhether to fix header to topbooleanfalse
FixSiderbarWhether to fix navigation menubooleanfalse
autoHideHeaderautomatically hide the header when slidingboolean'false
menuAbout the configuration of the menu, only locale, locale can turn off the globalization of the menu{ locale: boolean }{ locale: true }
iconfontUrlUse IconFont icon configurationstring-
localeThe language setting of the layout'zh-CN' | 'zh-TW' | 'en-US'navigator.language
settingslayout settingsSettingsSettings-
siderWidthwidth of sider menunumber256
collapsedcontrol menu's collapse and expansionbooleantrue
onCollapsefolding collapse event of menu(collapsed: boolean) => void-
headerRendercustom header render method(props: BasicLayoutProps) => ReactNode-
rightContentRenderheader right content render method(props: HeaderViewProps) => ReactNode-
collapsedButtonRendercustom collapsed button method(collapsed: boolean) => ReactNode-
footerRendercustom footer render method(props: BasicLayoutProps) => ReactNode-
pageTitleRendercustom page title render method(props: BasicLayoutProps) => ReactNode-
menuRendercustom menu render method(props: HeaderViewProps) => ReactNode-
menuDataRenderThe render method of menuData, with the definition of menuData(menuData: MenuDataItem[]) => MenuDataItem[]-
menuItemRenderthe render method of a custom menu item(itemProps: MenuDataItem) => ReactNode-
breadcrumbRendercustom breadcrumbs data(route)=>route-
routeUsed to assist in the generation of menu and bread crumbs. Umi will automatically bringroute-
disableMobileDisable automatic switch to mobile modebooleanfalse
menuPropsProps passed to ANTD MENU, SEE (https://ant.design/components/menu-cn/)MenuPropsundefined

Layout support for most of Menu 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.

PropertyDescriptionTypeDefault Value
settingslayout settingsSettingsSettings-
onSettingChangeThe setting changes event(settings: Settings) => void-

PageHeaderWrapper

PageHeaderWrapper 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. PageHeaderWrapper supports all the attributes of Tabs and PageHeader.

PropertyDescriptionTypeDefault Value
contentContent areaReactNode-
extraContentExtra content area, on the right side of contentReactNode-
tabListTabs title listArray<{key: string, tab: ReactNode}>-
tabActiveKeyThe currently highlighted tab itemstring-
onTabChangeSwitch panel callback(key) => void-
tabBarExtraContentExtra elements on the tab barReact.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 } from '@ant-design/pro-layout';

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

GridContent

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

PropertyDescriptionTypeDefault Value
contentWidthContent 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,
);
PropertyDescriptionTypeDefault Value
routesRouting configuration informationroute[]-
menuMenu configuration item, default {locale: true}{ locale: boolean }-
menuDataRenderThe render method of menuData, with the definition of menuData(menuData: MenuDataItem[]) => MenuDataItem[]-
formatMessageThe 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.

PropertyDescriptionTypeDefault Value
pathnameCurrent pathnamelocation.pathname-
breadcrumbCollection of MenuDataItem{ [path: string]: MenuDataItem }-
menuMenu configuration item, default {locale: true}{ locale: boolean }-
titleType of titlestring'Ant Design Pro'
formatMessageThe 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: `sidemenu` or `topmenu`
   */
  layout: 'sidemenu' | 'topmenu';
  /**
   * layout of content: `Fluid` or `Fixed`, only works when layout is topmenu
   */
  contentWidth: 'Fluid' | 'Fixed';
  /**
   * sticky header
   */
  fixedHeader: boolean;
  /**
   * auto hide header
   */
  autoHideHeader: 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'];
  }>;
}

Browsers support

Modern browsers and IE11.

IE / EdgeFirefoxChromeSafariOpera
IE11, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versions

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.