ConfigProvider.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. CONFIG_PROVIDER_KEY: () => CONFIG_PROVIDER_KEY,
  21. default: () => stdin_default
  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_global_z_index = require("../composables/use-global-z-index");
  28. const [name, bem] = (0, import_utils.createNamespace)("config-provider");
  29. const CONFIG_PROVIDER_KEY = Symbol(name);
  30. const configProviderProps = {
  31. tag: (0, import_utils.makeStringProp)("div"),
  32. zIndex: Number,
  33. themeVars: Object,
  34. iconPrefix: String
  35. };
  36. function mapThemeVarsToCSSVars(themeVars) {
  37. const cssVars = {};
  38. Object.keys(themeVars).forEach((key) => {
  39. cssVars[`--van-${(0, import_utils.kebabCase)(key)}`] = themeVars[key];
  40. });
  41. return cssVars;
  42. }
  43. var stdin_default = (0, import_vue2.defineComponent)({
  44. name,
  45. props: configProviderProps,
  46. setup(props, {
  47. slots
  48. }) {
  49. const style = (0, import_vue2.computed)(() => {
  50. if (props.themeVars) {
  51. return mapThemeVarsToCSSVars(props.themeVars);
  52. }
  53. });
  54. (0, import_vue2.provide)(CONFIG_PROVIDER_KEY, props);
  55. (0, import_vue2.watchEffect)(() => {
  56. if (props.zIndex !== void 0) {
  57. (0, import_use_global_z_index.setGlobalZIndex)(props.zIndex);
  58. }
  59. });
  60. return () => (0, import_vue.createVNode)(props.tag, {
  61. "class": bem(),
  62. "style": style.value
  63. }, {
  64. default: () => {
  65. var _a;
  66. return [(_a = slots.default) == null ? void 0 : _a.call(slots)];
  67. }
  68. });
  69. }
  70. });