如何覆盖已编译的类? [英] How do I override compiled classes?
问题描述
我试图将重写样式应用于已编译的类名.我的编译代码就像...
I cam trying to apply override styles to a compiled class name. my compiled code is like...
<div class="MuiListItemText-root-262" >
我希望能够定位到像这样的特定项目
I want to be able to target that specific item like this
const styles = () => { MultiListItemText-root-262: { color: red; } }
在普通CSS中,我只能做.MultiListItemText-root-262: { color: red; }
in vanilla CSS I could just do .MultiListItemText-root-262: { color: red; }
如何在JSS中做等效的事情?
How can I do the equivalent in JSS?
推荐答案
您不能以这种方式进行操作. 类名"MuiListItemText-root-262"是动态的,并且标识"262"不可靠并且可能会更改.
You cannot do it this way. The classname "MuiListItemText-root-262" is dynamic, and the id "262" is not reliable and may change.
请查看Material UI有关使用JSS覆盖的官方文档: https://material- ui.com/customization/overrides/
Please look at the official documentation of Material UI for using JSS overrides : https://material-ui.com/customization/overrides/
根据您想要达到的变化水平,有几种可用的技术.
There are several techniques available depending on the level of variation your want to achieve.
有关典型的一次性"替代,请参阅第一个使用withStyles HOC的示例代码
For a typical "one time" override, see the first sample code which uses the withStyles HOC
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
// We can inject some CSS into the DOM.
const styles = {
button: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
borderRadius: 3,
border: 0,
color: 'white',
height: 48,
padding: '0 30px',
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
},
};
function ClassNames(props) {
return (
<Button className={props.classes.button}>
{props.children ? props.children : 'class names'}
</Button>
);
}
ClassNames.propTypes = {
children: PropTypes.node,
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(ClassNames);
这篇关于如何覆盖已编译的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!