@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
123 lines (122 loc) • 4.29 kB
JavaScript
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
require("./kendo.core-kmRaf_Lg.js");
require("./kendo.icons.js");
//#region ../src/kendo.reasoning.js
const __meta__ = {
id: "reasoning",
name: "Reasoning",
category: "web",
description: "The Reasoning component.",
depends: ["core", "icons"]
};
(function($, undefined) {
const kendo = window.kendo;
const Widget = kendo.ui.Widget;
const encode = kendo.htmlEncode;
const NS = ".kendoReasoning";
const EXPANDED_CHANGE = "expandedChange";
const Reasoning = Widget.extend({
init: function(element, options) {
const that = this;
Widget.fn.init.call(that, element, options);
that._render();
that._bindEvents();
kendo.notify(that);
},
options: {
name: "Reasoning",
label: "Reasoning",
secondaryLabel: null,
svgIcon: "sparkles",
completed: false,
expanded: false,
expandable: false,
content: null,
contentTemplate: null,
time: null
},
events: [EXPANDED_CHANGE],
_render: function() {
const that = this;
const opts = that.options;
that.element.addClass("k-agent-step k-reasoning").toggleClass("k-agent-completed", !!opts.completed);
const headExpandedAttr = opts.expandable ? ` aria-expanded="${!!opts.expanded}"` : "";
const labelHtml = opts.label ? `<span class="k-agent-step-label">${encode(opts.label)}</span>` : "";
const secondaryHtml = opts.secondaryLabel ? `<span class="k-agent-step-sep">·</span><span class="k-agent-step-secondary">${encode(opts.secondaryLabel)}</span>` : "";
const timeHtml = opts.time ? `<span class="k-agent-step-sep">·</span><span class="k-agent-step-secondary">${encode(opts.time)}</span>` : "";
const expandIconHtml = opts.expandable ? kendo.ui.icon({
icon: opts.expanded ? "chevron-up" : "chevron-right",
iconClass: "k-agent-step-expand"
}) : "";
that.element.html(`<button class="k-agent-step-head"${headExpandedAttr}>` + kendo.ui.icon({
icon: opts.svgIcon,
iconClass: "k-agent-step-icon"
}) + `<span class="k-agent-step-content">` + labelHtml + secondaryHtml + timeHtml + expandIconHtml + "</span></button>");
that._head = that.element.find(".k-agent-step-head");
that._head.find(".k-svg-icon").attr("aria-hidden", "true");
that._body = $(`<div class="k-agent-step-body"></div>`);
that._renderContent();
if (opts.expanded) that._body.appendTo(that.element);
},
_renderContent: function() {
const that = this;
const opts = that.options;
if (opts.contentTemplate !== null) {
const tmpl = opts.contentTemplate;
that._body.html(tmpl({}));
} else if (opts.content !== null) that._body.text(opts.content);
},
_bindEvents: function() {
const that = this;
if (!that.options.expandable) return;
that._head.on("click.kendoReasoning", that._onToggle.bind(that)).on("keydown.kendoReasoning", that._onKeydown.bind(that));
},
_onToggle: function() {
const that = this;
const expand = !that.options.expanded;
if (!that.trigger(EXPANDED_CHANGE, { expanded: expand })) that.toggle(expand);
},
_onKeydown: function(e) {
const that = this;
if (e.keyCode === kendo.keys.ENTER || e.keyCode === kendo.keys.SPACEBAR) {
that._onToggle();
e.preventDefault();
}
},
toggle: function(expand) {
const that = this;
if (expand === undefined) expand = !that.options.expanded;
that.options.expanded = expand;
if (that.options.expandable) {
that._head.attr("aria-expanded", expand);
const newIcon = $(kendo.ui.icon({
icon: expand ? "chevron-up" : "chevron-right",
iconClass: "k-agent-step-expand"
})).attr("aria-hidden", "true");
that._head.find(".k-agent-step-expand").replaceWith(newIcon);
}
if (expand) that._body.appendTo(that.element);
else that._body.detach();
},
expand: function() {
if (this.options.expandable) this.toggle(true);
},
collapse: function() {
this.toggle(false);
},
destroy: function() {
const that = this;
if (that._head) that._head.off(NS);
that.element.off(NS);
Widget.fn.destroy.call(that);
}
});
kendo.ui.plugin(Reasoning);
})(window.kendo.jQuery);
var kendo_reasoning_default = kendo;
//#endregion
exports.__meta__ = __meta__;
exports.default = kendo_reasoning_default;