Adjustable icon dimensions in Material-UI

My current setup involves utilizing material-UI icons

<ArrowRightAlt/>

I have been able to manipulate the size of the icon using the fontSize attribute

<ArrowRightAlt fontSize="large" />

However, I am interested in having the size of the icon adjust based on the window size (e.g. md, xs, sm)

Is there a way to achieve this?

Answer №1

Here is a method to achieve this using the Box component from Material-UI. I am adjusting both the color and font-size to differentiate between breakpoints easily.

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>
  );
}

https://codesandbox.io/s/dynamic-icon-size-ir63l?fontsize=14&hidenavigation=1&theme=dark

Relevant documentation:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging Redux and React to efficiently map state to props, while efficiently managing large volumes of data and efficiently

Utilizing sockets for server listening, the Redux store undergoes continuous updates with a vast amount of data. While updating the store is quick, the process of connecting the state to the component through the redux connect function seems to be slower, ...

"Streamlining the development process with Redux Toolkit, RTK, and Mul

How can I upload an image using RTK and Multer? JSX file const onSubmit = (e) => { e.preventDefault(); const payload = new FormData(); payload.append("imagegif", image); payload.append("title", formData ...

Incorporating Swagger-UI into an Angular 10 project

Looking to integrate Swagger UI into your Angular application? After researching extensively, I found that the recommended approach is now to use the swagger-ui package instead of swagger-ui-dist for single-page applications. For those using React, there ...

Tips for transmitting `props` information between parent and child components using react router

Looking for guidance on how to properly pass props data from a parent component to a child component when navigating to a new route. I've attempted some solutions from this GitHub issue, but passing it through {...props} didn't work as expected. ...

What is the best way to shift a text element within the footer section?

I have arranged two columns within the container, but I am looking to position the .company and .copyright text at the bottom left of the footer column. The Follow Us heading should be on the right side with the .justify-text below it, followed by social m ...

Establishing the default state in React Redux by fetching data from an API

After successfully creating a react redux app, I am now facing the challenge of retrieving my initial data from an API endpoint. Here is how I have set up my postReducers.py file: var initialState = { employees: [] }; var postReducer = (state = initial ...

Set the value obtained from a resolved promise to a mutable reference object in a React component

I am in the process of developing a random movie generator. I am utilizing an external API to retrieve a list of movies and then selecting one randomly from the returned data. The current implementation is as follows: export default function Page() { con ...

What is the process for a Gatsby application to connect with Azure Key Vault?

After successfully deploying my Gatsby App to Azure using the steps outlined in this guide, I've realized that this process differs from deploying a traditional web app. Instead of deploying to the App Service resource, Gatsby apps are deployed to a s ...

Is it possible to use useDispatch asynchronously multiple times?

I am facing an issue where using useDispatch twice to update my todos and then change my login status is causing the second dispatch to overwrite my list of todos with an empty object []. Both actions work independently, but not when executed sequentially. ...

On my website, two elements are stacked on top of each other

The CSS framework I am currently utilizing is Materialize Whenever I try to add a new element, it inexplicably appears below the ones above it. I did not specifically instruct it to be positioned underneath or below the cover container. Adding a z-index c ...

Encountering a 401 error without any accompanying message when attempting to generate a teams meeting link through the Azure Graph client in Node.js

Just starting out with Azure and here is my code snippet: I have set the necessary permissions. Check them here const { startDateTimeAsync, endDateTimeAsync } = require('./dateTimeFormat'); const { ClientSecretCredential } = require('@azure ...

Having trouble with the npm package installation for react-circular-progressbar

I encountered an error when trying to install react-circular-progressbar in my React projects. Why is this happening? npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/em ...

What steps should I take to fix the Axios Network Error that keeps occurring while fetching data from my Express backend API?

I've been attempting to integrate my react native app with a database using the following code snippet: const axiosInstance=axios.create({ baseURL: config.API_URL }) try{ const res = await axiosInstance.get("/all") console.log( ...

Spin the content of a div after a button click with the power of jquery and css

Looking to add interactivity to rotate text within a div upon button click using jQuery and CSS. If the user selects Rotate Left, the text will rotate to the left. Alternatively, if the user chooses Rotate Right, the text will rotate to the right. Here&a ...

What steps can be taken to create an electron menu for easily conducting a general search within the current window?

I am searching for a solution to create an electron menu that includes the label "Find..." and performs a general search within the current browser window. While I was successful in adding the option, I am struggling to figure out how to access the browser ...

Unit test: Passing a deeply nested object as a prop to a React component

My functional component looks like this: const ImageScreen = (props: any) => { const images: object[] = []; props.navigation.state.params.images.forEach((image: any) => //some code ); return ( <View style={CommonStyles.normalPage} ...

How can CSS be instructed to "apply the following most specific rule in order to determine this property"?

Utilizing Material-UI and JSS for CSS management, I've encountered an issue where styles appear differently in development versus production. The discrepancy stems from the order of rules within the file. For instance, when defining an element like ...

Tips for Implementing SSR and Data Fetching in a Next.js 14 Application Router

Recently, I made the switch from a page router to an app router for its advanced features. However, I'm facing a dilemma when it comes to implementing SSR and data fetching. The Issue: According to the documentation, instead of using getServerSidePro ...

Why is it necessary to use 'this.' to reference a function inside a Component in React?

class First extends React.Component{ handleClick(){ alert('handle click'); } render(){ return <div> <button onClick={this.handleClick}>click</button> </div>; } } Explo ...

Overflow of nested item within flex container

I'm trying to make the content under "foo" fully scrollable, but I've been unsuccessful using flexbox. I attempted it with min-height, yet it didn't work out. Check out this JSFiddle for reference $('.ui.dropdown') .dropd ...