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

Commit 0808a8c

Browse files
authored
Merge pull request #407 from ckeditor/t/ckeditor5-table/24
Feature: Implemented list component separators (see ckeditor/ckeditor5-table#24).
2 parents a2ef073 + 48fdfe2 commit 0808a8c

File tree

5 files changed

+83
-8
lines changed

5 files changed

+83
-8
lines changed

src/dropdown/utils.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import DropdownButtonView from './button/dropdownbuttonview';
1313
import ToolbarView from '../toolbar/toolbarview';
1414
import ListView from '../list/listview';
1515
import ListItemView from '../list/listitemview';
16+
import ListSeparatorView from '../list/listseparatorview';
1617

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

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

175176
listView.items.bindTo( items ).using( itemModel => {
176-
const item = new ListItemView( locale );
177+
let item;
177178

178-
// Bind all attributes of the model to the item view.
179-
item.bind( ...Object.keys( itemModel ) ).to( itemModel );
179+
if ( itemModel.isSeparator ) {
180+
item = new ListSeparatorView( locale );
181+
} else {
182+
item = new ListItemView( locale );
183+
184+
// Bind all attributes of the model to the item view.
185+
item.bind( ...Object.keys( itemModel ) ).to( itemModel );
186+
}
180187

181188
return item;
182189
} );

src/list/listseparatorview.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/**
7+
* @module ui/list/listseparatorview
8+
*/
9+
10+
import View from '../view';
11+
12+
/**
13+
* The list separator view class.
14+
*
15+
* @extends module:ui/view~View
16+
*/
17+
export default class ListSeparatorView extends View {
18+
/**
19+
* @inheritDoc
20+
*/
21+
constructor( locale ) {
22+
super( locale );
23+
24+
this.setTemplate( {
25+
tag: 'li',
26+
attributes: {
27+
class: [
28+
'ck',
29+
'ck-list__separator'
30+
]
31+
}
32+
} );
33+
}
34+
}

tests/dropdown/utils.js

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import View from '../../src/view';
1919
import ToolbarView from '../../src/toolbar/toolbarview';
2020
import { createDropdown, addToolbarToDropdown, addListToDropdown } from '../../src/dropdown/utils';
2121
import ListItemView from '../../src/list/listitemview';
22+
import ListSeparatorView from '../../src/list/listseparatorview';
2223
import ListView from '../../src/list/listview';
2324

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

350351
dropdownView.listView.items.get( 0 ).fire( 'execute' );
351352
} );
353+
354+
it( 'is filled with separators', () => {
355+
const itemModel = new Model( { isSeparator: true } );
356+
357+
items.add( itemModel );
358+
359+
expect( dropdownView.listView.items.get( 0 ) ).to.be.instanceOf( ListSeparatorView );
360+
} );
352361
} );
353362
} );
354363
} );

tests/list/listseparatorview.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
import ListSeparatorView from '../../src/list/listseparatorview';
7+
8+
describe( 'ListSeparatorView', () => {
9+
let view;
10+
11+
beforeEach( () => {
12+
view = new ListSeparatorView();
13+
14+
view.render();
15+
} );
16+
17+
describe( 'template', () => {
18+
it( 'should create element from template', () => {
19+
expect( view.element.tagName ).to.equal( 'LI' );
20+
expect( view.element.classList.contains( 'ck' ) ).to.true;
21+
expect( view.element.classList.contains( 'ck-list__separator' ) ).to.true;
22+
} );
23+
} );
24+
} );

theme/components/list/list.css

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
/* Crop the the items when the list has huge border-radius. */
1212
overflow: hidden;
1313

14-
& .ck-list__item {
14+
& .ck-list__item,
15+
& .ck-list__separator {
1516
display: block;
17+
}
1618

17-
&:focus {
18-
position: relative;
19-
z-index: var(--ck-z-default);
20-
}
19+
& .ck-list__item:focus {
20+
position: relative;
21+
z-index: var(--ck-z-default);
2122
}
2223
}

0 commit comments

Comments
 (0)