|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2018 Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | + |
| 6 | +<script setup lang="ts"> |
| 7 | +import { ref, computed } from 'vue' |
| 8 | +import { DateTime } from 'luxon' |
| 9 | +import { t, n } from '@nextcloud/l10n' |
| 10 | +import { getDatesFromOption } from '@/composables/optionDateTime' |
| 11 | +
|
| 12 | +import NcModal from '@/components/Base/modules/CustomNcModal.vue' |
| 13 | +import MagnifyExpandIcon from 'vue-material-design-icons/MagnifyExpand.vue' |
| 14 | +import CalendarBlankOutlineIcon from 'vue-material-design-icons/CalendarBlankOutline.vue' |
| 15 | +import FormatListBulletedSquareIcon from 'vue-material-design-icons/FormatListBulletedSquare.vue' |
| 16 | +
|
| 17 | +import OptionItem from '@/components/Options/OptionItem.vue' |
| 18 | +import { useOptionsStore } from '@/stores/options' |
| 19 | +import { usePollStore } from '@/stores/poll' |
| 20 | +
|
| 21 | +defineOptions({ |
| 22 | + inheritAttrs: false, |
| 23 | +}) |
| 24 | +
|
| 25 | +const optionsStore = useOptionsStore() |
| 26 | +const pollStore = usePollStore() |
| 27 | +
|
| 28 | +const MAX_OPTIONS = 5 |
| 29 | +
|
| 30 | +const optionsExpanded = ref(false) |
| 31 | +
|
| 32 | +const previewOptions = computed(() => optionsStore.options.slice(0, MAX_OPTIONS)) |
| 33 | +
|
| 34 | +function optionLabel(option: (typeof optionsStore.options)[0]): string { |
| 35 | + if (pollStore.type === 'datePoll') { |
| 36 | + const { optionStart, optionEnd, isSameTime, isFullDays, isSameDay } = |
| 37 | + getDatesFromOption(option) |
| 38 | + const fmt = isFullDays ? DateTime.DATE_MED : DateTime.DATETIME_MED |
| 39 | + const start = optionStart.toLocaleString(fmt) |
| 40 | + if (isSameTime || (isFullDays && isSameDay)) return start |
| 41 | + return `${start} – ${optionEnd.toLocaleString(fmt)}` |
| 42 | + } |
| 43 | + return option.text |
| 44 | +} |
| 45 | +</script> |
| 46 | + |
| 47 | +<template> |
| 48 | + <div |
| 49 | + v-if="optionsStore.options.length" |
| 50 | + v-bind="$attrs" |
| 51 | + class="options_preview" |
| 52 | + role="button" |
| 53 | + :aria-label="t('polls', 'Expand options')" |
| 54 | + @click="optionsExpanded = true"> |
| 55 | + <span class="options_preview__expand" aria-hidden="true"> |
| 56 | + <MagnifyExpandIcon :size="20" /> |
| 57 | + </span> |
| 58 | + <h3>{{ t('polls', 'Available options') }}</h3> |
| 59 | + <ul> |
| 60 | + <li |
| 61 | + v-for="option in previewOptions" |
| 62 | + :key="option.id" |
| 63 | + class="options_preview__item"> |
| 64 | + <CalendarBlankOutlineIcon |
| 65 | + v-if="pollStore.type === 'datePoll'" |
| 66 | + :size="16" /> |
| 67 | + <FormatListBulletedSquareIcon v-else :size="16" /> |
| 68 | + {{ optionLabel(option) }} |
| 69 | + </li> |
| 70 | + </ul> |
| 71 | + <p |
| 72 | + v-if="optionsStore.options.length > MAX_OPTIONS" |
| 73 | + class="options_preview__more"> |
| 74 | + {{ |
| 75 | + n( |
| 76 | + 'polls', |
| 77 | + '+ %n more option', |
| 78 | + '+ %n more options', |
| 79 | + optionsStore.options.length - MAX_OPTIONS, |
| 80 | + ) |
| 81 | + }} |
| 82 | + </p> |
| 83 | + </div> |
| 84 | + |
| 85 | + <NcModal |
| 86 | + v-if="optionsExpanded" |
| 87 | + :name="t('polls', 'Available options')" |
| 88 | + size="normal" |
| 89 | + close-on-click-outside |
| 90 | + @close="optionsExpanded = false"> |
| 91 | + <ul class="options_preview__modal"> |
| 92 | + <OptionItem |
| 93 | + v-for="option in optionsStore.options" |
| 94 | + :key="option.id" |
| 95 | + :option="option" |
| 96 | + tag="li" /> |
| 97 | + </ul> |
| 98 | + </NcModal> |
| 99 | +</template> |
| 100 | + |
| 101 | +<style lang="scss" scoped> |
| 102 | +.options_preview { |
| 103 | + position: relative; |
| 104 | + cursor: zoom-in; |
| 105 | +
|
| 106 | + * { |
| 107 | + cursor: zoom-in; |
| 108 | + } |
| 109 | +
|
| 110 | + h3 { |
| 111 | + margin: 0 0 0.5rem; |
| 112 | + } |
| 113 | +
|
| 114 | + ul { |
| 115 | + list-style: none; |
| 116 | + padding: 0; |
| 117 | + margin: 0; |
| 118 | + } |
| 119 | +
|
| 120 | + .options_preview__item { |
| 121 | + display: flex; |
| 122 | + align-items: center; |
| 123 | + gap: 0.4rem; |
| 124 | + white-space: nowrap; |
| 125 | + overflow: hidden; |
| 126 | + text-overflow: ellipsis; |
| 127 | + padding: 0.25rem 0; |
| 128 | + border-bottom: 1px solid var(--color-border); |
| 129 | + background: transparent; |
| 130 | +
|
| 131 | + &:last-child { |
| 132 | + border-bottom: none; |
| 133 | + } |
| 134 | + } |
| 135 | +
|
| 136 | + .options_preview__expand { |
| 137 | + position: absolute; |
| 138 | + top: 0.25rem; |
| 139 | + inset-inline-end: 0.25rem; |
| 140 | + z-index: 1; |
| 141 | + display: flex; |
| 142 | + align-items: center; |
| 143 | + justify-content: center; |
| 144 | + width: 44px; |
| 145 | + height: 44px; |
| 146 | + border-radius: var(--border-radius-large); |
| 147 | + background-color: var(--color-background-hover); |
| 148 | + border: 2px solid var(--color-border); |
| 149 | + color: var(--color-main-text); |
| 150 | + pointer-events: none; |
| 151 | + opacity: 0; |
| 152 | + transition: opacity 0.2s; |
| 153 | + } |
| 154 | +
|
| 155 | + &:hover .options_preview__expand { |
| 156 | + opacity: 1; |
| 157 | + } |
| 158 | + .options_preview__more { |
| 159 | + text-align: center; |
| 160 | + font-weight: 600; |
| 161 | + } |
| 162 | +} |
| 163 | +
|
| 164 | +.options_preview__modal { |
| 165 | + list-style: none; |
| 166 | + padding: 1rem; |
| 167 | + margin: 0; |
| 168 | +
|
| 169 | + .options_preview__item { |
| 170 | + padding: 0.4rem 0; |
| 171 | + border-bottom: 1px solid var(--color-border); |
| 172 | +
|
| 173 | + &:last-child { |
| 174 | + border-bottom: none; |
| 175 | + } |
| 176 | + } |
| 177 | +} |
| 178 | +</style> |
0 commit comments