mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
39f3dbd945
* renames `select-box-kit` into `select-kit` * introduces `single-select` and `multi-select` as base components * introduces {{search-advanced-category-chooser}} as a better component for selecting category in advanced search * improves events handling in select-kit * recreates color selection inputs using {{multi-select}} and a custom {{selected-color}} component * replaces category-selector by a component using select-kit and based on multi-select * improves positioning of wrapper * removes the need for offscreen, and instead use `select-kit-header` as a base focus point for all select-kit based components * introduces a formal plugin api for select-kit based components * introduces a formal pattern for loading and updating select-kit based components: ``` computeValue() computeContent() mutateValue() ```
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
import MultiSelectComponent from "select-kit/components/multi-select";
|
|
|
|
export default MultiSelectComponent.extend({
|
|
pluginApiIdentifiers: ["list-setting"],
|
|
classNames: "list-setting",
|
|
tokenSeparator: "|",
|
|
settingValue: "",
|
|
choices: null,
|
|
filterable: true,
|
|
|
|
init() {
|
|
this._super();
|
|
|
|
if (!Ember.isNone(this.get("settingName"))) {
|
|
this.set("nameProperty", this.get("settingName"));
|
|
}
|
|
|
|
if (this.get("nameProperty").indexOf("color") > -1) {
|
|
this.set("headerComponentOptions", Ember.Object.create({
|
|
selectedNameComponent: "multi-select/selected-color"
|
|
}));
|
|
}
|
|
},
|
|
|
|
computeContent() {
|
|
let content;
|
|
if (Ember.isNone(this.get("choices"))) {
|
|
content = this.get("settingValue").split(this.get("tokenSeparator"));;
|
|
} else {
|
|
content = this.get("choices");
|
|
}
|
|
|
|
return Ember.makeArray(content).filter(c => c);
|
|
},
|
|
|
|
mutateValues(values) {
|
|
this.set("settingValue", values.join(this.get("tokenSeparator")));
|
|
},
|
|
|
|
computeValues() {
|
|
return this.get("settingValue")
|
|
.split(this.get("tokenSeparator"))
|
|
.filter(c => c);
|
|
},
|
|
|
|
_handleTabOnKeyDown(event) {
|
|
if (this.$highlightedRow().length === 1) {
|
|
this._super(event);
|
|
} else {
|
|
this.close();
|
|
return false;
|
|
}
|
|
}
|
|
});
|