Tabbar.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. TABBAR_KEY: () => TABBAR_KEY,
  21. default: () => stdin_default,
  22. tabbarProps: () => tabbarProps
  23. });
  24. module.exports = __toCommonJS(stdin_exports);
  25. var import_vue = require("vue");
  26. var import_vue2 = require("vue");
  27. var import_utils = require("../utils");
  28. var import_use = require("@vant/use");
  29. var import_use_placeholder = require("../composables/use-placeholder");
  30. const [name, bem] = (0, import_utils.createNamespace)("tabbar");
  31. const tabbarProps = {
  32. route: Boolean,
  33. fixed: import_utils.truthProp,
  34. border: import_utils.truthProp,
  35. zIndex: import_utils.numericProp,
  36. placeholder: Boolean,
  37. activeColor: String,
  38. beforeChange: Function,
  39. inactiveColor: String,
  40. modelValue: (0, import_utils.makeNumericProp)(0),
  41. safeAreaInsetBottom: {
  42. type: Boolean,
  43. default: null
  44. }
  45. };
  46. const TABBAR_KEY = Symbol(name);
  47. var stdin_default = (0, import_vue2.defineComponent)({
  48. name,
  49. props: tabbarProps,
  50. emits: ["change", "update:modelValue"],
  51. setup(props, {
  52. emit,
  53. slots
  54. }) {
  55. const root = (0, import_vue2.ref)();
  56. const {
  57. linkChildren
  58. } = (0, import_use.useChildren)(TABBAR_KEY);
  59. const renderPlaceholder = (0, import_use_placeholder.usePlaceholder)(root, bem);
  60. const enableSafeArea = () => {
  61. var _a;
  62. return (_a = props.safeAreaInsetBottom) != null ? _a : props.fixed;
  63. };
  64. const renderTabbar = () => {
  65. var _a;
  66. const {
  67. fixed,
  68. zIndex,
  69. border
  70. } = props;
  71. return (0, import_vue.createVNode)("div", {
  72. "ref": root,
  73. "role": "tablist",
  74. "style": (0, import_utils.getZIndexStyle)(zIndex),
  75. "class": [bem({
  76. fixed
  77. }), {
  78. [import_utils.BORDER_TOP_BOTTOM]: border,
  79. "van-safe-area-bottom": enableSafeArea()
  80. }]
  81. }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
  82. };
  83. const setActive = (active, afterChange) => {
  84. (0, import_utils.callInterceptor)(props.beforeChange, {
  85. args: [active],
  86. done() {
  87. emit("update:modelValue", active);
  88. emit("change", active);
  89. afterChange();
  90. }
  91. });
  92. };
  93. linkChildren({
  94. props,
  95. setActive
  96. });
  97. return () => {
  98. if (props.fixed && props.placeholder) {
  99. return renderPlaceholder(renderTabbar);
  100. }
  101. return renderTabbar();
  102. };
  103. }
  104. });