-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathRichTextInputToolbar.tsx
115 lines (111 loc) · 3.38 KB
/
RichTextInputToolbar.tsx
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import * as React from 'react';
import { ReactNode } from 'react';
import { styled } from '@mui/material/styles';
import {
AlignmentButtons,
ClearButtons,
FormatButtons,
LevelSelect,
ListButtons,
LinkButtons,
QuoteButtons,
ImageButtons,
ColorButtons,
} from './buttons';
/**
* A toolbar for the <RichTextInput>.
* @param props The toolbar props.
* @param {ReactNode} props.children The toolbar children, usually many <ToggleButton>.
* @param {'small' | 'medium' | 'large'} props.size The default size to apply to the **default** children.
*
* @example <caption>Customizing the size</caption>
* import { RichTextInput, RichTextInputToolbar } from 'ra-input-rich-text';
* const MyRichTextInput = (props) => (
* <RichTextInput
* toolbar={<RichTextInputToolbar size="large" />}
* label="Body"
* source="body"
* {...props}
* />
* );
*
* @example <caption>Customizing the children</caption>
* import { RichTextInput, RichTextInputToolbar } from 'ra-input-rich-text';
* const MyRichTextInput = ({ size, ...props }) => (
* <RichTextInput
* toolbar={(
* <RichTextInputToolbar>
* <LevelSelect size={size} />
* <FormatButtons size={size} />
* <ColorButtons size={size} />
* <ListButtons size={size} />
* <LinkButtons size={size} />
* <ImageButtons size={size} />
* <QuoteButtons size={size} />
* <ClearButtons size={size} />
* </RichTextInputToolbar>
* )}
* label="Body"
* source="body"
* {...props}
* />
* );
*/
export const RichTextInputToolbar = (props: RichTextInputToolbarProps) => {
const {
size = 'medium',
children = (
<>
<LevelSelect size={size} />
<FormatButtons size={size} />
<ColorButtons size={size} />
<AlignmentButtons size={size} />
<ListButtons size={size} />
<LinkButtons size={size} />
<ImageButtons size={size} />
<QuoteButtons size={size} />
<ClearButtons size={size} />
</>
),
...rest
} = props;
return (
<Root className={classes.root} {...rest}>
{children}
</Root>
);
};
const PREFIX = 'RaRichTextInputToolbar';
const classes = {
root: `${PREFIX}-root`,
};
const Root = styled('div')(({ theme }) => ({
[`&.${classes.root}`]: {
display: 'flex',
flexWrap: 'wrap',
alignItems: 'center',
'& > *': {
marginRight: theme.spacing(1),
marginBottom: theme.spacing(1),
},
'& > *:last-child': {
marginRight: 0,
},
'& button.MuiToggleButton-sizeSmall': {
padding: theme.spacing(0.3),
fontSize: theme.typography.pxToRem(18),
},
'& button.MuiToggleButton-sizeMedium': {
padding: theme.spacing(0.5),
fontSize: theme.typography.pxToRem(24),
},
'& button.MuiToggleButton-sizeLarge': {
padding: theme.spacing(1),
fontSize: theme.typography.pxToRem(24),
},
},
}));
export type RichTextInputToolbarProps = {
children?: ReactNode;
size?: 'small' | 'medium' | 'large';
};