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.5KB

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