discourse/app/assets/javascripts/wizard/addon/components/fields/dropdown.js
David Taylor e4c373194d
DEV: Refactor Wizard components (#24770)
This commit refactors the Wizard component code in preparation for moving it to the 'static' directory for Embroider route-splitting. It also includes a number of general improvements and simplifications.

Extracted from https://github.com/discourse/discourse/pull/23678

Co-authored-by: Godfrey Chan <godfreykfc@gmail.com>
2023-12-07 16:33:38 +00:00

34 lines
809 B
JavaScript

import Component from "@ember/component";
import { action, set } from "@ember/object";
import discourseComputed from "discourse-common/utils/decorators";
import ColorPalettes from "select-kit/components/color-palettes";
import ComboBox from "select-kit/components/combo-box";
export default Component.extend({
init() {
this._super(...arguments);
if (this.field.id === "color_scheme") {
for (let choice of this.field.choices) {
if (choice?.data?.colors) {
set(choice, "colors", choice.data.colors);
}
}
}
},
@discourseComputed("field.id")
component(id) {
return id === "color_scheme" ? ColorPalettes : ComboBox;
},
keyPress(e) {
e.stopPropagation();
},
@action
onChangeValue(value) {
this.set("field.value", value);
},
});