|
| 1 | +<!-- |
| 2 | + This source file is part of the Swift.org open source project |
| 3 | +
|
| 4 | + Copyright (c) 2022 Apple Inc. and the Swift project authors |
| 5 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | +
|
| 7 | + See https://swift.org/LICENSE.txt for license information |
| 8 | + See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +--> |
| 10 | + |
| 11 | +<template> |
| 12 | + <Card |
| 13 | + class="reference-card-grid-item" |
| 14 | + :url="item.url" |
| 15 | + :image="imageReferences.card" |
| 16 | + :title="item.title" |
| 17 | + floating-style |
| 18 | + :size="cardSize" |
| 19 | + :link-text="linkText" |
| 20 | + > |
| 21 | + <template v-if="!imageReferences.card" #cover="{ classes }"> |
| 22 | + <div :class="classes" class="reference-card-grid-item__image"> |
| 23 | + <TopicTypeIcon |
| 24 | + :type="item.role" |
| 25 | + :image-override="references[imageReferences.icon]" |
| 26 | + class="reference-card-grid-item__icon" |
| 27 | + /> |
| 28 | + </div> |
| 29 | + </template> |
| 30 | + <ContentNode v-if="!compact" :content="item.abstract" /> |
| 31 | + </Card> |
| 32 | +</template> |
| 33 | + |
| 34 | +<script> |
| 35 | +import Card from 'docc-render/components/Card.vue'; |
| 36 | +import TopicTypeIcon from 'docc-render/components/TopicTypeIcon.vue'; |
| 37 | +import { TopicRole } from 'docc-render/constants/roles'; |
| 38 | +import CardSize from 'docc-render/constants/CardSize'; |
| 39 | +
|
| 40 | +export const ROLE_LINK_TEXT = { |
| 41 | + [TopicRole.article]: 'Read article', |
| 42 | + [TopicRole.overview]: 'Start tutorial', |
| 43 | + [TopicRole.collection]: 'View API collection', |
| 44 | + [TopicRole.symbol]: 'View symbol', |
| 45 | + [TopicRole.sampleCode]: 'View sample code', |
| 46 | +}; |
| 47 | +
|
| 48 | +export default { |
| 49 | + name: 'TopicsLinkCardGridItem', |
| 50 | + components: { |
| 51 | + TopicTypeIcon, |
| 52 | + Card, |
| 53 | + ContentNode: () => import('docc-render/components/ContentNode.vue'), |
| 54 | + }, |
| 55 | + inject: ['references'], |
| 56 | + props: { |
| 57 | + item: { |
| 58 | + type: Object, |
| 59 | + required: true, |
| 60 | + }, |
| 61 | + compact: { |
| 62 | + type: Boolean, |
| 63 | + default: true, |
| 64 | + }, |
| 65 | + }, |
| 66 | + computed: { |
| 67 | + imageReferences: ({ item }) => (item.images || []).reduce((all, current) => { |
| 68 | + // eslint-disable-next-line no-param-reassign |
| 69 | + all[current.type] = current.identifier; |
| 70 | + return all; |
| 71 | + }, { icon: null, card: null }), |
| 72 | + linkText: ({ compact, item }) => (compact ? '' : (ROLE_LINK_TEXT[item.role] || 'Learn more')), |
| 73 | + cardSize: ({ compact }) => (compact ? undefined : CardSize.large), |
| 74 | + }, |
| 75 | +}; |
| 76 | +</script> |
| 77 | + |
| 78 | +<style scoped lang='scss'> |
| 79 | +@import 'docc-render/styles/_core.scss'; |
| 80 | +
|
| 81 | +.reference-card-grid-item { |
| 82 | + &__image { |
| 83 | + display: flex; |
| 84 | + align-items: center; |
| 85 | + justify-content: center; |
| 86 | + font-size: 80px; |
| 87 | + background-color: var(--color-fill-gray-quaternary); |
| 88 | + } |
| 89 | +
|
| 90 | + &__icon { |
| 91 | + display: flex; |
| 92 | + margin: 0; |
| 93 | + } |
| 94 | +} |
| 95 | +</style> |
0 commit comments