简体   繁体   English

覆盖officeUI导航雪佛龙图标

[英]Override officeUI nav chevron icon

in the office-ui react fabric how do i over ride the chevon icon https://developer.microsoft.com/en-us/fabric#/components/nav 在office-ui react fabric中,我如何克服chevon图标https://developer.microsoft.com/en-us/fabric#/components/nav

In the documentation there is this interface 在文档中有此接口

INavStyles 

but i am not able to override it with my own icons. 但是我无法用自己的图标覆盖它。 i want to replace the existing chevron with FolderHorizontal and OpenFolderHorizontal icons instead 我想用FolderHorizo​​ntalOpenFolderHorizo​​ntal图标代替现有的人字形

import { AppContainer } from 'react-hot-loader';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { Nav, INavProps } from 'office-ui-fabric-react/lib/Nav';

import { initializeIcons } from 'office-ui-fabric-react/lib/Icons';
initializeIcons(/* optional base url */);

....
....


public _getNavLink(): any[] {
return [
  {
    name: 'Home',
    url: '',
    links: [{
      name: 'Activity',
      url: '',
      key: 'key1'
    },
    {
      name: 'News',
      url: '',
      key: 'key2'
    }],
    isExpanded: true
  }
]}

public render() {
return (
  <div>
    <Nav
         getStyles={() => {
          return {
            chevronIcon: {
              color: 'transparent',
              transform: 'rotate(0)',
              selectors: {
                '&:before': {
                  color: 'rgb(51, 51, 51)',
                  fontFamily: "FabricMDL2Icons-7",
                  content: '"\\F12B"',
                },
                '.is-expanded > * > &:before': {
                  fontFamily: "FabricMDL2Icons-5",
                  content: '"\\ED25"',
                }
              }
            }
          }
        }}
      groups={
        [
          {
            links: this._getNavLink() 
          }
        ]
      }
      expandedStateText={ 'expanded' }
      collapsedStateText={ 'collapsed' }
      selectedKey={ 'key3' }
    />
  </div>
);

} }

在此处输入图片说明

You could set the getStyles property on the Nav component to apply CSS to the chevronIcon slot: 您可以在Nav组件上设置getStyles属性,以将CSS应用于chevronIcon插槽:

<Nav
    getStyles={ () => { return { 
        chevronIcon: { 
          color: 'transparent',
          transform: 'rotate(0)',
          selectors: {
            '&:before': { 
              color: 'rgb(51, 51, 51)', 
              fontFamily: "FabricMDL2Icons-7",
              content: '"\\F12B"',
            },
            '.is-expanded > * > &:before': { 
              fontFamily: "FabricMDL2Icons-5",
              content: '"\\ED25"',
            }
          }
        }
      }} }
      groups={...}
      expandedStateText={ 'expanded' }
      collapsedStateText={ 'collapsed' }
      selectedKey={ 'key3' }
    />

The solution is basically hiding away the original chevron, disables the rotation and shows desired icons in the background. 解决方案基本上是隐藏原始人字形,禁用旋转并在背景中显示所需的图标。

Note that the icons for FolderHorizontal and OpenFolderHorizontal are set using their Unicode representation which can be looked up in the Github repo (eg https://github.com/OfficeDev/office-ui-fabric-react/search?q=FolderHorizontal ). 请注意, FolderHorizontalOpenFolderHorizontal的图标是使用其Unicode表示形式设置的,可以在Github存储库中进行查找(例如https://github.com/OfficeDev/office-ui-fabric-react/search?q=FolderHorizo​​ntal )。 The two icons live in seperate font families, hence the fontFamily directive. 这两个图标位于单独的字体系列中,因此使用fontFamily指令。

UPDATE [20180417] 更新[20180417]

Make sure the fonts are initialized using initializeIcons(); 确保使用initializeIcons();字体initializeIcons(); or using a custom path. 或使用自定义路径。 The font files should then be loaded and appear in your DevTools: 然后应加载字体文件,并将其显示在您的DevTools中:

在此处输入图片说明

Note that - unlike your code - we are using 请注意,与您的代码不同,我们正在使用

import { initializeIcons } from '@uifabric/icons';

to import the initializeIcons . 导入initializeIcons

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM