4
4
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
*/
6
6
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js' ;
7
+ import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js' ;
7
8
import { SlotController } from '@vaadin/component-base/src/slot-controller.js' ;
8
9
import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js' ;
9
10
11
+ const DEFAULT_I18N = {
12
+ send : 'Send' ,
13
+ message : 'Message' ,
14
+ } ;
15
+
10
16
/**
11
17
* @polymerMixin
12
18
* @mixes ControllerMixin
13
19
*/
14
20
export const MessageInputMixin = ( superClass ) =>
15
- class MessageInputMixinClass extends ControllerMixin ( superClass ) {
21
+ class MessageInputMixinClass extends I18nMixin ( DEFAULT_I18N , ControllerMixin ( superClass ) ) {
16
22
static get properties ( ) {
17
23
return {
18
24
/**
@@ -24,35 +30,6 @@ export const MessageInputMixin = (superClass) =>
24
30
sync : true ,
25
31
} ,
26
32
27
- /**
28
- * The object used to localize this component.
29
- * For changing the default localization, change the entire
30
- * `i18n` object.
31
- *
32
- * The object has the following JSON structure and default values:
33
- *
34
- * ```
35
- * {
36
- * // Used as the button label
37
- * send: 'Send',
38
- *
39
- * // Used as the input field's placeholder and aria-label
40
- * message: 'Message'
41
- * }
42
- * ```
43
- *
44
- * @type {!MessageInputI18n }
45
- * @default {English}
46
- */
47
- i18n : {
48
- type : Object ,
49
- sync : true ,
50
- value : ( ) => ( {
51
- send : 'Send' ,
52
- message : 'Message' ,
53
- } ) ,
54
- } ,
55
-
56
33
/**
57
34
* Set to true to disable this element.
58
35
* @type {boolean }
@@ -80,11 +57,36 @@ export const MessageInputMixin = (superClass) =>
80
57
81
58
static get observers ( ) {
82
59
return [
83
- '__buttonPropsChanged(_button, disabled, i18n )' ,
84
- '__textAreaPropsChanged(_textArea, disabled, i18n , value)' ,
60
+ '__buttonPropsChanged(_button, disabled, __effectiveI18n )' ,
61
+ '__textAreaPropsChanged(_textArea, disabled, __effectiveI18n , value)' ,
85
62
] ;
86
63
}
87
64
65
+ /**
66
+ * The object used to localize this component. To change the default
67
+ * localization, replace this with an object that provides all properties, or
68
+ * just the individual properties you want to change.
69
+ *
70
+ * The object has the following JSON structure and default values:
71
+ * ```
72
+ * {
73
+ * // Used as the button label
74
+ * send: 'Send',
75
+ *
76
+ * // Used as the input field's placeholder and aria-label
77
+ * message: 'Message'
78
+ * }
79
+ * ```
80
+ * @return {!MessageInputI18n }
81
+ */
82
+ get i18n ( ) {
83
+ return super . i18n ;
84
+ }
85
+
86
+ set i18n ( value ) {
87
+ super . i18n = value ;
88
+ }
89
+
88
90
/** @protected */
89
91
ready ( ) {
90
92
super . ready ( ) ;
@@ -134,20 +136,20 @@ export const MessageInputMixin = (superClass) =>
134
136
}
135
137
136
138
/** @private */
137
- __buttonPropsChanged ( button , disabled , i18n ) {
139
+ __buttonPropsChanged ( button , disabled , effectiveI18n ) {
138
140
if ( button ) {
139
141
button . disabled = disabled ;
140
- button . textContent = i18n . send ;
142
+ button . textContent = effectiveI18n . send ;
141
143
}
142
144
}
143
145
144
146
/** @private */
145
- __textAreaPropsChanged ( textArea , disabled , i18n , value ) {
147
+ __textAreaPropsChanged ( textArea , disabled , effectiveI18n , value ) {
146
148
if ( textArea ) {
147
149
textArea . disabled = disabled ;
148
150
textArea . value = value ;
149
151
150
- const message = i18n . message ;
152
+ const message = effectiveI18n . message ;
151
153
textArea . placeholder = message ;
152
154
textArea . accessibleName = message ;
153
155
}
0 commit comments