import type { VNode } from 'vue'; import type { DropdownButtonItemArgs } from '../dropdown-button/dropdown-button-item'; import type { FormItemWrapperArgs, HintType, MarginType } from '../form/form-item-wrapper'; import { Prop, toNative } from 'vue-facing-decorator'; import TsxComponent, { Component } from '../../app/vuetsx'; import VueUtils from './../../common/utils/vue-utils'; import RadioButtonGroup from './radio-button-group'; import './css/radio-button-enhanced-group.css'; export interface RadioButtonExtendedItem { id: number | string; text: string; disabled?: boolean; subtitle?: string; image?: string | VNode; } interface RadioButtonExtendedGroupArgs extends FormItemWrapperArgs { changed: (newValue: RadioButtonExtendedItem) => void; customRenderOption?: (h, state: RadioButtonExtendedItem) => any; customRenderSelectionResult?: (h, state: RadioButtonExtendedItem) => any; options: Array; selected: RadioButtonExtendedItem; } @Component class RadioButtonEnhancedGroupComponent extends TsxComponent implements RadioButtonExtendedGroupArgs { @Prop() label!: string | VNode; @Prop() labelButtons!: DropdownButtonItemArgs[]; @Prop() subtitle!: string; @Prop() cssClass!: string; @Prop() mandatory!: boolean; @Prop() wrap!: boolean; @Prop() hint: string; @Prop() hintType!: HintType; @Prop() appendIcon: string; @Prop() prependIcon: string; @Prop() appendClicked: () => void; @Prop() prependClicked: () => void; @Prop() marginType?: MarginType; @Prop() maxWidth?: number; @Prop() changed: (newValue: string | any) => void; @Prop() customRenderOption?: (h, state: RadioButtonExtendedItem) => any; @Prop() customRenderSelectionResult?: (h, state: RadioButtonExtendedItem) => any; @Prop() options: Array; @Prop() selected: RadioButtonExtendedItem; render(h) { return ( 0 ? `pd-radio-button-enhanced-group ${this.cssClass}` : 'pd-radio-button-enhanced-group'} options={this.options} selected={this.selected} changed={(e) => { this.changed(e); }} customRenderOption={(h, state: RadioButtonExtendedItem) => { if (this.customRenderOption) { return this.customRenderOption(h, state); } const disabledCssClass = state.disabled ? ' disabled' : ''; const subtitle = state.subtitle; return (
{state.text} {subtitle && (
{subtitle}
)}
{this.renderImage( h, state.image, state, )}
); }} /> ); } renderImage( h, image: string | VNode, state: RadioButtonExtendedItem, ) { if (image == null) { return null; } if (VueUtils.isVNode(image)) { return (
{image}
); } if ((image as string).includes('/')) { return (
{state.text}
); } return (
); } } const RadioButtonEnahancedGroup = toNative(RadioButtonEnhancedGroupComponent); export default RadioButtonEnahancedGroup;