SearchResult.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React from 'react';
  2. import classNames from 'classnames';
  3. export class SearchResult extends React.Component<any, any> {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. search: '',
  8. };
  9. }
  10. render() {
  11. return this.state.search.sections.map(section => {
  12. return <SearchResultSection section={section} key={section.id} />;
  13. });
  14. }
  15. }
  16. export interface SectionProps {
  17. section: any;
  18. }
  19. export class SearchResultSection extends React.Component<SectionProps, any> {
  20. constructor(props) {
  21. super(props);
  22. }
  23. renderItem(item) {
  24. return (
  25. <a className="search-item" href={item.url} key={item.id}>
  26. <span className="search-item__icon">
  27. <i className="fa fa-th-large" />
  28. </span>
  29. <span className="search-item__body">
  30. <div className="search-item__body-title">{item.title}</div>
  31. </span>
  32. </a>
  33. );
  34. }
  35. toggleSection = () => {
  36. this.props.section.toggle();
  37. };
  38. render() {
  39. const collapseClassNames = classNames({
  40. fa: true,
  41. 'fa-plus': !this.props.section.expanded,
  42. 'fa-minus': this.props.section.expanded,
  43. 'search-section__header__toggle': true,
  44. });
  45. return (
  46. <div className="search-section" key={this.props.section.id}>
  47. <div className="search-section__header">
  48. <i className={classNames('search-section__header__icon', this.props.section.icon)} />
  49. <span className="search-section__header__text">{this.props.section.title}</span>
  50. <i className={collapseClassNames} onClick={this.toggleSection} />
  51. </div>
  52. {this.props.section.expanded && (
  53. <div className="search-section__items">{this.props.section.items.map(this.renderItem)}</div>
  54. )}
  55. </div>
  56. );
  57. }
  58. }