@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
150 lines (149 loc) • 4.22 kB
JavaScript
import DtSkeletonText from "./skeleton-text.vue.js";
import { resolveComponent, openBlock, createElementBlock, normalizeClass, Fragment, renderList, createBlock } from "vue";
import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
const validator = (number) => number !== "" && !Number.isNaN(Number(number));
const _sfc_main = {
compatConfig: { MODE: 3 },
name: "DtSkeletonParagraph",
components: {
DtSkeletonText
},
props: {
/**
* Quantity of rows to display
*/
rows: {
type: [Number, String],
default: 3,
validator
},
/**
* This property has higher priority than "option.animate"
* @values true, false
*/
animate: {
type: Boolean,
default: true
},
/**
* Controls the min width of paragraphs
*/
minWidth: {
type: [Number, String],
default: 30,
validator
},
/**
* Controls the max width of paragraphs
*/
maxWidth: {
type: [Number, String],
default: 100,
validator
},
/**
* Controls the width of paragraphs
*/
width: {
type: [String, Array],
default: null
},
/**
* If true, row widths will be random
* @values true, false
*/
randomWidth: {
type: Boolean,
default: false
},
/**
* RippleDuration controls how long the delay is for the animation of a
* placeholder 1000 pixels from the top of the page. Each placeholder
* from the top down will have a delay duration from 0 to this offset.
* The delay of each placeholder animation is based on how far down the page
* the placeholder is rendered. This is a linear relationship. The unit
* is milliseconds.
*/
offset: {
type: Number,
default: 1
},
/**
* Duration time of the animation (ms), set -1 for an infinite animation.
*/
animationDuration: {
type: Number,
default: -1
},
/**
* Additional class name for the content.
*/
contentClass: {
type: String,
default: ""
},
/**
* Additional class name for the row.
*/
rowClass: {
type: String,
default: ""
}
},
computed: {
integerRows() {
return Number(this.rows);
}
},
methods: {
randomWidthPercentage() {
const min = Math.min(this.minWidth, this.maxWidth);
const max = Math.max(this.minWidth, this.maxWidth);
return `${Math.round(Math.random() * (max - min)) + min}%`;
},
getSizeParagraphRow(row) {
const paragraphWidth = this.width;
const isArrayWidth = Array.isArray(paragraphWidth);
const currentWidth = paragraphWidth == null ? void 0 : paragraphWidth[row - 1];
const isLastRow = row === this.rows;
if (this.randomWidth) {
return this.randomWidthPercentage();
}
if (paragraphWidth && !isArrayWidth) {
return paragraphWidth;
}
if (paragraphWidth && isArrayWidth && currentWidth) {
return currentWidth;
}
return isLastRow ? "38%" : "100%";
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_dt_skeleton_text = resolveComponent("dt-skeleton-text");
return openBlock(), createElementBlock("div", {
class: normalizeClass([
"d-skeleton-paragraph",
$props.contentClass
]),
contentClass: "",
"data-qa": "skeleton-paragraph"
}, [
(openBlock(true), createElementBlock(Fragment, null, renderList($options.integerRows, (row) => {
return openBlock(), createBlock(_component_dt_skeleton_text, {
key: row,
"data-qa": "skeleton-paragraph-row",
"content-class": $props.rowClass,
animate: $props.animate,
offset: $props.offset,
"animation-duration": $props.animationDuration,
width: $options.getSizeParagraphRow(row)
}, null, 8, ["content-class", "animate", "offset", "animation-duration", "width"]);
}), 128))
], 2);
}
const DtSkeletonParagraph = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
DtSkeletonParagraph as default
};
//# sourceMappingURL=skeleton-paragraph.vue.js.map