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

Cannot utilize Map within each loop

Below is the less code snippet: @threshold:{ a:50; b:200; }; @themes:{ a:red; b:blue; }; .mymixin(@name,@color,@thrshld){ //do-something } each(@themes,{ .mymixin(@key,@value,@threshold[@key]); }); Upon executing the code, an error message ...

Manipulating toggle buttons using CSS and jQuery

Check out this jsfiddle to see my attempt at creating a toggle switch in the form of a mute button. The toggle button shows the current setting: mute or unmute When hovered over, it displays the alternative setting However, I am encountering an issue wh ...

Importing vs Referencing Videos in Next.js - What is the Best Practice for Video Integration in Next.js?

I'm looking to use a video as a background in my banner design. Typically, with images in Next.js, I would import them and then pass the import as src (for example: import img from '@images/about-us-page/img.svg'). However, when attempting ...

What is the best way to change the size of an SVG image

I have exhausted all the methods I could find on stackoverflow and Google, but my SVG is refusing to resize. Would someone kindly shed some light on why this might be happening? <div> <svg viewBox="32 32 32 32" height="100" width="100"> ...

What is the process of integrating Formik with Chakra using typescript?

I'm attempting to implement the following Chakra example in Typescript. <Formik initialValues={{ name: "Sasuke" }} onSubmit={(values, actions) => { setTimeout(() => { alert(JSON.stringify(values, null, 2)); actio ...

Creating a versatile MUI v5 TextField with a dynamic adornment

I am currently working on creating a versatile and reusable MUI v5 TextField component. However, I am facing some challenges in setting default endAdornment or startAdornment on InputProps based on certain conditions. The TextField should have different s ...

Encountering an issue with running the React Application due to an error when

I've been trying to launch my React app in a local environment but I keep encountering the following error PS npm start npm ERR! code ENOENT npm ERR! syscall open npm ERR! path C:\Documents\business-website-react-master\package.json np ...

Using jQuery to load the center HTML element

So here's the plan: I wanted to create a simple static website with responsive images that load based on the browser width. I followed some suggestions from this link, but unfortunately, it didn't work for me. I tried all the answers and even a ...

Issues arise when implementing a sticky position using CSS with incomplete functionality

I want to create a website with a menu bar that stays at the top even on long pages. However, when I use position: sticky in CSS, the menu disappears after scrolling a certain distance. Does anyone know how to fix this issue? HTML: <nav> <ul cla ...

The offcanvas menu in the NextJS Tailwind website does not handle hover or tap events properly when outside of the parent dimensions

My header includes an off-canvas menu that slides in from the right side. Everything seems to be working fine, except for one issue: when the menu is open and visible, the mouse and touch events pass through it to the content underneath. Check out the cod ...

.htacces Disables Styling on Page

I've been trying to understand the functionality of .htaccess RewriteRule. Here is a URL example where I have experimented with .htaccess: http://example.com/test/home This used to be: http://example.com/test/index.php?p=1 My goal is to redirect ...

"Encountering a Challenge with Setting Up Forms on

I've recently started learning to code and I'm facing an issue with my form appearing stretched out. You can view it here: I initially thought it was due to margins, so I increased them. Then, I tried adjusting the width to 50%, but that didn&ap ...

Currently, my nextjs project is up and running smoothly in vscode. When I execute `npm run dev` in the terminal, everything seems to be working fine. However

Whenever I run npm run dev in my terminal to start a nextJS project, it shows the following output: > [email protected] dev > next dev ready - started server on 0.0.0.0:3000, url: http://localhost:3000 but when I try to access it in the browser, ...

Python Script for Modifying Material and Texture

I need help modifying my script to change the material and texture of a model using a dropdown menu and slider. Currently, I am facing challenges in applying these changes to the model. How can I adjust my script to meet this requirement? import maya.cm ...

JavaScript code that displays items in a shopping cart

I've set up the HTML and JS functionality for the cart, but I'm facing an issue where the JS doesn't render the cart items when the shop item is clicked. The styling in my HTML is done using Tailwind. If anyone could provide some assistance ...

Adjusting the dimensions of the canvas leads to a loss of sharpness

When I click to change the size of the graph for a better view of my data in the PDF, the canvas element becomes blurry and fuzzy. Even though I am using $('canvas').css("width","811"); to resize the canvas, it still results in a blurry graph. I ...

Two separate pieces of text converge within a single span

I am facing a challenge with alignment in a bootstrap <span> element. Specifically, I want to align the word "amount" to the left, and the "$" to the right, within the same label. I attempted to nest a <span> inside another <span> and app ...

How to retrieve the first option selected in Material-UI React?

Hey there! I am currently working with React Material UI select. I have a question - how can I set the first option of items as selected without triggering the onChange method? When I change an option, it triggers the onChange method and adds an attribut ...

Implementing Micro Frontend Architecture in React Native App

Currently, I am in the process of developing a react-native application that consists of various modules such as: Login Module Payment Cart Product etc. My goal is to implement the Micro Frontend Architecture for each module. Despite researching online, ...

I am struggling to make the map method display the specific components I need

Attempting to create a scalable Custom Form using an array of objects and a custom Input field in a React-Typescript project import React, { ChangeEvent } from "react" import { InputField } from "./InputField" interface FormItem { ...