Skip to content
Open
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
22 changes: 22 additions & 0 deletions contentcuration/contentcuration/frontend/shared/utils/icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ContentKindsNames } from 'shared/leUtils/ContentKinds';

const EMPTY = '_empty';
const CONTENT_KIND_ICONS = {
[ContentKindsNames.TOPIC]: 'topic',
[ContentKindsNames.TOPIC + EMPTY]: 'emptyTopic',
[ContentKindsNames.VIDEO]: 'video',
[ContentKindsNames.AUDIO]: 'audio',
[ContentKindsNames.SLIDESHOW]: 'slideshow',
[ContentKindsNames.EXERCISE]: 'exercise',
[ContentKindsNames.DOCUMENT]: 'document',
[ContentKindsNames.HTML5]: 'html5',
[ContentKindsNames.ZIM]: 'html5',
};

export function getContentKindIcon(kind, isEmpty = false) {
const icon = (isEmpty ? [kind + EMPTY] : []).concat([kind]).find(k => k in CONTENT_KIND_ICONS);
if (!icon) {
throw new Error(`Icon not found for content kind: ${kind}`);
}
return CONTENT_KIND_ICONS[icon];
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
>
<VCard
ref="thumbnail"
class="thumbnail"
class="thumbnail-wrapper"
data-test="loading"
>
<VLayout
Expand Down Expand Up @@ -355,7 +355,7 @@
border: 2px solid var(--v-grey-darken2);
}

.thumbnail {
.thumbnail-wrapper {
padding: 28% 0;
/* stylelint-disable-next-line custom-property-pattern */
border-color: var(--v-greyBorder-base) !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
[kind]: compact,
'icon-only': compact,
nothumbnail: !showThumbnail && !compact,
'with-caption': showCaption,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can I preview before / after of thumbnails with captions?

}"
:style="{ 'max-width': maxWidth }"
>
<VLayout
v-if="kind && !printing && showKind && !compact"
v-if="showCaption"
tag="figcaption"
row
align-center
Expand All @@ -21,12 +22,10 @@
shrink
class="px-1"
>
<VIconWrapper
v-if="!compact"
dark
small
:aria-label="kindTitle"
v-text="icon"
<KIcon
:icon="icon"
class="icon-thumbnail"
:style="{ fill: $themeTokens.textInverted }"
/>
</VFlex>
<VFlex shrink>
Expand All @@ -46,51 +45,42 @@
v-else-if="printing"
class="printable-icon"
>
<VIconWrapper
:color="$vuetify.theme[kind]"
<KIcon
class="icon-thumbnail"
:icon="icon"
capture-as-image
>
{{ icon }}
</VIconWrapper>
/>
</div>

<!-- Bury icon within SVG so it's more responsive, since font-size scaling is more difficult -->
<svg
<div
v-else-if="compact"
viewBox="0 0 24 24"
:aria-label="kindTitle"
class="thumbnail-image"
class="kicon-wrapper"
>
<KIcon
icon="infoOutline"
:x="+10"
:y="y + 20"
:style="{ fill: '#ffffff' }"
:icon="icon"
class="icon-thumbnail"
:style="{ fill: $themeTokens.textInverted }"
/>
</svg>
<svg
</div>
<div
v-else
viewBox="0 0 40 40"
:aria-label="kindTitle"
class="nothumbnail-image"
:class="$isRTL ? 'rtl-image' : 'ltr-image'"
class="kicon-wrapper"
>
<KIcon
icon="image"
:x="-3"
:y="y - 14"
:style="{ fill: '#999999' }"
class="icon-thumbnail"
:style="{ fill: $themePalette.grey.v_400, width: '40%', height: '50px' }"
/>
</svg>
</div>
</figure>

</template>


<script>

import { getContentKindIcon } from 'shared/utils/icons';
import { constantsTranslationMixin, printingMixin } from 'shared/mixins';
import { getContentKindIcon } from 'shared/vuetify/icons';

export default {
name: 'Thumbnail',
Expand Down Expand Up @@ -136,22 +126,15 @@
},
},
computed: {
y() {
switch (this.kind) {
case 'exercise':
return 28;
case 'topic':
case 'audio':
default:
return 26;
}
},
objectFit() {
return this.kind ? 'cover' : 'contain';
},
icon() {
return getContentKindIcon(this.kind, this.isEmpty);
},
showCaption() {
return this.kind && !this.printing && this.showKind && !this.compact;
},
thumbnailSrc() {
return this.encoding && this.encoding.base64 ? this.encoding.base64 : this.src;
},
Expand All @@ -176,16 +159,8 @@
<style lang="scss" scoped>

$caption-height: 25px;
$svg-scale: 1.25;
$aspect-ratio: 9 / 16;

$aspect-percentage: $aspect-ratio * 100%;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's referenced from .thumbnail, is that style actually taking effect? Seems like something that was closely interconnected with the calculations we're now removing. So just double-checking if this is something to be cleaned up as well.

$half-aspect-percentage: $aspect-percentage / 2;

$svg-width: $aspect-percentage / $svg-scale;
$svg-top: $half-aspect-percentage - ($svg-width / 2);
$svg-width-quarter: $svg-width / 4;
$svg-left-position: 50% - $svg-width-quarter;

.thumbnail {
position: relative;
Expand Down Expand Up @@ -218,15 +193,11 @@
line-height: 11px;
}

.thumbnail-image,
.nothumbnail-image {
.thumbnail-image {
position: absolute;
display: block;
}

img.thumbnail-image {
bottom: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
overflow: hidden; // Don't show alt text outside of img boundaries
Expand All @@ -236,61 +207,6 @@
}
}

svg.thumbnail-image {
top: 0;
left: $svg-left-position;
width: $svg-width-quarter;
margin: 0 auto;
overflow: visible;

.icon-only & {
top: 18%;
left: 21%;
display: block;
width: 55%;

[dir='rtl'] & {
left: -10px;
}
}

text {
font-size: 1.8em;
line-height: 1.8em;
}
}

svg.nothumbnail-image {
top: 0;
width: $svg-width;
margin: 0 auto;
overflow: visible;

&.ltr-image {
left: 36%;
}

&.rtl-image {
right: 66%;
}

.caption + & {
top: calc(#{$caption-height / 2} + #{$svg-top});
}

.icon-only & {
top: 18%;
left: 21%;
display: block;
width: 55%;
}

text {
font-size: 1em;
line-height: 1em;
}
}

.printable-icon {
width: 100%;
height: 0;
Expand All @@ -302,4 +218,23 @@
}
}

.kicon-wrapper {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;

.icon-thumbnail {
top: 0;
}
}

.thumbnail.with-caption {
.kicon-wrapper {
height: calc(100% - #{$caption-height});
}
}

</style>