Skip to content
This repository has been archived by the owner on Jun 1, 2020. It is now read-only.

How to customize style #214

Open
mjozan opened this issue Apr 24, 2020 · 1 comment
Open

How to customize style #214

mjozan opened this issue Apr 24, 2020 · 1 comment

Comments

@mjozan
Copy link

mjozan commented Apr 24, 2020

Hello,

It may be a simple question but can somebody show me how to change some simple style like the color of a checkbox? Thank you for your answer.

@tisdadd
Copy link
Contributor

tisdadd commented May 4, 2020

Hello, I have been using the Material-UI Theming for my own project to do so. I have set up the following example on code sandbox. It includes a bit extra, in case you need a starting point for other things.

import React from "react";
import "./styles.css";

import { ThemeProvider, createMuiTheme, Button } from "@material-ui/core";

import MuiForm from "@rjsf/material-ui";

const theme = createMuiTheme({
  palette: {
    secondary: {
      main: "#263238",
      light: "#4f5b62",
      dark: "#000a12"
    },
    primary: {
      main: "#212121",
      light: "#484848",
      dark: "#000000"
    }
  },
  props: {
    MuiTextField: {
      variant: "filled"
    },
    MuiSelect: {
      variant: "filled"
    },
    MuiInputLabel: {
      variant: "filled"
    },
    MuiButton: {
      variant: "contained"
    },
    MuiCheckbox: {
      color: "primary"
    }
  },
  overrides: {
    MuiInputBase: {
      input: {
        color: "red"
      }
    }
  }
});

const simpleSchema = {
  title: "A registration form",
  description: "A simple form example.",
  type: "object",
  required: ["firstName", "lastName"],
  properties: {
    firstName: {
      type: "string",
      title: "First name",
      default: "Chuckie"
    },
    lastName: {
      type: "string",
      title: "Last name"
    },
    age: {
      type: "integer",
      title: "Age"
    },
    bio: {
      type: "string",
      title: "Bio"
    },
    password: {
      type: "string",
      title: "Password",
      minLength: 3
    },
    telephone: {
      type: "string",
      title: "Telephone",
      minLength: 10
    },
    checkBox: {
      type: "boolean",
      title: "A random checkbox"
    }
  }
};

export default function App() {
  return (
    <div className="App">
      <ThemeProvider theme={theme}>
        <MuiForm schema={simpleSchema}>
          <div>
            <Button color="primary" type="submit">
              Submit
            </Button>
          </div>
        </MuiForm>
      </ThemeProvider>
    </div>
  );
}

This method still requires a lot of digging through the docs initially, but keeps everything uniform.

For further customization, you can still make custom widgets and fields as needed, using uiSchema to pass it in.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants