Debian Codegraph @

packages/mui/src/IconButton/IconButton.tsx

raw
1 import IconButton, { IconButtonProps as MuiIconButtonProps } from '@mui/material/IconButton';
2 import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
3 import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
4 import CopyIcon from '@mui/icons-material/ContentCopy';
5 import RemoveIcon from '@mui/icons-material/Remove';
6 import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
7
8 export default function MuiIconButton<
9 T = any,
10 S extends StrictRJSFSchema = RJSFSchema,
11 F extends FormContextType = any
12 >(props: IconButtonProps<T, S, F>) {
13 const { icon, color, uiSchema, registry, ...otherProps } = props;
14 return (
15 <IconButton {...otherProps} size='small' color={color as MuiIconButtonProps['color']}>
16 {icon}
17 </IconButton>
18 );
19 }
20
21 export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
22 props: IconButtonProps<T, S, F>
23 ) {
24 const {
25 registry: { translateString },
26 } = props;
27 return (
28 <MuiIconButton
29 title={translateString(TranslatableString.CopyButton)}
30 {...props}
31 icon={<CopyIcon fontSize='small' />}
32 />
33 );
34 }
35
36 export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
37 props: IconButtonProps<T, S, F>
38 ) {
39 const {
40 registry: { translateString },
41 } = props;
42 return (
43 <MuiIconButton
44 title={translateString(TranslatableString.MoveDownButton)}
45 {...props}
46 icon={<ArrowDownwardIcon fontSize='small' />}
47 />
48 );
49 }
50
51 export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
52 props: IconButtonProps<T, S, F>
53 ) {
54 const {
55 registry: { translateString },
56 } = props;
57 return (
58 <MuiIconButton
59 title={translateString(TranslatableString.MoveUpButton)}
60 {...props}
61 icon={<ArrowUpwardIcon fontSize='small' />}
62 />
63 );
64 }
65
66 export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
67 props: IconButtonProps<T, S, F>
68 ) {
69 const { iconType, ...otherProps } = props;
70 const {
71 registry: { translateString },
72 } = otherProps;
73 return (
74 <MuiIconButton
75 title={translateString(TranslatableString.RemoveButton)}
76 {...otherProps}
77 color='error'
78 icon={<RemoveIcon fontSize={iconType === 'default' ? undefined : 'small'} />}
79 />
80 );
81 }