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 #407 from ckeditor/t/ckeditor5-table/24
Browse files Browse the repository at this point in the history
Feature: Implemented list component separators (see ckeditor/ckeditor5-table#24).
  • Loading branch information
jodator authored Jun 13, 2018
2 parents a2ef073 + 48fdfe2 commit 0808a8c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/dropdown/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import DropdownButtonView from './button/dropdownbuttonview';
import ToolbarView from '../toolbar/toolbarview';
import ListView from '../list/listview';
import ListItemView from '../list/listitemview';
import ListSeparatorView from '../list/listseparatorview';

import clickOutsideHandler from '../bindings/clickoutsidehandler';

Expand Down Expand Up @@ -173,10 +174,16 @@ export function addListToDropdown( dropdownView, items ) {
const listView = dropdownView.listView = new ListView( locale );

listView.items.bindTo( items ).using( itemModel => {
const item = new ListItemView( locale );
let item;

// Bind all attributes of the model to the item view.
item.bind( ...Object.keys( itemModel ) ).to( itemModel );
if ( itemModel.isSeparator ) {
item = new ListSeparatorView( locale );
} else {
item = new ListItemView( locale );

// Bind all attributes of the model to the item view.
item.bind( ...Object.keys( itemModel ) ).to( itemModel );
}

return item;
} );
Expand Down
34 changes: 34 additions & 0 deletions src/list/listseparatorview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/**
* @module ui/list/listseparatorview
*/

import View from '../view';

/**
* The list separator view class.
*
* @extends module:ui/view~View
*/
export default class ListSeparatorView extends View {
/**
* @inheritDoc
*/
constructor( locale ) {
super( locale );

this.setTemplate( {
tag: 'li',
attributes: {
class: [
'ck',
'ck-list__separator'
]
}
} );
}
}
9 changes: 9 additions & 0 deletions tests/dropdown/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import View from '../../src/view';
import ToolbarView from '../../src/toolbar/toolbarview';
import { createDropdown, addToolbarToDropdown, addListToDropdown } from '../../src/dropdown/utils';
import ListItemView from '../../src/list/listitemview';
import ListSeparatorView from '../../src/list/listseparatorview';
import ListView from '../../src/list/listview';

const assertBinding = utilsTestUtils.assertBinding;
Expand Down Expand Up @@ -349,6 +350,14 @@ describe( 'utils', () => {

dropdownView.listView.items.get( 0 ).fire( 'execute' );
} );

it( 'is filled with separators', () => {
const itemModel = new Model( { isSeparator: true } );

items.add( itemModel );

expect( dropdownView.listView.items.get( 0 ) ).to.be.instanceOf( ListSeparatorView );
} );
} );
} );
} );
24 changes: 24 additions & 0 deletions tests/list/listseparatorview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

import ListSeparatorView from '../../src/list/listseparatorview';

describe( 'ListSeparatorView', () => {
let view;

beforeEach( () => {
view = new ListSeparatorView();

view.render();
} );

describe( 'template', () => {
it( 'should create element from template', () => {
expect( view.element.tagName ).to.equal( 'LI' );
expect( view.element.classList.contains( 'ck' ) ).to.true;
expect( view.element.classList.contains( 'ck-list__separator' ) ).to.true;
} );
} );
} );
11 changes: 6 additions & 5 deletions theme/components/list/list.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
/* Crop the the items when the list has huge border-radius. */
overflow: hidden;

& .ck-list__item {
& .ck-list__item,
& .ck-list__separator {
display: block;
}

&:focus {
position: relative;
z-index: var(--ck-z-default);
}
& .ck-list__item:focus {
position: relative;
z-index: var(--ck-z-default);
}
}

0 comments on commit 0808a8c

Please # to comment.