Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): add RTL support in description editor #14057

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
* limitations under the License.
*/

import LTRIcon from '../../../assets/svg/ic-ltr.svg';
import RTLIcon from '../../../assets/svg/ic-rtl.svg';
import MarkdownIcon from '../../../assets/svg/markdown.svg';
import i18n from '../../../utils/i18next/LocalUtil';

@@ -41,6 +43,55 @@ const markdownButton = (): HTMLButtonElement => {
return button;
};

const getRTLButtonIcon = (mode: 'rtl' | 'ltr') => `
<img
alt="rtl-icon"
class="svg-icon"
height="24px"
width="24px"
src="${mode === 'rtl' ? RTLIcon : LTRIcon}" />`;

const toggleEditorDirection = (button: HTMLButtonElement) => {
const editorElement = document.querySelector(
'.toastui-editor.md-mode.active'
);

if (editorElement) {
const editorElementDir = editorElement.getAttribute('dir');
const newDir = editorElementDir === 'rtl' ? 'ltr' : 'rtl';
const textAlign = newDir === 'rtl' ? 'right' : 'left';

editorElement.setAttribute('dir', newDir);
editorElement.setAttribute('style', `text-align: ${textAlign};`);
button.innerHTML = getRTLButtonIcon(newDir === 'rtl' ? 'ltr' : 'rtl');
}
};

const rtlButton = (): HTMLButtonElement => {
const button = document.createElement('button');

button.onclick = () => toggleEditorDirection(button);

button.className = 'toastui-editor-toolbar-icons rtl-icon';
button.id = 'rtl-button';
button.style.cssText = 'background-image: none; margin: 0; margin-top: 4px;';
button.type = 'button';
button.innerHTML = getRTLButtonIcon('rtl');

return button;
};

const rtlButtonUpdateHandler = (toolbarState: {
active: boolean;
disabled?: boolean;
}) => {
const rtlButtonElement = document.getElementById('rtl-button');
if (rtlButtonElement) {
(rtlButtonElement as HTMLButtonElement).disabled =
toolbarState.disabled || false;
}
};

export const EDITOR_TOOLBAR_ITEMS = [
'heading',
'bold',
@@ -53,6 +104,12 @@ export const EDITOR_TOOLBAR_ITEMS = [
'quote',
'code',
'codeblock',
{
name: i18n.t('label.rtl-ltr-direction'),
el: rtlButton(),
tooltip: i18n.t('label.rtl-ltr-direction'),
onUpdated: rtlButtonUpdateHandler,
},
{
name: i18n.t('label.markdown-guide'),
el: markdownButton(),
Original file line number Diff line number Diff line change
@@ -855,6 +855,7 @@
"row": "Zeile",
"row-count-lowercase": "Anzahl der Zeilen",
"row-plural": "Zeilen",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "Regel",
"rule-effect": "Regelwirkung",
"rule-lowercase": "regel",
Original file line number Diff line number Diff line change
@@ -855,6 +855,7 @@
"row": "Row",
"row-count-lowercase": "row count",
"row-plural": "Rows",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "Rule",
"rule-effect": "Rule Effect",
"rule-lowercase": "rule",
Original file line number Diff line number Diff line change
@@ -855,6 +855,7 @@
"row": "Fila",
"row-count-lowercase": "número de filas",
"row-plural": "Filas",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "Regla",
"rule-effect": "Efecto de la Regla",
"rule-lowercase": "rule",
Original file line number Diff line number Diff line change
@@ -855,6 +855,7 @@
"row": "Ligne",
"row-count-lowercase": "Nombre de Ligne",
"row-plural": "Lignes",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "Règle",
"rule-effect": "Effet de la Règle",
"rule-lowercase": "règle",
Original file line number Diff line number Diff line change
@@ -855,6 +855,7 @@
"row": "",
"row-count-lowercase": "行数",
"row-plural": "",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "ルール",
"rule-effect": "ルールの効果",
"rule-lowercase": "rule",
Original file line number Diff line number Diff line change
@@ -855,6 +855,7 @@
"row": "Linha",
"row-count-lowercase": "contagem de linhas",
"row-plural": "Linhas",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "Regra",
"rule-effect": "Efeito da regra",
"rule-lowercase": "rule",
Original file line number Diff line number Diff line change
@@ -855,6 +855,7 @@
"row": "Строка",
"row-count-lowercase": "количество строк",
"row-plural": "Строки",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "Правило",
"rule-effect": "Действие правила",
"rule-lowercase": "правило",
Original file line number Diff line number Diff line change
@@ -855,6 +855,7 @@
"row": "",
"row-count-lowercase": "行计数",
"row-plural": "",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "规则",
"rule-effect": "规则生效",
"rule-lowercase": "规则",