2017-11-21 05:53:09 -05:00
|
|
|
import SelectKitComponent from "select-kit/components/select-kit";
|
2020-02-03 08:22:14 -05:00
|
|
|
import { computed } from "@ember/object";
|
|
|
|
import { isEmpty } from "@ember/utils";
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
export default SelectKitComponent.extend({
|
|
|
|
pluginApiIdentifiers: ["single-select"],
|
2018-02-26 05:42:57 -05:00
|
|
|
layoutName: "select-kit/templates/components/single-select",
|
2020-02-03 08:22:14 -05:00
|
|
|
classNames: ["single-select"],
|
|
|
|
singleSelect: true,
|
2018-03-22 06:29:55 -04:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
selectKitOptions: {
|
|
|
|
headerComponent: "select-kit/single-select-header"
|
2017-11-21 05:53:09 -05:00
|
|
|
},
|
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
selectedContent: computed("value", "content.[]", function() {
|
|
|
|
if (!isEmpty(this.value)) {
|
|
|
|
let content;
|
2018-03-22 06:29:55 -04:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
if (this.selectKit.valueProperty) {
|
|
|
|
content = (this.content || []).findBy(
|
|
|
|
this.selectKit.valueProperty,
|
|
|
|
this.value
|
2018-03-22 06:29:55 -04:00
|
|
|
);
|
2020-02-03 08:22:14 -05:00
|
|
|
return this.selectKit.modifySelection(
|
|
|
|
content || this.defaultItem(this.value, this.value)
|
2019-12-04 13:33:51 -05:00
|
|
|
);
|
2020-02-03 08:22:14 -05:00
|
|
|
} else {
|
|
|
|
return this.selectKit.modifySelection(
|
|
|
|
(this.content || []).filter(c => c === this.value)
|
|
|
|
);
|
|
|
|
}
|
2018-03-22 06:29:55 -04:00
|
|
|
} else {
|
2020-02-03 08:22:14 -05:00
|
|
|
return this.selectKit.noneItem;
|
2017-11-21 05:53:09 -05:00
|
|
|
}
|
2020-02-03 08:22:14 -05:00
|
|
|
})
|
2017-11-21 05:53:09 -05:00
|
|
|
});
|