Skip to content

Commit d165964

Browse files
committed
Use theme to set input variant
1 parent dc6bce6 commit d165964

10 files changed

+46
-18
lines changed

examples/demo/src/layout/themes.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
export const darkTheme = {
1+
import { ThemeOptions } from '@mui/material';
2+
3+
type RaTheme = {
4+
sidebar: { width: number };
5+
components: { RaMenuItemLink: { styleOverrides: any } };
6+
};
7+
8+
export const darkTheme: ThemeOptions & RaTheme = {
29
palette: {
310
primary: {
411
main: '#90caf9',
@@ -56,10 +63,17 @@ export const darkTheme = {
5663
},
5764
},
5865
},
66+
MuiTextField: {
67+
defaultProps: {
68+
variant: 'filled',
69+
margin: 'dense',
70+
size: 'small',
71+
},
72+
},
5973
},
6074
};
6175

62-
export const lightTheme = {
76+
export const lightTheme: ThemeOptions & RaTheme = {
6377
palette: {
6478
primary: {
6579
main: '#4f3cc9',
@@ -164,5 +178,12 @@ export const lightTheme = {
164178
},
165179
},
166180
},
181+
MuiTextField: {
182+
defaultProps: {
183+
variant: 'filled',
184+
margin: 'dense',
185+
size: 'small',
186+
},
187+
},
167188
},
168189
};

packages/ra-ui-materialui/src/defaultTheme.ts

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ export const defaultTheme = {
7575
},
7676
},
7777
},
78+
MuiTextField: {
79+
defaultProps: {
80+
variant: 'filled',
81+
margin: 'dense',
82+
size: 'small',
83+
},
84+
},
7885
},
7986
};
8087

packages/ra-ui-materialui/src/input/AutocompleteInput.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const AutocompleteInput = <
143143
label,
144144
limitChoicesToValue,
145145
matchSuggestion,
146-
margin = 'dense',
146+
margin,
147147
fieldState: fieldStateOverride,
148148
filterToQuery = DefaultFilterToQuery,
149149
formState: formStateOverride,
@@ -159,13 +159,13 @@ export const AutocompleteInput = <
159159
resource: resourceProp,
160160
shouldRenderSuggestions,
161161
setFilter,
162-
size = 'small',
162+
size,
163163
source: sourceProp,
164164
suggestionLimit,
165165
TextFieldProps,
166166
translateChoice,
167167
validate,
168-
variant = 'filled',
168+
variant,
169169
...rest
170170
} = props;
171171

packages/ra-ui-materialui/src/input/DateInput.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ export const DateInput = ({
3939
source,
4040
resource,
4141
helperText,
42-
margin = 'dense',
42+
margin,
4343
onBlur,
4444
onChange,
4545
parse,
4646
validate,
47-
variant = 'filled',
47+
variant,
4848
...rest
4949
}: DateInputProps) => {
5050
const { field, fieldState, formState, id, isRequired } = useInput({

packages/ra-ui-materialui/src/input/DateTimeInput.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ export const DateTimeInput = ({
2626
format = formatDateTime,
2727
label,
2828
helperText,
29-
margin = 'dense',
29+
margin,
3030
onBlur,
3131
onChange,
3232
source,
3333
resource,
3434
parse = parseDateTime,
3535
validate,
36-
variant = 'filled',
36+
variant,
3737
...rest
3838
}: DateTimeInputProps) => {
3939
const { field, fieldState, formState, id, isRequired } = useInput({

packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export const NullableBooleanInput = (props: NullableBooleanInputProps) => {
1616
format = getStringFromBoolean,
1717
helperText,
1818
label,
19-
margin = 'dense',
19+
margin,
2020
onBlur,
2121
onChange,
2222
parse = getBooleanFromString,
2323
resource,
2424
source,
2525
validate,
26-
variant = 'filled',
26+
variant,
2727
nullLabel = 'ra.boolean.null',
2828
falseLabel = 'ra.boolean.false',
2929
trueLabel = 'ra.boolean.true',

packages/ra-ui-materialui/src/input/NumberInput.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const NumberInput = ({
2626
format = convertNumberToString,
2727
helperText,
2828
label,
29-
margin = 'dense',
29+
margin,
3030
onBlur,
3131
onChange,
3232
parse = convertStringToNumber,
@@ -36,7 +36,7 @@ export const NumberInput = ({
3636
min,
3737
max,
3838
validate,
39-
variant = 'filled',
39+
variant,
4040
inputProps: overrideInputProps,
4141
...rest
4242
}: NumberInputProps) => {

packages/ra-ui-materialui/src/input/ResettableTextField.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const ResettableTextField = forwardRef(
2323
value,
2424
resettable,
2525
disabled,
26-
variant = 'filled',
27-
margin = 'dense',
26+
variant,
27+
margin,
2828
className,
2929
...rest
3030
} = props;

packages/ra-ui-materialui/src/input/SelectArrayInput.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const SelectArrayInput = (props: SelectArrayInputProps) => {
9595
label,
9696
isFetching: isFetchingProp,
9797
isLoading: isLoadingProp,
98-
margin = 'dense',
98+
margin,
9999
onBlur,
100100
onChange,
101101
onCreate,
@@ -106,7 +106,7 @@ export const SelectArrayInput = (props: SelectArrayInputProps) => {
106106
source: sourceProp,
107107
translateChoice,
108108
validate,
109-
variant = 'filled',
109+
variant,
110110
...rest
111111
} = props;
112112

packages/ra-ui-materialui/src/list/filter/FilterLiveSearch.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const FilterLiveSearch = memo(
2828
sx?: SxProps;
2929
variant?: 'filled' | 'outlined';
3030
}) => {
31-
const { source = 'q', variant = 'filled', ...rest } = props;
31+
const { source = 'q', variant, ...rest } = props;
3232
const { filterValues, setFilters } = useListFilterContext();
3333
const translate = useTranslate();
3434

0 commit comments

Comments
 (0)