2016-02-26 77 views
7

我在theme.ts定义原始主题material-ui印刷术和间隔材料的UI

import {Colors, Spacing} from 'material-ui/lib/styles/'; 
import {ColorManipulator} from 'material-ui/lib/utils/'; 
import {Styles} from 'material-ui'; 

export default <Styles.RawTheme> { 
    spacing: Spacing, 
    fontFamily: 'Roboto, sans-serif', 
    palette: <Styles.ThemePalette> { 
     primary1Color: Colors.red500, 
     primary2Color: Colors.red700, 
     primary3Color: Colors.lightBlack, 
     accent1Color: Colors.orangeA200, 
     accent2Color: Colors.grey100, 
     accent3Color: Colors.grey500, 
     textColor: Colors.darkBlack, 
     alternateTextColor: Colors.white, 
     canvasColor: Colors.white, 
     borderColor: Colors.grey300, 
     disabledColor: ColorManipulator.fade(Colors.darkBlack, 0.3), 
     pickerHeaderColor: Colors.red500, 
    } 
}; 

然后在我的定制阵营部件app.tsx我应用这个主题:

import * as React from 'react'; 
import {AppBar, AppCanvas} from 'material-ui'; 
import {ThemeManager, ThemeDecorator} from 'material-ui/lib/styles/'; 
import Theme from 'theme'; 

@ThemeDecorator(ThemeManager.getMuiTheme(Theme)) 
export class App extends React.Component<{}, {}> { 
    constructor(props) { 
     super(props); 
    } 

    render() { 
     return (
      <div> 
       <AppBar title={ 'App' } showMenuIconButton={false}/> 
       <AppCanvas> 
        <h1>Test</h1> 
       </AppCanvas> 
      </div> 
     ); 
    } 
} 

但是h1头不是因为它必须是材质设计。没有Roboto字体,更小的尺寸。

material-ui是否有内置样式或其他可用于根据材质准则轻松设置标题样式的其他内容,还可以为元素提供间距(边距和填充)?

回答

0

我不知道大小如何字体在最后的主题进行计算,但如果是在距内容的功能,那么你可以通过添加分隔区间,将原始的主题这样的操作是:

export default <Styles.RawTheme> { 
    fontFamily: 'Roboto, sans-serif', 
    spacing: { 
     iconSize: 24, 
     desktopGutter: 24, 
     desktopGutterMore: 32, 
     desktopGutterLess: 16, 
     desktopGutterMini: 8, 
     desktopKeylineIncrement: 60, // left-nav width = this * 4 
     desktopDropDownMenuItemHeight: 32, 
     desktopDropDownMenuFontSize: 15, 
     desktopLeftNavMenuItemHeight: 30, 
     desktopSubheaderHeight: 48, 
     desktopToolbarHeight: 56 
    }, 
    palette: {...} 
} 

并玩这些设置。

2

Material-UI不包含Roboto字体,it is up to you to include it in your project

迅速在你的HTML的<head>元素加入以下和检查,如果你的h1头的样式验证这一点:

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet"> 

如果你想下载的Roboto字体,包括它在你的静态资产,你可以从这里得到它:https://www.fontsquirrel.com/fonts/roboto

+0

谢谢。我upvoted。我从https://material.io/guidelines/style/typography.html#typography-styles寻找版式样式的实现。我已经做了一些解决方法。稍后会尝试分享。 – mixel