在官方 material-ui 文档中,此处AppBar
组件的示例如下所示:
import React, {Component} from 'react';
import AppBar from 'material-ui/AppBar';
import IconButton from 'material-ui/IconButton';
import IconMenu from 'material-ui/IconMenu';
import MenuItem from 'material-ui/MenuItem';
import FlatButton from 'material-ui/FlatButton';
import Toggle from 'material-ui/Toggle';
import MoreVertIcon from 'material-ui/svg-icons/navigation/more-vert';
import NavigationClose from 'material-ui/svg-icons/navigation/close';
class Login extends Component {
static muiName = 'FlatButton';
render() {
return (
<FlatButton {...this.props} label="Login" />
);
}
}
const Logged = (props) => (
<IconMenu
{...props}
iconButtonElement={
<IconButton><MoreVertIcon /></IconButton>
}
targetOrigin={{horizontal: 'right', vertical: 'top'}}
anchorOrigin={{horizontal: 'right', vertical: 'top'}}
>
<MenuItem primaryText="Refresh" />
<MenuItem primaryText="Help" />
<MenuItem primaryText="Sign out" />
</IconMenu>
);
Logged.muiName = 'IconMenu';
/**
* This example is taking advantage of the composability of the `AppBar`
* to render different components depending on the application state.
*/
class AppBarExampleComposition extends Component {
state = {
logged: true,
};
handleChange = (event, logged) => {
this.setState({logged: logged});
};
render() {
return (
<div>
<Toggle
label="Logged"
defaultToggled={true}
onToggle={this.handleChange}
labelPosition="right"
style={{margin: 20}}
/>
<AppBar
title="Title"
iconElementLeft={<IconButton><NavigationClose /></IconButton>}
iconElementRight={this.state.logged ? <Logged /> : <Login />}
/>
</div>
);
}
}
export default AppBarExampleComposition;
我的问题是关于陈述的
static muiName = 'FlatButton';
和
Logged.muiName = 'IconMenu';
什么是muiName
以及何时/为什么我必须设置它?是否应该始终设置为render()
方法中顶级组件的名称?
在同一个网页上,有未设置AppBar
where 的示例muiName
。