7

I am trying to customize my PrimeNG Editor I'm having adding a select dropdown list with custom font sizes [12px, 14px, 16px...]

Here is the component HTML

<p-editor [(ngModel)]="value" (onTextChange)="onTextChanged($event)">
            <p-header>
                    <span class="ql-formats">
                     ...
                      <select class="ql-size">
                            <option value="12px">12</option>
                            <option value="14px">14</option>
                            <option value="16px">16</option>
                        </select>
                    </span>
                   ...
                  </p-header>               
    </p-editor>

I can get the select list to show with all the font sizes enter image description here

I'm not sure how to add the functionality to change the font size when selecting an option in the list. I don't see any examples in their docs for typescript. How can I make a select list of custom font sizes?

Here are the docs I followed

example

7
  • Can you provide a working stackblitz demo? Commented May 12, 2019 at 15:03
  • @ConnorsFan Sure thing! Commented May 12, 2019 at 19:36
  • Check how to do it on quill stackoverflow.com/questions/38623716/… Commented May 12, 2019 at 22:20
  • @ConnorsFan Updated! Commented May 13, 2019 at 2:09
  • 1
    @OrthoHomeDefense your code is fine, uncomment the "constructor" and import Quill as follow "declare const Quill: any;" github.com/angular/angular-cli/issues/… Commented May 13, 2019 at 11:35

2 Answers 2

5
+100

Firstly,put your component.ts

import { Editor } from 'primeng/editor';
declare var Quill: any;

and add this line in constructor

var fontSizeStyle = Quill.import('attributors/style/size');
fontSizeStyle.whitelist = ['24px', '48px', '100px', '200px'];
Quill.register(fontSizeStyle, true);

At the last,change your html

<span class="ql-formats">
   <select class="ql-size">
       <option value="24px">24</option>
       <option value="48px">48</option>
       <option value="100px">100</option>
       <option value="200px">200</option>
   </select>
</span>

Example

Sign up to request clarification or add additional context in comments.

Comments

0

First get the style/size whitelisted in the .ts:

constructor(){
    var fontSizeStyle = Quill.import('attributors/style/size');
    fontSizeStyle.whitelist = ['0.75em','1em','1.5em','2.5em', '24px', '48px', '100px', '200px'];
    Quill.register(fontSizeStyle, true);
}

Now in the html file we used this whitelisted options:

<span class="ql-formats">
   <select class="ql-size">
     <option value="0.75em">small</option>
     <option value="1em" selected></option>
     <option value="1.5em">large</option>
     <option value="2.5em">huge</option>
   </select>
 </span>
 <span class="ql-formats">
   <select class="ql-size">
      <option value="24px">24</option>
      <option value="48px">48</option>
      <option value="100px">100</option>
      <option value="200px">200</option>
    </select>
 </span>

Check the change of the value of the first dropdown options.

You can declare the var Quill so it doesn't have problems with the undefined variable: (this is how primeng does it too)

declare var Quill: any;

Working example here:

https://stackblitz.com/edit/quill-55477705?file=src/app/app.component.ts

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.