Skip to content

fix: support for predefined colors to color picker #327

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions projects/angular-editor-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AngularEditorConfig } from './../../../angular-editor/src/lib/config';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep import.

import {Component, OnInit} from '@angular/core';
import {AngularEditorConfig} from 'angular-editor';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';

@Component({
Expand Down Expand Up @@ -47,7 +47,8 @@ export class AppComponent implements OnInit {
toolbarHiddenButtons: [
['bold', 'italic'],
['fontSize']
]
],
defaultPickerColors: []
};

config2: AngularEditorConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,33 @@
</ae-select>
</div>
<div class="angular-editor-toolbar-set">
<input
style="display: none"
<div style="position: relative; display: inline-block;" [hidden]="isButtonHidden('textColor')">
<input
[attr.list]="defaultPickerColors ? 'picker-colors-textColor': null"
type="color" (change)="insertColor(fgInput.value, 'textColor')"
class="color-picker"
#fgInput>
<button [id]="'foregroundColorPicker-'+id" type="button" class="angular-editor-button" (click)="focus(); ; fgInput.click()"
title="Text Color"
[disabled]="htmlMode" [hidden]="isButtonHidden('textColor')" tabindex="-1"><span
class="color-label foreground"><i class="fa fa-font"></i></span>
</button>
<input
style="display: none"
<ng-container *ngTemplateOutlet="predefinedColorPickers; context:{type: 'textColor'}"></ng-container>
<button [id]="'foregroundColorPicker-'+id" type="button" class="angular-editor-button" (click)="focus(); ; fgInput.click()"
title="Text Color"
[disabled]="htmlMode" [hidden]="isButtonHidden('textColor')" tabindex="-1"><span
class="color-label foreground"><i class="fa fa-font"></i></span>
</button>
</div>

<div style="position: relative; display: inline-block;" [hidden]="isButtonHidden('backgroundColor')">
<input
[attr.list]="defaultPickerColors ? 'picker-colors-backgroundColor': null"
type="color" (change)="insertColor(bgInput.value, 'backgroundColor')"
class="color-picker"
#bgInput>
<button [id]="'backgroundColorPicker-'+id" type="button" class="angular-editor-button" (click)="focus(); ; bgInput.click()"
title="Background Color"
[disabled]="htmlMode" [hidden]="isButtonHidden('backgroundColor')" tabindex="-1"><span
class="color-label background"><i class="fa fa-font"></i></span>
</button>
<ng-container *ngTemplateOutlet="predefinedColorPickers; context:{type: 'backgroundColor'}"></ng-container>
<button [id]="'backgroundColorPicker-'+id" type="button" class="angular-editor-button" (click)="focus(); ; bgInput.click()"
title="Background Color"
[disabled]="htmlMode" [hidden]="isButtonHidden('backgroundColor')" tabindex="-1"><span
class="color-label background"><i class="fa fa-font"></i></span>
</button>
</div>
</div>
<div *ngIf="_customClasses" class="angular-editor-toolbar-set">
<ae-select class="select-custom-style" [options]="customClassList"
Expand Down Expand Up @@ -160,3 +169,9 @@
class='fa fa-code'></i></button>
</div>
</div>

<ng-template #predefinedColorPickers let-type="type">
<datalist id="{{'picker-colors-' + type}}">
<option *ngFor="let pColor of defaultPickerColors" [value]="pColor">{{pColor}}</option>
</datalist>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@
transition: 0.2s ease;
}
}

.color-picker {
opacity: 0;
visibility: hidden;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 85%;
margin: 0;
padding: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export class AngularEditorToolbarComponent {
return this.htmlMode || !Boolean(this.editorService.selectedText);
}

@Input() defaultPickerColors: string[] = [];

constructor(
private r: Renderer2,
private editorService: AngularEditorService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[customClasses]="config.customClasses"
[defaultFontName]="config.defaultFontName"
[defaultFontSize]="config.defaultFontSize"
[defaultPickerColors]="config.defaultPickerColors"
[hiddenButtons]="config.toolbarHiddenButtons"
(execute)="executeCommand($event)"
></angular-editor-toolbar>
Expand Down
1 change: 1 addition & 0 deletions projects/angular-editor/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface AngularEditorConfig {
toolbarPosition?: 'top' | 'bottom';
outline?: boolean;
toolbarHiddenButtons?: string[][];
defaultPickerColors?: string[];
}

export const angularEditorConfig: AngularEditorConfig = {
Expand Down