striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

commit 81d220bc5297264ae3d407a42977782794bffa9d
parent 23f7071c6d9daf51c9dd02d62a58e2097951b34e
Author: unitehenry <unitehenry@gmail.com>
Date:   Tue, 12 Nov 2019 09:04:56 -0500

toolbar custom option with img

Diffstat:
Mdemo/src/App.vue | 6+-----
Msrc/striveneditor.css | 13++++++++++---
Msrc/striveneditor.js | 11++++++++---
3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/demo/src/App.vue b/demo/src/App.vue @@ -42,11 +42,7 @@ export default { }, toolbarOptions: [ { - icon: { - viewBox: "0 0 1792 1792", - d: - "M1600 736v192q0 40-28 68t-68 28h-416v416q0 40-28 68t-68 28h-192q-40 0-68-28t-28-68v-416h-416q-40 0-68-28t-28-68v-192q0-40 28-68t68-28h416v-416q0-40 28-68t68-28h192q40 0 68 28t28 68v416h416q40 0 68 28t28 68z" - }, + icon: 'https://innovate.test.striven.com/Images/striven-icon.svg', handler: () => { const range = this.editor.range; if(range && range.startContainer !== document) { diff --git a/src/striveneditor.css b/src/striveneditor.css @@ -79,16 +79,22 @@ .striven-editor .se-toolbar-option { border: 1px solid transparent; display: inline-block; - padding: 8px; + padding: 7px; cursor: pointer; user-select: none; } -.striven-editor .se-toolbar.option svg { +.striven-editor .se-toolbar-option svg { width: 16px; height: 14px; } +.striven-editor .se-toolbar-option img { + width: 16px; + height: 14px; + vertical-align: middle; +} + .striven-editor .se-toolbar-option.se-toolbar-option-active { border: 1px solid rgba(0, 0, 0, .25); background-color: #d4e7fc; @@ -100,7 +106,7 @@ .striven-editor .se-toolbar-group { z-index: 1500; - background-color: #fff; + background-color: transparent; display: inline-block; } @@ -126,6 +132,7 @@ .striven-editor .se-toolbar-option:focus, .striven-editor .se-toolbar-option:active { background-color: #eee; + border-color: transparent; } .striven-editor .se-toolbar #toolbar-template { diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -311,13 +311,18 @@ export default class StrivenEditor { this.customOptionsGroup.appendChild(option); } else { - const option = document.createElement('img'); - option.setAttribute('src', opt.icon); - option.setAttribute('alt', 'custom option'); + const option = document.createElement('span'); + const image = document.createElement('img'); + image.setAttribute('src', opt.icon); + image.setAttribute('alt', 'custom option'); + + option.style.paddingTop = '6px'; + option.style.paddingBottom = '8px'; option.classList.add('se-toolbar-option'); option.onclick = () => handler(); + option.append(image); this.customOptionsGroup.appendChild(option); }