Button Hover Effect: Transition with Style

I am trying to implement a one-second transition from the default color scheme to the hover color for a Button element in Material UI. I am using the

transitions.create(props, options)
method as described in this article: https://medium.com/@octaviocoria/custom-css-transitions-with-react-material-ui-5d41cb2e7c5. The transition does work, but the hover color appears immediately when the mouse hovers over the button. How can I delay the color change until the transition is finished?

Here is the relevant code snippet:

function Mbutton({ classes }) {
  return (
    <Button variant="outlined" className={classes.cart} disableRipple>
      Add to Cart
    </Button>
  );
}

const styles = theme => ({
  cart: {
    padding: "6px 16px",
    borderRadius: 0,
    border: "2px solid #000",
    "&:hover": {
      transition: theme.transitions.create(["backgroundColor", "color"], {
        duration: 1000
      }),
      backgroundColor: "#000",
      color: "#fff"
    }
  }
});

You can also view and test it on Code Sandbox: https://codesandbox.io/s/mbutton-fogco

Thank you.

Answer №1

Transform this into plain CSS format


.cart {
    padding: 6px 16px;
    border-radius: 0;
    border: 2px solid #000;
    background-color: white;
    color: black;
    transition: background 1s, color 1s;
}

.cart:hover {
    background-color: #000;
    color: #fff;
}

View the Code on CodeSandbox

The theme parameter is not necessary in this context. It should be used when utilizing the default Material-UI theme object for transition styles, which is not needed in this particular case.

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

Integrating Next.js with a authentication provider and a Redux provider

During the development of my Next js project, I incorporated Next auth using import {Provider} from 'next-auth/client' to wrap the <Component /> in _app.js. However, I also want to integrate Redux into the project. This involves importing ...

Monitoring a folder using webpack

Currently, I have webpack set up in my development environment to bundle all of my dependencies. To help concatenate various js files and include them in a script tag within the markup, I am utilizing the webpack-merge-and-include-globally plugin. Althoug ...

What is the best way to create non-standard text wrapping in HTML and CSS that is both semantic and sleek, avoiding square or circular shapes?

Is there a way to achieve text wrapping like this using semantic and clean HTML and CSS that is compatible with all browsers? The only solution I can think of is adding different classes to the <p> element. However, the drawback of this approach is ...

Divide a single image into several smaller images and enable clickable links on each separate image, similar to an interactive image map

Challenge: I am faced with the task of splitting a large image (1920px x 1080px) into smaller 40px by 40px images to be displayed on a webpage. These smaller images should come together seamlessly to recreate the original full-size image, with 48 images a ...

Redirecting to a separate component outside the current structure and transferring a callback function

How can I navigate from App.js, the default component, to a new component that is not within the hierarchy while passing a function? I have three components: Question for displaying questions, Upvote for upvoting, and Downvote for downvoting. Here is the ...

Struggling to find a way to showcase API data on a HTML site

Is there a way to dynamically show the live prices of crypto currencies on my website? I wrote a script that successfully displays the current price, but I'm struggling with implementing auto-refresh using setInterval. Here's the code I have so f ...

Formik-powered button group for decreasing/increasing

Looking to enhance a Formik form framework by integrating a decrementer/incrementer button group. Link to Button Group Demo Button group codebase: import React from "react"; import Button from "@material-ui/core/Button"; import Button ...

Tips for transmitting HTML as a JSON object through the res.render function in expressjs

My issue involves a JavaScript function that returns an HTML element. I want to pass this element along for users to view as actual HTML, but it ends up appearing as a string with special characters like "<" and ">". For example, "<" appears as (& ...

What methods can I use to make sure the right side of my React form is properly aligned for a polished appearance?

Trying to create a React component with multiple input field tables, the challenge is aligning the right side of the table correctly. The issue lies in inconsistent alignment of content within the cells leading to disruption in overall layout. Experimente ...

Create a Bootstrap jumbotron that is centered and only half of the width

I have a unique password reset method here: Jumbotron-Form-Bootstrap-My-Attempt Displayed below is the code from the image above: <div class="container"> <div class="jumbotron"> <br><br> <h2>Forget Passwo ...

Implementing single sign-on across different domains with an express server, react client, and redirect functionality

To tackle the challenge at hand, I am working on developing a web application that involves a form submission to my express server. The process includes generating a token from an external endpoint post using the form value, utilizing this token from an ex ...

Invoke the API when the value of a property in the SPFX property pane is modified

Here's a question that might sound silly, but I'll ask anyway. I have a dropdown field in my Property pane that is filled with all the lists from the current site. It's working fine. When I change the dropdown selection, it populates a pro ...

Bidirectional data flow in AngularJS Directives

In an effort to create a dynamic form with different "widgets" based on field types and parameters stored in a database, I have been exploring directives for handling layout changes in response to various scenarios. After experimenting with some examples, ...

Unable to retrieve the item from the current slug content within Sanity and Next.js

What I am attempting to achieve is retrieving the set_name from the set schema that corresponds to the current slug. The schema is defined as *[_type == 'set']{set_name, slug}. However, upon clicking on the slug, I am not able to fetch the set_na ...

Github Pages is experiencing a bit of a hiccup with 400 errors due to a problem with the manifest.json file

I'm encountering some issues while trying to deploy my Github Pages website at . The errors I keep facing are as follows: - Failed to load resource: the server responded with a status of 400 () - manifest.json:1 Failed to load resource: the server ...

Vanishing border around the sticky table header

While working on creating a table in an excel style using html and css with a sticky header, I noticed that the borders on the table head appeared strange. Take a look at the code snippet below: table { border-collapse: collapse; position: relative ...

In the process of attempting to upload a .tsv file through the front end interface, I am encountering a challenge as the file remains stored on my server. What is the

I've got a function set up on my Express server that sends a file dependent on D3.JS. app.get('/dashboard', function(req, res) { var timestamp = utility.timestamp(); console.log('[' + timestamp + '] Request made to rend ...

Guide to creating a horizontal scroll feature in ReactJS with the help of MUI Grid

Is there a way to set the container direction as "row" above md size screens and "column" below md size screens? How can I achieve this? I am attempting to scroll horizontally using MUI Grid. <Grid container sx={{ flex: 1, flexDirection: { xs: ...

The process of incorporating injected JavaScript into an existing function

It seems like a classic issue, but I haven't been able to find the solution. I have a form that connects to a MySQL (actually MariaDB) database table called contacts. As part of the jQuery.ready() function, a drop-down list is populated through AJAX ...

Utilizing JSON Data with Angular

Currently, I am in the process of developing an AngularJS client that communicates with a REST API running on NodeJS. To retrieve data, I make GET requests by accessing specific URLs with stock symbols appended, such as localhost:8080/stocks/aapl for Apple ...