|
| 1 | +# 🖥️ puiButtonSelect |
| 2 | + |
| 3 | +## Purpose of the plugin |
| 4 | + |
| 5 | +This plugin is suitable for providing a simple 🔘▼ button with a selection list. |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +1. Prepare the configuration with values according to [puiButton][puiButton]. |
| 10 | + |
| 11 | +## Implementation |
| 12 | + |
| 13 | +2. The new plugin will always have [puiButtonSelect][puiButtonSelect] as its base class. |
| 14 | + |
| 15 | +```javascript |
| 16 | +class puiButtonSelectNew extends puiButtonSelect { |
| 17 | + constructor(aliasName, data) { |
| 18 | + super(aliasName, data); |
| 19 | + |
| 20 | + this.DEFAULT_KEY_CFG_ID = 'downP-selNew'; |
| 21 | + this.DEFAULT_KEY_CFG_CAPTION = '🖼️'; |
| 22 | + this.DEFAULT_KEY_CFG_TARGET = UI_PLUGIN_SIDEBAR; |
| 23 | + } |
| 24 | + |
| 25 | + async init() { |
| 26 | + // ... insert application event initialization here ... |
| 27 | + |
| 28 | + super.init(); |
| 29 | + |
| 30 | + // ... insert component data initialization here ... |
| 31 | + |
| 32 | + const items = ['A', 'B', 'C']; // items |
| 33 | + const selVal = 'B'; // default selected value |
| 34 | + |
| 35 | + appendComboBoxItems(this.select, items, selVal); |
| 36 | + } |
| 37 | + |
| 38 | + deInit() { |
| 39 | + super.deInit(); |
| 40 | + } |
| 41 | + |
| 42 | + _handle(e) { |
| 43 | + const newVal = e.target.options[e.target.selectedIndex].text; |
| 44 | + // ... |
| 45 | + } |
| 46 | + |
| 47 | + _handleFocus(e) { |
| 48 | + // ... |
| 49 | + } |
| 50 | + |
| 51 | + // ... |
| 52 | +} |
| 53 | + |
| 54 | +Plugins.catalogize(puiButtonSelectNew); |
| 55 | + |
| 56 | +``` |
| 57 | + |
| 58 | +- The **this.DEFAULT_KEY_CFG_** lines can be removed if you want to rely solely on the configuration from the file. However, considering the automatic documentation of objects in the plugin, I recommend leaving them. |
| 59 | + |
| 60 | +## Functionality description |
| 61 | + |
| 62 | +- **appendComboBoxItems** adds a set of items to the selection box. Indexes are assigned from 0 |
| 63 | +- **e.target.selectedIndex** index of the selected item |
| 64 | +- **e.target.options\[e.target.selectedIndex\].text** text of the selected item |
| 65 | +- **this.select.options.length = 0** deletes the items in the selection box |
| 66 | +- **_handleFocus** action before opening the list of possible options |
| 67 | +- **this.select** contains a link to the created selection list |
| 68 | +- **e** represents JavaScript system events |
| 69 | +- **sendEvent('ButtonSelectIconSet', (x) => {x.payload = '🖥️'; id = '';});** changes the button icon to 🖥️ |
| 70 | + |
| 71 | +## Implementation examples |
| 72 | + |
| 73 | +- 🖥️ [puiButtonSelectSkin][puiButtonSelectSkin] and other descendants of the class 🖥️ [puiButtonSelect][puiButtonSelect] |
| 74 | + |
| 75 | +[puiButton]: puiButton.md#h-2-1 "puiButton" |
| 76 | +[puiButtonSelect]: :_plg:puiButtonSelect.md "puiButtonSelect" |
| 77 | +[puiButtonSelectSkin]: :_plg:puiButtonSelectSkin.md "puiButtonSelectSkin" |
0 commit comments