Browse Source

Add getOption to radio property

up-style-manager
Artur Arseniev 4 years ago
parent
commit
dd3dd3e066
  1. 15
      src/style_manager/model/PropertyRadio.js

15
src/style_manager/model/PropertyRadio.js

@ -5,7 +5,7 @@ export default class PropertyRadio extends Property {
return {
...Property.prototype.defaults,
options: [], // Array of options, eg. [{ id: '100', label: 'Set 100' }]
full: 1
full: 1,
};
}
@ -19,6 +19,15 @@ export default class PropertyRadio extends Property {
return (options && options.length ? options : list) || [];
}
/**
* Get current selected option.
* @returns {Object | null}
*/
getOption() {
const id = this.getValue();
return this.getOptions().filter(o => this.getOptionId(o) === id)[0] || null;
}
/**
* Update options.
* @param {Array<Object>} value Array of options, eg. `[{ id: 'val-1', label: 'Value 1' }]`
@ -62,9 +71,7 @@ export default class PropertyRadio extends Property {
const option = options.filter(o => this.getOptionId(o) === id)[0] || {};
const label = option.label || option.name || id;
const propId = this.getId();
return (
(locale && this.em?.t(`styleManager.options.${propId}.${id}`)) || label
);
return (locale && this.em?.t(`styleManager.options.${propId}.${id}`)) || label;
}
initialize(...args) {

Loading…
Cancel
Save