Designing the button outline variant with Material-UI styling

I've recently started using Material UI and I'm facing some difficulties. One of the challenges I'm encountering is with a button component

export default function TheButton(props: PropsWithChildren<Props>) {
  const { className, hover, level,...rest } = props;

  const classes = useStyles();

  return (
    <Button
      {...rest}
      className={clsx(classes.root, className, hover === 'contained' && classes.hoverContained)}
    >
      {props.children}
    </Button>
  );
}

In this component, I want to create two different versions: contained and outlined. Here's an example of my outlined button.

<TheButton
      variant="outlined"
      color="secondary"
    >
      secondary
</TheButton>

When the outlined variant is selected, the button receives the class Muibutton-outlined. I'd like to customize this class specifically to change the border (only for the outlined variant). I've attempted something like:

const useStyles = makeStyles((theme: Theme) => 
  createStyles({
    '.MuiButton-outlinedSecondary':{ 
      border:"2px solid red" ,
    },
  }
)

Unfortunately, it hasn't been successful so far.

Answer №1

In a similar scenario, I attempted the following:

  • Assigned a class submit to my button component
<Button
 type="submit"
 variant="outlined"
 disabled={isSaving || invalid || unchanged}
 color="secondary"
 className={classes.submit}
>
  SAVE CHANGES
</Button>
  • By utilizing the submit class, I was able to specify my styling more accurately:
const useStyles = makeStyles({
  submit: {
    marginTop: padding.medium,
    marginLeft: padding.small,
    '&.MuiButton-outlinedSecondary': {
      border: '1px solid pink',
    },
  },
});

The final outcome can be seen below:

View Material-ui button with pink border image

Answer №2

I've been working with the Ant Design UI kit and have customized its default styles using the following code:

<Button type="primary" className={styles.custom_css}>click</Button>

This customization was implemented in a React environment, where the custom_css class overrides the default styles.

If you need further assistance, please feel free to reach out.

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

SVG: organizing objects based on event priority

I am struggling with layering and event handling in an SVG element. Check out the example here: https://stackblitz.com/edit/angular-ivy-rkxuic?file=src/app/app.component.ts app.component.ts import { Component, VERSION } from '@angular/core'; @ ...

Developing elements in React Native based on JSON data dynamically

Hello everyone, I'm brand new to this forum and just starting out with React Native. I was wondering if someone could help me by providing a code snippet to create form elements (such as an image and a toggle switch) based on JSON data. Here is what ...

How can a border be applied to a table created with React components?

I have been utilizing the following react component from https://www.npmjs.com/package/react-sticky-table Is there a method to incorporate a border around this component? const Row = require("react-sticky-table").Row; <Row style={{ border: 3, borderco ...

Tips for handling notifications that have been read and unread in a React application

In my current project using React JS, I am tasked with creating a notifications component that will display account-related activities. The notifications need to be sorted into read and unread categories. My main question is how should I manage the read a ...

Personalized designing of each letter

Is there a way to style numbers without using something like <span></span>? I'm looking for a clean way to do this for each sign. Attached is an example showing a "flip clock" effect that I would like to achieve. I have come across plugi ...

Creating a carousel of cards using JavaScript, CSS, and HTML

Here is a visual reference of what I'm attempting to achieve: https://i.stack.imgur.com/EoQYV.png I've been working on creating a carousel with cards, but I'm struggling to synchronize the button indicators with card advancement when clicke ...

implementing click functionality in a styled React component

There is a collection of simple divs containing names: I want to be able to click on one and have its background turn green. If I click on another one, the first should revert back to its original color so only one is colored at a time. I'm not sure ...

Steps for appending a string to a variable

Currently working on creating a price configurator for a new lighting system within homes using Angular 7. Instead of using TypeScript and sass, I'm coding it in plain JavaScript. Page 1: The user will choose between a new building or an existing one ...

Error: The value is null and cannot be read

My external application is set up within a const called setupRemote, where it starts with the appConfig in the variable allowAppInstance. export const setupRemote = () => { if (isRemoteAvailable) { try { ... const allowAppInstance = S ...

Having trouble installing firebase using npm

Currently, I am utilizing React (if that's relevant). While researching on Google, the common solution I found was to clear the npm cache: npm cache clean --force However, this method didn't resolve the issue. I also went ahead and deleted the ...

React components can be used to dynamically render and display an array of objects through methods like reduce and

Here's the scenario at hand: (https://codesandbox.io/s/8p21n6p09l) I have an array of objects (referred to as modules) structured like this: const modules = [ { thematicArea: "Topic 1", id: 1, name: "Building assertive attitude", d ...

Using the <!DOCTYPE html> tag seems to cause issues with the measurements of div elements

Currently in the process of developing a website, I created this div: #container #content .imagewindow { width: 560; height: 380; background-color: #1E1640; } After adding the doctype html tag, the browser appears to be disregarding my styling commands ...

Avoiding Flickering While Implementing Personalized Style in Next.js Version 13

Hey there, fellow Next/React enthusiasts! I'm new to the exciting world of Next.js and React, and currently delving into replicating a cool custom theme feature I stumbled upon in a tutorial video here (specifically from minutes 2:33 to 5:00). In my ...

Updating the highlighted button within a scrolling MUI List component in a React application

I am currently facing an issue with my sticky MUI List. I have a list of headers that are supposed to scroll the sticky list and highlight the corresponding category when clicked. However, the functionality is not working as expected. I attempted to implem ...

Tips for implementing nested resources in Rails, React, and Redux

My current project consists of 3 models: users, concerts, and reviews. I find myself struggling with how to effectively render nested and un-nested resources using React and Redux. Specifically, I am unsure of how to dynamically switch between rendering al ...

ReactDataGrid and webpack's transpile causing issues

Recently, I've been working on creating a ReactDataGrid component. The jsx file for the component was sourced from examples on the data grid's official website: import React from 'react'; import ReactDataGrid from 'react-data-grid& ...

Data extracted from the range selector

Is there a way to take values and use them for hiding or displaying certain divs? I have been using jQuery Simple Slider for this purpose. I attempted the following code, but it did not work well. I want the div with id "3" to be visible when the slider ...

Troubleshooting the Owl carousel's responsiveness with a div width of 1170px

Whenever my display size is less than 1170px, the width of the owl carousel div overflows. How can I fix this issue? jQuery(document).ready(function($) { "use strict"; // CUSTOMERS TESTIMONIALS CAROUSEL $('#customers-testimonials&a ...

Is there a jQuery or Javascript alternative to CSS Counter?

Can a counter be implemented that changes the text of a tag directly using jQuery/Javascript? For example, if there were two tags like this: <a>hello</a> <a>bye</a> After executing the jQuery/JS function, the result would be: < ...

What could be causing my state not to change in Nextjs even though I followed the quick start guide for Easy Peasy?

I recently encountered an issue while trying to implement easy peasy for global state management in my nextjs app. The problem I faced was that the state would only update when I changed pages, which seemed odd. To better understand what was going on, I de ...