Skip to content

Commit

Permalink
fix(ui/divider): support passing string inset with unit to divider
Browse files Browse the repository at this point in the history
  • Loading branch information
yuding2019 authored and BeADre committed Jun 14, 2021
1 parent b88edb2 commit 5cbd457
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/varlet-ui/src/divider/Divider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<script lang="ts">
import { defineComponent, computed, reactive, onMounted, toRefs } from 'vue'
import { toSizeUnit } from '../utils/elements'
import { isBool } from '../utils/shared'
import { isBool, toNumber } from '../utils/shared'
import { props } from './props'
export default defineComponent({
Expand All @@ -37,16 +37,19 @@ export default defineComponent({
if (isBool(inset) || inset === 0) return { ...baseStyle }
const absInset = Math.abs(inset)
// -18px -> -18
const _inset = toNumber(inset)
// -18px -> 18px
const absInsetWithUnit = Math.abs(_inset) + (inset + '').replace(_inset + '', '')
return vertical
? {
...baseStyle,
height: `calc(80% - ${toSizeUnit(absInset)})`,
height: `calc(80% - ${toSizeUnit(absInsetWithUnit)})`,
}
: {
...baseStyle,
width: `calc(100% - ${toSizeUnit(absInset)})`,
left: inset > 0 ? toSizeUnit(inset) : toSizeUnit(0),
width: `calc(100% - ${toSizeUnit(absInsetWithUnit)})`,
left: _inset > 0 ? toSizeUnit(absInsetWithUnit) : toSizeUnit(0),
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/divider/props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const props = {
inset: {
type: [Boolean, Number],
type: [Boolean, Number, String],
default: false,
},
vertical: {
Expand Down

0 comments on commit 5cbd457

Please sign in to comment.