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.

Navbar.js 2.8 KiB

3 jaren geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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, deprecated, tagPropType } from './utils';
  7. var propTypes = {
  8. light: PropTypes.bool,
  9. dark: PropTypes.bool,
  10. inverse: deprecated(PropTypes.bool, 'Please use the prop "dark"'),
  11. full: PropTypes.bool,
  12. fixed: PropTypes.string,
  13. sticky: PropTypes.string,
  14. color: PropTypes.string,
  15. role: PropTypes.string,
  16. tag: tagPropType,
  17. className: PropTypes.string,
  18. cssModule: PropTypes.object,
  19. toggleable: deprecated(PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), 'Please use the prop "expand"'),
  20. expand: PropTypes.oneOfType([PropTypes.bool, PropTypes.string])
  21. };
  22. var defaultProps = {
  23. tag: 'nav',
  24. expand: false
  25. };
  26. var getExpandClass = function getExpandClass(expand) {
  27. if (expand === false) {
  28. return false;
  29. } else if (expand === true || expand === 'xs') {
  30. return 'navbar-expand';
  31. }
  32. return "navbar-expand-" + expand;
  33. }; // To better maintain backwards compatibility while toggleable is deprecated.
  34. // We must map breakpoints to the next breakpoint so that toggleable and expand do the same things at the same breakpoint.
  35. var toggleableToExpand = {
  36. xs: 'sm',
  37. sm: 'md',
  38. md: 'lg',
  39. lg: 'xl'
  40. };
  41. var getToggleableClass = function getToggleableClass(toggleable) {
  42. if (toggleable === undefined || toggleable === 'xl') {
  43. return false;
  44. } else if (toggleable === false) {
  45. return 'navbar-expand';
  46. }
  47. return "navbar-expand-" + (toggleable === true ? 'sm' : toggleableToExpand[toggleable] || toggleable);
  48. };
  49. var Navbar = function Navbar(props) {
  50. var _classNames;
  51. var toggleable = props.toggleable,
  52. expand = props.expand,
  53. className = props.className,
  54. cssModule = props.cssModule,
  55. light = props.light,
  56. dark = props.dark,
  57. inverse = props.inverse,
  58. fixed = props.fixed,
  59. sticky = props.sticky,
  60. color = props.color,
  61. Tag = props.tag,
  62. attributes = _objectWithoutPropertiesLoose(props, ["toggleable", "expand", "className", "cssModule", "light", "dark", "inverse", "fixed", "sticky", "color", "tag"]);
  63. var classes = mapToCssModules(classNames(className, 'navbar', getExpandClass(expand) || getToggleableClass(toggleable), (_classNames = {
  64. 'navbar-light': light,
  65. 'navbar-dark': inverse || dark
  66. }, _classNames["bg-" + color] = color, _classNames["fixed-" + fixed] = fixed, _classNames["sticky-" + sticky] = sticky, _classNames)), cssModule);
  67. return React.createElement(Tag, _extends({}, attributes, {
  68. className: classes
  69. }));
  70. };
  71. Navbar.propTypes = propTypes;
  72. Navbar.defaultProps = defaultProps;
  73. export default Navbar;