add send button to input

This commit is contained in:
igoradamenko
2018-01-28 23:41:37 +02:00
parent 8ebdb94d3a
commit a0632c89f8
6 changed files with 77 additions and 30 deletions
@@ -0,0 +1,23 @@
@import '../input.vars';
.input__button {
display: none;
position: absolute;
top: 0;
right: 0;
bottom: 0;
box-sizing: border-box;
width: $buttonWidth;
height: 100%;
padding: 0 10px;
font-size: 16px;
border: 0;
background: #00aaaa;
border-radius: 0 $borderRadius $borderRadius 0;
color: #fff;
cursor: pointer;
&:hover {
background: #00ffff;
}
}
@@ -0,0 +1,32 @@
@import '../input.vars';
.input__field {
$lineHeight: 1.4;
$fontSize: 16px;
$paddingVrt: 10px;
$height: $fontSize * $lineHeight + $paddingVrt * 2;
box-sizing: border-box;
width: 100%;
height: $height;
min-height: $height;
padding: $paddingVrt ($buttonWidth + 8px) $paddingVrt 15px;
font-family: 'PT Sans', Helvetica, Arial, sans-serif;
font-size: $fontSize;
line-height: $lineHeight;
box-shadow: 0 0 0 1px #eee;
border: 0;
border-radius: $borderRadius;
resize: none;
&:focus {
box-shadow: 0 0 0 1px #aaa;
outline: none;
}
&:valid {
+ .input__button {
display: block;
}
}
}
+3
View File
@@ -1,3 +1,6 @@
export { default } from './input';
require('./input.scss');
require('./__button/input__button.scss');
require('./__field/input__field.scss');
+15 -8
View File
@@ -8,18 +8,25 @@ export default class Input extends Component {
}
autoResize() {
this.rootNode.style.height = '';
this.setState({ height: this.rootNode.scrollHeight });
this.fieldNode.style.height = '';
this.setState({ height: this.fieldNode.scrollHeight });
}
render(props, { height }) {
return (
<textarea
className={b('input', props)}
onInput={this.autoResize}
style={{ height }}
ref={r => (this.rootNode = r)}
>{props.children}</textarea>
<div className={b('input', props)}>
<textarea
className="input__field"
onInput={this.autoResize}
style={{ height }}
ref={r => (this.fieldNode = r)}
required
>
{props.children}
</textarea>
<button className="input__button" type="button">Send</button>
</div>
);
}
}
+2 -22
View File
@@ -1,24 +1,4 @@
.input {
$lineHeight: 1.4;
$fontSize: 16px;
$paddingVrt: 10px;
$height: $fontSize * $lineHeight + $paddingVrt * 2;
box-sizing: border-box;
width: 100%;
height: $height;
min-height: $height;
padding: $paddingVrt 15px;
font-family: 'PT Sans', Helvetica, Arial, sans-serif;
font-size: $fontSize;
line-height: $lineHeight;
box-shadow: 0 0 0 1px #eee;
border: 0;
border-radius: 4px;
resize: none;
&:focus {
box-shadow: 0 0 0 1px #aaa;
outline: none;
}
position: relative;
font-size: 0;
}
+2
View File
@@ -0,0 +1,2 @@
$borderRadius: 4px;
$buttonWidth: 72px;