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.
 
 
 
 

71 line
2.0 KiB

  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import React from 'react';
  4. import PropTypes from 'prop-types';
  5. import classNames from 'classnames';
  6. import { mapToCssModules, tagPropType } from './utils';
  7. var propTypes = {
  8. body: PropTypes.bool,
  9. bottom: PropTypes.bool,
  10. children: PropTypes.node,
  11. className: PropTypes.string,
  12. cssModule: PropTypes.object,
  13. heading: PropTypes.bool,
  14. left: PropTypes.bool,
  15. list: PropTypes.bool,
  16. middle: PropTypes.bool,
  17. object: PropTypes.bool,
  18. right: PropTypes.bool,
  19. tag: tagPropType,
  20. top: PropTypes.bool
  21. };
  22. var Media = function Media(props) {
  23. var body = props.body,
  24. bottom = props.bottom,
  25. className = props.className,
  26. cssModule = props.cssModule,
  27. heading = props.heading,
  28. left = props.left,
  29. list = props.list,
  30. middle = props.middle,
  31. object = props.object,
  32. right = props.right,
  33. tag = props.tag,
  34. top = props.top,
  35. attributes = _objectWithoutPropertiesLoose(props, ["body", "bottom", "className", "cssModule", "heading", "left", "list", "middle", "object", "right", "tag", "top"]);
  36. var defaultTag;
  37. if (heading) {
  38. defaultTag = 'h4';
  39. } else if (attributes.href) {
  40. defaultTag = 'a';
  41. } else if (attributes.src || object) {
  42. defaultTag = 'img';
  43. } else if (list) {
  44. defaultTag = 'ul';
  45. } else {
  46. defaultTag = 'div';
  47. }
  48. var Tag = tag || defaultTag;
  49. var classes = mapToCssModules(classNames(className, {
  50. 'media-body': body,
  51. 'media-heading': heading,
  52. 'media-left': left,
  53. 'media-right': right,
  54. 'media-top': top,
  55. 'media-bottom': bottom,
  56. 'media-middle': middle,
  57. 'media-object': object,
  58. 'media-list': list,
  59. media: !body && !heading && !left && !right && !top && !bottom && !middle && !object && !list
  60. }), cssModule);
  61. return React.createElement(Tag, _extends({}, attributes, {
  62. className: classes
  63. }));
  64. };
  65. Media.propTypes = propTypes;
  66. export default Media;