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

Commit dec72c7

Browse files
authored
Use icon component instead of mask-image for formatting buttons (matrix-org#9732)
Use icon component instead of mask-image for formatting buttons
1 parent 5c99450 commit dec72c7

File tree

7 files changed

+41
-74
lines changed

7 files changed

+41
-74
lines changed

res/css/views/rooms/wysiwyg_composer/components/_FormattingButtons.pcss

+16-56
Original file line numberDiff line numberDiff line change
@@ -21,80 +21,40 @@ limitations under the License.
2121

2222
.mx_FormattingButtons_Button {
2323
--size: 28px;
24-
position: relative;
2524
cursor: pointer;
2625
height: var(--size);
27-
line-height: var(--size);
28-
width: auto;
29-
padding-left: 22px;
26+
width: var(--size);
3027
background-color: transparent;
3128
border: none;
32-
33-
&::before {
34-
content: '';
35-
position: absolute;
36-
top: 6px;
37-
left: 6px;
38-
height: 16px;
39-
width: 16px;
40-
background-color: $tertiary-content;
41-
mask-repeat: no-repeat;
42-
mask-size: contain;
43-
mask-position: center;
44-
}
45-
46-
&::after {
47-
content: '';
48-
position: absolute;
49-
left: 0;
50-
top: 0;
51-
z-index: 0;
52-
width: var(--size);
53-
height: var(--size);
54-
border-radius: 5px;
55-
}
29+
display: flex;
30+
align-items: center;
31+
justify-content: center;
32+
border-radius: 5px;
5633
}
5734

5835
.mx_FormattingButtons_Button_hover {
5936
&:hover {
60-
&::after {
61-
background: rgba($secondary-content, 0.1);
62-
}
37+
background: rgba($secondary-content, 0.1);
6338

64-
&::before {
65-
background-color: $secondary-content;
39+
.mx_FormattingButtons_Icon {
40+
color: $secondary-content;
6641
}
6742
}
6843
}
6944

7045
.mx_FormattingButtons_active {
71-
&::after {
72-
background: rgba($accent, 0.1);
73-
}
46+
background: rgba($accent, 0.1);
7447

75-
&::before {
76-
background-color: $accent;
48+
.mx_FormattingButtons_Icon {
49+
color: $accent;
7750
}
7851
}
7952

80-
.mx_FormattingButtons_Button_bold::before {
81-
mask-image: url('$(res)/img/element-icons/room/composer/bold.svg');
82-
}
83-
84-
.mx_FormattingButtons_Button_italic::before {
85-
mask-image: url('$(res)/img/element-icons/room/composer/italic.svg');
86-
}
87-
88-
.mx_FormattingButtons_Button_underline::before {
89-
mask-image: url('$(res)/img/element-icons/room/composer/underline.svg');
90-
}
91-
92-
.mx_FormattingButtons_Button_strikethrough::before {
93-
mask-image: url('$(res)/img/element-icons/room/composer/strikethrough.svg');
94-
}
95-
96-
.mx_FormattingButtons_Button_inline_code::before {
97-
mask-image: url('$(res)/img/element-icons/room/composer/inline_code.svg');
53+
.mx_FormattingButtons_Icon {
54+
--size: 16px;
55+
height: var(--size);
56+
width: var(--size);
57+
color: $tertiary-content;
9858
}
9959
}
10060

Loading
Loading
Loading
Loading
Loading

src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { MouseEventHandler } from "react";
17+
import React, { MouseEventHandler, ReactNode } from "react";
1818
import { FormattingFunctions, AllActionStates } from "@matrix-org/matrix-wysiwyg";
1919
import classNames from "classnames";
2020

21+
import { Icon as BoldIcon } from '../../../../../../res/img/element-icons/room/composer/bold.svg';
22+
import { Icon as ItalicIcon } from '../../../../../../res/img/element-icons/room/composer/italic.svg';
23+
import { Icon as UnderlineIcon } from '../../../../../../res/img/element-icons/room/composer/underline.svg';
24+
import { Icon as StrikeThroughIcon } from '../../../../../../res/img/element-icons/room/composer/strikethrough.svg';
25+
import { Icon as InlineCodeIcon } from '../../../../../../res/img/element-icons/room/composer/inline_code.svg';
2126
import AccessibleTooltipButton from "../../../elements/AccessibleTooltipButton";
2227
import { Alignment } from "../../../elements/Tooltip";
2328
import { KeyboardShortcut } from "../../../settings/KeyboardShortcut";
@@ -38,24 +43,26 @@ function Tooltip({ label, keyCombo }: TooltipProps) {
3843
}
3944

4045
interface ButtonProps extends TooltipProps {
41-
className: string;
46+
icon: ReactNode;
4247
isActive: boolean;
4348
onClick: MouseEventHandler<HTMLButtonElement>;
4449
}
4550

46-
function Button({ label, keyCombo, onClick, isActive, className }: ButtonProps) {
51+
function Button({ label, keyCombo, onClick, isActive, icon }: ButtonProps) {
4752
return <AccessibleTooltipButton
4853
element="button"
4954
onClick={onClick as (e: ButtonEvent) => void}
5055
title={label}
5156
className={
52-
classNames('mx_FormattingButtons_Button', className, {
57+
classNames('mx_FormattingButtons_Button', {
5358
'mx_FormattingButtons_active': isActive,
5459
'mx_FormattingButtons_Button_hover': !isActive,
5560
})}
5661
tooltip={keyCombo && <Tooltip label={label} keyCombo={keyCombo} />}
5762
alignment={Alignment.Top}
58-
/>;
63+
>
64+
{ icon }
65+
</AccessibleTooltipButton>;
5966
}
6067

6168
interface FormattingButtonsProps {
@@ -65,10 +72,10 @@ interface FormattingButtonsProps {
6572

6673
export function FormattingButtons({ composer, actionStates }: FormattingButtonsProps) {
6774
return <div className="mx_FormattingButtons">
68-
<Button isActive={actionStates.bold === 'reversed'} label={_td("Bold")} keyCombo={{ ctrlOrCmdKey: true, key: 'b' }} onClick={() => composer.bold()} className="mx_FormattingButtons_Button_bold" />
69-
<Button isActive={actionStates.italic === 'reversed'} label={_td('Italic')} keyCombo={{ ctrlOrCmdKey: true, key: 'i' }} onClick={() => composer.italic()} className="mx_FormattingButtons_Button_italic" />
70-
<Button isActive={actionStates.underline === 'reversed'} label={_td('Underline')} keyCombo={{ ctrlOrCmdKey: true, key: 'u' }} onClick={() => composer.underline()} className="mx_FormattingButtons_Button_underline" />
71-
<Button isActive={actionStates.strikeThrough === 'reversed'} label={_td('Strikethrough')} onClick={() => composer.strikeThrough()} className="mx_FormattingButtons_Button_strikethrough" />
72-
<Button isActive={actionStates.inlineCode === 'reversed'} label={_td('Code')} keyCombo={{ ctrlOrCmdKey: true, key: 'e' }} onClick={() => composer.inlineCode()} className="mx_FormattingButtons_Button_inline_code" />
75+
<Button isActive={actionStates.bold === 'reversed'} label={_td("Bold")} keyCombo={{ ctrlOrCmdKey: true, key: 'b' }} onClick={() => composer.bold()} icon={<BoldIcon className="mx_FormattingButtons_Icon" />} />
76+
<Button isActive={actionStates.italic === 'reversed'} label={_td('Italic')} keyCombo={{ ctrlOrCmdKey: true, key: 'i' }} onClick={() => composer.italic()} icon={<ItalicIcon className="mx_FormattingButtons_Icon" />} />
77+
<Button isActive={actionStates.underline === 'reversed'} label={_td('Underline')} keyCombo={{ ctrlOrCmdKey: true, key: 'u' }} onClick={() => composer.underline()} icon={<UnderlineIcon className="mx_FormattingButtons_Icon" />} />
78+
<Button isActive={actionStates.strikeThrough === 'reversed'} label={_td('Strikethrough')} onClick={() => composer.strikeThrough()} icon={<StrikeThroughIcon className="mx_FormattingButtons_Icon" />} />
79+
<Button isActive={actionStates.inlineCode === 'reversed'} label={_td('Code')} keyCombo={{ ctrlOrCmdKey: true, key: 'e' }} onClick={() => composer.inlineCode()} icon={<InlineCodeIcon className="mx_FormattingButtons_Icon" />} />
7380
</div>;
7481
}

0 commit comments

Comments
 (0)