Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

引用ブロックを折り畳めるように #4051

Merged
merged 7 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,25 @@
:user-id="message.userId"
/>
<div :class="$style.messageContents">
<markdown-content :content="content" />
<div
:id="markdownId"
ref="contentRef"
:class="[$style.markdownContainer, oversized && $style.oversized]"
:data-expanded="!isFold"
>
<markdown-content :content="content" />
</div>
<fold-button
v-if="oversized"
:is-fold="isFold"
:class="$style.foldButton"
:aria-expanded="!isFold"
:aria-controls="markdownId"
background="none"
show-icon
small
@click="toggleFold"
/>
</div>
<message-quote-list-item-footer :class="$style.footer" :message="message" />
</div>
Expand All @@ -24,12 +42,16 @@
import UserIcon from '/@/components/UI/UserIcon.vue'
import MessageQuoteListItemHeader from './MessageQuoteListItemHeader.vue'
import MessageQuoteListItemFooter from './MessageQuoteListItemFooter.vue'
import { computed } from 'vue'
import { computed, ref } from 'vue'
import type { MessageId, ChannelId, DMChannelId } from '/@/types/entity-ids'
import { useMessagesView } from '/@/store/domain/messagesView'
import { useMessagesStore } from '/@/store/entities/messages'
import { useChannelsStore } from '/@/store/entities/channels'
import MarkdownContent from '/@/components/UI/MarkdownContent.vue'
import useToggle from '/@/composables/utils/useToggle'
import FoldButton from '/@/components/UI/FoldButton.vue'
import { randomString } from '/@/lib/basic/randomString'
import useBoxSize from '/@/composables/dom/useBoxSize'

const props = defineProps<{
parentMessageChannelId: ChannelId | DMChannelId
Expand All @@ -52,6 +74,17 @@ const shouldShow = computed(
const content = computed(
() => renderedContentMap.value.get(props.messageId) ?? ''
)

const MAX_HEIGHT = 200

const contentRef = ref<HTMLDivElement | null>(null)
const { height } = useBoxSize(contentRef)
const oversized = computed(
() => height.value !== undefined && height.value >= MAX_HEIGHT
)

const markdownId = randomString()
ras0q marked this conversation as resolved.
Show resolved Hide resolved
const { value: isFold, toggle: toggleFold } = useToggle(true)
</script>

<style lang="scss" module>
Expand Down Expand Up @@ -98,12 +131,56 @@ const content = computed(
padding-top: 4px;
padding-left: 8px;
min-width: 0;
position: relative;

pre {
white-space: pre-wrap;
}
}

$message-max-height: 200px;
$fold-button-height: 28px;
$mask-image: linear-gradient(
black,
black calc(100% - $fold-button-height * 2),
rgba(0, 0, 0, 0.1) calc(100% - $fold-button-height),
transparent 100%
);

.markdownContainer {
&.oversized {
&[data-expanded='false'] {
max-height: $message-max-height;
overflow: hidden;
overflow: clip;
-webkit-mask-image: $mask-image;
mask-image: $mask-image;
}

&[data-expanded='true'] {
max-height: unset;
padding-bottom: $fold-button-height;
}
}
}

.foldButton {
@include color-text-primary;
cursor: pointer;
position: absolute;
left: 8px;
bottom: 0;

@media (any-hover: hover) {
&:hover {
@include background-tertiary;
}
}
&:focus-visible {
@include background-tertiary;
}
}

.footer {
grid-area: footer;
margin-top: 4px;
Expand Down
21 changes: 17 additions & 4 deletions src/components/UI/FoldButton.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<button :class="$style.button" :data-background="background">
<button
:class="[$style.button, small && $style.small]"
:data-background="background"
>
<a-icon
v-if="showIcon"
:name="isFold ? 'down' : 'up'"
Expand All @@ -15,18 +18,22 @@ import AIcon from '/@/components/UI/AIcon.vue'

interface Props extends /* @vue-ignore */ ButtonHTMLAttributes {
showIcon?: boolean
background?: 'primary' | 'secondary' | 'tertiary'
background?: 'primary' | 'secondary' | 'tertiary' | 'none'
isFold: boolean
small?: boolean
}

withDefaults(defineProps<Props>(), {
showIcon: false,
background: 'tertiary'
background: 'tertiary',
small: false
})
</script>

<style lang="scss" module>
.button {
@include color-text-primary;

cursor: pointer;

display: flex;
Expand All @@ -36,12 +43,15 @@ withDefaults(defineProps<Props>(), {
font-weight: bold;
border-radius: 4px;
padding: 0 24px;
&.small {
padding: 0 8px;
}

min-height: 24px;
font-size: 12px;
line-height: 1.5;
width: fit-content;

color: $theme-text-primary-default;
&[data-background='primary'] {
background-color: $theme-ui-primary-default;
}
Expand All @@ -55,5 +65,8 @@ withDefaults(defineProps<Props>(), {
.icon {
margin-left: -12px;
}
&.small .icon {
margin-left: -4px;
}
}
</style>