Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 77543b3

Browse files
authored
Merge pull request #9410 from matrix-org/feat/add-formating-buttons-to-wysiwyg
Add formatting buttons to the WysiwygComposer
2 parents bbb02c3 + 1638c5a commit 77543b3

File tree

19 files changed

+368
-39
lines changed

19 files changed

+368
-39
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"dependencies": {
5858
"@babel/runtime": "^7.12.5",
5959
"@matrix-org/analytics-events": "^0.2.0",
60-
"@matrix-org/matrix-wysiwyg": "^0.0.2",
60+
"@matrix-org/matrix-wysiwyg": "^0.2.0",
6161
"@matrix-org/react-sdk-module-api": "^0.0.3",
6262
"@sentry/browser": "^6.11.0",
6363
"@sentry/tracing": "^6.11.0",

res/css/_components.pcss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
@import "./views/rooms/_TopUnreadMessagesBar.pcss";
298298
@import "./views/rooms/_VoiceRecordComposerTile.pcss";
299299
@import "./views/rooms/_WhoIsTypingTile.pcss";
300+
@import "./views/rooms/wysiwyg_composer/_FormattingButtons.pcss";
300301
@import "./views/rooms/wysiwyg_composer/_WysiwygComposer.pcss";
301302
@import "./views/settings/_AvatarSetting.pcss";
302303
@import "./views/settings/_CrossSigningPanel.pcss";

res/css/views/rooms/_MessageComposer.pcss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ limitations under the License.
233233
}
234234
}
235235

236+
/*
237+
The wysisyg composer increase the size of the MessageComposer. We temporary move the buttons
238+
Soon the dom structure of the MessageComposer will change with the next evolution of the wysiwyg composer
239+
and this workaround will disappear
240+
*/
241+
.mx_MessageComposer_wysiwyg {
242+
.mx_MessageComposer_e2eIcon.mx_E2EIcon,.mx_MessageComposer_button, .mx_MessageComposer_sendMessage {
243+
margin-top: 22px;
244+
}
245+
}
246+
236247
.mx_MessageComposer_upload::before {
237248
mask-image: url('$(res)/img/element-icons/room/composer/attach.svg');
238249
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_FormattingButtons {
18+
display: flex;
19+
justify-content: start;
20+
21+
.mx_FormattingButtons_Button {
22+
--size: 28px;
23+
position: relative;
24+
cursor: pointer;
25+
height: var(--size);
26+
line-height: var(--size);
27+
width: auto;
28+
padding-left: 22px;
29+
margin-right: 8px;
30+
background-color: transparent;
31+
border: none;
32+
33+
&:first-child {
34+
margin-left: 12px;
35+
}
36+
37+
&:last-child {
38+
margin-right: auto;
39+
}
40+
41+
&::before {
42+
content: '';
43+
position: absolute;
44+
top: 6px;
45+
left: 6px;
46+
height: 16px;
47+
width: 16px;
48+
background-color: $icon-button-color;
49+
mask-repeat: no-repeat;
50+
mask-size: contain;
51+
mask-position: center;
52+
}
53+
54+
&::after {
55+
content: '';
56+
position: absolute;
57+
left: 0;
58+
top: 0;
59+
z-index: 0;
60+
width: var(--size);
61+
height: var(--size);
62+
border-radius: 5px;
63+
}
64+
65+
&:hover {
66+
&::after {
67+
background: rgba($secondary-content, 0.1);
68+
}
69+
70+
&::before {
71+
background-color: $secondary-content;
72+
}
73+
}
74+
}
75+
76+
.mx_FormattingButtons_active {
77+
&::after {
78+
background: rgba($accent, 0.1);
79+
}
80+
81+
&::before {
82+
background-color: $accent;
83+
}
84+
}
85+
86+
.mx_FormattingButtons_Button_bold::before {
87+
mask-image: url('$(res)/img/element-icons/room/composer/bold.svg');
88+
}
89+
90+
.mx_FormattingButtons_Button_italic::before {
91+
mask-image: url('$(res)/img/element-icons/room/composer/italic.svg');
92+
}
93+
94+
.mx_FormattingButtons_Button_underline::before {
95+
mask-image: url('$(res)/img/element-icons/room/composer/underline.svg');
96+
}
97+
98+
.mx_FormattingButtons_Button_strikethrough::before {
99+
mask-image: url('$(res)/img/element-icons/room/composer/strikethrough.svg');
100+
}
101+
}
102+
103+
.mx_FormattingButtons_Tooltip {
104+
padding: 0 2px 0 2px;
105+
106+
.mx_FormattingButtons_Tooltip_KeyboardShortcut {
107+
color: $tertiary-content;
108+
109+
kbd {
110+
margin-top: 2px;
111+
text-align: center;
112+
display: inline-block;
113+
text-transform: capitalize;
114+
font-size: 12px;
115+
font-family: Inter, sans-serif;
116+
}
117+
}
118+
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

src/components/views/rooms/MessageComposer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
389389
}
390390

391391
public render() {
392+
const isWysiwygComposerEnabled = SettingsStore.getValue("feature_wysiwyg_composer");
392393
const controls = [
393394
this.props.e2eStatus ?
394395
<E2EIcon key="e2eIcon" status={this.props.e2eStatus} className="mx_MessageComposer_e2eIcon" /> :
@@ -403,8 +404,6 @@ export default class MessageComposer extends React.Component<IProps, IState> {
403404

404405
const canSendMessages = this.context.canSendMessages && !this.context.tombstone;
405406
if (canSendMessages) {
406-
const isWysiwygComposerEnabled = SettingsStore.getValue("feature_wysiwyg_composer");
407-
408407
if (isWysiwygComposerEnabled) {
409408
controls.push(
410409
<WysiwygComposer key="controls_input"
@@ -503,6 +502,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
503502
"mx_MessageComposer": true,
504503
"mx_MessageComposer--compact": this.props.compact,
505504
"mx_MessageComposer_e2eStatus": this.props.e2eStatus != undefined,
505+
"mx_MessageComposer_wysiwyg": isWysiwygComposerEnabled,
506506
});
507507

508508
return (
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React, { forwardRef, memo } from 'react';
18+
19+
interface EditorProps {
20+
disabled: boolean;
21+
}
22+
23+
export const Editor = memo(
24+
forwardRef<HTMLDivElement, EditorProps>(
25+
function Editor({ disabled }: EditorProps, ref,
26+
) {
27+
return <div className="mx_WysiwygComposer_container">
28+
<div className="mx_WysiwygComposer_content"
29+
ref={ref!}
30+
contentEditable={!disabled}
31+
role="textbox"
32+
aria-multiline="true"
33+
aria-autocomplete="list"
34+
aria-haspopup="listbox"
35+
dir="auto"
36+
aria-disabled={disabled}
37+
/>
38+
</div>;
39+
},
40+
),
41+
);

0 commit comments

Comments
 (0)