UNPKG

@vuesax-alpha/nightly

Version:
58 lines (53 loc) 1.85 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var shared = require('@vue/shared'); require('../../../../tokens/index.js'); require('../../../../hooks/index.js'); require('../../../../utils/index.js'); var index = require('../../../../hooks/use-group-inject/index.js'); var avatar = require('../../../../tokens/avatar.js'); var error = require('../../../../utils/error.js'); const useAvatarStatus = (slots) => { const avatarGroup = index.useGroupInject(avatar.avatarGroupContextKey); const isHidden = vue.computed( () => avatarGroup && avatarGroup.index.value > avatarGroup.max - 1 ); const isLastest = vue.computed( () => !!(avatarGroup == null ? void 0 : avatarGroup.max) && avatarGroup.index.value === avatarGroup.max - 1 ); const moreNumber = vue.computed( () => avatarGroup && avatarGroup.children.length - avatarGroup.index.value - 1 ); const showLastest = vue.computed( () => avatarGroup && avatarGroup.children.length - avatarGroup.index.value - 1 != 0 ); const getText = vue.computed(() => { var _a; const slotText = (_a = slots.text) == null ? void 0 : _a.call(slots); if (!slotText) return ""; if (slotText.length > 1) { error.debugWarn('Avatar slot="text"', "requires exact only one valid child."); return ""; } const nodeText = slotText[0]; if (shared.isArray(nodeText.children) || !nodeText.children) return ""; const text = nodeText.children; let getLetters = [text]; if (text.length > 5) { getLetters = text.split(/\s/g).map((item) => item[0]); } return getLetters.join(""); }); return { isHidden, isLastest, getText, moreNumber, showLastest }; }; exports.useAvatarStatus = useAvatarStatus; //# sourceMappingURL=use-avatar-status.js.map