Skip to content

Commit 5eb8561

Browse files
marker-daomarker dao ®
andauthored
Chat File: Inherits DOMComponent (#31446)
Co-authored-by: marker dao ® <[email protected]>
1 parent 79248de commit 5eb8561

File tree

2 files changed

+87
-8
lines changed
  • packages/devextreme

2 files changed

+87
-8
lines changed

packages/devextreme/js/__internal/ui/chat/file_view/file.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ import type {
77
AttachmentDownloadEvent,
88
} from '@js/ui/chat';
99
import { getImageContainer } from '@ts/core/utils/m_icon';
10+
import type { DOMComponentProperties } from '@ts/core/widget/dom_component';
11+
import DOMComponent from '@ts/core/widget/dom_component';
1012
import type { OptionChanged } from '@ts/core/widget/types';
11-
import type { WidgetProperties } from '@ts/core/widget/widget';
12-
import Widget from '@ts/core/widget/widget';
1313
import type { ButtonProps as ButtonProperties } from '@ts/ui/button/button';
1414
import { getFileIconName } from '@ts/ui/file_uploader/file_uploader.utils';
1515

16-
export type Properties = WidgetProperties & {
16+
export type Properties = DOMComponentProperties<File> & {
17+
activeStateEnabled?: boolean;
18+
19+
focusStateEnabled?: boolean;
20+
21+
hoverStateEnabled?: boolean;
22+
1723
data: Attachment;
1824

1925
onDownload?: (e: AttachmentDownloadEvent) => void;
@@ -25,14 +31,17 @@ const CHAT_FILE_NAME_CLASS = 'dx-chat-file-name';
2531
const CHAT_FILE_SIZE_CLASS = 'dx-chat-file-size';
2632
const CHAT_FILE_DOWNLOAD_BUTTON_CLASS = 'dx-chat-file-download-button';
2733

28-
class File extends Widget<Properties> {
34+
class File extends DOMComponent<File, Properties> {
2935
private _downloadButton?: Button | null;
3036

3137
private _downloadAction?: (e: Partial<AttachmentDownloadEvent>) => void;
3238

3339
_getDefaultOptions(): Properties {
3440
return {
3541
...super._getDefaultOptions(),
42+
activeStateEnabled: true,
43+
focusStateEnabled: true,
44+
hoverStateEnabled: true,
3645
data: {
3746
name: '',
3847
size: 0,
@@ -119,9 +128,17 @@ class File extends Widget<Properties> {
119128
}
120129

121130
private _getButtonConfig(): ButtonProperties {
122-
const { data } = this.option();
131+
const {
132+
data,
133+
activeStateEnabled,
134+
focusStateEnabled,
135+
hoverStateEnabled,
136+
} = this.option();
123137

124138
const configuration = {
139+
activeStateEnabled,
140+
focusStateEnabled,
141+
hoverStateEnabled,
125142
icon: 'download',
126143
stylingMode: 'text' as const,
127144
onClick: (e: ClickEvent): void => {
@@ -138,9 +155,15 @@ class File extends Widget<Properties> {
138155
}
139156

140157
_optionChanged(args: OptionChanged<Properties>): void {
141-
const { name } = args;
158+
const { name, value } = args;
142159

143160
switch (name) {
161+
case 'activeStateEnabled':
162+
case 'focusStateEnabled':
163+
case 'hoverStateEnabled':
164+
this._downloadButton?.option(name, value);
165+
break;
166+
144167
case 'data':
145168
this._invalidate();
146169
break;
@@ -154,10 +177,15 @@ class File extends Widget<Properties> {
154177
}
155178
}
156179

157-
_dispose(): void {
180+
_clean(): void {
181+
this._cleanDownloadButton();
182+
this.$element().empty();
183+
super._clean();
184+
}
185+
186+
_cleanDownloadButton(): void {
158187
this._downloadButton?.dispose();
159188
this._downloadButton = null;
160-
super._dispose();
161189
}
162190
}
163191

packages/devextreme/testing/tests/DevExpress.ui.widgets/chatParts/file.tests.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,57 @@ QUnit.module('File', moduleConfig, () => {
193193
});
194194
});
195195

196+
QUnit.module('Proxy state options', () => {
197+
[true, false].forEach(value => {
198+
QUnit.test(`passed state options should be equal to download button state options when value is ${value}`, function(assert) {
199+
const options = {
200+
activeStateEnabled: value,
201+
focusStateEnabled: value,
202+
hoverStateEnabled: value,
203+
};
204+
205+
this.reinit({
206+
data: {
207+
name: 'test.txt',
208+
size: 1024,
209+
},
210+
...options,
211+
});
212+
213+
Object.entries(options).forEach(([key, value]) => {
214+
assert.strictEqual(this.downloadButton.option(key), value, `button ${key} value is correct`);
215+
});
216+
});
217+
218+
QUnit.test(`passed state options should be updated when state options are changed at runtime with value ${value}`, function(assert) {
219+
const options = {
220+
activeStateEnabled: value,
221+
focusStateEnabled: value,
222+
hoverStateEnabled: value,
223+
};
224+
225+
this.instance.option(options);
226+
227+
Object.entries(options).forEach(([key, value]) => {
228+
assert.strictEqual(this.downloadButton.option(key), value, `button ${key} value is correct`);
229+
});
230+
});
231+
});
232+
233+
QUnit.test('should have correct default state options', function(assert) {
234+
this.reinit({
235+
data: {
236+
name: 'test.txt',
237+
size: 1024,
238+
},
239+
});
240+
241+
[ 'activeStateEnabled', 'focusStateEnabled', 'hoverStateEnabled' ].forEach((option) => {
242+
assert.strictEqual(this.instance.option(option), true, `${option} is true by default`);
243+
});
244+
});
245+
});
246+
196247
QUnit.module('Dispose', () => {
197248
QUnit.test('should properly dispose download button', function(assert) {
198249
const buttonDisposeSpy = sinon.spy(this.downloadButton, 'dispose');

0 commit comments

Comments
 (0)