-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
stylegridbuttonview.ts
83 lines (68 loc) · 1.98 KB
/
stylegridbuttonview.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module style/ui/stylegridbuttonview
*/
import type { Locale } from 'ckeditor5/src/utils.js';
import { ButtonView, View } from 'ckeditor5/src/ui.js';
import type { NormalizedStyleDefinition } from '../styleutils.js';
/**
* A class representing an individual button (style) in the grid. Renders a rich preview of the style.
*/
export default class StyleGridButtonView extends ButtonView {
/**
* Definition of the style the button will apply when executed.
*/
public readonly styleDefinition: NormalizedStyleDefinition;
/**
* The view rendering the preview of the style.
*/
public readonly previewView: View;
/**
* Creates an instance of the {@link module:style/ui/stylegridbuttonview~StyleGridButtonView} class.
*
* @param locale The localization services instance.
* @param styleDefinition Definition of the style.
*/
constructor( locale: Locale, styleDefinition: NormalizedStyleDefinition ) {
super( locale );
this.styleDefinition = styleDefinition;
this.previewView = this._createPreview();
this.set( {
label: styleDefinition.name,
class: 'ck-style-grid__button',
withText: true
} );
this.extendTemplate( {
attributes: {
role: 'option'
}
} );
this.children.add( this.previewView, 0 );
}
/**
* Creates the view representing the preview of the style.
*/
private _createPreview(): View {
const previewView = new View( this.locale );
previewView.setTemplate( {
tag: 'div',
attributes: {
class: [
'ck',
'ck-reset_all-excluded',
'ck-style-grid__button__preview',
'ck-content'
],
// The preview "AaBbCcDdEeFfGgHhIiJj" should not be read by screen readers because it is purely presentational.
'aria-hidden': 'true'
},
children: [
this.styleDefinition.previewTemplate
]
} );
return previewView;
}
}