Skip to content

Commit 1c8b40e

Browse files
florrie-90ifox
andauthored
Add alignment buttons to TipTap editor (#2305)
* Add alignment buttons to TipTap editor * Add WYSIWYG alignment icons * Tiptap toolbar improvements: - Hide disabled unlink icon when not on a link - Improve icon labels - Improve opacity and cursor of disabled button --------- Co-authored-by: Quentin Renard <[email protected]>
1 parent a0955a1 commit 1c8b40e

20 files changed

+293
-114
lines changed

docs/content/1_docs/4_form-fields/02_wysiwyg.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ $wysiwygOptions = [
7878
'underline',
7979
'strike',
8080
'blockquote',
81-
"code-block",
81+
'code-block',
8282
'ordered',
8383
'bullet',
8484
'hr',
8585
'code',
8686
'link',
8787
'clean',
8888
'table',
89+
'align',
8990
];
9091
@endphp
9192
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading

frontend/js/components/WysiwygMenuBarButton.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
:class="`icon--wysiwyg_${icon}`"
1313
aria-hidden="true">
1414
<svg>
15-
<title>{{ icon }}</title>
15+
<title>{{ label ?? icon }}</title>
1616
<use :xlink:href="`#icon--wysiwyg_${icon}`"></use>
1717
</svg>
1818
</span>
@@ -58,7 +58,8 @@
5858

5959
<style lang="scss">
6060
.wysiwyg__menubar-button:disabled {
61-
opacity: 10%;
61+
opacity: 50%;
62+
cursor: unset !important;
6263
}
6364
6465
.icon--custom {

frontend/js/components/WysiwygTiptap.vue

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/>
6161

6262
<wysiwyg-menu-bar-btn icon="unlink"
63-
v-if="toolbar.link"
63+
v-if="toolbar.link && editor.isActive('link')"
6464
:disabled="!editor.isActive('link')"
6565
:isActive="editor.isActive('link')"
6666
@btn:click="removeLink()"/>
@@ -90,6 +90,27 @@
9090
:isActive="editor.isActive('code')"
9191
@btn:click="editor.chain().focus().setCode().run()"/>
9292

93+
<wysiwyg-menu-bar-btn icon="align_left"
94+
label="align left"
95+
v-if="toolbar.align || toolbar['align-left']"
96+
:isActive="editor.isActive({ textAlign: 'left' })"
97+
@btn:click="setTextAlign('left')"/>
98+
<wysiwyg-menu-bar-btn icon="align_center"
99+
label="align center"
100+
v-if="toolbar.align || toolbar['align-center']"
101+
:isActive="editor.isActive({ textAlign: 'center' })"
102+
@btn:click="setTextAlign('center')"/>
103+
<wysiwyg-menu-bar-btn icon="align_right"
104+
label="align right"
105+
v-if="toolbar.align || toolbar['align-right']"
106+
:isActive="editor.isActive({ textAlign: 'right' })"
107+
@btn:click="setTextAlign('right')"/>
108+
<wysiwyg-menu-bar-btn icon="align_justify"
109+
label="justify"
110+
v-if="toolbar.align || toolbar['align-justify']"
111+
:isActive="editor.isActive({ textAlign: 'justify' })"
112+
@btn:click="setTextAlign('justify')"/>
113+
93114
<wysiwyg-menu-bar-btn icon="table"
94115
v-if="toolbar.table"
95116
@btn:click="editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run()"/>
@@ -244,6 +265,7 @@
244265
import {Placeholder} from "@tiptap/extension-placeholder";
245266
import {HardBreak} from "@tiptap/extension-hard-break";
246267
import {HorizontalRule} from "@tiptap/extension-horizontal-rule";
268+
import {TextAlign} from '@tiptap/extension-text-align';
247269
248270
export default {
249271
name: 'A17Wysiwyg',
@@ -498,7 +520,14 @@
498520
499521
this.$refs['link-modal'].close()
500522
this.linkWindow = null
501-
}
523+
},
524+
setTextAlign(align) {
525+
this.editor
526+
.chain()
527+
.focus()
528+
.setTextAlign(align)
529+
.run();
530+
},
502531
},
503532
beforeMount () {
504533
if (this.toolbar.header) {
@@ -509,7 +538,10 @@
509538
510539
const content = this.value || ''
511540
const extensions = [
512-
HardBreak
541+
HardBreak,
542+
TextAlign.configure({
543+
types: ['heading','paragraph'],
544+
}),
513545
]
514546
515547
if (this.placeholder && this.placeholder.length > 0) {
@@ -633,7 +665,7 @@
633665
&--link {
634666
z-index: $zindex__modal__lower;
635667
}
636-
668+
637669
.input {
638670
margin-top: 35px !important;
639671
}

0 commit comments

Comments
 (0)