Tips for styling buttons in react-admin with custom CSS

I need some help with customizing buttons in react-admin. I am new to the platform and unsure about how to go about changing the button CSS for various actions such as create, edit, and export. Can anyone provide guidance on the best way to customize these buttons?

Currently, the default buttons appear as shown in the image below:

https://i.stack.imgur.com/HWn7S.png

Below is a snippet of my code for reference:

// Custom button styles
const useStyles = makeStyles((theme) => ({
  userCard: {
    padding: "20px",
    borderRadius: "12px",
  },
  btn_edit: {
    background: "#5E35B1",
    color: "#fff",
    fontSize: "10px",
  },

  mainList: {
    boxShadow: "none !important",
    borderRadius: "0px",
  },
  listCreateIcon: {
    padding: "0px !important",
  },
}));
// User List component
export const UserList = (props) => {
  const classes = useStyles();
  return (
    <Card className={classes.userCard}>
      <List
        {...props}
        pagination={null}
        perPage={9999}
        className={classes.mainList}
      >
        <Datagrid>
          <TextField source="username" />
          <BooleanField source="enabled" />
          <ReferenceArrayField reference="_roles" source="roles">
            <SingleFieldList>
              <ChipField source="name" />
            </SingleFieldList>
          </ReferenceArrayField>
          <EditButton className={classes.btn_edit} />
        </Datagrid>
      </List>
    </Card>
  );
};

// User Create component
export const UserCreate = (props) => {
  const classes = useStyles();
  return (
    <Create {...props} className={classes.listCreateIcon}>
      <SimpleForm style={{ padding: "0px !important" }}>
        <TextInput source="username" />
        <TextInput type="password" source="password" />
        <ReferenceArrayInput source="roles" reference="_roles" allowEmpty>
          <SelectArrayInput optionText="name" />
        </ReferenceArrayInput>
        <BooleanInput source="enabled" defaultValue={true} />
      </SimpleForm>
    </Create>
  );
};

// User Edit component
export const UserEdit = (props) => (
  <Edit {...props}>
    <SimpleForm>
      <TextField source="username" />
      <ReferenceArrayInput source="roles" reference="_roles">
        <SelectArrayInput optionText="name" />
      </ReferenceArrayInput>
      <BooleanInput source="enabled" />
    </SimpleForm>
  </Edit>
);

Answer №1

This solution is tailored for your needs.

btn_custom: {   
    display: "inline-flex",
    alignItems: "center",
    gridGap: 4,
    backgroundColor: "transparent",
    borderColor: "transparent",
    fontSize: 16, 
    color: "blue" // desired text color
    // for svg icon usage
    svg : {
       width: 16,
       height: 16,
       path: {
           fill : "blue" //color code of the icon 
       }
    }
  },
btn_container: {
    display:"flex",
    gridGap: "16px",
    alignItems: "Center",
}

Implementing on Component

<div className={classes.btn_container}>
    <CustomButton className={classes.btn_custom} />
    <CustomButton className={classes.btn_custom} />
</div>

Note: If using a font icon, disregard the svg styling.

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

Limiting the number of times a specific character appears using a regular expression

Currently, I am in search of a regular expression that allows me to set a limit on the number of times a special character can appear. For instance, if I want to restrict the occurrence of * to a maximum of 5 times in the entire text, then the output shou ...

Enhance your web form with the Bootstrap 4 tags input feature that allows users to add tags exclusively

I'm currently utilizing Bootstrap 4 along with Bootstrap Tags Input to create a multiple category selection feature. My goal is to enable users to choose multiple items exclusively from the predefined categories listed in the predefined_list. At pres ...

Elegant Bootstrap 4 Carousel featuring a glimpse of the upcoming slide alongside the primary carousel item

I am in search of a straightforward Bootstrap 4 carousel that showcases a glimpse of the next slide on the right. Despite exploring similar questions, I have not found a suitable solution. The links to those questions are: 1)Bootstrap carousel reveal part ...

difficulties arise when adjusting font size in html and css

When I first created an all HTML/CSS website, I used clickable images as a menu that scaled perfectly on all monitors and browsers. Now, for my new project, I wanted to use a background image for the menu with hyperlinked text on top. I thought setting the ...

