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

Dollar Sign vs "$$()" Sparkling Protractor with "by.css()" vs "$()"

I'm a bit confused about the purposes of the $ and $$ commands. I initially thought they were just substitutes for 'by.css', but why use $$? <element id = "eId"></element> Based on the example above, I assumed that these two l ...

Choose all elements by their class except for a particular container defined by the parent element's ID

Can you provide an example of translating the function below into utilizing the .not method (or not selector)? $(".CLASS").filter(function(i, e){ return (e.parentNode.id != "ID"); } ...

Issue with attaching dynamic events is not functioning as expected

var smartActionsId = ['smartActions1','smartActions5','smartActions10']; for (let i in smartActionsId) { console.log("smartActionsId ="+smartActionsId[i]); $('#' + smartActionsId[i] + ' select').c ...

Upgrade your input button style using jQuery to swap background images

I have an input button with an initial background image. When a certain condition changes, I want to update its image using jQuery without overriding the button's global CSS in the stylesheet. Is there a way to only change the background attribute wit ...

Guide to retrieving a value from a field and transferring it to a FieldArray value using the Push event in Redux-Form V6-RC3

I am working on a FieldArray component that displays telephone information. Users have the ability to add a telephone object which includes a number field, a type field, and a button to add the phone to the phone list (FieldArray). Within the Phone List c ...

Tips for refreshing information in the Angular front-end Grid system?

I am currently working with the Angular UI Grid. The HTML code snippet in my file looks like this. <div ui-grid="gridOptions"></div> In my controller, I have the following JavaScript code. $scope.values = [{ id: 0, name: 'Erik&a ...

Develop an onclick function with an href attribute

I am interested in transforming links into AJAX versions whenever possible. To achieve this, I plan to implement a function called replaceLinks that will add an onClick handler to each link on the page and trigger ajaxPageWSM(href). This is what I currentl ...

How can I display a "loading..." message as a temporary placeholder while waiting for my Apexcharts to load?

I've spent a day trying to solve this issue but couldn't find a solution. Any help would be greatly appreciated. Recently, I was working on creating a cryptocurrency tracker in React. I successfully built a table that displays multiple currencie ...

Using TypeScript with React: Initializing State in the Constructor

Within my TypeScript React App, I have a long form that needs to dynamically hide/show or enable/disable elements based on the value of the status. export interface IState { Status: string; DisableBasicForm: boolean; DisableFeedbackCtrl: boolean; ...

Tips for maintaining the material-ui button in an active state post-click

After setting up a top navigation bar using material IU buttons to dictate the displayed content on the page, I want to ensure that the selected button stays active after being clicked. This will serve as a visual indicator that the current page content ...

jQuery Form Validator: requiring double submission

I've been working on implementing the Form Validator using Jquery. After some testing, I noticed that I have to click the submit button twice before the validation kicks in. Why is that? The script is housed in a separate file and included in my proj ...

How to hide text within a contenteditable element

I'm trying to create a contenteditable span that behaves like a password field in a Linux terminal; the text is entered, but not visible. I've experimented with different CSS properties like visibility: hidden and display: none, but they don&apos ...

Guide to inspecting file contents with Node.js

I am working on viewing the content of a file that is posted from the client using the fs module. However, with the code below, the contents are coming up as undefined. Can anyone help me identify what is missing in the code? To ensure I am receiving the ...

Avoiding the page from scrolling to the top when the sidebar is opened (NextJS, Typescript, TailwindCSS)

I'm currently working on a website that features a sidebar for smaller screens. While the sidebar functions properly, I would like to keep the background page fixed in place when the sidebar is active so it does not scroll. In my code, I have utilize ...

What is the process of invoking a function on a specific element when it is encapsulated within an if statement in Meteor.js

Here is an example: {{#if currentUser}} <li><a class="waves-effect waves-light btn modal-trigger modal-close" href="#upload">Upload Image</a></li> {{/if}} Currently, I am implementing the following: Template.MasterLayout.onRe ...

DOJO Dialogue Box Report - Problem

I'm currently facing a challenge with incorporating javascript into the dialog box of my application. Here is an example of the code I am struggling with - var profileDialog1 = new Dialog({ title: "Create Profile", style: "width: 700px;he ...

Sidebar-driven top navigation menu

I am currently developing a Single Page Application using VueJS along with vuerouter. In my App.vue file, the structure is as follows: <template> <div id="app"> <header><topbar></topbar></header> <div cl ...

Warning from React 17: Unexpected presence of <a> tag inside <div> tag in server-rendered HTML

I've checked out the existing solutions and still can't seem to make it work. components/NavBar.tsx import { Box, Link } from "@chakra-ui/react"; import { FunctionComponent } from "react"; import NextLink from "next/link ...

What is the best way to display text from a header box across multiple line boxes in real time on an HTML page?

Looking to enhance an HTML layout with a header box and line comment boxes. <textarea name="order[header_comments]"></textarea> The line comment boxes are structured as follows: <textarea name="line_comments[0][line_comments]"></tex ...

What is the best way to design a grid with various squares in React Native?

Here's the design I aim to achieve: I am looking to implement the above layout in react native and ensure it is responsive on all screen sizes. I attempted using flexbox but couldn't figure out how to make the boxes square shaped. The code provi ...