import { QComboBox , NodeWidget , QSize , QVariant , SizeAdjustPolicy , InsertPolicy , QIcon , } from '@nodegui/nodegui' ; import { VNWidget } from 'widgets/config' ; import { ViewProps , viewPropsSetters } from '../View/VNView' ; import { PropSetters , Prop } from '../../renderer/patchProp' ; /**
 * The ComboBox component provides the ability to add and manipulate native combobox widgets.
 * It is based on [NodeGui's QComboBox](https://docs.nodegui.org/docs/api/generated/classes/qcombobox/).
 *
 * ## Usage
 *
 * ```html
 * <template>
 *   <vn-view>
 *     <vn-text>Choose a color</vn-text>
 *     <vn-combobox :items="data" v-model="index" />
 *     <vn-text>You have picked: {{data[index].text}}</vn-text>
 *   </vn-view>
 * </template>
 *
 * <script>
 *   import { ref } from 'vue';
 *
 *   export default {
 *     setup() {
 *       const index = ref(0);
 *       const data = [
 *         {text: "Red"},
 *         {text: "Yellow"},
 *         {text: "Blue"},
 *         {text: "Green"},
 *       ];
 *
 *       return {
 *         index,
 *         data,
 *       }
 *     }
 *   };
 * </script>
 *
 * ```
 *
 * ## What it looks like?
 *
 * ![combobox-demo](/img/vn-combobox.gif)
 *
 * ## Props and styling
 *
 * You can find all the props `vn-combobox` accepts listed below.
 * Apart from this, you can take a look at the [styling](/docs/guides/3-styling)
 * and [event handling](/docs/guides/5-handle-events) docs
 */ export interface ComboBoxProps extends ViewProps { items ? : ComboBoxItem [ ] ; count ? : number ; iconSize ? : QSize ; frame ? : boolean ; currentIndex ? : number ; currentData ? : QVariant ; currentText ? : string ; duplicatesEnabled ? : boolean ; editable ? : boolean ; insertPolicy ? : InsertPolicy ; maxCount ? : number ; maxVisibleItems ? : number ; minimumContentsLength ? : number ; modelColumn ? : number ; sizeAdjustPolicy ? : SizeAdjustPolicy ; } type ComboBoxItem = { text : string ; icon ? : QIcon ; userData ? : QVariant ; } ; const comboBoxPropsSetters = { ... viewPropsSetters , items ( widget , _ , items ) { widget . clear ( ) ; items . forEach ( ( item ) => { widget . addItem ( item . icon , item . text , item . userData ) ; } ) ; } , count ( widget , _ , count ) { widget . setProperty ( 'count' , count ) ; } , iconSize ( widget , _ , iconSize ) { widget . setProperty ( 'iconSize' , iconSize . native ) ; } , frame ( widget , _ , frame ) { widget . setProperty ( 'frame' , frame ) ; } , currentIndex ( widget , _ , currentIndex ) { widget . setCurrentIndex ( currentIndex ) ; } , currentData ( widget , _ , currentData ) { widget . setProperty ( 'currentData' , currentData . native ) ; } , currentText ( widget , _ , currentText ) { widget . setCurrentText ( currentText ) ; } , editable ( widget , _ , editable ) { widget . setEditable ( editable ) ; } , duplicatesEnabled ( widget , _ , duplicatesEnabled ) { widget . setProperty ( 'duplicatesEnabled' , duplicatesEnabled ) ; } , insertPolicy ( widget , _ , insertPolicy ) { widget . setProperty ( 'insertPolicy' , insertPolicy ) ; } , maxCount ( widget , _ , maxCount ) { widget . setProperty ( 'maxCount' , maxCount ) ; } , maxVisibleItems ( widget , _ , maxVisibleItems ) { widget . setMaxVisibleItems ( maxVisibleItems ) ; } , minimumContentsLength ( widget , _ , minimumContentsLength ) { widget . setProperty ( 'minimumContentsLength' , minimumContentsLength ) ; } , modelColumn ( widget , _ , modelColumn ) { widget . setProperty ( 'modelColumn' , modelColumn ) ; } , sizeAdjustPolicy ( widget , _ , sizeAdjustPolicy ) { widget . setSizeAdjustPolicy ( sizeAdjustPolicy ) ; } , } ; internal export class VNComboBox extends QComboBox implements VNWidget < ComboBoxProps > { patchProp ( key , prevValue , nextValue ) { const propSetter = comboBoxPropsSetters [ key ] ; if ( propSetter !== undefined ) { propSetter ( this , prevValue as never , nextValue as never ) ; } } insertChild ( ) { throw new Error ( 'Cannot add child to ComboBox elements' ) ; } getNextSibling ( ) { throw new Error ( 'ComboBox elements cannot have children' ) ; } insertBefore ( ) { throw new Error ( 'Cannot add child to ComboBox elements' ) ; } removeChild ( ) { throw new Error ( 'Cannot remove/add child to ComboBox elements' ) ; } }