78b8e5368c96f289abdad97fd46098a31c6411be24069da6f6f26685e5e31fea52db6153dda0ae0f33fc6131ca7d79c4c9c46b897f7c96260222497bca7bdf 1.8 KB

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