Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Add background to toolbar #2568

Merged
merged 1 commit into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions packages/ra-ui-materialui/src/form/SimpleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,20 @@ export class SimpleForm extends Component {
/>
))}
</CardContentInner>
{toolbar && (
<CardContentInner>
{React.cloneElement(toolbar, {
basePath,
handleSubmitWithRedirect: this
.handleSubmitWithRedirect,
handleSubmit: this.props.handleSubmit,
invalid,
pristine,
record,
redirect,
resource,
saving,
submitOnEnter,
})}
</CardContentInner>
)}
{toolbar &&
React.cloneElement(toolbar, {
basePath,
handleSubmitWithRedirect: this
.handleSubmitWithRedirect,
handleSubmit: this.props.handleSubmit,
invalid,
pristine,
record,
redirect,
resource,
saving,
submitOnEnter,
})}
</form>
);
}
Expand Down
37 changes: 17 additions & 20 deletions packages/ra-ui-materialui/src/form/TabbedForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const sanitizeRestProps = ({

const getTabFullPath = (tab, index, baseUrl) =>
`${baseUrl}${
tab.props.path ? `/${tab.props.path}` : index > 0 ? `/${index}` : ''
tab.props.path ? `/${tab.props.path}` : index > 0 ? `/${index}` : ''
}`;

export class TabbedForm extends Component {
Expand Down Expand Up @@ -136,7 +136,7 @@ export class TabbedForm extends Component {
value: tabPath,
className:
tabsWithErrors.includes(tab.props.label) &&
location.pathname !== tabPath
location.pathname !== tabPath
? classes.errorTabButton
: null,
});
Expand Down Expand Up @@ -182,24 +182,21 @@ export class TabbedForm extends Component {
)
)}
</CardContentInner>
{toolbar && (
<CardContentInner>
{React.cloneElement(toolbar, {
basePath,
className: 'toolbar',
handleSubmitWithRedirect: this
.handleSubmitWithRedirect,
handleSubmit: this.props.handleSubmit,
invalid,
pristine,
record,
redirect,
resource,
saving,
submitOnEnter,
})}{' '}
</CardContentInner>
)}
{toolbar &&
React.cloneElement(toolbar, {
basePath,
className: 'toolbar',
handleSubmitWithRedirect: this
.handleSubmitWithRedirect,
handleSubmit: this.props.handleSubmit,
invalid,
pristine,
record,
redirect,
resource,
saving,
submitOnEnter,
})}
</form>
);
}
Expand Down
122 changes: 65 additions & 57 deletions packages/ra-ui-materialui/src/form/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import classnames from 'classnames';

import { SaveButton, DeleteButton } from '../button';

const styles = {
const styles = theme => ({
toolbar: {
backgroundColor: theme.palette.type === 'light' ? theme.palette.grey[200] : theme.palette.grey[900],
},
desktopToolbar: {
marginTop: theme.spacing.unit * 2,
},
mobileToolbar: {
position: 'fixed',
bottom: 0,
Expand All @@ -18,15 +24,14 @@ const styles = {
width: '100%',
boxSizing: 'border-box',
flexShrink: 0,
backgroundColor: 'white',
zIndex: 2,
},
defaultToolbar: {
flex: 1,
display: 'flex',
justifyContent: 'space-between',
},
};
});

const valueOrDefault = (value, defaultValue) =>
typeof value === 'undefined' ? defaultValue : value;
Expand All @@ -48,60 +53,63 @@ const Toolbar = ({
width,
...rest
}) => (
<MuiToolbar
className={classnames(
{ [classes.mobileToolbar]: width === 'xs' },
className
)}
disableGutters
{...rest}
>
{Children.count(children) === 0 ? (
<div className={classes.defaultToolbar}>
<SaveButton
handleSubmitWithRedirect={handleSubmitWithRedirect}
invalid={invalid}
redirect={redirect}
saving={saving}
submitOnEnter={submitOnEnter}
/>
{record &&
typeof record.id !== 'undefined' && (
<DeleteButton
basePath={basePath}
record={record}
resource={resource}
/>
)}
</div>
) : (
Children.map(
children,
button =>
button
? React.cloneElement(button, {
basePath,
handleSubmit: valueOrDefault(
button.props.handleSubmit,
handleSubmit
),
handleSubmitWithRedirect: valueOrDefault(
button.props.handleSubmitWithRedirect,
handleSubmitWithRedirect
),
invalid,
pristine,
saving,
submitOnEnter: valueOrDefault(
button.props.submitOnEnter,
submitOnEnter
),
})
: null
)
)}
</MuiToolbar>
);
<MuiToolbar
className={classnames(
classes.toolbar,
{
[classes.mobileToolbar]: width === 'xs',
[classes.desktopToolbar]: width !== 'xs'
},
className
)}
{...rest}
>
{Children.count(children) === 0 ? (
<div className={classes.defaultToolbar}>
<SaveButton
handleSubmitWithRedirect={handleSubmitWithRedirect}
invalid={invalid}
redirect={redirect}
saving={saving}
submitOnEnter={submitOnEnter}
/>
{record &&
typeof record.id !== 'undefined' && (
<DeleteButton
basePath={basePath}
record={record}
resource={resource}
/>
)}
</div>
) : (
Children.map(
children,
button =>
button
? React.cloneElement(button, {
basePath,
handleSubmit: valueOrDefault(
button.props.handleSubmit,
handleSubmit
),
handleSubmitWithRedirect: valueOrDefault(
button.props.handleSubmitWithRedirect,
handleSubmitWithRedirect
),
invalid,
pristine,
saving,
submitOnEnter: valueOrDefault(
button.props.submitOnEnter,
submitOnEnter
),
})
: null
)
)}
</MuiToolbar>
);

Toolbar.propTypes = {
basePath: PropTypes.string,
Expand Down