Skip to content

Commit

Permalink
fix: show active bg color in color palette
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Jan 29, 2022
1 parent c7df506 commit e2d4f43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions projects/ngx-editor/src/lib/commands/TextColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { applyMark, removeMark } from 'ngx-editor/commands';
import { Dispatch } from './types';

type Name = 'text_color' | 'text_background_color';
type AttrName = 'color' | 'backgroundColor';

interface ColorAttrs {
color: string;
Expand All @@ -19,9 +20,11 @@ interface BackgroundColorAttrs {

class TextColor {
name: Name;
attrName: AttrName;

constructor(name: Name) {
constructor(name: Name, attrName: AttrName = 'color') {
this.name = name;
this.attrName = attrName
}

apply(attrs: ColorAttrs | BackgroundColorAttrs): Command {
Expand Down Expand Up @@ -68,7 +71,9 @@ class TextColor {

const colors = marks
.filter(mark => mark.type === schema.marks[this.name])
.map(mark => mark.attrs['color'])
.map(mark => {
return mark.attrs[this.attrName]
})
.filter(Boolean);

return colors;
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-editor/src/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export const ALIGN_RIGHT = new TextAlign('right');
export const ALIGN_JUSTIFY = new TextAlign('justify');
export const LINK = new Link();
export const IMAGE = new Image();
export const TEXT_COLOR = new TextColor('text_color');
export const TEXT_BACKGROUND_COLOR = new TextColor('text_background_color');
export const TEXT_COLOR = new TextColor('text_color', 'color');
export const TEXT_BACKGROUND_COLOR = new TextColor('text_background_color', 'backgroundColor');

0 comments on commit e2d4f43

Please sign in to comment.