context.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { computed, inject, provide } from 'vue';
  2. import { objectType } from '../_util/type';
  3. export const defaultIconPrefixCls = 'anticon';
  4. export const GlobalFormContextKey = Symbol('GlobalFormContextKey');
  5. export const useProvideGlobalForm = state => {
  6. provide(GlobalFormContextKey, state);
  7. };
  8. export const useInjectGlobalForm = () => {
  9. return inject(GlobalFormContextKey, {
  10. validateMessages: computed(() => undefined)
  11. });
  12. };
  13. export const GlobalConfigContextKey = Symbol('GlobalConfigContextKey');
  14. export const configProviderProps = () => ({
  15. iconPrefixCls: String,
  16. getTargetContainer: {
  17. type: Function
  18. },
  19. getPopupContainer: {
  20. type: Function
  21. },
  22. prefixCls: String,
  23. getPrefixCls: {
  24. type: Function
  25. },
  26. renderEmpty: {
  27. type: Function
  28. },
  29. transformCellText: {
  30. type: Function
  31. },
  32. csp: objectType(),
  33. input: objectType(),
  34. autoInsertSpaceInButton: {
  35. type: Boolean,
  36. default: undefined
  37. },
  38. locale: objectType(),
  39. pageHeader: objectType(),
  40. componentSize: {
  41. type: String
  42. },
  43. componentDisabled: {
  44. type: Boolean,
  45. default: undefined
  46. },
  47. direction: {
  48. type: String,
  49. default: 'ltr'
  50. },
  51. space: objectType(),
  52. virtual: {
  53. type: Boolean,
  54. default: undefined
  55. },
  56. dropdownMatchSelectWidth: {
  57. type: [Number, Boolean],
  58. default: true
  59. },
  60. form: objectType(),
  61. pagination: objectType(),
  62. theme: objectType(),
  63. select: objectType(),
  64. wave: objectType()
  65. });
  66. export const configProviderKey = Symbol('configProvider');
  67. export const defaultConfigProvider = {
  68. getPrefixCls: (suffixCls, customizePrefixCls) => {
  69. if (customizePrefixCls) return customizePrefixCls;
  70. return suffixCls ? `ant-${suffixCls}` : 'ant';
  71. },
  72. iconPrefixCls: computed(() => defaultIconPrefixCls),
  73. getPopupContainer: computed(() => () => document.body),
  74. direction: computed(() => 'ltr')
  75. };
  76. export const useConfigContextInject = () => {
  77. return inject(configProviderKey, defaultConfigProvider);
  78. };
  79. export const useConfigContextProvider = props => {
  80. return provide(configProviderKey, props);
  81. };