Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

reactjs - Customize existing component with fixed css classes in React

I'm using react-calendar in my project, and it uses a plain CSS stylesheet (basically you import it in your project (import 'react-calendar/dist/Calendar.css';).

I'm able to customize the component writing my own CSS file, but since my project is themeable, I'd like to be able to pass some react props to the CSS.

I'm using Material-UI with JSS on all the other components, but these classes are dynamically named, and I couldn't find a way to use JSS with "fixed" class names.

Is there any way to have a CSS-in-JS solution but with fixed CSS classes?

Something like:

.react-calendar__tile--active:enabled:focus {
  background: {prop.backgroundColor};
}

Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

material-UI comes with global CSS plugin. With that at your component you can define/override global classes by declaring inside @global property:

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles({
  '@global': {
    '.react-calendar__tile--active:enabled:focus': {
      backgroundColor: props => props.backgroundColor,
    },
  },
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...