4.2.2 • Published 11 months ago

@hi-ui/classic-theme v4.2.2

Weekly downloads
9
License
MIT
Repository
github
Last release
11 months ago

使用

npm i @hi-ui/classic-theme --save
// or
yarn add @hi-ui/classic-theme
import Theme from "@hi-ui/classic-theme";

render(<Theme />, document.getElementById("app"));

示例

基于配置化实现主题布局和菜单匹配,数组中元素的层级即代表其在菜单中的层级

import React, { Component } from "react";
import { Theme } from "@hi-ui/classic-theme";
import { Link } from "react-router-dom";
import { Input, Icon } from "@hi-ui/hiui";

const Mi = () => <div>小米手机</div>;
const RedMi = () => <div>红米手机</div>;
const BlackShark = () => <div>黑鲨手机</div>;
const TV = () => <div>小米电视</div>;
const SoundBox = () => (
  <div>
    小米音响<Link to="/robot-detail/1?b=1">去详情页</Link>
  </div>
);
const Robot = () => <div>米家扫地机器人</div>;
const RobotDetail = () => <div>米家扫地机器人详情页</div>;

const routeConfig = [
  {
    name: "手机",
    children: [
      { name: "小米", path: "/mi", component: Mi },
      { name: "红米", path: "/red-mi", component: RedMi, withoutLayout: true },
      { name: "黑鲨", path: "/black-shark", component: BlackShark },
    ],
  },
  { name: "电视", path: "/tv", component: TV },
  {
    name: "智能硬件",
    children: [
      { name: "音响", path: "/audio", component: SoundBox },
      { name: "扫地机器人", path: "/robot", component: Robot },
      { path: "/robot-detail/:id", component: RobotDetail },
    ],
  },
];

const logoConfig = {
  logoUrl:
    "https://xiaomi.github.io/hiui/static/img/logo.png?241e0618fe55d933c280e38954edea05",
  name: "HIUI Theme",
  url: "https://xiaomi.github.io/hiui/#/",
};

const loginConfig = {
  name: "Mi Guest",
  icon: "user",
  children: [
    <div key="1" style={{ textAlign: "center", margin: 4, width: "100px" }}>
      <a href="#info">个人信息</a>
    </div>,
    <div key="2" style={{ textAlign: "center", margin: 4, width: 100 }}>
      <a href="#logout">注销</a>
    </div>,
  ],
};
const toolbar = [<Input key="1" />, <Icon key="2" name="prompt" />];

class App extends Component {
  render() {
    return (
      <Theme
        routes={routeConfig}
        logo={logoConfig}
        login={loginConfig}
        toolbar={toolbar}
      />
    );
  }
}

export default App;

关于路由跳转

组件内

使用 react-router <Link /> 即可

API 跳转

内部对 react-router 的 history 进行了封装

import Theme, {History} from '@hi-ui/classic-theme'

History[`${your history type}`].push()

详细使用可参考 react-router 官网

API

Theme

属性名描述类型默认值
type主题类型'classic' | 'genuine''classic'
dynamic开启动态布局booleantrue
tagsView开启页面顶部标签页视图booleanfalse
routes路由配置项Route[]-
historyType路由跳转类型'hashHistory' | 'browserHistory''browserHistory'
headergenuine 类型下的顶部功能栏ReactNode | null不传时默认为主题自带 header
apperance主题外观配置项Apperance{color:'dark'}
logo主题 logo 配置项Logo | (toggle: boolean) => Logo-
login主题登录信息配置项Login-
toolbar顶部工具栏,一般用于放置通知、全局搜索等ReactNode-
pageHeader自定义页头(selectedMenus: Route [], location: Location) => ReactNode-
defaultExpandAll是否默认展开侧边栏菜单booleanfalse
siderTopRender侧边栏自定义顶部渲染区域(toggle: boolean) => ReactNode-
siderBottomRender侧边栏自定义底部渲染区域(toggle: boolean) => ReactNode-
accordion左侧菜单是否采用手风琴模式booleantrue
basename路由基础路径string'/'
authority用户拥有权限配置string[]-
fallback路由无法匹配时的候补跳转string-
onToggle侧边栏展开收起触发的回调mini: boolean => void-
defaultToggle设置默认侧边栏展开形式(设置后 dynamic 将无效)'mini' | 'large'-
onMenuClick菜单点击事件(menuItem: Object) => void-

type: Route

属性名描述类型默认值
name菜单名称string-
icon菜单 iconReactNode-
children子菜单配置项Route[]-
path菜单跳转路径string-
exact菜单跳转路径是否严格匹配对应的 componentbooleantrue
component菜单对应页面组件ReactNode-
withoutLayout页面组件渲染时,不显示顶部导航栏和侧边栏booleanfalse
extraData向路由匹配的页面组件注入额外的数据object-
authority允许访问该路由的权限(和 Theme 中的 authority 配置的内容能够匹配上)string[]-
keepAlive缓存组件实例booleanfalse
hideInMenu设置 true 强制在菜单中隐藏展示booleanfalse
unmountOnTagClose点击 tag 关闭时销毁组件实例booleanfalse
target是否新标签打开路由HTMLAttributeAnchorTarget-

type: Apperance

属性名描述类型默认值
color主题颜色'dark' | 'light''dark'
contentBackground内容区域背景色string'#f6f6f6'
contentPadding内容区域内边距number0

tye: Logo

属性名描述类型默认值
name系统名称string-
logoUrllogo 图片地址string-
url点击 logo 跳转地址string-

type: Login

属性名描述类型默认值
name登录用户姓名string-
avatar头像图片的链接地址string-
icon登录用户 iconReactNode-
children登录菜单项ReactNode[]-
4.2.2

11 months ago

5.0.0-alpha.7

1 year ago

5.0.0-alpha.6

1 year ago

5.0.0-alpha.8

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.1.0

1 year ago

5.0.0-alpha.5

1 year ago

5.0.0-alpha.4

2 years ago

5.0.0-alpha.3

2 years ago

5.0.0-alpha.2

2 years ago

4.0.6

1 year ago

4.1.0-alpha.4

1 year ago

4.0.6-beta.0

1 year ago

4.1.0-alpha.3

1 year ago

5.0.0-alpha.1

2 years ago

5.0.0-alpha.0

2 years ago

4.1.0-alpha.2

2 years ago

4.0.5

2 years ago

4.1.0-alpha.1

2 years ago

4.0.4

2 years ago

4.0.3-beta.2

2 years ago

4.1.0-alpha.0

2 years ago

4.0.1

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.3-beta.0

2 years ago

4.0.3-beta.1

2 years ago

4.0.0

2 years ago

3.7.0-rc

3 years ago

3.6.0-rc.1

3 years ago

3.5.3

3 years ago

3.5.2

3 years ago

3.5.0

3 years ago

3.5.4

3 years ago

3.4.2

3 years ago

3.4.0

3 years ago

3.4.1

3 years ago

3.3.0

4 years ago

3.2.3

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.1-rc.1

4 years ago

3.0.0

4 years ago

3.0.0-rc.13

4 years ago

3.0.0-rc.14

4 years ago

3.0.0-rc.12

4 years ago

3.0.0-rc.11

4 years ago

3.0.0-rc.10

4 years ago

2.0.1

4 years ago

3.0.0-rc.9

4 years ago

3.0.0-rc.8

4 years ago

3.0.0-rc.7

4 years ago

3.0.0-rc.6

4 years ago

3.0.0-rc.5

4 years ago

3.0.0-rc.4

4 years ago

3.0.0-rc.3

4 years ago

2.0.0

4 years ago

3.0.0-rc.2

4 years ago

3.0.0-rc.1

4 years ago

3.0.0-rc

4 years ago

2.0.0-rc.31

4 years ago

2.0.0-rc.32

4 years ago

2.0.0-rc.30

4 years ago

2.0.0-rc.29

4 years ago

2.0.0-rc.28

4 years ago

2.0.0-rc.27

5 years ago

2.0.0-rc.26

5 years ago

2.0.0-rc.25

5 years ago

2.0.0-rc.24

5 years ago

2.0.0-rc.23

5 years ago

2.0.0-rc.22

5 years ago

2.0.0-rc.21

5 years ago

2.0.0-rc.20

5 years ago

2.0.0-rc.19

5 years ago

2.0.0-rc.18

5 years ago

2.0.0-rc.17

5 years ago

2.0.0-rc.16

5 years ago

2.0.0-rc.15

5 years ago

2.0.0-rc.14

5 years ago

2.0.0-rc.13

5 years ago

2.0.0-rc.12

5 years ago

2.0.0-rc.11

5 years ago

2.0.0-rc.10

5 years ago

2.0.0-rc.9

5 years ago

2.0.0-rc.8

5 years ago

2.0.0-rc.7

5 years ago

2.0.0-rc.6

5 years ago

2.0.0-rc.5

5 years ago

2.0.0-rc.4

5 years ago

2.0.0-rc.3

5 years ago

2.0.0-rc.2

5 years ago

2.0.0-rc

5 years ago

2.0.0-beta.7

5 years ago

2.0.0-beta.6

5 years ago

2.0.0-beta.5

5 years ago

2.0.0-beta.4

5 years ago

2.0.0-beta.3

5 years ago

2.0.0-beta.2

5 years ago

2.0.0-beta.1

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1-beta.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-beta.9

6 years ago

1.0.0-beta.8

6 years ago

1.0.0-beta.7

6 years ago

1.0.0-beta.6

6 years ago

1.0.0-beta.5

6 years ago

1.0.0-beta.4

6 years ago

0.9.7-beta.1

6 years ago

1.0.0-beta.2

6 years ago

1.0.0-beta.1

6 years ago

0.9.6

6 years ago

0.9.6-beta.1

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago