forked from marmelab/react-admin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRadioButtonGroupInputItem.tsx
More file actions
84 lines (73 loc) · 2.19 KB
/
RadioButtonGroupInputItem.tsx
File metadata and controls
84 lines (73 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as React from 'react';
import FormControlLabel from '@mui/material/FormControlLabel';
import Radio from '@mui/material/Radio';
import { type ChoicesProps, useChoices } from 'ra-core';
import { FormControlLabelProps } from '@mui/material';
import {
ComponentsOverrides,
styled,
useThemeProps,
} from '@mui/material/styles';
import { sanitizeInputRestProps } from './sanitizeInputRestProps';
export const RadioButtonGroupInputItem = (
props: RadioButtonGroupInputItemProps
) => {
const {
choice,
optionText,
optionValue,
source,
translateChoice,
...rest
} = useThemeProps({
props: props,
name: PREFIX,
});
const { getChoiceText, getChoiceValue, getDisableValue } = useChoices({
optionText,
optionValue,
translateChoice,
});
const label = getChoiceText(choice);
const value = getChoiceValue(choice);
const disabled = getDisableValue(choice);
const nodeId = `${source}_${value}`;
return (
<StyledFormControlLabel
label={label}
htmlFor={nodeId}
value={value}
disabled={disabled}
control={<Radio id={nodeId} color="primary" />}
{...sanitizeInputRestProps(rest)}
/>
);
};
export default RadioButtonGroupInputItem;
export interface RadioButtonGroupInputItemProps
extends Omit<FormControlLabelProps, 'control' | 'label'>,
Pick<ChoicesProps, 'optionValue' | 'optionText' | 'translateChoice'> {
choice: any;
source: any;
}
const PREFIX = 'RaRadioButtonGroupInputItem';
const StyledFormControlLabel = styled(FormControlLabel, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
})({});
declare module '@mui/material/styles' {
interface ComponentNameToClassKey {
[PREFIX]: 'root';
}
interface ComponentsPropsList {
[PREFIX]: Partial<RadioButtonGroupInputItemProps>;
}
interface Components {
[PREFIX]?: {
defaultProps?: ComponentsPropsList[typeof PREFIX];
styleOverrides?: ComponentsOverrides<
Omit<Theme, 'components'>
>[typeof PREFIX];
};
}
}