NavBar.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_utils = require("../utils");
  26. var import_use_placeholder = require("../composables/use-placeholder");
  27. var import_icon = require("../icon");
  28. const [name, bem] = (0, import_utils.createNamespace)("nav-bar");
  29. const navBarProps = {
  30. title: String,
  31. fixed: Boolean,
  32. zIndex: import_utils.numericProp,
  33. border: import_utils.truthProp,
  34. leftText: String,
  35. rightText: String,
  36. leftDisabled: Boolean,
  37. rightDisabled: Boolean,
  38. leftArrow: Boolean,
  39. placeholder: Boolean,
  40. safeAreaInsetTop: Boolean,
  41. clickable: import_utils.truthProp
  42. };
  43. var stdin_default = (0, import_vue.defineComponent)({
  44. name,
  45. props: navBarProps,
  46. emits: ["clickLeft", "clickRight"],
  47. setup(props, {
  48. emit,
  49. slots
  50. }) {
  51. const navBarRef = (0, import_vue.ref)();
  52. const renderPlaceholder = (0, import_use_placeholder.usePlaceholder)(navBarRef, bem);
  53. const onClickLeft = (event) => {
  54. if (!props.leftDisabled) {
  55. emit("clickLeft", event);
  56. }
  57. };
  58. const onClickRight = (event) => {
  59. if (!props.rightDisabled) {
  60. emit("clickRight", event);
  61. }
  62. };
  63. const renderLeft = () => {
  64. if (slots.left) {
  65. return slots.left();
  66. }
  67. return [props.leftArrow && (0, import_vue.createVNode)(import_icon.Icon, {
  68. "class": bem("arrow"),
  69. "name": "arrow-left"
  70. }, null), props.leftText && (0, import_vue.createVNode)("span", {
  71. "class": bem("text")
  72. }, [props.leftText])];
  73. };
  74. const renderRight = () => {
  75. if (slots.right) {
  76. return slots.right();
  77. }
  78. return (0, import_vue.createVNode)("span", {
  79. "class": bem("text")
  80. }, [props.rightText]);
  81. };
  82. const renderNavBar = () => {
  83. const {
  84. title,
  85. fixed,
  86. border,
  87. zIndex
  88. } = props;
  89. const style = (0, import_utils.getZIndexStyle)(zIndex);
  90. const hasLeft = props.leftArrow || props.leftText || slots.left;
  91. const hasRight = props.rightText || slots.right;
  92. return (0, import_vue.createVNode)("div", {
  93. "ref": navBarRef,
  94. "style": style,
  95. "class": [bem({
  96. fixed
  97. }), {
  98. [import_utils.BORDER_BOTTOM]: border,
  99. "van-safe-area-top": props.safeAreaInsetTop
  100. }]
  101. }, [(0, import_vue.createVNode)("div", {
  102. "class": bem("content")
  103. }, [hasLeft && (0, import_vue.createVNode)("div", {
  104. "class": [bem("left", {
  105. disabled: props.leftDisabled
  106. }), props.clickable && !props.leftDisabled ? import_utils.HAPTICS_FEEDBACK : ""],
  107. "onClick": onClickLeft
  108. }, [renderLeft()]), (0, import_vue.createVNode)("div", {
  109. "class": [bem("title"), "van-ellipsis"]
  110. }, [slots.title ? slots.title() : title]), hasRight && (0, import_vue.createVNode)("div", {
  111. "class": [bem("right", {
  112. disabled: props.rightDisabled
  113. }), props.clickable && !props.rightDisabled ? import_utils.HAPTICS_FEEDBACK : ""],
  114. "onClick": onClickRight
  115. }, [renderRight()])])]);
  116. };
  117. return () => {
  118. if (props.fixed && props.placeholder) {
  119. return renderPlaceholder(renderNavBar);
  120. }
  121. return renderNavBar();
  122. };
  123. }
  124. });