Skip to content

Commit 78554d1

Browse files
Merge pull request LucasBassetti#114 from gamedevsam/master
Hide input option, customize height plus fix for styled-components
2 parents e86e41e + dfa94ae commit 78554d1

File tree

12 files changed

+136
-81
lines changed

12 files changed

+136
-81
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

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.

lib/ChatBot.jsx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ class ChatBot extends Component {
214214
if (data && data.value) {
215215
currentStep.value = data.value;
216216
}
217+
if (data && data.hideInput) {
218+
currentStep.hideInput = data.hideInput;
219+
}
217220
if (data && data.trigger) {
218221
currentStep.trigger = this.getTriggeredStep(data.trigger, data.value);
219222
}
@@ -509,6 +512,7 @@ class ChatBot extends Component {
509512
inputInvalid,
510513
inputValue,
511514
opened,
515+
currentStep,
512516
renderedSteps,
513517
speaking,
514518
recognitionEnable,
@@ -528,6 +532,7 @@ class ChatBot extends Component {
528532
style,
529533
submitButtonStyle,
530534
width,
535+
height,
531536
} = this.props;
532537

533538
const header = headerComponent || (
@@ -564,32 +569,37 @@ class ChatBot extends Component {
564569
opened={opened}
565570
style={style}
566571
width={width}
572+
height={height}
567573
>
568574
{!hideHeader && header}
569575
<Content
570576
className="rsc-content"
571577
innerRef={contentRef => (this.content = contentRef)}
572578
floating={floating}
573579
style={contentStyle}
580+
height={height}
581+
hideInput={currentStep.hideInput}
574582
>
575583
{_.map(renderedSteps, this.renderStep)}
576584
</Content>
577585
<Footer className="rsc-footer" style={footerStyle}>
578-
<Input
579-
type="textarea"
580-
style={inputStyle}
581-
innerRef={inputRef => (this.input = inputRef)}
582-
className="rsc-input"
583-
placeholder={inputInvalid ? '' : inputPlaceholder}
584-
onKeyPress={this.handleKeyPress}
585-
onChange={this.onValueChange}
586-
value={inputValue}
587-
floating={floating}
588-
invalid={inputInvalid}
589-
disabled={disabled}
590-
hasButton={!hideSubmitButton}
591-
/>
592-
{!hideSubmitButton && (
586+
{!currentStep.hideInput && (
587+
<Input
588+
type="textarea"
589+
style={inputStyle}
590+
innerRef={inputRef => (this.input = inputRef)}
591+
className="rsc-input"
592+
placeholder={inputInvalid ? '' : inputPlaceholder}
593+
onKeyPress={this.handleKeyPress}
594+
onChange={this.onValueChange}
595+
value={inputValue}
596+
floating={floating}
597+
invalid={inputInvalid}
598+
disabled={disabled}
599+
hasButton={!hideSubmitButton}
600+
/>
601+
)}
602+
{!currentStep.hideInput && !hideSubmitButton && (
593603
<SubmitButton
594604
className="rsc-submit-button"
595605
style={submitButtonStyle}
@@ -643,6 +653,7 @@ ChatBot.propTypes = {
643653
userAvatar: PropTypes.string,
644654
userDelay: PropTypes.number,
645655
width: PropTypes.string,
656+
height: PropTypes.string,
646657
};
647658

648659
ChatBot.defaultProps = {
@@ -677,6 +688,7 @@ ChatBot.defaultProps = {
677688
toggleFloating: undefined,
678689
userDelay: 1000,
679690
width: '350px',
691+
height: '520px',
680692
botAvatar:
681693
'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE5LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDUxMiA1MTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwI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wzOC41NTgsMCw0Ni41NDUsMCw2OS44MThsMCwwYzM4LjU1OCwwLDY5LjgxOC0zMS4yNiw2OS44MTgtNjkuODE4SDI1NnoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K',
682694
userAvatar:

lib/ChatBotContainer.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const ChatBotContainer = styled.div`
1111
bottom: ${props => props.floating ? '32px' : 'initial'};
1212
right: ${props => props.floating ? '32px' : 'initial'};
1313
width: ${props => props.width};
14+
height: ${props => props.height};
1415
z-index: 999;
1516
transform: ${props => props.opened ? 'scale(1)' : 'scale(0)'};
1617
transform-origin: bottom right;

lib/Content.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components';
22

33
const Content = styled.div`
4-
height: 400px;
4+
height: calc(${props => props.height} - ${props => props.hideInput ? '56px' : '112px'});
55
overflow-y: scroll;
66
margin-top: 2px;
77
padding-top: 6px;

lib/schemas/customSchema.js

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

lib/schemas/optionsSchema.js

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

lib/schemas/textSchema.js

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

0 commit comments

Comments
 (0)