Skip to content

Commit

Permalink
Use theme to set input variant
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed May 4, 2022
1 parent df1d9c1 commit 6c577e9
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 18 deletions.
25 changes: 23 additions & 2 deletions examples/demo/src/layout/themes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export const darkTheme = {
import { ThemeOptions } from '@mui/material';

type RaTheme = {
sidebar: { width: number };
components: { RaMenuItemLink: { styleOverrides: any } };
};

export const darkTheme: ThemeOptions & RaTheme = {
palette: {
primary: {
main: '#90caf9',
Expand Down Expand Up @@ -56,10 +63,17 @@ export const darkTheme = {
},
},
},
MuiTextField: {
defaultProps: {
variant: 'filled',
margin: 'dense',
size: 'small',
},
},
},
};

export const lightTheme = {
export const lightTheme: ThemeOptions & RaTheme = {
palette: {
primary: {
main: '#4f3cc9',
Expand Down Expand Up @@ -164,5 +178,12 @@ export const lightTheme = {
},
},
},
MuiTextField: {
defaultProps: {
variant: 'filled',
margin: 'dense',
size: 'small',
},
},
},
};
7 changes: 7 additions & 0 deletions packages/ra-ui-materialui/src/defaultTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ export const defaultTheme = {
},
},
},
MuiTextField: {
defaultProps: {
variant: 'filled',
margin: 'dense',
size: 'small',
},
},
},
};

Expand Down
6 changes: 3 additions & 3 deletions packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const AutocompleteInput = <
label,
limitChoicesToValue,
matchSuggestion,
margin = 'dense',
margin,
fieldState: fieldStateOverride,
filterToQuery = DefaultFilterToQuery,
formState: formStateOverride,
Expand All @@ -159,13 +159,13 @@ export const AutocompleteInput = <
resource: resourceProp,
shouldRenderSuggestions,
setFilter,
size = 'small',
size,
source: sourceProp,
suggestionLimit,
TextFieldProps,
translateChoice,
validate,
variant = 'filled',
variant,
...rest
} = props;

Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/input/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export const DateInput = ({
source,
resource,
helperText,
margin = 'dense',
margin,
onBlur,
onChange,
parse,
validate,
variant = 'filled',
variant,
...rest
}: DateInputProps) => {
const { field, fieldState, formState, id, isRequired } = useInput({
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/input/DateTimeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export const DateTimeInput = ({
format = formatDateTime,
label,
helperText,
margin = 'dense',
margin,
onBlur,
onChange,
source,
resource,
parse = parseDateTime,
validate,
variant = 'filled',
variant,
...rest
}: DateTimeInputProps) => {
const { field, fieldState, formState, id, isRequired } = useInput({
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export const NullableBooleanInput = (props: NullableBooleanInputProps) => {
format = getStringFromBoolean,
helperText,
label,
margin = 'dense',
margin,
onBlur,
onChange,
parse = getBooleanFromString,
resource,
source,
validate,
variant = 'filled',
variant,
nullLabel = 'ra.boolean.null',
falseLabel = 'ra.boolean.false',
trueLabel = 'ra.boolean.true',
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/input/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const NumberInput = ({
format = convertNumberToString,
helperText,
label,
margin = 'dense',
margin,
onBlur,
onChange,
parse = convertStringToNumber,
Expand All @@ -36,7 +36,7 @@ export const NumberInput = ({
min,
max,
validate,
variant = 'filled',
variant,
inputProps: overrideInputProps,
...rest
}: NumberInputProps) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/input/ResettableTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const ResettableTextField = forwardRef(
value,
resettable,
disabled,
variant = 'filled',
margin = 'dense',
variant,
margin,
className,
...rest
} = props;
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/input/SelectArrayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const SelectArrayInput = (props: SelectArrayInputProps) => {
label,
isFetching: isFetchingProp,
isLoading: isLoadingProp,
margin = 'dense',
margin,
onBlur,
onChange,
onCreate,
Expand All @@ -106,7 +106,7 @@ export const SelectArrayInput = (props: SelectArrayInputProps) => {
source: sourceProp,
translateChoice,
validate,
variant = 'filled',
variant,
...rest
} = props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const FilterLiveSearch = memo(
sx?: SxProps;
variant?: 'filled' | 'outlined';
}) => {
const { source = 'q', variant = 'filled', ...rest } = props;
const { source = 'q', variant, ...rest } = props;
const { filterValues, setFilters } = useListFilterContext();
const translate = useTranslate();

Expand Down

0 comments on commit 6c577e9

Please sign in to comment.