@gitlab/ui
Version:
GitLab UI Components
116 lines (104 loc) • 3.85 kB
JavaScript
import isPlainObject from 'lodash/isPlainObject';
import { BTab } from '../../../../vendor/bootstrap-vue/src/components/tabs/tab';
import GlBadge from '../../badge/badge';
import { logWarning } from '../../../../utils/utils';
import { DEFAULT_TAB_TITLE_LINK_CLASS } from '../constants';
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
//
var script = {
name: 'GlTab',
components: {
BTab,
GlBadge
},
inheritAttrs: false,
props: {
titleLinkClass: {
type: [String, Array, Object],
required: false,
default: ''
},
/**
* Query string parameter value to use when `gl-tabs` `sync-active-tab-with-query-params` prop is set to `true`.
*/
queryParamValue: {
type: String,
required: false,
default: null
},
/**
* Display a count badge next to the tab title.
*/
tabCount: {
type: Number,
required: false,
default: null
},
/**
* Screen reader text to provide context for the tab count value.
* Should be the result of calling n__() with the count.
* Example: :tab-count-sr-text="n__('%d changed file', '%d changed files', count)"
*/
tabCountSrText: {
type: String,
required: false,
default: null
}
},
computed: {
linkClass() {
const {
titleLinkClass
} = this;
if (Array.isArray(titleLinkClass)) {
return [...titleLinkClass, DEFAULT_TAB_TITLE_LINK_CLASS];
}
if (isPlainObject(titleLinkClass)) {
return {
...titleLinkClass,
[DEFAULT_TAB_TITLE_LINK_CLASS]: true
};
}
return `${titleLinkClass} ${DEFAULT_TAB_TITLE_LINK_CLASS}`.trim();
},
hasTabCount() {
return this.tabCount != null && this.tabCount >= 0;
}
},
created() {
if (this.hasTabCount && !this.tabCountSrText) {
logWarning('When using "tab-count", you should also provide "tab-count-sr-text" for screen reader accessibility. Example: :tab-count-sr-text="n__(\'%d item\', \'%d items\', count)"', {
name: 'GlTab'
});
}
}
};
/* script */
const __vue_script__ = script;
/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('b-tab',_vm._g(_vm._b({attrs:{"title":_vm.hasTabCount ? null : _vm.$attrs.title,"title-link-class":_vm.linkClass,"query-param-value":_vm.queryParamValue},scopedSlots:_vm._u([(_vm.hasTabCount)?{key:"title",fn:function(){return [_vm._t("title",function(){return [_vm._v(_vm._s(_vm.$attrs.title))]}),_vm._v(" "),_c('gl-badge',{staticClass:"gl-ml-2",attrs:{"variant":"neutral","aria-hidden":"true","data-testid":"tab-counter-badge"}},[_vm._v("\n "+_vm._s(_vm.tabCount)+"\n ")]),_vm._v(" "),(_vm.tabCountSrText)?_c('span',{staticClass:"gl-sr-only"},[_vm._v(_vm._s(_vm.tabCountSrText))]):_vm._e()]},proxy:true}:null,_vm._l((Object.keys(_vm.$scopedSlots)),function(slot){return {key:slot,fn:function(){return [_vm._t(slot)]},proxy:true}})],null,true)},'b-tab',_vm.$attrs,false),_vm.$listeners))};
var __vue_staticRenderFns__ = [];
/* style */
const __vue_inject_styles__ = undefined;
/* scoped */
const __vue_scope_id__ = undefined;
/* module identifier */
const __vue_module_identifier__ = undefined;
/* functional template */
const __vue_is_functional_template__ = false;
/* style inject */
/* style inject SSR */
/* style inject shadow dom */
const __vue_component__ = /*#__PURE__*/__vue_normalize__(
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
__vue_inject_styles__,
__vue_script__,
__vue_scope_id__,
__vue_is_functional_template__,
__vue_module_identifier__,
false,
undefined,
undefined,
undefined
);
export { __vue_component__ as default };