Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 5, 2022
1 parent 8a94d1b commit f613046
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
10 changes: 7 additions & 3 deletions packages/core/useElementSize/demo.vue
Expand Up @@ -4,9 +4,13 @@ import { stringify } from '@vueuse/docs-utils'
import { useElementSize } from '@vueuse/core'
const el = ref(null)
const size = reactive(useElementSize(el, { width: 0, height: 0 }, {
box: 'border-box',
}))
const size = reactive(
useElementSize(
el,
{ width: 0, height: 0 },
{ box: 'border-box' },
),
)
const text = stringify(size)
</script>

Expand Down
17 changes: 12 additions & 5 deletions packages/core/useElementSize/index.ts
Expand Up @@ -31,7 +31,9 @@ export function useElementSize(
([entry]) => {
const boxSize = box === 'border-box'
? entry.borderBoxSize
: (box === 'content-box' ? entry.contentBoxSize : entry.devicePixelContentBoxSize)
: box === 'content-box'
? entry.contentBoxSize
: entry.devicePixelContentBoxSize

if (boxSize) {
width.value = boxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0)
Expand All @@ -45,10 +47,15 @@ export function useElementSize(
},
options,
)
watch(() => unrefElement(target), (ele) => {
width.value = ele ? initialSize.width : 0
height.value = ele ? initialSize.height : 0
})

watch(
() => unrefElement(target),
(ele) => {
width.value = ele ? initialSize.width : 0
height.value = ele ? initialSize.height : 0
},
)

return {
width,
height,
Expand Down

0 comments on commit f613046

Please sign in to comment.