Skip to content

Commit

Permalink
add custom validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOXDi committed Jul 30, 2024
1 parent 811576f commit 02be998
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions lib/KCard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@
import BaseCard from './BaseCard.vue';
const Layouts = {
HORIZONTAL: 'horizontal',
VERTICAL: 'vertical'
};
const Thumbnail_Displays = {
NONE: 'none',
SMALL: 'small',
LARGE: 'large'
};
function cardValidator(allowedValues, propName) {
return function(value) {
if (!Object.values(allowedValues).includes(value)) {
throw new Error(`Invalid ${propName} value: '${value}'. Allowed values are: ${Object.values(allowedValues).join(', ')}`);
}
return true;
}
}
export default {
name: 'KCard',
components: { BaseCard },
Expand Down Expand Up @@ -107,19 +127,20 @@
* @param {String} value - The layout value.
* @returns {Boolean} - True if the value is not empty, false otherwise.
*/
layout: {
type: String,
default: 'horizontal',
layout: {
type: String,
default: Layouts .HORIZONTAL,
validator: cardValidator(Layouts, 'layout')
},
/**
* Controls how the thumbnail appears in the card.
* Expected Options: 'none' (default), 'small', or 'large'.
* */
thumbnailDisplay: {
type: String,
required: false,
default: 'none',
},
thumbnailDisplay: {
type: String,
default: Thumbnail_Displays.NONE,
validator: cardValidator(Thumbnail_Displays, 'thumbnailDisplay')
},
/**
* Sets the thumbnail path.
* Defaults to null if not provided.
Expand Down

0 comments on commit 02be998

Please sign in to comment.