I've tried both Carbon Design for React (@carbon/react
) and Material UI (@mui/material
) with Next.js and the components are not stylized correctly. They work basically, but I noticed subtle and very notable issues. I decided to forget about IBM's Carbon and am noticing this with @mui
:
我已经用Next.js尝试了用于Reaction(@Carbon/Reaction)的Carbon Design(@Carbon/Reaction)和材质UI(@Mui/Material),但组件的样式设置不正确。它们基本上是有效的,但我注意到了一些微妙而非常值得注意的问题。我决定忘掉IBM的碳排放,在@Mui上注意到了这一点:
CardHeader
is not showing
- Typography and button text colors are black, but I've specified the theme provider to use the dark mode.
- My Sig In button has
variant="contained"
, but its contained style does not apply.
This is the code:
代码是这样的:
'use client';
import { useState } from 'react';
import Image from 'next/image'
import { Box, Container, Card, CardHeader, CardContent, TextField, Typography, Button } from '@mui/material';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
const darkTheme = createTheme({
palette: {
mode: 'dark',
},
});
export default function Home() {
const [auth, setAuth] = useState<void>(undefined);
return (
<ThemeProvider theme={darkTheme}>
<CssBaseline/>
<main className="flex flex-col items-center justify-center w-full h-full">
<Container>
<Box>
{auth == null ? <SigIn setAuth={setAuth}/> : null}
</Box>
</Container>
</main>
</ThemeProvider>
)
}
type SigInProps = {
setAuth: (auth: void) => void,
};
function SigIn({setAuth}: SigInProps) {
return (
<Card>
<CardHeader>
<Typography variant="subtitle1">Subtitle</Typography>
</CardHeader>
<CardContent>
<div className="flex flex-col gap-4">
<TextField required id="username" label="Username"/>
<TextField required id="password" type="password" label="Password" autoComplete="current-password"/>
<Button variant="contained">Sig in</Button>
</div>
</CardContent>
</Card>
);
}
Result:
结果:
I've posted the issue at GitHub also: https://github.com/mui/material-ui/issues/38901
我也在GitHub上发布了这个问题:https://github.com/mui/material-ui/issues/38901
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!