Skip to content

Commit 684218e

Browse files
authored
SpeechToText: add story and stop button animation (#31124)
1 parent de28d52 commit 684218e

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import React from 'react';
2+
import type { Meta, StoryObj } from '@storybook/react';
3+
import dxSpeechToText from 'devextreme/ui/speech_to_text';
4+
import { wrapDxWithReact } from '../utils';
5+
6+
7+
const SpeechToText = wrapDxWithReact(dxSpeechToText);
8+
9+
const meta: Meta<typeof SpeechToText> = {
10+
title: 'Components/SpeechToText',
11+
component: SpeechToText,
12+
};
13+
14+
export default meta;
15+
16+
type Story = StoryObj<typeof SpeechToText>;
17+
18+
export const DefaultSpeechToText: Story = {
19+
args: {
20+
width: 'auto',
21+
startIcon: 'micoutline',
22+
stopIcon: 'stopfilled',
23+
startText: '',
24+
stopText: '',
25+
stylingMode: 'contained',
26+
type: 'normal',
27+
visible: true,
28+
rtlEnabled: false,
29+
disabled: false,
30+
},
31+
argTypes: {
32+
width: {
33+
options: ['auto', '100%'],
34+
control: { type: 'radio' }
35+
},
36+
startIcon: {
37+
options: ['micoutline', 'video', 'isnotblank', undefined],
38+
control: { type: 'select' }
39+
},
40+
stopIcon: {
41+
options: ['stopfilled', 'square', 'indeterminatestate', undefined],
42+
control: { type: 'select' }
43+
},
44+
startText: {
45+
options: ['', 'start'],
46+
control: { type: 'select' }
47+
},
48+
stopText: {
49+
options: ['', 'stop'],
50+
control: { type: 'select' }
51+
},
52+
stylingMode: {
53+
options: ['contained', 'text', 'outlined'],
54+
control: { type: 'select' }
55+
},
56+
type: {
57+
options: ['normal', 'default', 'success', 'danger'],
58+
control: { type: 'select' }
59+
},
60+
visible: {
61+
control: 'boolean'
62+
},
63+
rtlEnabled: {
64+
control: 'boolean'
65+
},
66+
disabled: {
67+
control: 'boolean'
68+
},
69+
},
70+
render: ({
71+
width,
72+
startIcon,
73+
stopIcon,
74+
startText,
75+
stopText,
76+
stylingMode,
77+
type,
78+
visible,
79+
rtlEnabled,
80+
disabled,
81+
}) => {
82+
return (
83+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
84+
<SpeechToText
85+
width={width}
86+
startIcon={startIcon}
87+
stopIcon={stopIcon}
88+
startText={startText}
89+
stopText={stopText}
90+
stylingMode={stylingMode}
91+
type={type}
92+
disabled={disabled}
93+
rtlEnabled={rtlEnabled}
94+
visible={visible}
95+
/>
96+
</div>
97+
);
98+
}
99+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.dx-speech-to-text-listening {
2+
animation: dx-speech-to-text-listening-animation 1.5s ease-in-out 0.5s infinite;
3+
}
4+
5+
@keyframes dx-speech-to-text-listening-animation {
6+
0% {
7+
opacity: 1;
8+
}
9+
10+
50% {
11+
opacity: 0.4;
12+
}
13+
14+
100% {
15+
opacity: 1;
16+
}
17+
}

packages/devextreme/testing/tests/DevExpress.ui.widgets/speechToText.tests.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ QUnit.module('State Management', moduleConfig, () => {
186186

187187
assert.ok(this.$element.hasClass(SPEECH_TO_TEXT_LISTENING_CLASS), 'custom engine works after enabling');
188188
});
189+
190+
QUnit.test('INITIAL state should not have animation by default', function(assert) {
191+
const animation = this.$element.css('animation');
192+
193+
assert.strictEqual(animation, 'none 0s ease 0s 1 normal none running');
194+
});
195+
196+
QUnit.test('LISTENING state should have animation by default', function(assert) {
197+
const $button = this.getButton();
198+
199+
$button.trigger('dxclick');
200+
201+
const animation = this.$element.css('animation');
202+
const easeInOutAnimationEnabled = animation.includes('1.5s ease-in-out 0.5s infinite normal none running');
203+
204+
assert.strictEqual(easeInOutAnimationEnabled, true);
205+
});
189206
});
190207

191208
QUnit.module('Events', moduleConfig, () => {

0 commit comments

Comments
 (0)