You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractContainer.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React, { Component } from 'react';
  2. /**
  3. * Abstract (base) class for container of React Component children with a style.
  4. *
  5. * @extends Component
  6. */
  7. export default class AbstractContainer extends Component {
  8. /**
  9. * AbstractContainer component's property types.
  10. *
  11. * @static
  12. */
  13. static propTypes = {
  14. children: React.PropTypes.node,
  15. /**
  16. * The event handler/listener to be invoked when this AbstractContainer
  17. * is clicked on Web or pressed on React Native. If onClick is defined
  18. * and touchFeedback is undefined, touchFeedback is considered defined
  19. * as true.
  20. */
  21. onClick: React.PropTypes.func,
  22. /**
  23. * The style (as in stylesheet) to be applied to this AbstractContainer.
  24. */
  25. style: React.PropTypes.object,
  26. /**
  27. * True if this instance is to provide visual feedback when touched;
  28. * otherwise, false. If touchFeedback is undefined and onClick is
  29. * defined, touchFeedback is considered defined as true.
  30. */
  31. touchFeedback: React.PropTypes.bool,
  32. /**
  33. * True if this AbstractContainer is to be visible or false if this
  34. * instance is to be hidden or not rendered at all.
  35. */
  36. visible: React.PropTypes.bool
  37. };
  38. /**
  39. * Renders this AbstractContainer as a React Component of a specific type.
  40. *
  41. * @param {string|ReactClass} type - The type of the React Component which
  42. * is to be rendered.
  43. * @param {Object|undefined} props - The read-only React Component
  44. * properties, if any, to render. If undefined, the props of this instance
  45. * will be rendered.
  46. * @protected
  47. * @returns {ReactElement}
  48. */
  49. _render(type, props) {
  50. const {
  51. children,
  52. /* eslint-disable no-unused-vars */
  53. // The following properties are defined for the benefit of
  54. // AbstractContainer and its extenders so they are to not be
  55. // propagated.
  56. touchFeedback,
  57. visible,
  58. /* eslint-enable no-unused-vars */
  59. ...filteredProps
  60. } = props || this.props;
  61. // visible
  62. if (typeof visible !== 'undefined' && !visible) {
  63. return null;
  64. }
  65. return React.createElement(type, filteredProps, children);
  66. }
  67. }