primevue
Version:
PrimeVue is a premium UI library for Vue featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, wh
156 lines (150 loc) • 6.16 kB
JavaScript
import { createMotion } from '@primeuix/motion';
import { isElement } from '@primeuix/utils/dom';
import { mergeProps, openBlock, createBlock, resolveDynamicComponent, withCtx, renderSlot, normalizeClass } from 'vue';
import BaseComponent from '@primevue/core/basecomponent';
import SidebarMenuSubStyle from 'primevue/sidebarmenusub/style';
var script$1 = {
name: 'BaseSidebarMenuSub',
"extends": BaseComponent,
props: {
as: {
type: [String, Object],
"default": 'UL'
},
asChild: {
type: Boolean,
"default": false
}
},
style: SidebarMenuSubStyle,
provide: function provide() {
return {
$pcSidebarMenuSub: this,
$parentInstance: this
};
}
};
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var script = {
name: 'SidebarMenuSub',
"extends": script$1,
inheritAttrs: false,
inject: {
$pcSidebar: {
"default": null
},
$pcSidebarMenuItem: {
"default": null
}
},
subEl: null,
motion: null,
mounted: function mounted() {
this.syncMotion(false);
},
beforeUnmount: function beforeUnmount() {
this.cancelMotion();
},
watch: {
isCollapsible: function isCollapsible() {
this.syncMotion(true);
},
isOpen: function isOpen() {
this.syncMotion(true);
}
},
methods: {
setRef: function setRef(el) {
var _el$$el;
var resolved = isElement(el) ? el : (_el$$el = el === null || el === void 0 ? void 0 : el.$el) !== null && _el$$el !== void 0 ? _el$$el : null;
this.subEl = isElement(resolved) ? resolved : null;
},
ensureMotion: function ensureMotion() {
if (!this.subEl) return null;
if (!this.motion) {
this.motion = createMotion(this.subEl, {
name: 'p-sidebar-menu-sub',
cssVarPrefix: 'px-sidebar-menu-sub',
autoHeight: true,
duration: 200
});
}
return this.motion;
},
cancelMotion: function cancelMotion() {
var _this$motion;
(_this$motion = this.motion) === null || _this$motion === void 0 || _this$motion.cancel();
this.motion = null;
},
syncMotion: function syncMotion(animate) {
var _this = this;
var el = this.subEl;
if (typeof window === 'undefined' || !el) return;
if (!this.isCollapsible) {
this.cancelMotion();
el.style.removeProperty('display');
return;
}
var motion = this.ensureMotion();
if (!motion) return;
if (!animate) {
if (this.isOpen) el.style.removeProperty('display');else el.style.display = 'none';
return;
}
if (this.isOpen) {
el.style.removeProperty('display');
motion.enter();
} else {
motion.leave().then(function () {
if (_this.isCollapsible && !_this.isOpen && _this.subEl) {
_this.subEl.style.display = 'none';
}
});
}
}
},
computed: {
isCollapsible: function isCollapsible() {
var _this$$pcSidebarMenuI;
return !!((_this$$pcSidebarMenuI = this.$pcSidebarMenuItem) !== null && _this$$pcSidebarMenuI !== void 0 && _this$$pcSidebarMenuI.collapsible);
},
isOpen: function isOpen() {
var _this$$pcSidebarMenuI2;
return this.isCollapsible ? !!((_this$$pcSidebarMenuI2 = this.$pcSidebarMenuItem) !== null && _this$$pcSidebarMenuI2 !== void 0 && _this$$pcSidebarMenuI2.d_open) : true;
},
a11yAttrs: function a11yAttrs() {
var _this$$pcSidebar$getS, _this$$pcSidebar;
var sidebarPart = (_this$$pcSidebar$getS = (_this$$pcSidebar = this.$pcSidebar) === null || _this$$pcSidebar === void 0 ? void 0 : _this$$pcSidebar.getSectionAttrs('menusub')) !== null && _this$$pcSidebar$getS !== void 0 ? _this$$pcSidebar$getS : {};
return _objectSpread(_objectSpread({}, sidebarPart), {}, {
role: 'list',
'data-pc-section': 'menusub'
});
},
attrs: function attrs() {
return mergeProps(this.a11yAttrs, this.ptmi('root'));
}
}
};
function render(_ctx, _cache, $props, $setup, $data, $options) {
return !_ctx.asChild ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.as), mergeProps({
key: 0,
ref: $options.setRef,
"class": _ctx.cx('root')
}, $options.attrs), {
"default": withCtx(function () {
return [renderSlot(_ctx.$slots, "default")];
}),
_: 3
}, 16, ["class"])) : renderSlot(_ctx.$slots, "default", {
key: 1,
a11yAttrs: $options.a11yAttrs,
"class": normalizeClass(_ctx.cx('root'))
});
}
script.render = render;
export { script as default };