From 5abf617b009fbb63409724a3394b207949cc3a2c Mon Sep 17 00:00:00 2001 From: haoziqaq <357229046@qq.com> Date: Sat, 20 Nov 2021 14:32:24 +0800 Subject: [PATCH] fix(ui/space): modify the behavior of space in space-around and space-between modes affects: @varlet/ui --- packages/varlet-ui/src/space/Space.tsx | 20 ++++++++++++++----- .../__snapshots__/index.spec.js.snap | 18 ++++++++--------- packages/varlet-ui/src/space/docs/en-US.md | 5 ++++- packages/varlet-ui/src/space/docs/zh-CN.md | 5 ++++- .../varlet-ui/src/space/example/index.vue | 5 ++++- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/packages/varlet-ui/src/space/Space.tsx b/packages/varlet-ui/src/space/Space.tsx index 98b9aeb261e..ede890c1ca9 100644 --- a/packages/varlet-ui/src/space/Space.tsx +++ b/packages/varlet-ui/src/space/Space.tsx @@ -36,12 +36,22 @@ export default defineComponent({ let margin = '0' if (direction === 'row') { - if (index === 0) { - margin = `${y / 2}px ${x / 2}px ${y / 2}px 0` - } else if (index === lastIndex) { - margin = `${y / 2}px 0 ${y / 2}px ${x / 2}px` - } else { + if (justify === 'start' || justify === 'center' || justify === 'end') { + if (index !== lastIndex) { + margin = `${y / 2}px ${x}px ${y / 2}px 0` + } else { + margin = `${y / 2}px 0` + } + } else if (justify === 'space-around') { margin = `${y / 2}px ${x / 2}px` + } else if (justify === 'space-between') { + if (index === 0) { + margin = `${y / 2}px ${x / 2}px ${y / 2}px 0` + } else if (index === lastIndex) { + margin = `${y / 2}px 0 ${y / 2}px ${x / 2}px` + } else { + margin = `${y / 2}px ${x / 2}px` + } } } diff --git a/packages/varlet-ui/src/space/__tests__/__snapshots__/index.spec.js.snap b/packages/varlet-ui/src/space/__tests__/__snapshots__/index.spec.js.snap index 01ea6985344..1a56dca572b 100644 --- a/packages/varlet-ui/src/space/__tests__/__snapshots__/index.spec.js.snap +++ b/packages/varlet-ui/src/space/__tests__/__snapshots__/index.spec.js.snap @@ -2,13 +2,13 @@ exports[`test child in space 1`] = ` "