Created
May 11, 2020 07:40
-
-
Save basz/d66e710ddddf6d7ced67c3340272b3ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import BaseControl from 'ember-bootstrap/components/bs-form/element/control'; | |
import defaultValue from 'ember-bootstrap/utils/default-decorator'; | |
import formValidationClass from 'ember-bootstrap/utils/cp/form-validation-class'; | |
import sizeClass from 'ember-bootstrap/utils/cp/size-class'; | |
import { action, computed, getWithDefault } from '@ember/object'; | |
import { isNone, isEmpty } from '@ember/utils'; | |
import { tagName } from '@ember-decorators/component'; | |
import { tracked } from '@glimmer/tracking'; | |
@tagName('') | |
export default class SelectNative extends BaseControl { | |
classTypePrefix = 'custom-select'; | |
@defaultValue | |
size = null; | |
@formValidationClass('validationType') | |
formValidationClass; | |
@sizeClass('custom-select', 'size') | |
sizeClass; | |
@computed('sizeClass', 'formValidationClass') | |
get classNamesProxy() { | |
return [this.classTypePrefix, this.sizeClass, this.formValidationClass].join(' '); | |
} | |
@tracked collection = []; | |
@tracked defaultValue = { value: null, label: 'select', conditional: true }; | |
@tracked inline = false; | |
@tracked isLoading = false; | |
@tracked labelKey = 'label'; | |
@tracked translateLabels = true; | |
@tracked translateMaterialPrefix = ''; | |
@tracked valueKey = 'value'; | |
set options(options) { | |
this.collection = getWithDefault(options, 'collection', []); | |
this.defaultValue = getWithDefault(options, 'defaultValue', this.defaultValue); | |
this.inline = getWithDefault(options, 'inline', this.inline); | |
this.isLoading = getWithDefault(options, 'isLoading', this.isLoading); | |
this.labelKey = getWithDefault(options, 'labelKey', this.labelKey); | |
this.translateLabels = getWithDefault(options, 'translateLabels', this.translateLabels); | |
this.translateMaterialPrefix = getWithDefault(options, 'translateMaterialPrefix', this.translateMaterialPrefix); | |
this.valueKey = getWithDefault(options, 'valueKey', this.valueKey); | |
} | |
get showDefaultValue() { | |
const defaultValue = this.defaultValue; | |
const value = this.value; | |
const valueKey = this.valueKey; | |
if (isNone(defaultValue)) { | |
return false; | |
} | |
return !defaultValue.conditional || defaultValue[valueKey] === value; | |
} | |
get selectedValue() { | |
if (!isEmpty(this.value)) { | |
return this.value.toString(); | |
} | |
const valueKey = this.valueKey; | |
return getWithDefault(this, `defaultValue.${valueKey}`, null); | |
} | |
@action | |
onChangeNative(value) { | |
this.onChange(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moving
<form.element @disabled={{not this.enableType}} ...
to@options={{hash disabled=(not this.enableType)...
will work if i change theset options(options)
incomponents/bs-form/element/control/select-native/component.js
. Not sure if that is the recommended way...