import * as React from 'react' ; import * as ReactDOM from 'react-dom' ; import { IPropertyPaneField , PropertyPaneFieldType } from '@microsoft/sp-webpart-base' ; import omit from 'lodash/omit' ; import PropertyFieldToggleWithCalloutHost from './PropertyFieldChoiceGroupWithCalloutHost' ; import { IPropertyFieldChoiceGroupWithCalloutPropsInternal , IPropertyFieldChoiceGroupWithCalloutProps } from './IPropertyFieldChoiceGroupWithCallout' ; import { IChoiceGroupOption } from 'office-ui-fabric-react/lib/components/ChoiceGroup' ; class PropertyFieldChoiceGroupWithCalloutBuilder implements IPropertyPaneField < IPropertyFieldChoiceGroupWithCalloutPropsInternal > { public targetProperty : string ; public type : PropertyPaneFieldType = PropertyPaneFieldType . Custom ; public properties : IPropertyFieldChoiceGroupWithCalloutPropsInternal ; private _onChangeCallback : ( targetProperty ? : string , newValue ? : any ) => void ; public constructor ( _targetProperty , _properties ) { this . targetProperty = _targetProperty ; this . properties = _properties ; this . properties . onRender = this . _render . bind ( this ) ; this . properties . onDispose = this . _dispose . bind ( this ) ; } private _render ( elem , context ? , changeCallback ? ) { const options = this . properties . options . map < IChoiceGroupOption > ( o => { return { ... omit ( o , [ 'key' , 'iconProps' ] ) , iconProps : o . iconProps && { iconName : o . iconProps . officeFabricIconFontName } , key : o . key . toString ( ) } ; } ) ; const props = this . properties as IPropertyFieldChoiceGroupWithCalloutProps ; const element = React . createElement ( PropertyFieldToggleWithCalloutHost , { ... omit ( props , [ 'options' ] ) , options : options , onChanged : this . _onChanged . bind ( this ) } ) ; ReactDOM . render ( element , elem ) ; if ( changeCallback ) { this . _onChangeCallback = changeCallback ; } } private _dispose ( elem ) { ReactDOM . unmountComponentAtNode ( elem ) ; } private _onChanged ( option ) { if ( this . _onChangeCallback ) { this . _onChangeCallback ( this . targetProperty , option . key ) ; } } } export function PropertyFieldChoiceGroupWithCallout ( targetProperty , properties ) { return new PropertyFieldChoiceGroupWithCalloutBuilder ( targetProperty , { ... properties , onRender : null , onDispose : null } ) ; }