gpt4 book ai didi

React-admin:如何从 AppBar 隐藏刷新按钮?

转载 作者:行者123 更新时间:2023-12-03 16:50:47 25 4
gpt4 key购买 nike

我正在创建基于 react-admin 的 admin ui,目前正在寻找一种解决方案来隐藏 AppBar 中的刷新按钮.
禁用导出按钮很简单( exporter={false} )。 RefreshButton 有什么同样简单的东西吗?我找不到任何有效的解决方案。

我的 React-admin 版本:2.9.3

我知道您可以在 List 上使用“actions” Prop 自定义操作组件,但这似乎已过时,因为刷新按钮已移至应用程序栏..

我可以将代码提供给我的自定义 AppBar如果需要的话。

最佳答案

没有简单的解决办法,AppBar中没有配置LoadingIndicator组件的存在:
https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/layout/AppBar.js

您可以实现您的 AppBar 组件,然后将其连接到 AppLayout:

// Layout.js

import React from 'react';
import { Layout } from 'react-admin';
import AppBarEx from './components/AppBarEx';

const AppLayout = (props) => (
<Layout
{...props}
appBar={AppBarEx}
/>
);

export default AppLayout;

// AppBarEx.js

import React, { Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import classNames from 'classnames';
import MuiAppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import { withStyles, createStyles } from '@material-ui/core/styles';
import MenuIcon from '@material-ui/icons/Menu';
import withWidth from '@material-ui/core/withWidth';
import compose from 'recompose/compose';
import { toggleSidebar as toggleSidebarAction } from 'ra-core';
import { UserMenu, Headroom } from 'react-admin';

const styles = theme =>
createStyles({
toolbar: {
paddingRight: 24,
},
menuButton: {
marginLeft: '0.5em',
marginRight: '0.5em',
},
menuButtonIconClosed: {
transition: theme.transitions.create(['transform'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
transform: 'rotate(0deg)',
},
menuButtonIconOpen: {
transition: theme.transitions.create(['transform'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
transform: 'rotate(180deg)',
},
title: {
flex: 1,
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden',
},
});

const AppBar = ({
children,
classes,
className,
logo,
logout,
open,
title,
toggleSidebar,
userMenu,
width,
...rest
}) => (
<Headroom>
<MuiAppBar
className={className}
color="secondary"
position="static"
{...rest}
>
<Toolbar
disableGutters
variant={width === 'xs' ? 'regular' : 'dense'}
className={classes.toolbar}
>
<IconButton
color="inherit"
aria-label="open drawer"
onClick={toggleSidebar}
className={classNames(classes.menuButton)}
>
<MenuIcon
classes={{
root: open
? classes.menuButtonIconOpen
: classes.menuButtonIconClosed,
}}
/>
</IconButton>
{Children.count(children) === 0 ? (
<Typography
variant="title"
color="inherit"
className={classes.title}
id="react-admin-title"
/>
) : (
children
)}
{cloneElement(userMenu, { logout })}
</Toolbar>
</MuiAppBar>
</Headroom>
);

AppBar.propTypes = {
children: PropTypes.node,
classes: PropTypes.object,
className: PropTypes.string,
logout: PropTypes.element,
open: PropTypes.bool,
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]).isRequired,
toggleSidebar: PropTypes.func.isRequired,
userMenu: PropTypes.node,
width: PropTypes.string,
};

AppBar.defaultProps = {
userMenu: <UserMenu />,
};

const enhance = compose(
connect(
state => ({
locale: state.i18n.locale, // force redraw on locale change
}),
{
toggleSidebar: toggleSidebarAction,
}
),
withStyles(styles),
withWidth()
);

export default enhance(AppBar);

关于React-admin:如何从 AppBar 隐藏刷新按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57510975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com