Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import { Component, State, EventEmitter, Event, Prop, h } from '@stencil/core';
  2.  
  3. @Component({
  4. tag: 'my-accordion',
  5. styleUrl: 'my-accordion.scss',
  6. shadow: true
  7. })
  8.  
  9. export class MyComponent {
  10.  
  11. @State() toggle: boolean = false;
  12.  
  13. @Event() onToggle: EventEmitter;
  14.  
  15. @Prop() label: string;
  16.  
  17. @Prop() description: string;
  18.  
  19. @Prop() width: string;
  20.  
  21. @Prop() color: string;
  22.  
  23. toggleComponent() {
  24. this.toggle = !this.toggle;
  25. this.onToggle.emit({ visible: this.toggle });
  26. }
  27.  
  28. render() {
  29.  
  30. return (
  31. <div>
  32. <button class="accordion"
  33. style={{
  34. width: this.width,
  35. backgroundColor: this.color,
  36. }}
  37. onClick={() => this.toggleComponent()}>
  38. {this.label}
  39. {this.toggle ? <span>&#9650;</span> : <span>&#9660;</span>}
  40. </button>
  41. <div class={`content-box ${this.toggle ? 'open' : 'close'}`}
  42. style={{width: this.width}}>
  43. <p>{this.description}</p>
  44. </div>
  45. </div>
  46. )
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement