Skip to content

Commit

Permalink
Fix style overrides for Ra* components
Browse files Browse the repository at this point in the history
  • Loading branch information
sweco-sedalh committed May 2, 2022
1 parent f08bd9c commit c558aa5
Show file tree
Hide file tree
Showing 79 changed files with 166 additions and 78 deletions.
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/Labeled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import clsx from 'clsx';

import { FieldTitle } from 'ra-core';
import { ResponsiveStyleValue } from '@mui/system';
import { makeOverridesResolver } from './detail/makeOverridesResolver';

/**
* Wrap a field or an input with a label if necessary.
Expand Down Expand Up @@ -89,7 +90,7 @@ export const LabeledClasses = {

const Root = styled(Stack, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(LabeledClasses),
})(({ theme }) => ({
display: 'inline-flex',
marginBottom: '0.2em',
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useNavigate } from 'react-router-dom';
import { useCheckAuth } from 'ra-core';

import { LoginForm as DefaultLoginForm } from './LoginForm';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

/**
* A standalone login page, to serve as authentication gate to the admin
Expand Down Expand Up @@ -95,7 +96,7 @@ export const LoginClasses = {

const Root = styled('div', {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(LoginClasses),
})(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/auth/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useSafeSetState,
} from 'ra-core';
import { TextInput } from '../input';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const LoginForm = (props: LoginFormProps) => {
const { redirectTo, className } = props;
Expand Down Expand Up @@ -105,7 +106,7 @@ export const LoginFormClasses = {

const StyledForm = styled(Form, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(LoginFormClasses),
})(({ theme }) => ({
[`& .${LoginFormClasses.content}`]: {
width: 300,
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/auth/Logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MenuItemProps } from '@mui/material/MenuItem';
import ExitIcon from '@mui/icons-material/PowerSettingsNew';
import clsx from 'clsx';
import { useTranslate, useLogout } from 'ra-core';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

/**
* Logout button component, to be passed to the Admin component
Expand Down Expand Up @@ -65,7 +66,7 @@ export const LogoutClasses = {

const StyledMenuItem = styled(MenuItem, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(LogoutClasses),
})(({ theme }) => ({
color: theme.palette.text.secondary,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { Confirm } from '../layout';
import { Button, ButtonProps } from './Button';
import { BulkActionProps } from '../types';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const BulkDeleteWithConfirmButton = (
props: BulkDeleteWithConfirmButtonProps
Expand Down Expand Up @@ -153,7 +154,7 @@ const PREFIX = 'RaBulkDeleteWithConfirmButton';

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})(({ theme }) => ({
color: theme.palette.error.main,
'&:hover': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import { Button, ButtonProps } from './Button';
import { BulkActionProps } from '../types';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const BulkDeleteWithUndoButton = (
props: BulkDeleteWithUndoButtonProps
Expand Down Expand Up @@ -105,7 +106,7 @@ const PREFIX = 'RaBulkDeleteWithUndoButton';

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})(({ theme }) => ({
color: theme.palette.error.main,
'&:hover': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { Confirm } from '../layout';
import { Button, ButtonProps } from './Button';
import { BulkActionProps } from '../types';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const BulkUpdateWithConfirmButton = (
props: BulkUpdateWithConfirmButtonProps
Expand Down Expand Up @@ -171,7 +172,7 @@ const PREFIX = 'RaBulkUpdateWithConfirmButton';

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})(({ theme }) => ({
color: theme.palette.primary.main,
'&:hover': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import { Button, ButtonProps } from './Button';
import { BulkActionProps } from '../types';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const BulkUpdateWithUndoButton = (
props: BulkUpdateWithUndoButtonProps
Expand Down Expand Up @@ -123,7 +124,7 @@ const PREFIX = 'RaBulkUpdateWithUndoButton';

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})(({ theme }) => ({
color: theme.palette.primary.main,
'&:hover': {
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
useTranslate,
} from 'ra-core';
import { Path } from 'react-router';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export type LocationDescriptor = Partial<Path> & {
redirect?: boolean;
Expand Down Expand Up @@ -149,7 +150,7 @@ const PREFIX = 'RaButton';

const StyledButton = styled(MuiButton, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})({
'&.MuiButton-sizeSmall': {
// fix for icon misalignment on small buttons, see https://github.com/mui/material-ui/pull/30240
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/button/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Link } from 'react-router-dom';
import { useTranslate, useResourceContext, useCreatePath } from 'ra-core';

import { Button, ButtonProps, sanitizeButtonRestProps } from './Button';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

/**
* Opens the Create view of a given resource
Expand Down Expand Up @@ -98,7 +99,7 @@ export const CreateButtonClasses = {

const StyledFab = styled(Fab, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(CreateButtonClasses),
})(({ theme }) => ({
[`&.${CreateButtonClasses.floating}`]: {
color: theme.palette.getContrastText(theme.palette.primary.main),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {

import { Confirm } from '../layout';
import { Button, ButtonProps } from './Button';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const DeleteWithConfirmButton = <RecordType extends RaRecord = any>(
props: DeleteWithConfirmButtonProps<RecordType>
Expand Down Expand Up @@ -136,7 +137,7 @@ const PREFIX = 'RaDeleteWithConfirmButton';

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})(({ theme }) => ({
color: theme.palette.error.main,
'&:hover': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from 'ra-core';

import { Button, ButtonProps } from './Button';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const DeleteWithUndoButton = <RecordType extends RaRecord = any>(
props: DeleteWithUndoButtonProps<RecordType>
Expand Down Expand Up @@ -90,7 +91,7 @@ const PREFIX = 'RaDeleteWithUndoButton';

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})(({ theme }) => ({
color: theme.palette.error.main,
'&:hover': {
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/button/LocalesMenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useLocaleState } from 'ra-core';
import { Box, Button, Menu, MenuItem, styled } from '@mui/material';
import LanguageIcon from '@mui/icons-material/Translate';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

/**
* Language selector. Changes the locale in the app and persists it in
Expand Down Expand Up @@ -90,7 +91,7 @@ export const LocalesMenuButtonClasses = {

const Root = styled(Box, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(LocalesMenuButtonClasses),
})(({ theme }) => ({
[`& .${LocalesMenuButtonClasses.selectedLanguage}`]: {
marginLeft: theme.spacing(1),
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/button/SaveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from 'ra-core';

import { sanitizeButtonRestProps } from './Button';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

/**
* Submit button for resource forms (Edit and Create).
Expand Down Expand Up @@ -179,7 +180,7 @@ const PREFIX = 'RaSaveButton';

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})(({ theme }) => ({
position: 'relative',
[`& .MuiSvgIcon-root, & .MuiIcon-root, & .MuiCircularProgress-root`]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { styled } from '@mui/material/styles';
import { Button } from './Button';
import { useTranslate } from 'ra-core';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const SkipNavigationButton = () => {
const translate = useTranslate();
Expand All @@ -20,7 +21,7 @@ const PREFIX = 'RaSkipNavigationButton';

const StyledButton = styled(Button, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})(({ theme }) => ({
position: 'fixed',
padding: theme.spacing(1),
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/button/SortButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getFieldLabelTranslationArgs,
shallowEqual,
} from 'ra-core';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

/**
* A button allowing to change the sort field and order.
Expand Down Expand Up @@ -156,7 +157,7 @@ export interface SortButtonProps {

const StyledButton = styled(Button, {
name: 'RaSortButton',
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})({
'&.MuiButton-sizeSmall': {
// fix for icon misalignment on small buttons, see https://github.com/mui/material-ui/pull/30240
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/detail/CreateView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import clsx from 'clsx';

import { CreateProps } from '../types';
import { Title } from '../layout';
import { makeOverridesResolver } from './makeOverridesResolver';

export const CreateView = (props: CreateViewProps) => {
const {
Expand Down Expand Up @@ -97,7 +98,7 @@ export const CreateClasses = {

const Root = styled('div', {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(CreateClasses),
})(({ theme }) => ({
[`& .${CreateClasses.main}`]: {
display: 'flex',
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/detail/EditView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { EditActions as DefaultActions } from './EditActions';
import { Title } from '../layout';
import { EditProps } from '../types';
import { makeOverridesResolver } from './makeOverridesResolver';

export const EditView = (props: EditViewProps) => {
const {
Expand Down Expand Up @@ -122,7 +123,7 @@ export const EditClasses = {

const Root = styled('div', {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(EditClasses),
})({
[`& .${EditClasses.main}`]: {
display: 'flex',
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/detail/ShowView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useShowContext, useResourceDefinition } from 'ra-core';
import { ShowProps } from '../types';
import { ShowActions } from './ShowActions';
import { Title } from '../layout';
import { makeOverridesResolver } from './makeOverridesResolver';

const defaultActions = <ShowActions />;

Expand Down Expand Up @@ -89,7 +90,7 @@ export const ShowClasses = {

const Root = styled('div', {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(ShowClasses),
})(({ theme }) => ({
[`& .${ShowClasses.main}`]: {
display: 'flex',
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/detail/SimpleShowLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
OptionalRecordContextProvider,
} from 'ra-core';
import { Labeled } from '../Labeled';
import { makeOverridesResolver } from './makeOverridesResolver';

/**
* Layout for a Show view showing fields in one column.
Expand Down Expand Up @@ -114,7 +115,7 @@ export const SimpleShowLayoutClasses = {

const Root = styled('div', {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(SimpleShowLayoutClasses),
})(({ theme }) => ({
flex: 1,
padding: `${theme.spacing(1)} ${theme.spacing(2)}`,
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/detail/TabbedShowLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TabbedShowLayoutTabs,
getShowLayoutTabFullPath,
} from './TabbedShowLayoutTabs';
import { makeOverridesResolver } from './makeOverridesResolver';

/**
* Layout for a Show view showing fields grouped in tabs and laid out in a single column.
Expand Down Expand Up @@ -210,7 +211,7 @@ export const TabbedShowLayoutClasses = {

const Root = styled('div', {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(TabbedShowLayoutClasses),
})(({ theme }) => ({
flex: 1,
[`& .${TabbedShowLayoutClasses.content}`]: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function makeOverridesResolver(classes: { [key: string]: string }) {
return (props, styles) => [
styles.root,
...Object.entries(classes).map(([name, clazz]) => ({
[`& .${clazz}`]: styles[name],
})),
];
}
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/field/BooleanField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useTranslate, useRecordContext } from 'ra-core';

import { PublicFieldProps, InjectedFieldProps, fieldPropTypes } from './types';
import { sanitizeFieldRestProps } from './sanitizeFieldRestProps';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const BooleanField: FunctionComponent<BooleanFieldProps> = memo(
props => {
Expand Down Expand Up @@ -96,7 +97,7 @@ const PREFIX = 'RaBooleanField';

const StyledTypography = styled(Typography, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver({}),
})({
display: 'inline-flex',
verticalAlign: 'middle',
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/field/ChipField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useRecordContext } from 'ra-core';

import { sanitizeFieldRestProps } from './sanitizeFieldRestProps';
import { PublicFieldProps, InjectedFieldProps, fieldPropTypes } from './types';
import { makeOverridesResolver } from '../detail/makeOverridesResolver';

export const ChipField: FC<ChipFieldProps> = memo(props => {
const { className, source, emptyText, ...rest } = props;
Expand Down Expand Up @@ -59,7 +60,7 @@ const ChipFieldClasses = {

const StyledChip = styled(Chip, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
overridesResolver: makeOverridesResolver(ChipFieldClasses),
})({
[`&.${ChipFieldClasses.chip}`]: { margin: 4, cursor: 'inherit' },
});
Loading

0 comments on commit c558aa5

Please sign in to comment.