Dynamic icon size in Material-UI

让人想犯罪 __ 提交于 2021-01-28 14:14:20

问题


I use materiel-UI icon

<ArrowRightAlt/>

I can control the size of the icon by fontSize

<ArrowRightAlt fontSize="large" />

But I want v size to depend on window size (like md,xs,sm)

Can this be done?


回答1:


Below is one way of doing this using Box. I'm changing color in addition to font-size just to make it easier to tell which breakpoint it is at.

import React from "react";
import ArrowRightAlt from "@material-ui/icons/ArrowRightAlt";
import Box from "@material-ui/core/Box";

export default function App() {
  return (
    <Box
      clone
      color={{ xs: "red", sm: "orange", md: "yellow", lg: "green", xl: "blue" }}
      fontSize={{ sm: 48, md: 96, lg: 192, xl: 384 }}
    >
      <ArrowRightAlt />
    </Box>
  );
}

Related documentation:

  • https://material-ui.com/components/box/#box
  • https://material-ui.com/system/basics/#object
  • https://material-ui.com/system/typography/#font-size
  • https://material-ui.com/components/icons/#size


来源:https://stackoverflow.com/questions/62784041/dynamic-icon-size-in-material-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!