Express session not persisting following JQuery Get request

I need to save the server variable that the user inputs. Once they submit, they are directed to another page. On this new page, I check if their server exists and redirect them back if it doesn't. When I make a post request, the session is saved, and ...

What is the method for writing to an HTML file with the use of expressjs?

Alright, I have an interesting idea here. I am looking for a way to allow users to push a button and have a new p element permanently added to the HTML file. This means that even after reloading the page, everyone should be able to see this new element. An ...

Localhost Firebase authentication with Facebook integration

I am currently working on a Vue.js app that integrates Firebase for authentication, specifically with the Facebook provider. Despite configuring my Firebase code correctly, I continue to encounter the "Can't load URL: The domain of this URL isn't ...

Based on the action taken, send specific data through AJAX - whether a form submission or a div click

There is a function called search, which can be triggered either by clicking on a div or submitting a form. When the div is clicked, the id of the div is sent as data in an AJAX call. However, if the form is submitted, I want to send the inputted data thr ...

The number input is not compatible with JavaScript/jQuery validation

While working on input field validation using javascript/jQuery code, I encountered an issue where the code worked fine with input type text but did not support input type number. Specifically, the 'number' type input did not work at all in FireF ...

The local authentication feature in NodeJS Passport is experiencing issues and not functioning properly

I have integrated passportjs local for authentication. However, I am facing an issue where it always redirects to the failureRedirect without displaying any error messages. The redirect also includes the original username and password, resulting in a dupli ...

The menu is loaded dynamically by Ajax from JavaScript once the page is refreshed

$('#subregionListPage').bind('pageinit', function(event){ var output = $('#subregions'); var region = getUrlVars()["reg"]; $.ajax({ url: 'http://localhost:8888/my/getsubregions.php', dat ...

Is it necessary for the keys in separate loops to be unique among siblings?

Does the use of key in loops create separate branches, or do they still need to be unique for the same parent? Take a look at this example: // This is obviously an error: <div> <div key="gimme-a-break" /> <div key="gim ...

Exploring the world of interfaces in nested mapping functions

Currently, I'm faced with the challenge of mapping an array inside another map with an array. These are the specific interfaces that I am working with: interface Props { columns: Array<{field: string, headerName: string, width: number}>; row ...

What is the method for individually extracting values from HTML using class li?

Is there a way to extract each value from the HTML within the li class separately? I have tried various methods but none have been successful. Can anyone provide a solution? Here is my JavaScript code: $(document).ready(function() { $(".list-grou ...

What is the best way to make just the background image transparent using HTML and CSS?

Hey there! I'm trying to make just the background image transparent, while leaving everything else non-transparent. Is this possible with Bootstrap? Here's a snippet of my HTML: HTML Section: <!-- Homepage Section --> <section id= ...

Convert the date and time of "2018-03-31T05:37:57.000Z" to a

I need help converting the universal time 2018-03-31T05:37:57.000Z to a timestamp in the form of 1520919620673. Can someone please provide guidance on how I can achieve this conversion? ...

The :focus pseudo-class is failing to target the input element

I'm dealing with a simple input field of type text: <input matInput type="text" placeholder="{{placeholder}}" class="input-field" [ngClass]="{'error': hasErrors}" [readonly]="isReadonly&quo ...

Using jQuery to display a div after a 2-second delay on my website, ensuring it only appears once and does not reappear when the page is refreshed or when navigating to a

I manage a website that includes a blog section. Every time someone visits the site, I want a popup window to appear. (To achieve this, follow these steps - Utilize jQuery for showing a div in 5 seconds) I would like this popup to only be displayed once ...

Removing the column name from a JSON return in C# involves using a variety of techniques

Below is a JSON output I have received : [ { positionCode: "POS1", positionName: "POSITION 1", positionDescription: "", parentPosition: "POS2", }, { positionCode: "POS2", positionName: "POSITION ...

Optimizing loading times for mobile banners through media queries

I currently have a standard size banner that loads when my page is accessed on a computer. However, I would like to optimize the loading speed by having a smaller version specifically for mobile devices using a media query. My main question is how does t ...