我知道在createMuiTheme()
函数中,您可以像这样更新断点的值。
const theme = createMuiTheme({
breakpoints: {
values: {
xs: 0,
sm: 600,
md: 960,
lg: 1280,
xl: 1920,
},
},
})
我还知道Material UI(相对)最近对其进行了更改,您可以在其中添加断点的自定义值。
breakpoints: {
values: {
tablet: 640,
laptop: 1024,
desktop: 1280,
},
},
});
但是,我正在使用Typescript,但是我无法通过覆盖断点值来使它正常工作,
declare module "@material-ui/core/styles/createBreakpoints"
{
interface BreakpointOverrides
{
xs: false; // removes the `xs` breakpoint
sm: false;
md: false;
lg: false;
xl: false;
tablet: true; // adds the `tablet` breakpoint
laptop: true;
desktop: true;
}
}
,而是出现此错误
Type '{ tablet: number; laptop: number; desktop: number; }' is not assignable to type 'BreakpointValues'.
Object literal may only specify known properties, and 'tablet' does not exist in type 'BreakpointValues'.
不确定我在做什么错吗?任何帮助将不胜感激。
答案 0 :(得分:0)
我正在使用打字稿和断点MaterialUI,我认为您需要导入和修改一些界面,如文档所述(https://material-ui.com/guides/typescript/#customization-of-theme)。例如,我有一个Theme.tsx,如下所示:
import { createMuiTheme } from '@material-ui/core/styles'
import {BreakpointOverrides} from "@material-ui/core/styles/createBreakpoints"
declare module "@material-ui/core/styles/createBreakpoints" {
interface BreakpointOverrides {
xs: false; // removes the `xs` breakpoint
sm: false;
md: false;
lg: false;
xl: false;
tablet: true; // adds the `tablet` breakpoint
laptop: true;
desktop: true;
}
}
declare module '@material-ui/core/styles/createMuiTheme' {
interface Theme {
appDrawer: {
width: React.CSSProperties['width']
breakpoint: BreakpointOverrides
}
}
// allow configuration using `createMuiTheme`
interface ThemeOptions {
appDrawer?: {
width?: React.CSSProperties['width']
breakpoint?: BreakpointOverrides
}
}
}
export const theme = createMuiTheme({
breakpoints: {
values: {
tablet: 400,
laptop: 900,
desktop: 1200
}
},})
答案 1 :(得分:0)
我发现问题是由于material-ui的版本引起的。 @ material-ui / core的4.9.9版本将导致错误消息。当我更新到4.11.0时,它可以正常工作。