summaryrefslogtreecommitdiff
path: root/packages/client/src/components
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2022-06-20 13:20:28 +0900
committerGitHub <noreply@github.com>2022-06-20 13:20:28 +0900
commit30a39a296dcea701deb1cf5ac323aa1e6bcee13f (patch)
tree60d62d0af304b64af3c6178563ce3b7e612cfb1b /packages/client/src/components
parentfeat: Add Badge Image to Push Notification (#8012) (diff)
downloadsharkey-30a39a296dcea701deb1cf5ac323aa1e6bcee13f.tar.gz
sharkey-30a39a296dcea701deb1cf5ac323aa1e6bcee13f.tar.bz2
sharkey-30a39a296dcea701deb1cf5ac323aa1e6bcee13f.zip
refactor: チャットルームをComposition API化 (#8850)
* pick form * pick message * pick room * fix lint * fix scroll? * fix scroll.ts * fix directives/sticky-container * update global/sticky-container.vue * fix, :art: * test.1
Diffstat (limited to 'packages/client/src/components')
-rw-r--r--packages/client/src/components/global/sticky-container.vue92
1 files changed, 42 insertions, 50 deletions
diff --git a/packages/client/src/components/global/sticky-container.vue b/packages/client/src/components/global/sticky-container.vue
index 89d397f082..98a7ee9c30 100644
--- a/packages/client/src/components/global/sticky-container.vue
+++ b/packages/client/src/components/global/sticky-container.vue
@@ -1,71 +1,63 @@
<template>
<div ref="rootEl">
<slot name="header"></slot>
- <div ref="bodyEl">
+ <div ref="bodyEl" :data-sticky-container-header-height="headerHeight">
<slot></slot>
</div>
</div>
</template>
-<script lang="ts">
-import { defineComponent, onMounted, onUnmounted, ref } from 'vue';
+<script lang="ts" setup>
+import { onMounted, onUnmounted } from 'vue';
-export default defineComponent({
- props: {
- autoSticky: {
- type: Boolean,
- required: false,
- default: false,
- },
- },
+const props = withDefaults(defineProps<{
+ autoSticky?: boolean;
+}>(), {
+ autoSticky: false,
+});
- setup(props, context) {
- const rootEl = ref<HTMLElement>(null);
- const bodyEl = ref<HTMLElement>(null);
+const rootEl = $ref<HTMLElement>();
+const bodyEl = $ref<HTMLElement>();
- const calc = () => {
- const currentStickyTop = getComputedStyle(rootEl.value).getPropertyValue('--stickyTop') || '0px';
+let headerHeight = $ref<string | undefined>();
- const header = rootEl.value.children[0];
- if (header === bodyEl.value) {
- bodyEl.value.style.setProperty('--stickyTop', currentStickyTop);
- } else {
- bodyEl.value.style.setProperty('--stickyTop', `calc(${currentStickyTop} + ${header.offsetHeight}px)`);
+const calc = () => {
+ const currentStickyTop = getComputedStyle(rootEl).getPropertyValue('--stickyTop') || '0px';
- if (props.autoSticky) {
- header.style.setProperty('--stickyTop', currentStickyTop);
- header.style.position = 'sticky';
- header.style.top = 'var(--stickyTop)';
- header.style.zIndex = '1';
- }
- }
- };
+ const header = rootEl.children[0] as HTMLElement;
+ if (header === bodyEl) {
+ bodyEl.style.setProperty('--stickyTop', currentStickyTop);
+ } else {
+ bodyEl.style.setProperty('--stickyTop', `calc(${currentStickyTop} + ${header.offsetHeight}px)`);
+ headerHeight = header.offsetHeight.toString();
- onMounted(() => {
- calc();
+ if (props.autoSticky) {
+ header.style.setProperty('--stickyTop', currentStickyTop);
+ header.style.position = 'sticky';
+ header.style.top = 'var(--stickyTop)';
+ header.style.zIndex = '1';
+ }
+ }
+};
- const observer = new MutationObserver(() => {
- window.setTimeout(() => {
- calc();
- }, 100);
- });
+const observer = new MutationObserver(() => {
+ window.setTimeout(() => {
+ calc();
+ }, 100);
+});
- observer.observe(rootEl.value, {
- attributes: false,
- childList: true,
- subtree: false,
- });
+onMounted(() => {
+ calc();
- onUnmounted(() => {
- observer.disconnect();
- });
- });
+ observer.observe(rootEl, {
+ attributes: false,
+ childList: true,
+ subtree: false,
+ });
+});
- return {
- rootEl,
- bodyEl,
- };
- },
+onUnmounted(() => {
+ observer.disconnect();
});
</script>