Skip to content

Commit

Permalink
feat(ui): add RTL support in description editor (#14057)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin-chaurasiya authored Nov 22, 2023
1 parent 5e6e1d4 commit e97559b
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 0 deletions.
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
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@
"row": "",
"row-count-lowercase": "行数",
"row-plural": "",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "ルール",
"rule-effect": "ルールの効果",
"rule-lowercase": "rule",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@
"row": "Строка",
"row-count-lowercase": "количество строк",
"row-plural": "Строки",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "Правило",
"rule-effect": "Действие правила",
"rule-lowercase": "правило",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@
"row": "",
"row-count-lowercase": "行计数",
"row-plural": "",
"rtl-ltr-direction": "RTL/LTR direction",
"rule": "规则",
"rule-effect": "规则生效",
"rule-lowercase": "规则",
Expand Down

0 comments on commit e97559b

Please sign in to comment.