简体   繁体   中英

Access Office UI Fabric theme colours in JavaScript

Based upon the documentation about Usage via JavaScript styling libraries , I'm trying to access the Office Fabric UI theme colours in my application. I've followed the instructions and installed @uifabric/styling . I'm then supposed to simply import the styles as

import {
  styles
} from '@uifabric/styling'; 

...to get access to the colours. But I get the following TypeScript error:

[ts] Module '"c:/.../node_modules/@uifabric/styling/lib/index"' has 
no exported member 'styles'. Did you mean 'IStyle'?

Is the documentation old or maybe the typescript definitions are old?

Any ideas?

How the example in the documentation is supposed to work is still an enigma for me. But I managed to get getTheme() to work together with custom styles.

Here's a quick React-Typescript example of how themes can be used in Javascript, and maybe also what the documentation should be saying. A complete theme can be created with the Theme Generator

import { getTheme, loadTheme } from '@uifabric/styling';
import * as React from 'react';

loadTheme(
  {
    palette: {
      "themePrimary": "#489958" 
    }
  }
);

class App extends React.Component {
  private theme = getTheme();

  public render() {
    return (
      <div className="App">
        <h1 style={{color: this.theme.palette.themePrimary}}>It works</h1>
      </div>
    );
  }
}

export default App;

you definitely found a bug in our documentation. We've recently moved most of our docs over to the wiki. I'll get this cleaned up one way or another.

Here's an issue to track the work.

https://github.com/OfficeDev/office-ui-fabric-react/issues/5770

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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