Skip to content

Commit

Permalink
restores code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOXDi committed Aug 2, 2024
1 parent 675d121 commit 6b0a82c
Showing 1 changed file with 84 additions and 20 deletions.
104 changes: 84 additions & 20 deletions lib/KCard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@
:title="title"
:headingLevel="headingLevel"
:titleLines="titleLines"
:class="rootClasses"
:class="['k-card',rootClasses]"
:headingStyles="headingStyles"
>
<template v-if="$slots.title" #title>
<div
data-test="title"
class="title"
>

<!-- @slot Optional slot section containing the title contents, should not contain a heading element. -->
<slot name="title"></slot>
</div>
<!-- @slot Optional slot section containing the title contents, should not contain a heading element. -->
<slot name="title"></slot>
</template>
<template #default>
<div class="thumbnail">
<!--
Render KImg even if thumbnailSrc is not provided since in that case
KImg
-->
<KImg
:src="thumbnailSrc"
:scaleType="thumbnailScaleType"
:aspectRatio="thumbnailAspectRatio"
:isDecorative="true"
:appearanceOverrides="thumbnailStyles"
/>
<!--
This is a duplicate of the same slot in KImg. I didn't find a way to utilize
KImg's placeholder slot from here, likely because this part of code is nested
in one slot already
Show it even when thumbnail source is provided - then the placeholder serves
as progressive loading experience.
-->
<span
v-if="$slots.thumbnailPlaceholder"
class="thumbnail-placeholder"
Expand Down Expand Up @@ -77,40 +82,84 @@
name: 'KCard',
components: { BaseCard, KImg },
props: {
/**
* Sets card title if provided. The title should be
* unique and descriptive to aid searching through list of links.
*/
title: {
type: String,
required: false,
default: null,
},
/**
* Sets the HTML heading level in range (h2 - h6) for the title .
*/
headingLevel: {
type: Number,
required: true,
},
/**
* An object containing the route definition for the link.
* Required and cannot be empty.
*/
to: {
type: Object,
required: true,
},
/**
* Controls card orientation. Required and cannot be empty.
* Expected Options: 'horizontal' (default) or 'vertical'.
*
* @param {String} value - The layout value.
* @returns {Boolean} - True if the value is not empty, false otherwise.
*/
layout: {
type: String,
default: 'horizontal',
validator: value => ['horizontal', 'vertical'].includes(value),
},
/**
* Controls how the thumbnail appears in the card.
* Expected Options: 'none' (default), 'small', or 'large'.
* */
thumbnailDisplay: {
type: String,
required: false,
default: 'none',
validator: value => ['none', 'small', 'large'].includes(value),
},
/**
* Sets the thumbnail path.
* Defaults to null if not provided.
*
* @type {String}
* @default null
* */
thumbnailSrc: {
type: String,
required: false,
default: null,
},
/**
* Specifies how the thumbnail scales in the card.
* Options: 'centerInside', 'contain', 'fitXY'.
* @type {String}
* @default 'centerInside'
*/
thumbnailScaleType: {
type: String,
default: 'centerInside',
validator: value => ['centerInside', 'contain', 'fitXY'].includes(value),
},
/**
* Sets the thumbnail in a specific direction on the card.
* Options: 'left', 'right'.
* Defaults to left if not provided.
*
* @type {String}
* @default left
* */
thumbnailAlign: {
type: String,
default: ThumbnailAlign.LEFT,
Expand All @@ -119,7 +168,7 @@
},
computed: {
rootClasses() {
return ['k-card', `thumbnail-${this.thumbnailAlign}`, ...this.stylesAndClasses.rootClasses];
return [`thumbnail-${this.thumbnailAlign}`, ...this.stylesAndClasses.rootClasses];
},
titleLines() {
return this.stylesAndClasses.titleLines;
Expand All @@ -133,6 +182,12 @@
thumbnailStyles() {
return this.stylesAndClasses.thumbnailStyles;
},
/*
Returns dynamic classes and few style-like data that CSS was cumbersome/impossible to use for ,or are in need of using theme, grouped by all possible combinations of layouts.
New styles and classes are meant to be added to this single-source-of-truth object so
that we can easily locate all styling being applied to a particular layout
Could be further simplified by using solely dynamic styles, but that would have detrimental effects on our auto RTL machinery and we would need to take care manually of more places.
*/
stylesAndClasses() {
const baseClasses = [];
const headingCommonStyles = {
Expand Down Expand Up @@ -229,8 +284,16 @@
$spacer: 12px;
/*
Just couple of comments that are referenced from several places:
- (1) Intentionally fixed. Cards on the same row of a grid should have the same overall height and their sections too should have the same height so that information is placed consistently. As documented, consumers need to ensure that contents provided via slots fits well or is truncated.
- (2) Solves issues with fixed height in a flex item
*/
/************* Common styles **************/
.k-card {
position: relative;
position: relative; /* basis for absolute positioning of thumbnail images */
display: flex;
flex-direction: column;
flex-wrap: nowrap;
Expand All @@ -239,24 +302,24 @@
}
.thumbnail {
position: relative;
position: relative; /* basis for absolute positioning of 'thumbnailPlaceholder' slot content */
order: 1;
}
.above-title {
order: 2;
height: 24px;
min-height: 24px;
height: 24px; /* (1) */
min-height: 24px; /* (2) */
margin: $spacer $spacer 0;
overflow: hidden;
overflow: hidden; /* (1) */
}
.below-title {
order: 4;
height: 18px;
min-height: 18px;
height: 18px; /* (1) */
min-height: 18px; /* (2) */
margin: 0 $spacer $spacer;
overflow: hidden;
overflow: hidden; /* (1) */
}
.footer {
Expand All @@ -273,9 +336,10 @@
right: 0;
bottom: 0;
left: 0;
z-index: 0;
z-index: 0; /* <img> in KImg with z-index 1 should cover the placeholder after loaded */
}
/************* Layout-specific styles *************/
.vertical {
&.with-large-thumbnail {
height: 480px;
Expand Down Expand Up @@ -310,7 +374,7 @@
.above-title,
.below-title,
.footer {
width: calc(60% - 2 * #{$spacer});
width: calc(60% - 2 * #{$spacer}); /* same as heading width defined in script */
}
&.thumbnail-left {
Expand Down

0 comments on commit 6b0a82c

Please sign in to comment.