Skip to content

Commit e2e65dc

Browse files
committed
adds extra control
1 parent 68af9ce commit e2e65dc

File tree

8 files changed

+98
-15
lines changed

8 files changed

+98
-15
lines changed

dist/react-simple-chatbot.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-simple-chatbot.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ChatBot.jsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ class ChatBot extends Component {
7272
const chatSteps = {};
7373

7474
const defaultBotSettings = { delay: botDelay, avatar: botAvatar };
75-
const defaultUserSettings = { delay: userDelay, avatar: userAvatar, hideInput: false };
75+
const defaultUserSettings = {
76+
delay: userDelay,
77+
avatar: userAvatar,
78+
hideInput: false,
79+
hideExtraControl: false
80+
};
7681
const defaultCustomSettings = { delay: customDelay };
7782

7883
for (let i = 0, len = steps.length; i < len; i += 1) {
@@ -246,6 +251,9 @@ class ChatBot extends Component {
246251
if (data && data.hideInput) {
247252
currentStep.hideInput = data.hideInput;
248253
}
254+
if (data && data.hideExtraControl) {
255+
currentStep.hideExtraControl = data.hideExtraControl;
256+
}
249257
if (data && data.trigger) {
250258
currentStep.trigger = this.getTriggeredStep(data.trigger, data.value);
251259
}
@@ -593,6 +601,7 @@ class ChatBot extends Component {
593601
const {
594602
className,
595603
contentStyle,
604+
extraControl,
596605
floating,
597606
floatingIcon,
598607
floatingStyle,
@@ -681,18 +690,21 @@ class ChatBot extends Component {
681690
{...inputAttributesOverride}
682691
/>
683692
)}
684-
{!currentStep.hideInput && !hideSubmitButton && (
685-
<SubmitButton
686-
className="rsc-submit-button"
687-
style={submitButtonStyle}
688-
onClick={this.handleSubmitButton}
689-
invalid={inputInvalid}
690-
disabled={disabled}
691-
speaking={speaking}
692-
>
693-
{icon}
694-
</SubmitButton>
695-
)}
693+
<div className="rsc-controls">
694+
{!currentStep.hideInput && !currentStep.hideExtraControl && extraControl}
695+
{!currentStep.hideInput && !hideSubmitButton && (
696+
<SubmitButton
697+
className="rsc-submit-button"
698+
style={submitButtonStyle}
699+
onClick={this.handleSubmitButton}
700+
invalid={inputInvalid}
701+
disabled={disabled}
702+
speaking={speaking}
703+
>
704+
{icon}
705+
</SubmitButton>
706+
)}
707+
</div>
696708
</Footer>
697709
</ChatBotContainer>
698710
</div>
@@ -714,6 +726,7 @@ ChatBot.propTypes = {
714726
customStyle: PropTypes.objectOf(PropTypes.any),
715727
enableMobileAutoFocus: PropTypes.bool,
716728
enableSmoothScroll: PropTypes.bool,
729+
extraControl: PropTypes.objectOf(PropTypes.element),
717730
floating: PropTypes.bool,
718731
floatingIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
719732
floatingStyle: PropTypes.objectOf(PropTypes.any),
@@ -763,6 +776,7 @@ ChatBot.defaultProps = {
763776
customDelay: 1000,
764777
enableMobileAutoFocus: false,
765778
enableSmoothScroll: false,
779+
extraControl: undefined,
766780
floating: false,
767781
floatingIcon: <ChatIcon />,
768782
floatingStyle: {},

lib/schemas/customSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export default [
5454
types: ['boolean'],
5555
required: false
5656
},
57+
{
58+
key: 'hideExtraControl',
59+
types: ['boolean'],
60+
required: false
61+
},
5762
{
5863
key: 'inputAttributes',
5964
types: ['object'],

lib/schemas/optionsSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export default [
2424
types: ['boolean'],
2525
required: false
2626
},
27+
{
28+
key: 'hideExtraControl',
29+
types: ['boolean'],
30+
required: false
31+
},
2732
{
2833
key: 'inputAttributes',
2934
types: ['object'],

lib/schemas/textSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export default [
3939
types: ['boolean'],
4040
required: false
4141
},
42+
{
43+
key: 'hideExtraControl',
44+
types: ['boolean'],
45+
required: false
46+
},
4247
{
4348
key: 'inputAttributes',
4449
types: ['object'],

lib/schemas/userSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export default [
99
types: ['boolean'],
1010
required: true
1111
},
12+
{
13+
key: 'hideExtraControl',
14+
types: ['boolean'],
15+
required: false
16+
},
1217
{
1318
key: 'trigger',
1419
types: ['string', 'number', 'function'],

tests/lib/ChatBot.spec.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,53 @@ describe('ChatBot', () => {
371371
expect(wrapper.find('input.rsc-input').props().autoComplete).to.be.equal('firstname');
372372
});
373373
});
374+
375+
describe('Extra control', () => {
376+
const CustomControl = () => (
377+
<button className="my-button">custom</button>
378+
);
379+
const wrapper = mount(
380+
<ChatBot
381+
botDelay={10}
382+
userDelay={10}
383+
customDelay={10}
384+
extraControl={<CustomControl />}
385+
steps={[
386+
{
387+
id: '1',
388+
user: true,
389+
hideExtraControl: false,
390+
trigger: '2'
391+
},
392+
{
393+
id: '2',
394+
user: true,
395+
hideExtraControl: true,
396+
trigger: '3'
397+
},
398+
{
399+
id: '3',
400+
message: 'end',
401+
end: true
402+
}
403+
]}
404+
/>,
405+
);
406+
407+
it('should be rendered with an extra control beside submit button', () => {
408+
expect(wrapper.find('div.rsc-controls button.my-button')).to.have.length(1);
409+
});
410+
411+
it('the extra control should be hidden', () => {
412+
console.log("Setting input value");
413+
wrapper.setState({ inputValue: 'test' });
414+
console.log("Simulate key press");
415+
wrapper.find('input.rsc-input').simulate('keyPress', { key: 'Enter' });
416+
setTimeout(() => {
417+
console.log("testing hidden");
418+
expect(wrapper.find('div.rsc-controls button.my-button')).to.have.length(0);
419+
}, 500);
420+
});
421+
422+
});
374423
});

0 commit comments

Comments
 (0)