Col.mjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { computed, defineComponent, createVNode as _createVNode } from "vue";
  2. import { numericProp, createNamespace, makeNumericProp, makeStringProp, extend } from "../utils/index.mjs";
  3. import { useParent } from "@vant/use";
  4. import { ROW_KEY } from "../row/Row.mjs";
  5. const [name, bem] = createNamespace("col");
  6. const colProps = {
  7. tag: makeStringProp("div"),
  8. span: makeNumericProp(0),
  9. offset: numericProp
  10. };
  11. var stdin_default = defineComponent({
  12. name,
  13. props: colProps,
  14. setup(props, {
  15. slots
  16. }) {
  17. const {
  18. parent,
  19. index
  20. } = useParent(ROW_KEY);
  21. const style = computed(() => {
  22. if (!parent) {
  23. return;
  24. }
  25. const {
  26. spaces,
  27. verticalSpaces
  28. } = parent;
  29. let styles = {};
  30. if (spaces && spaces.value && spaces.value[index.value]) {
  31. const {
  32. left,
  33. right
  34. } = spaces.value[index.value];
  35. styles = {
  36. paddingLeft: left ? `${left}px` : null,
  37. paddingRight: right ? `${right}px` : null
  38. };
  39. }
  40. const {
  41. bottom
  42. } = verticalSpaces.value[index.value] || {};
  43. return extend(styles, {
  44. marginBottom: bottom ? `${bottom}px` : null
  45. });
  46. });
  47. return () => {
  48. const {
  49. tag,
  50. span,
  51. offset
  52. } = props;
  53. return _createVNode(tag, {
  54. "style": style.value,
  55. "class": bem({
  56. [span]: span,
  57. [`offset-${offset}`]: offset
  58. })
  59. }, {
  60. default: () => {
  61. var _a;
  62. return [(_a = slots.default) == null ? void 0 : _a.call(slots)];
  63. }
  64. });
  65. };
  66. }
  67. });
  68. export {
  69. colProps,
  70. stdin_default as default
  71. };