NavBar.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. default: () => stdin_default,
  21. navBarProps: () => navBarProps
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. var import_use_placeholder = require("../composables/use-placeholder");
  28. var import_icon = require("../icon");
  29. const [name, bem] = (0, import_utils.createNamespace)("nav-bar");
  30. const navBarProps = {
  31. title: String,
  32. fixed: Boolean,
  33. zIndex: import_utils.numericProp,
  34. border: import_utils.truthProp,
  35. leftText: String,
  36. rightText: String,
  37. leftArrow: Boolean,
  38. placeholder: Boolean,
  39. safeAreaInsetTop: Boolean,
  40. clickable: import_utils.truthProp
  41. };
  42. var stdin_default = (0, import_vue2.defineComponent)({
  43. name,
  44. props: navBarProps,
  45. emits: ["clickLeft", "clickRight"],
  46. setup(props, {
  47. emit,
  48. slots
  49. }) {
  50. const navBarRef = (0, import_vue2.ref)();
  51. const renderPlaceholder = (0, import_use_placeholder.usePlaceholder)(navBarRef, bem);
  52. const onClickLeft = (event) => emit("clickLeft", event);
  53. const onClickRight = (event) => emit("clickRight", event);
  54. const renderLeft = () => {
  55. if (slots.left) {
  56. return slots.left();
  57. }
  58. return [props.leftArrow && (0, import_vue.createVNode)(import_icon.Icon, {
  59. "class": bem("arrow"),
  60. "name": "arrow-left"
  61. }, null), props.leftText && (0, import_vue.createVNode)("span", {
  62. "class": bem("text")
  63. }, [props.leftText])];
  64. };
  65. const renderRight = () => {
  66. if (slots.right) {
  67. return slots.right();
  68. }
  69. return (0, import_vue.createVNode)("span", {
  70. "class": bem("text")
  71. }, [props.rightText]);
  72. };
  73. const renderNavBar = () => {
  74. const {
  75. title,
  76. fixed,
  77. border,
  78. zIndex
  79. } = props;
  80. const style = (0, import_utils.getZIndexStyle)(zIndex);
  81. const hasLeft = props.leftArrow || props.leftText || slots.left;
  82. const hasRight = props.rightText || slots.right;
  83. return (0, import_vue.createVNode)("div", {
  84. "ref": navBarRef,
  85. "style": style,
  86. "class": [bem({
  87. fixed
  88. }), {
  89. [import_utils.BORDER_BOTTOM]: border,
  90. "van-safe-area-top": props.safeAreaInsetTop
  91. }]
  92. }, [(0, import_vue.createVNode)("div", {
  93. "class": bem("content")
  94. }, [hasLeft && (0, import_vue.createVNode)("div", {
  95. "class": [bem("left"), props.clickable ? import_utils.HAPTICS_FEEDBACK : ""],
  96. "onClick": onClickLeft
  97. }, [renderLeft()]), (0, import_vue.createVNode)("div", {
  98. "class": [bem("title"), "van-ellipsis"]
  99. }, [slots.title ? slots.title() : title]), hasRight && (0, import_vue.createVNode)("div", {
  100. "class": [bem("right"), props.clickable ? import_utils.HAPTICS_FEEDBACK : ""],
  101. "onClick": onClickRight
  102. }, [renderRight()])])]);
  103. };
  104. return () => {
  105. if (props.fixed && props.placeholder) {
  106. return renderPlaceholder(renderNavBar);
  107. }
  108. return renderNavBar();
  109. };
  110. }
  111. });