@nextcloud/vue
Version:
Nextcloud vue components
96 lines (95 loc) • 2.98 kB
JavaScript
import '../assets/NcEllipsisedOption-DRkFZ9bI.css';
import { N as NcHighlight, F as FindRanges } from "../chunks/index-CxTT94_h.mjs";
import { n as normalizeComponent } from "../chunks/_plugin-vue2_normalizer-DU4iP6Vu.mjs";
const _sfc_main = {
name: "NcEllipsisedOption",
components: {
NcHighlight
},
props: {
/**
* The text to be display in one line. If it is longer than 10 characters, it is be truncated with ellipsis in the end but keeping up to 10 last characters to fit the parent container.
*/
name: {
type: String,
default: ""
},
/**
* The search value to highlight in the text
*/
search: {
type: String,
default: ""
}
},
computed: {
needsTruncate() {
return this.name && this.name.length >= 10;
},
/**
* Index at which to split the name if it is longer than 10 characters.
*
* @return {number} The position at which to split
*/
split() {
return this.name.length - Math.min(Math.floor(this.name.length / 2), 10);
},
part1() {
if (this.needsTruncate) {
return this.name.slice(0, this.split);
}
return this.name;
},
part2() {
if (this.needsTruncate) {
return this.name.slice(this.split);
}
return "";
},
/**
* The ranges to highlight. Since we split the string for ellipsising,
* the Highlight component cannot figure this out itself and needs the ranges provided.
*
* @return {Array} The array with the ranges to highlight
*/
highlight1() {
if (!this.search) {
return [];
}
return FindRanges(this.name, this.search);
},
/**
* We shift the ranges for the second part by the position of the split.
* Ranges out of the string length are discarded by the Highlight component,
* so we don't need to take care of this here.
*
* @return {Array} The array with the ranges to highlight
*/
highlight2() {
return this.highlight1.map((range) => {
return {
start: range.start - this.split,
end: range.end - this.split
};
});
}
}
};
var _sfc_render = function render() {
var _vm = this, _c = _vm._self._c;
return _c("span", { staticClass: "name-parts", attrs: { "dir": "auto", "title": _vm.name } }, [_c("NcHighlight", { staticClass: "name-parts__first", attrs: { "text": _vm.part1, "search": _vm.search, "highlight": _vm.highlight1 } }), _vm.part2 ? _c("NcHighlight", { staticClass: "name-parts__last", attrs: { "text": _vm.part2, "search": _vm.search, "highlight": _vm.highlight2 } }) : _vm._e()], 1);
};
var _sfc_staticRenderFns = [];
var __component__ = /* @__PURE__ */ normalizeComponent(
_sfc_main,
_sfc_render,
_sfc_staticRenderFns,
false,
null,
"592b8444"
);
const NcEllipsisedOption = __component__.exports;
export {
NcEllipsisedOption as default
};
//# sourceMappingURL=NcEllipsisedOption.mjs.map