UNPKG

@vuesax-alpha/nightly

Version:
54 lines (51 loc) 1.75 kB
import { computed } from 'vue'; import { isArray } from '@vue/shared'; import '../../../../tokens/index.mjs'; import '../../../../hooks/index.mjs'; import '../../../../utils/index.mjs'; import { useGroupInject } from '../../../../hooks/use-group-inject/index.mjs'; import { avatarGroupContextKey } from '../../../../tokens/avatar.mjs'; import { debugWarn } from '../../../../utils/error.mjs'; const useAvatarStatus = (slots) => { const avatarGroup = useGroupInject(avatarGroupContextKey); const isHidden = computed( () => avatarGroup && avatarGroup.index.value > avatarGroup.max - 1 ); const isLastest = computed( () => !!(avatarGroup == null ? void 0 : avatarGroup.max) && avatarGroup.index.value === avatarGroup.max - 1 ); const moreNumber = computed( () => avatarGroup && avatarGroup.children.length - avatarGroup.index.value - 1 ); const showLastest = computed( () => avatarGroup && avatarGroup.children.length - avatarGroup.index.value - 1 != 0 ); const getText = computed(() => { var _a; const slotText = (_a = slots.text) == null ? void 0 : _a.call(slots); if (!slotText) return ""; if (slotText.length > 1) { debugWarn('Avatar slot="text"', "requires exact only one valid child."); return ""; } const nodeText = slotText[0]; if (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 }; }; export { useAvatarStatus }; //# sourceMappingURL=use-avatar-status.mjs.map