This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9410 from matrix-org/feat/add-formating-buttons-t…
…o-wysiwyg Add formatting buttons to the WysiwygComposer
- Loading branch information
Showing
19 changed files
with
368 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
res/css/views/rooms/wysiwyg_composer/_FormattingButtons.pcss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.mx_FormattingButtons { | ||
display: flex; | ||
justify-content: start; | ||
|
||
.mx_FormattingButtons_Button { | ||
--size: 28px; | ||
position: relative; | ||
cursor: pointer; | ||
height: var(--size); | ||
line-height: var(--size); | ||
width: auto; | ||
padding-left: 22px; | ||
margin-right: 8px; | ||
background-color: transparent; | ||
border: none; | ||
|
||
&:first-child { | ||
margin-left: 12px; | ||
} | ||
|
||
&:last-child { | ||
margin-right: auto; | ||
} | ||
|
||
&::before { | ||
content: ''; | ||
position: absolute; | ||
top: 6px; | ||
left: 6px; | ||
height: 16px; | ||
width: 16px; | ||
background-color: $icon-button-color; | ||
mask-repeat: no-repeat; | ||
mask-size: contain; | ||
mask-position: center; | ||
} | ||
|
||
&::after { | ||
content: ''; | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
z-index: 0; | ||
width: var(--size); | ||
height: var(--size); | ||
border-radius: 5px; | ||
} | ||
|
||
&:hover { | ||
&::after { | ||
background: rgba($secondary-content, 0.1); | ||
} | ||
|
||
&::before { | ||
background-color: $secondary-content; | ||
} | ||
} | ||
} | ||
|
||
.mx_FormattingButtons_active { | ||
&::after { | ||
background: rgba($accent, 0.1); | ||
} | ||
|
||
&::before { | ||
background-color: $accent; | ||
} | ||
} | ||
|
||
.mx_FormattingButtons_Button_bold::before { | ||
mask-image: url('$(res)/img/element-icons/room/composer/bold.svg'); | ||
} | ||
|
||
.mx_FormattingButtons_Button_italic::before { | ||
mask-image: url('$(res)/img/element-icons/room/composer/italic.svg'); | ||
} | ||
|
||
.mx_FormattingButtons_Button_underline::before { | ||
mask-image: url('$(res)/img/element-icons/room/composer/underline.svg'); | ||
} | ||
|
||
.mx_FormattingButtons_Button_strikethrough::before { | ||
mask-image: url('$(res)/img/element-icons/room/composer/strikethrough.svg'); | ||
} | ||
} | ||
|
||
.mx_FormattingButtons_Tooltip { | ||
padding: 0 2px 0 2px; | ||
|
||
.mx_FormattingButtons_Tooltip_KeyboardShortcut { | ||
color: $tertiary-content; | ||
|
||
kbd { | ||
margin-top: 2px; | ||
text-align: center; | ||
display: inline-block; | ||
text-transform: capitalize; | ||
font-size: 12px; | ||
font-family: Inter, sans-serif; | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React, { forwardRef, memo } from 'react'; | ||
|
||
interface EditorProps { | ||
disabled: boolean; | ||
} | ||
|
||
export const Editor = memo( | ||
forwardRef<HTMLDivElement, EditorProps>( | ||
function Editor({ disabled }: EditorProps, ref, | ||
) { | ||
return <div className="mx_WysiwygComposer_container"> | ||
<div className="mx_WysiwygComposer_content" | ||
ref={ref!} | ||
contentEditable={!disabled} | ||
role="textbox" | ||
aria-multiline="true" | ||
aria-autocomplete="list" | ||
aria-haspopup="listbox" | ||
dir="auto" | ||
aria-disabled={disabled} | ||
/> | ||
</div>; | ||
}, | ||
), | ||
); |
69 changes: 69 additions & 0 deletions
69
src/components/views/rooms/wysiwyg_composer/FormattingButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React, { MouseEventHandler } from "react"; | ||
import { useWysiwyg } from "@matrix-org/matrix-wysiwyg"; | ||
import classNames from "classnames"; | ||
|
||
import AccessibleTooltipButton from "../../elements/AccessibleTooltipButton"; | ||
import { Alignment } from "../../elements/Tooltip"; | ||
import { KeyboardShortcut } from "../../settings/KeyboardShortcut"; | ||
import { KeyCombo } from "../../../../KeyBindingsManager"; | ||
import { _td } from "../../../../languageHandler"; | ||
|
||
interface TooltipProps { | ||
label: string; | ||
keyCombo?: KeyCombo; | ||
} | ||
|
||
function Tooltip({ label, keyCombo }: TooltipProps) { | ||
return <div className="mx_FormattingButtons_Tooltip"> | ||
{ label } | ||
{ keyCombo && <KeyboardShortcut value={keyCombo} className="mx_FormattingButtons_Tooltip_KeyboardShortcut" /> } | ||
</div>; | ||
} | ||
|
||
interface ButtonProps extends TooltipProps { | ||
className: string; | ||
isActive: boolean; | ||
onClick: MouseEventHandler<HTMLButtonElement>; | ||
} | ||
|
||
function Button({ label, keyCombo, onClick, isActive, className }: ButtonProps) { | ||
return <AccessibleTooltipButton | ||
element="button" | ||
onClick={onClick} | ||
title={label} | ||
className={ | ||
classNames('mx_FormattingButtons_Button', className, { 'mx_FormattingButtons_active': isActive })} | ||
tooltip={keyCombo && <Tooltip label={label} keyCombo={keyCombo} />} | ||
alignment={Alignment.Top} | ||
/>; | ||
} | ||
|
||
interface FormattingButtonsProps { | ||
composer: ReturnType<typeof useWysiwyg>['wysiwyg']; | ||
formattingStates: ReturnType<typeof useWysiwyg>['formattingStates']; | ||
} | ||
|
||
export function FormattingButtons({ composer, formattingStates }: FormattingButtonsProps) { | ||
return <div className="mx_FormattingButtons"> | ||
<Button isActive={formattingStates.bold === 'reversed'} label={_td("Bold")} keyCombo={{ ctrlOrCmdKey: true, key: 'b' }} onClick={() => composer.bold()} className="mx_FormattingButtons_Button_bold" /> | ||
<Button isActive={formattingStates.italic === 'reversed'} label={_td('Italic')} keyCombo={{ ctrlOrCmdKey: true, key: 'i' }} onClick={() => composer.italic()} className="mx_FormattingButtons_Button_italic" /> | ||
<Button isActive={formattingStates.underline === 'reversed'} label={_td('Underline')} keyCombo={{ ctrlOrCmdKey: true, key: 'u' }} onClick={() => composer.underline()} className="mx_FormattingButtons_Button_underline" /> | ||
<Button isActive={formattingStates.strikeThrough === 'reversed'} label={_td('Strikethrough')} onClick={() => composer.strikeThrough()} className="mx_FormattingButtons_Button_strikethrough" /> | ||
</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.