@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
198 lines (197 loc) • 5.92 kB
JavaScript
import Modal from "../../common/mixins/modal.js";
import utils from "../../common/utils.js";
import SrOnlyCloseButtonMixin from "../../common/mixins/sr_only_close_button.js";
import normalizeComponent from "../../_virtual/_plugin-vue2_normalizer.js";
import DtNoticeIcon from "../notice/notice_icon.vue.js";
import DtNoticeContent from "../notice/notice_content.vue.js";
import DtNoticeAction from "../notice/notice_action.vue.js";
import { NOTICE_KINDS } from "../notice/notice_constants.js";
const _sfc_main = {
name: "DtBanner",
components: {
DtNoticeIcon,
DtNoticeContent,
DtNoticeAction
},
mixins: [Modal, SrOnlyCloseButtonMixin],
props: {
/**
* Sets an ID on the title element of the component. Useful for aria-describedby
* or aria-labelledby or any other reason you may need an id to refer to the title.
*/
titleId: {
type: String,
default() {
return utils.getUniqueString();
}
},
/**
* Sets an ID on the content element of the component. Useful for aria-describedby
* or aria-labelledby or any other reason you may need an id to refer to the content.
*/
contentId: {
type: String,
default() {
return utils.getUniqueString();
}
},
/**
* Title header of the notice. This can be left blank to remove the title from the notice entirely.
*/
title: {
type: String,
default: ""
},
/**
* Used in scenarios where the message needs to visually dominate the screen.
* This will also change the aria role from status to alertdialog.
* and will modally trap the keyboard focus in the dialog as soon as it displays.
* @values true, false
*/
important: {
type: Boolean,
default: false
},
/**
* Pins the banner to the top of the window and pushes all app content down.
* @values true, false
*/
pinned: {
type: Boolean,
default: false
},
/**
* Severity level of the notice, sets the icon and background
* @values base, error, info, success, warning
*/
kind: {
type: String,
default: "base",
validate(kind) {
return NOTICE_KINDS.includes(kind);
}
},
/**
* Props for the notice close button.
*/
closeButtonProps: {
type: Object,
default: () => ({})
},
/**
* Hides the close button from the notice
* @values true, false
*/
hideClose: {
type: Boolean,
default: false
},
/**
* Hides the icon from the notice
* @values true, false
*/
hideIcon: {
type: Boolean,
default: false
},
/**
* Hides the action from the notice
* @values true, false
*/
hideAction: {
type: Boolean,
default: false
},
/**
* Inner dialog class
*/
dialogClass: {
type: String,
default: ""
},
/**
* Banner background image
*/
backgroundImage: {
type: String,
default: ""
},
/**
* Background image size, follows the background-size CSS property values
* <a class="d-link" href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-size" target="_blank">
* CSS background-sizes
* </a>
*/
backgroundSize: {
type: String,
default: "cover"
}
},
emits: [
/**
* Close button click event
*
* @event close
*/
"close"
],
computed: {
role() {
return this.important ? "alertdialog" : "status";
},
bannerClass() {
const kindClasses = {
error: "d-banner--error",
info: "d-banner--info",
success: "d-banner--success",
warning: "d-banner--warning",
base: "d-banner--base"
};
return [
"d-banner",
kindClasses[this.kind],
{
"d-banner--important": this.important,
"d-banner--pinned": this.pinned
}
];
},
bannerBackgroundImage() {
if (this.backgroundImage === "") return null;
return `background-image: url(${this.backgroundImage});
background-size: ${this.backgroundSize};`;
}
},
mounted() {
if (this.important) {
this.focusFirstElement();
}
},
methods: {
trapFocus(e) {
if (this.important) {
this.focusTrappedTabPress(e);
}
}
}
};
var _sfc_render = function render() {
var _vm = this, _c = _vm._self._c;
return _c("aside", { class: _vm.bannerClass, style: _vm.bannerBackgroundImage, on: { "keydown": function($event) {
if (!$event.type.indexOf("key") && _vm._k($event.keyCode, "tab", 9, $event.key, "Tab")) return null;
return _vm.trapFocus.apply(null, arguments);
} } }, [_c("div", { staticClass: "d-banner__dialog", class: _vm.dialogClass, attrs: { "role": _vm.role, "aria-labelledby": _vm.titleId, "aria-describedby": _vm.contentId } }, [!_vm.hideIcon ? _c("dt-notice-icon", _vm._g({ attrs: { "kind": _vm.kind } }, _vm.$listeners), [_vm._t("icon")], 2) : _vm._e(), _c("dt-notice-content", _vm._g({ attrs: { "title-id": _vm.titleId, "content-id": _vm.contentId, "title": _vm.title }, scopedSlots: _vm._u([{ key: "titleOverride", fn: function() {
return [_vm._t("titleOverride")];
}, proxy: true }], null, true) }, _vm.$listeners), [_vm._t("default")], 2), _c("dt-notice-action", _vm._g({ attrs: { "hide-action": _vm.hideAction, "hide-close": _vm.hideClose, "close-button-props": _vm.closeButtonProps, "visually-hidden-close": _vm.visuallyHiddenClose, "visually-hidden-close-label": _vm.visuallyHiddenCloseLabel } }, _vm.$listeners), [_vm._t("action")], 2)], 1)]);
};
var _sfc_staticRenderFns = [];
var __component__ = /* @__PURE__ */ normalizeComponent(
_sfc_main,
_sfc_render,
_sfc_staticRenderFns
);
const banner = __component__.exports;
export {
banner as default
};
//# sourceMappingURL=banner.vue.js.map