FIX: adds select-kit api to modify header computed content (#5476)

This api would allow to simply modify header text or icons, eg:

```
      api.modifySelectKit("select-kit")
        .modifyHeaderComputedContent((context, computedContent) => {
          computedContent.title = "Not so evil";
          return computedContent;
        });
```
This commit is contained in:
Joffrey JAFFEUX
2018-01-09 10:52:32 +01:00
committed by GitHub
parent c9f42506b7
commit c9921869f1
6 changed files with 68 additions and 7 deletions

View File

@ -45,7 +45,7 @@ export default SelectKitComponent.extend({
values = this.willComputeValues(values);
values = this.computeValues(values);
values = this._beforeDidComputeValues(values);
this.set("headerComputedContent", this.computeHeaderContent());
this._setHeaderComputedContent();
this.didComputeContent(content);
this.didComputeValues(values);
this.didComputeAttributes();
@ -86,7 +86,7 @@ export default SelectKitComponent.extend({
this.mutateContent(this.get("computedContent"));
this.mutateValues(this.get("computedValues"));
applyOnSelectPluginApiCallbacks(this.get("pluginApiIdentifiers"), this.get("computedValues"), this);
this.set("headerComputedContent", this.computeHeaderContent());
this._setHeaderComputedContent();
});
},
mutateValues(computedValues) {

View File

@ -5,7 +5,8 @@ import DomHelpersMixin from "select-kit/mixins/dom-helpers";
import EventsMixin from "select-kit/mixins/events";
import PluginApiMixin from "select-kit/mixins/plugin-api";
import {
applyContentPluginApiCallbacks
applyContentPluginApiCallbacks,
applyHeaderContentPluginApiCallbacks
} from "select-kit/mixins/plugin-api";
export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixin, EventsMixin, {
@ -224,6 +225,15 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
this.setProperties({ filter: "" });
},
_setHeaderComputedContent() {
const headerComputedContent = applyHeaderContentPluginApiCallbacks(
this.get("pluginApiIdentifiers"),
this.computeHeaderContent(),
this
);
this.set("headerComputedContent", headerComputedContent);
},
actions: {
onToggle() {
if (this.get("onToggle")) this.sendAction("onToggle");
@ -231,6 +241,8 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
if (this.get("onExpand") && this.get("isExpanded") === false) this.sendAction("onExpand");
this.get("isExpanded") === true ? this.collapse() : this.expand();
this._setHeaderComputedContent();
},
onHighlight(rowComputedContent) {

View File

@ -26,7 +26,7 @@ export default SelectKitComponent.extend({
value = this._beforeDidComputeValue(value);
this.didComputeContent(content);
this.didComputeValue(value);
this.set("headerComputedContent", this.computeHeaderContent());
this._setHeaderComputedContent();
this.didComputeAttributes();
if (this.get("allowInitialValueMutation")) this.mutateAttributes();
@ -40,7 +40,7 @@ export default SelectKitComponent.extend({
this.mutateContent(this.get("computedContent"));
this.mutateValue(this.get("computedValue"));
applyOnSelectPluginApiCallbacks(this.get("pluginApiIdentifiers"), this.get("computedValue"), this);
this.set("headerComputedContent", this.computeHeaderContent());
this._setHeaderComputedContent();
});
},
mutateContent() {},