@vue-widget/hooks
Version:
hooks from react to vue
33 lines (32 loc) • 841 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getUUID = getUUID;
exports.isBrowserClient = void 0;
exports.useId = useId;
var _vue = require("vue");
var uuid = 0;
/** Is client side and not jsdom */
var isBrowserClient = exports.isBrowserClient = !!(typeof window !== "undefined" && window.document && window.document.createElement);
/** Get unique id for accessibility usage */
function getUUID() {
var retId;
// Test never reach
/* istanbul ignore if */
if (isBrowserClient) {
retId = uuid;
uuid += 1;
} else {
retId = "TEST_OR_SSR";
}
return retId;
}
function useId(id) {
if (id === void 0) {
id = (0, _vue.ref)("");
}
// Inner id for accessibility usage. Only work in client side
var innerId = "rv_unique_".concat(getUUID());
return id.value || innerId;
}