Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #12 from ckeditor/t/ckeditor5-theme-lark/148
Browse files Browse the repository at this point in the history
Internal: Removed the `.ck-highlight-button` and `.ck-highlight-dropdown` CSS classes. Used the `IconView#fillColor` API to control the colors of the icons (see ckeditor/ckeditor5-theme-lark#148).
  • Loading branch information
dkonopka authored Feb 22, 2018
2 parents d08c10a + 9ffd2ca commit b87b797
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 55 deletions.
38 changes: 4 additions & 34 deletions src/highlightui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import ToolbarSeparatorView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarsepa
import SplitButtonView from '@ckeditor/ckeditor5-ui/src/dropdown/button/splitbuttonview';
import { createDropdown, addToolbarToDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';

import './../theme/highlight.css';

/**
* The default Highlight UI plugin. It introduces:
* * the `'highlightDropdown'` drop-down,
Expand Down Expand Up @@ -125,13 +123,7 @@ export default class HighlightUI extends Plugin {
function decorateHighlightButton( button ) {
button.bind( 'isEnabled' ).to( command, 'isEnabled' );
button.bind( 'isOn' ).to( command, 'value', value => value === option.model );

button.extendTemplate( {
attributes: {
style: `color: ${ option.color }`,
class: 'ck-highlight-button'
}
} );
button.iconView.fillColor = option.color;
}
}

Expand Down Expand Up @@ -212,12 +204,6 @@ export default class HighlightUI extends Plugin {

splitButtonView.delegate( 'execute' ).to( dropdownView );

splitButtonView.extendTemplate( {
attributes: {
class: 'ck-highlight-button'
}
} );

// Create buttons array.
const buttons = options.map( option => {
// Get existing highlighter button.
Expand All @@ -237,14 +223,7 @@ export default class HighlightUI extends Plugin {
buttons.push( componentFactory.create( 'removeHighlight' ) );

addToolbarToDropdown( dropdownView, buttons );

bindIconStyleToColor( dropdownView );

dropdownView.extendTemplate( {
attributes: {
class: [ 'ck-highlight-dropdown' ]
}
} );
bindToolbarIconStyleToActiveColor( dropdownView );

// Execute current action from dropdown's split button action button.
splitButtonView.on( 'execute', () => {
Expand All @@ -268,19 +247,10 @@ export default class HighlightUI extends Plugin {
}

// Extends split button icon style to reflect last used button style.
function bindIconStyleToColor( dropdownView ) {
function bindToolbarIconStyleToActiveColor( dropdownView ) {
const actionView = dropdownView.buttonView.actionView;

const bind = actionView.bindTemplate;

// Color will propagate to iconView.
actionView.extendTemplate( {
attributes: {
style: bind.to( 'color', color => `color:${ color }` )
}
} );

actionView.bind( 'color' ).to( dropdownView.buttonView, 'color' );
actionView.iconView.bind( 'fillColor' ).to( dropdownView.buttonView, 'color' );
}

// Returns icon for given highlighter type.
Expand Down
30 changes: 18 additions & 12 deletions tests/highlightui.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ describe( 'HighlightUI', () => {
expect( button ).to.have.property( 'icon', markerIcon );
} );

it( 'should add custom CSS class to dropdown and dropdown buttons', () => {
dropdown.render();

expect( dropdown.element.classList.contains( 'ck-highlight-dropdown' ) ).to.be.true;
expect( dropdown.buttonView.element.classList.contains( 'ck-highlight-button' ) ).to.be.true;
// There should be 5 highlight buttons, one separator and highlight remove button in toolbar.
expect( dropdown.toolbarView.items.map( button => button.element.classList.contains( 'ck-highlight-button' ) ) )
.to.deep.equal( [ true, true, true, true, true, true, false, false ] );
} );

it( 'should have proper icons in dropdown', () => {
const toolbar = dropdown.toolbarView;

Expand All @@ -102,6 +92,21 @@ describe( 'HighlightUI', () => {
.to.deep.equal( [ markerIcon, markerIcon, markerIcon, markerIcon, penIcon, penIcon, undefined, eraserIcon ] );
} );

it( 'should have proper colors in dropdown', () => {
const toolbar = dropdown.toolbarView;

expect( toolbar.items.map( item => item.iconView && item.iconView.fillColor ) ).to.deep.equal( [
'#fdfd77',
'#63f963',
'#fc7999',
'#72cdfd',
'#e91313',
'#118800',
undefined,
'',
] );
} );

it( 'should activate current option in dropdown', () => {
const toolbar = dropdown.toolbarView;

Expand All @@ -115,7 +120,8 @@ describe( 'HighlightUI', () => {
command.value = 'greenMarker';

// The second item is 'greenMarker' highlighter.
expect( toolbar.items.map( item => item.isOn ) ).to.deep.equal( [ false, true, false, false, false, false, undefined, false ] );
expect( toolbar.items.map( item => item.isOn ) )
.to.deep.equal( [ false, true, false, false, false, false, undefined, false ] );
} );

describe( 'toolbar button behavior', () => {
Expand All @@ -129,7 +135,7 @@ describe( 'HighlightUI', () => {

function validateButton( which ) {
expect( button.icon ).to.equal( buttons[ which ].icon );
expect( button.actionView.color ).to.equal( options[ which ].color );
expect( button.actionView.iconView.fillColor ).to.equal( options[ which ].color );
}

it( 'should have properties of first defined highlighter', () => {
Expand Down
9 changes: 0 additions & 9 deletions theme/highlight.css

This file was deleted.

0 comments on commit b87b797

Please # to comment.