Skip to content

Commit

Permalink
Merge pull request #8624 from IAmVisco/bugfix/add-classes-to-special-…
Browse files Browse the repository at this point in the history
…buttons

Add classnames to Create and Edit buttons
  • Loading branch information
fzaninotto authored Feb 7, 2023
2 parents 3758606 + aefb60a commit a69ba1f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
12 changes: 9 additions & 3 deletions packages/ra-ui-materialui/src/button/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ const CreateButton = (props: CreateButtonProps) => {
{icon}
</StyledFab>
) : (
<Button
<StyledButton
component={Link}
to={createPath({ resource, type: 'create' })}
state={scrollStates[String(scrollToTop)]}
className={className}
className={clsx(CreateButtonClasses.root, className)}
label={label}
variant={variant}
{...(rest as any)}
>
{icon}
</Button>
</StyledButton>
);
};

Expand Down Expand Up @@ -94,6 +94,7 @@ CreateButton.propTypes = {
const PREFIX = 'RaCreateButton';

export const CreateButtonClasses = {
root: `${PREFIX}-root`,
floating: `${PREFIX}-floating`,
};

Expand All @@ -113,6 +114,11 @@ const StyledFab = (styled(Fab, {
},
})) as unknown) as typeof Fab;

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (_props, styles) => styles.root,
})({});

export default memo(CreateButton, (prevProps, nextProps) => {
return (
prevProps.resource === nextProps.resource &&
Expand Down
19 changes: 17 additions & 2 deletions packages/ra-ui-materialui/src/button/EditButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import { ReactElement } from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled } from '@mui/material/styles';
import ContentCreate from '@mui/icons-material/Create';
import { Link } from 'react-router-dom';
import {
Expand Down Expand Up @@ -31,23 +33,25 @@ export const EditButton = <RecordType extends RaRecord = any>(
icon = defaultIcon,
label = 'ra.action.edit',
scrollToTop = true,
className,
...rest
} = props;
const resource = useResourceContext(props);
const record = useRecordContext(props);
const createPath = useCreatePath();
if (!record) return null;
return (
<Button
<StyledButton
component={Link}
to={createPath({ type: 'edit', resource, id: record.id })}
state={scrollStates[String(scrollToTop)]}
label={label}
onClick={stopPropagation}
className={clsx(EditButtonClasses.root, className)}
{...(rest as any)}
>
{icon}
</Button>
</StyledButton>
);
};

Expand Down Expand Up @@ -81,3 +85,14 @@ EditButton.propTypes = {
record: PropTypes.any,
scrollToTop: PropTypes.bool,
};

const PREFIX = 'RaEditButton';

export const EditButtonClasses = {
root: `${PREFIX}-root`,
};

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (_props, styles) => styles.root,
})({});

0 comments on commit a69ba1f

Please sign in to comment.