use-space.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index = require('../../../hooks/use-namespace/index.js');
  5. var shared = require('@vue/shared');
  6. var types = require('../../../utils/types.js');
  7. const SIZE_MAP = {
  8. small: 8,
  9. default: 12,
  10. large: 16
  11. };
  12. function useSpace(props) {
  13. const ns = index.useNamespace("space");
  14. const classes = vue.computed(() => [ns.b(), ns.m(props.direction), props.class]);
  15. const horizontalSize = vue.ref(0);
  16. const verticalSize = vue.ref(0);
  17. const containerStyle = vue.computed(() => {
  18. const wrapKls = props.wrap || props.fill ? { flexWrap: "wrap" } : {};
  19. const alignment = {
  20. alignItems: props.alignment
  21. };
  22. const gap = {
  23. rowGap: `${verticalSize.value}px`,
  24. columnGap: `${horizontalSize.value}px`
  25. };
  26. return [wrapKls, alignment, gap, props.style];
  27. });
  28. const itemStyle = vue.computed(() => {
  29. return props.fill ? { flexGrow: 1, minWidth: `${props.fillRatio}%` } : {};
  30. });
  31. vue.watchEffect(() => {
  32. const { size = "small", wrap, direction: dir, fill } = props;
  33. if (shared.isArray(size)) {
  34. const [h = 0, v = 0] = size;
  35. horizontalSize.value = h;
  36. verticalSize.value = v;
  37. } else {
  38. let val;
  39. if (types.isNumber(size)) {
  40. val = size;
  41. } else {
  42. val = SIZE_MAP[size || "small"] || SIZE_MAP.small;
  43. }
  44. if ((wrap || fill) && dir === "horizontal") {
  45. horizontalSize.value = verticalSize.value = val;
  46. } else {
  47. if (dir === "horizontal") {
  48. horizontalSize.value = val;
  49. verticalSize.value = 0;
  50. } else {
  51. verticalSize.value = val;
  52. horizontalSize.value = 0;
  53. }
  54. }
  55. }
  56. });
  57. return {
  58. classes,
  59. containerStyle,
  60. itemStyle
  61. };
  62. }
  63. exports.useSpace = useSpace;
  64. //# sourceMappingURL=use-space.js.map