Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import { Component, Prop, h } from '@stencil/core';
  2.  
  3. @Component({
  4. tag: 'wp-input',
  5. styleUrl: 'input.css',
  6. shadow: true
  7. })
  8. export class InputComponent {
  9.  
  10. @Prop() type: string = 'text';
  11. @Prop() disabled: boolean = false;
  12. @Prop() required: boolean = false;
  13. @Prop() labelTxt: string = '';
  14. @Prop() class: string = '';
  15. @Prop() value: string = '';
  16. @Prop() error: string = '';
  17. @Prop() id: string;
  18. @Prop() whenChange: Function;
  19.  
  20.  
  21. render() {
  22. return (
  23. <div class={`wp-input-wrapper`}>
  24. <label htmlFor={this.id}>{this.labelTxt}</label>
  25. <input type="text"
  26. onInput={event => this.whenChange(event)}
  27. class={`wp-input`} id={this.id}
  28. value={this.value} required={this.required} />
  29. {this.error && <div class="error">
  30. {this.error}
  31. </div>}
  32. </div>
  33. )
  34.  
  35. }
  36. }
  37.  
  38. <script>
  39. changeFunction = event => {
  40. console.log(event)
  41. }
  42. </script>
  43.  
  44. <wp-input
  45. when-change='changeFunction'
  46. value='i am here' error='adf' label-txt='Label text'></wp-input>
  47.  
  48. customElements.whenDefined('wp-input').then( () => {
  49. var input = document.querySelector("wp-input").shadowRoot.querySelector("input");
  50.  
  51. input.addEventListener('keyup', event => {
  52. console.log(event.target.value)
  53. });
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement