小编hot*_*dev的帖子

如何在 Material ui 中为网格项添加新行?

我将像这样打破一行网格项目。 在此输入图像描述 正如您所看到的图像,网格的其余空间应该是空的。

<Grid container spacing={3}
  <Grid item xs={12}>
    "Grid Item xs={12}"
  </Grid>
  <Grid item xs={4}>
    "Grid Item xs={4}"
  </Grid>
  // empty space
  <Grid item xs={12}>
    "Grid Item xs={12}"
  </Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)

我应该使用内部grid container吗?或者我应该使用display flex

css flexbox reactjs css-grid material-ui

11
推荐指数
2
解决办法
1万
查看次数

如何比较next.js中的当前路径名和路由?

我目前正在将使用creat-react-app创建的项目迁移到next.js项目。

我面临的一件事是将matchPath函数从react-router-dom迁移到某种next.js函数,比较当前路径名和一种传递的href路由名称,以便实现并选择当前导航项。

import { useLocation, matchPath } from 'react-router-dom';

const NavBar = ({ item, pathname }) => {
  const open = matchPath(pathname, {
    path: item.href,
    exact: false
  });
  ...
}

Run Code Online (Sandbox Code Playgroud)

我能够pathname使用next/router获取当前电流,但之后,我不知道如何比较它们。

import { useRouter } from 'next/router';

const NavBar = () => {
  const { pathname } = useRouter();

  ...
}
Run Code Online (Sandbox Code Playgroud)

这种情况下,该如何解决呢?

提前致谢。

reactjs next.js react-router-dom

9
推荐指数
1
解决办法
3885
查看次数

如何使用 Material UI 和 TypeScript 将自定义道具传递给样式组件?

我正在使用 TypeScript(v4.2.3)和 Material UI(v4.11.3),并尝试将自定义道具传递给styled组件。

import React from 'react';
import {
  IconButton,
  styled,
} from '@material-ui/core';

const NavListButton = styled(IconButton)(
 ({ theme, panelOpen }: { theme: Theme; panelOpen: boolean }) => ({
   display: 'inline-block',
   width: 48,
   height: 48,
   borderRadius: 24,
   margin: theme.spacing(1),
   backgroundColor: panelOpen ? theme.palette.secondary.dark : 'transparent',
 }),
);

...

const Component: React.FC<Props> = () => {
  return (
    <NavListButton panelOpen={true} />
  );
};

Run Code Online (Sandbox Code Playgroud)

这工作正常,但如果我检查控制台,它会遇到错误。

Warning: React does not recognize the `panelOpen` prop on a DOM element. If …
Run Code Online (Sandbox Code Playgroud)

typescript material-ui styled-components

6
推荐指数
1
解决办法
8672
查看次数

如何更改 Material-UI 中单选按钮的边框颜色?

我想更改 Material UI 单选按钮的外环。

https://material-ui.com/components/radio-buttons/

现在我有这个:

单选按钮 1

但我想得到的是

单选按钮 2

我尝试过用PrivateRadioButtonIcon-layer蓝色和MuiSvgIcon-root黑色设计班级风格,但我找不到一种风格设计方法PrivateRadioButtonIcon-layer

css reactjs material-ui

5
推荐指数
1
解决办法
4166
查看次数

特定断点处元素的边距在 Tailwind 中不起作用

我试图div通过添加 a 在特定断点处设置元素的边距{screen}: prefix,但它不起作用。我尝试过的如下;

<div className={'flex justify-center'}>
  <div className={'w-full my-8 sm:my-20 md:my-48'}>
    <div {...props}>
      {children}
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

检查模式,我可以确定只有my-8类有效。

在此输入图像描述

Tailwind 的所有类都工作良好,flex响应式也能正常工作,但响应式的边距(填充)不起作用。我使用 Next.js 和 Tailwind CSS。

css plugins themes next.js tailwind-css

4
推荐指数
1
解决办法
9296
查看次数

无法将主题传递给“@mui/system” styled()

我试图通过以下方式传递主题:

declare module "@mui/styles/defaultTheme" {
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
  interface DefaultTheme extends Theme {}
}

ReactDOM.render(
  <StyledEngineProvider injectFirst>
    <ThemeProvider theme={theme}>
      <Main />
    </ThemeProvider>
  </StyledEngineProvider>,
  document.getElementById("root")
);
Run Code Online (Sandbox Code Playgroud)

我尝试通过以下方式来阅读:

import { styled } from "@mui/system";

type StyledTabProps = {
  isActive: boolean;
};

const StyledTab = styled("div", {
  shouldForwardProp: (prop) => prop !== "isActive"
})<StyledTabProps>(({ theme, isActive }) => {
  console.log("theme", theme);
  return {
    color: isActive ? "red" : "blue"
  };
});
Run Code Online (Sandbox Code Playgroud)

我尝试传递的主题与最终获得 console.logged 的​​主题不同(调色板对象中缺少属性)

问题的代码沙箱可以在这里找到:

https://codesandbox.io/s/wandering-https-ubhqs?file=/src/Main.tsx

reactjs material-ui

0
推荐指数
1
解决办法
1298
查看次数