diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2022-06-22 16:29:31 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2022-06-22 16:30:55 +0900 |
| commit | be383aa5b2161674149df8f6708b1411399641c7 (patch) | |
| tree | 20190b0eb1205bd6b00e379e07c0e53739eb8b61 /packages/client/src/components/global | |
| parent | refactor(client): refactor header tab handling (diff) | |
| download | misskey-be383aa5b2161674149df8f6708b1411399641c7.tar.gz misskey-be383aa5b2161674149df8f6708b1411399641c7.tar.bz2 misskey-be383aa5b2161674149df8f6708b1411399641c7.zip | |
refactor(client): use composition api
Diffstat (limited to 'packages/client/src/components/global')
| -rw-r--r-- | packages/client/src/components/global/spacer.vue | 109 |
1 files changed, 46 insertions, 63 deletions
diff --git a/packages/client/src/components/global/spacer.vue b/packages/client/src/components/global/spacer.vue index f2eda1907b..53adf07771 100644 --- a/packages/client/src/components/global/spacer.vue +++ b/packages/client/src/components/global/spacer.vue @@ -6,78 +6,61 @@ </div> </template> -<script lang="ts"> +<script lang="ts" setup> +import { inject, onMounted, onUnmounted, ref } from 'vue'; import { deviceKind } from '@/scripts/device-kind'; -import { defineComponent, inject, onMounted, onUnmounted, ref } from 'vue'; -export default defineComponent({ - props: { - contentMax: { - type: Number, - required: false, - default: null, - }, - marginMin: { - type: Number, - required: false, - default: 12, - }, - marginMax: { - type: Number, - required: false, - default: 24, - }, - }, +const props = withDefaults(defineProps<{ + contentMax?: number | null; + marginMin?: number; + marginMax?: number; +}>(), { + contentMax: null, + marginMin: 12, + marginMax: 24, +}); - setup(props, context) { - let ro: ResizeObserver; - const root = ref<HTMLElement>(); - const content = ref<HTMLElement>(); - const margin = ref(0); - const shouldSpacerMin = inject('shouldSpacerMin', false); - const adjust = (rect: { width: number; height: number; }) => { - if (shouldSpacerMin || deviceKind === 'smartphone') { - margin.value = props.marginMin; - return; - } +let ro: ResizeObserver; +let root = $ref<HTMLElement>(); +let content = $ref<HTMLElement>(); +let margin = $ref(0); +const shouldSpacerMin = inject('shouldSpacerMin', false); - if (rect.width > props.contentMax || (rect.width > 360 && window.innerWidth > 400)) { - margin.value = props.marginMax; - } else { - margin.value = props.marginMin; - } - }; +const adjust = (rect: { width: number; height: number; }) => { + if (shouldSpacerMin || deviceKind === 'smartphone') { + margin = props.marginMin; + return; + } - onMounted(() => { - ro = new ResizeObserver((entries) => { - /* iOSが対応していない - adjust({ - width: entries[0].borderBoxSize[0].inlineSize, - height: entries[0].borderBoxSize[0].blockSize, - }); - */ - adjust({ - width: root.value!.offsetWidth, - height: root.value!.offsetHeight, - }); - }); - ro.observe(root.value!); + if (rect.width > (props.contentMax ?? 0) || (rect.width > 360 && window.innerWidth > 400)) { + margin = props.marginMax; + } else { + margin = props.marginMin; + } +}; - if (props.contentMax) { - content.value!.style.maxWidth = `${props.contentMax}px`; - } +onMounted(() => { + ro = new ResizeObserver((entries) => { + /* iOSが対応していない + adjust({ + width: entries[0].borderBoxSize[0].inlineSize, + height: entries[0].borderBoxSize[0].blockSize, }); - - onUnmounted(() => { - ro.disconnect(); + */ + adjust({ + width: root!.offsetWidth, + height: root!.offsetHeight, }); + }); + ro.observe(root!); + + if (props.contentMax) { + content!.style.maxWidth = `${props.contentMax}px`; + } +}); - return { - root, - content, - margin, - }; - }, +onUnmounted(() => { + ro.disconnect(); }); </script> |