首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Material-UI和Typescript

Material-UI和Typescript
EN

Stack Overflow用户
提问于 2018-02-14 20:31:51
回答 2查看 2.5K关注 0票数 1

我是TypeScript的新手,正在尝试遵循material-ui存储库中提供的示例。提供的示例代码正在传递root CSS类。我想通过‘`root’传递更多的CSS类。

代码语言:javascript
复制
const styles: StyleRulesCallback<'root'> = theme => ({
  root: {
    textAlign: 'center',
    paddingTop: theme.spacing.unit * 20,
  }
});

这里是material-ui提供的完整示例代码的链接。

https://github.com/mui-org/material-ui/blob/v1-beta/examples/create-react-app-with-typescript/src/pages/index.tsx

EN

回答 2

Stack Overflow用户

发布于 2018-05-21 19:06:32

您可以这样实现它:

代码语言:javascript
复制
const styles: StyleRulesCallback = theme => ({
    paper: {
        maxWidth: 1000,
        minWidth: 1000,
        display: 'inline-block'
    },
    table: {
        maxWidth: 1000,
    },
});

并在组件中使用该类,如下所示:

代码语言:javascript
复制
 <Paper className={classes.paper}>

将这个样板作为参考:https://github.com/innFactory/create-react-app-material-typescript-redux

票数 1
EN

Stack Overflow用户

发布于 2019-06-21 18:00:38

Toni提供的东西在4.1.1 (我正在使用的那个)中似乎不再起作用。相反,您需要的内容如下所示

代码语言:javascript
复制
import { StyleRulesCallback, Theme } from '@material-ui/core/styles';

interface IComponentProps {
  // props
}

const styles: StyleRulesCallback<Theme, IComponentProps> = theme = ({
  someClass: {}
  someClassWithProps: (props) => ({})
})

或者,如果您更喜欢使用createStyles

代码语言:javascript
复制
import { createStyles, Theme } from '@material-ui/core/styles';

interface IComponentProps {
  // props
}

const styles = (theme: Theme) => createStyles({
  someClass: {}
  someClassWithProps: (props: IComponentProps) => ({})
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48787315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档