Tabbar.js 3.1 KB

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