|
| 1 | +<script lang="ts"> |
| 2 | +import { defineComponent, PropType } from "vue"; |
| 3 | +import Modal from "bootstrap/js/dist/modal"; |
| 4 | +
|
| 5 | +// A share/action item rendered as a card. `href` items open an external link |
| 6 | +// (e.g. a previous export); the others emit their `id` so the parent (the editor) |
| 7 | +// runs the matching method. `disabled` items render greyed-out and inert. |
| 8 | +export interface ShareItem { |
| 9 | + id: string; |
| 10 | + icon: string; |
| 11 | + /** i18n key for the card title; ignored when `label` is given. */ |
| 12 | + labelKey?: string; |
| 13 | + /** pre-translated title (use when the label needs interpolation). */ |
| 14 | + label?: string; |
| 15 | + descriptionKey?: string; |
| 16 | + disabled?: boolean; |
| 17 | + href?: string; |
| 18 | +} |
| 19 | +
|
| 20 | +export interface ShareSection { |
| 21 | + headingKey?: string; |
| 22 | + items: ShareItem[]; |
| 23 | +} |
| 24 | +
|
| 25 | +export interface ShareTab { |
| 26 | + id: string; |
| 27 | + labelKey: string; |
| 28 | + sections: ShareSection[]; |
| 29 | +} |
| 30 | +
|
| 31 | +// Tabbed card chooser that replaces the editor's old "menu" dropdown. It groups |
| 32 | +// every share / publish / GitHub / local-folder action into tabs of cards. The |
| 33 | +// component is purely presentational: the parent passes the tabs (built from its |
| 34 | +// reactive state) and handles the emitted action ids. |
| 35 | +export default defineComponent({ |
| 36 | + name: "ShareModal", |
| 37 | +
|
| 38 | + props: { |
| 39 | + tabs: { |
| 40 | + type: Array as PropType<ShareTab[]>, |
| 41 | + required: true, |
| 42 | + }, |
| 43 | + }, |
| 44 | +
|
| 45 | + emits: ["action"], |
| 46 | +
|
| 47 | + data() { |
| 48 | + return { |
| 49 | + active: "" as string, |
| 50 | + modal: null as Modal | null, |
| 51 | + }; |
| 52 | + }, |
| 53 | +
|
| 54 | + methods: { |
| 55 | + open() { |
| 56 | + if (!this.active && this.tabs.length) this.active = this.tabs[0].id; |
| 57 | + if (!this.modal) { |
| 58 | + this.modal = new Modal(this.$refs.el as Element); |
| 59 | + } |
| 60 | + this.modal.show(); |
| 61 | + }, |
| 62 | +
|
| 63 | + cardTag(item: ShareItem): string { |
| 64 | + return !item.disabled && item.href ? "a" : "button"; |
| 65 | + }, |
| 66 | +
|
| 67 | + onCardClick(item: ShareItem) { |
| 68 | + if (item.disabled) return; |
| 69 | + // href cards keep their default behaviour (open in a new tab); just close |
| 70 | + // the modal. Action cards emit their id for the parent to handle. |
| 71 | + this.modal?.hide(); |
| 72 | + if (!item.href) this.$emit("action", item.id); |
| 73 | + }, |
| 74 | + }, |
| 75 | +}); |
| 76 | +</script> |
| 77 | + |
| 78 | +<template> |
| 79 | + <div ref="el" class="modal fade" tabindex="-1" aria-hidden="true"> |
| 80 | + <div class="modal-dialog modal-lg modal-dialog-centered"> |
| 81 | + <div class="modal-content"> |
| 82 | + <div class="modal-header"> |
| 83 | + <h5 class="modal-title">{{ $t("share.modalTitle") }}</h5> |
| 84 | + <button |
| 85 | + type="button" |
| 86 | + class="btn-close" |
| 87 | + data-bs-dismiss="modal" |
| 88 | + :aria-label="$t('card.close')" |
| 89 | + ></button> |
| 90 | + </div> |
| 91 | + <div class="modal-body"> |
| 92 | + <ul class="nav nav-tabs mb-3"> |
| 93 | + <li v-for="tab in tabs" :key="tab.id" class="nav-item"> |
| 94 | + <button |
| 95 | + type="button" |
| 96 | + class="nav-link" |
| 97 | + :class="{ active: active === tab.id }" |
| 98 | + @click="active = tab.id" |
| 99 | + > |
| 100 | + {{ $t(tab.labelKey) }} |
| 101 | + </button> |
| 102 | + </li> |
| 103 | + </ul> |
| 104 | + |
| 105 | + <template v-for="tab in tabs" :key="tab.id"> |
| 106 | + <div v-if="active === tab.id"> |
| 107 | + <template v-for="(section, i) in tab.sections" :key="i"> |
| 108 | + <h6 |
| 109 | + v-if="section.headingKey" |
| 110 | + class="share-section-heading text-uppercase text-muted" |
| 111 | + > |
| 112 | + {{ $t(section.headingKey) }} |
| 113 | + </h6> |
| 114 | + <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3 mb-2"> |
| 115 | + <div v-for="item in section.items" :key="item.id" class="col"> |
| 116 | + <component |
| 117 | + :is="cardTag(item)" |
| 118 | + class="share-card" |
| 119 | + :class="{ 'share-card--disabled': item.disabled }" |
| 120 | + :href="!item.disabled && item.href ? item.href : null" |
| 121 | + :target="item.href ? '_blank' : null" |
| 122 | + :disabled="item.disabled || null" |
| 123 | + @click="onCardClick(item)" |
| 124 | + > |
| 125 | + <i class="bi share-card-icon" :class="item.icon"></i> |
| 126 | + <span class="share-card-title"> |
| 127 | + {{ item.label || (item.labelKey ? $t(item.labelKey) : "") }} |
| 128 | + </span> |
| 129 | + <small |
| 130 | + v-if="item.descriptionKey" |
| 131 | + class="share-card-desc text-muted" |
| 132 | + > |
| 133 | + {{ $t(item.descriptionKey) }} |
| 134 | + </small> |
| 135 | + </component> |
| 136 | + </div> |
| 137 | + </div> |
| 138 | + </template> |
| 139 | + </div> |
| 140 | + </template> |
| 141 | + </div> |
| 142 | + </div> |
| 143 | + </div> |
| 144 | + </div> |
| 145 | +</template> |
| 146 | + |
| 147 | +<style scoped> |
| 148 | +.share-section-heading { |
| 149 | + font-size: 0.75rem; |
| 150 | + letter-spacing: 0.04em; |
| 151 | + margin: 0.75rem 0 0.4rem; |
| 152 | +} |
| 153 | +
|
| 154 | +.share-card { |
| 155 | + display: flex; |
| 156 | + flex-direction: column; |
| 157 | + align-items: center; |
| 158 | + text-align: center; |
| 159 | + width: 100%; |
| 160 | + height: 100%; |
| 161 | + gap: 0.4rem; |
| 162 | + padding: 1.1rem 0.9rem; |
| 163 | + background: var(--bs-body-bg, #fff); |
| 164 | + border: 1px solid var(--bs-border-color, #dee2e6); |
| 165 | + border-radius: 0.75rem; |
| 166 | + cursor: pointer; |
| 167 | + text-decoration: none; |
| 168 | + color: inherit; |
| 169 | + transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease; |
| 170 | +} |
| 171 | +
|
| 172 | +.share-card:hover, |
| 173 | +.share-card:focus-visible { |
| 174 | + transform: translateY(-3px); |
| 175 | + box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12); |
| 176 | + border-color: var(--bs-primary, #0d6efd); |
| 177 | + outline: none; |
| 178 | + color: inherit; |
| 179 | +} |
| 180 | +
|
| 181 | +.share-card--disabled { |
| 182 | + cursor: not-allowed; |
| 183 | + opacity: 0.55; |
| 184 | +} |
| 185 | +
|
| 186 | +.share-card--disabled:hover, |
| 187 | +.share-card--disabled:focus-visible { |
| 188 | + transform: none; |
| 189 | + box-shadow: none; |
| 190 | + border-color: var(--bs-border-color, #dee2e6); |
| 191 | +} |
| 192 | +
|
| 193 | +.share-card--disabled .share-card-icon { |
| 194 | + color: var(--bs-secondary, #6c757d); |
| 195 | +} |
| 196 | +
|
| 197 | +.share-card-icon { |
| 198 | + font-size: 2rem; |
| 199 | + line-height: 1; |
| 200 | + color: var(--bs-primary, #0d6efd); |
| 201 | +} |
| 202 | +
|
| 203 | +.share-card-title { |
| 204 | + font-weight: 600; |
| 205 | +} |
| 206 | +
|
| 207 | +.share-card-desc { |
| 208 | + font-size: 0.8125rem; |
| 209 | + line-height: 1.3; |
| 210 | +} |
| 211 | +</style> |
0 commit comments