-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #594 from pnp/dev
3.15.1
- Loading branch information
Showing
9 changed files
with
154 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const version: string = "3.15.0"; | ||
export const version: string = "3.15.1"; |
131 changes: 80 additions & 51 deletions
131
src/propertyFields/choiceGroupWithCallout/PropertyFieldChoiceGroupWithCallout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,101 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { | ||
IPropertyPaneField, | ||
PropertyPaneFieldType | ||
IPropertyPaneField, | ||
PropertyPaneFieldType, | ||
} from '@microsoft/sp-property-pane'; | ||
import omit from 'lodash/omit'; | ||
|
||
import PropertyFieldToggleWithCalloutHost from './PropertyFieldChoiceGroupWithCalloutHost'; | ||
|
||
import {IPropertyFieldChoiceGroupWithCalloutPropsInternal, IPropertyFieldChoiceGroupWithCalloutProps} from './IPropertyFieldChoiceGroupWithCallout'; | ||
import { | ||
IPropertyFieldChoiceGroupWithCalloutPropsInternal, | ||
IPropertyFieldChoiceGroupWithCalloutProps, | ||
} from './IPropertyFieldChoiceGroupWithCallout'; | ||
import { IChoiceGroupOption } from '@fluentui/react/lib/components/ChoiceGroup'; | ||
|
||
class PropertyFieldChoiceGroupWithCalloutBuilder implements IPropertyPaneField<IPropertyFieldChoiceGroupWithCalloutPropsInternal> { | ||
public targetProperty: string; | ||
public type: PropertyPaneFieldType = PropertyPaneFieldType.Custom; | ||
public properties: IPropertyFieldChoiceGroupWithCalloutPropsInternal; | ||
class PropertyFieldChoiceGroupWithCalloutBuilder | ||
implements | ||
IPropertyPaneField<IPropertyFieldChoiceGroupWithCalloutPropsInternal> | ||
{ | ||
public targetProperty: string; | ||
public type: PropertyPaneFieldType = PropertyPaneFieldType.Custom; | ||
public properties: IPropertyFieldChoiceGroupWithCalloutPropsInternal; | ||
|
||
private _onChangeCallback: (targetProperty?: string, newValue?: any) => void; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
private _onChangeCallback: (targetProperty?: string, newValue?: any) => void; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
|
||
public constructor(_targetProperty: string, _properties: IPropertyFieldChoiceGroupWithCalloutPropsInternal) { | ||
this.targetProperty = _targetProperty; | ||
this.properties = _properties; | ||
public constructor( | ||
_targetProperty: string, | ||
_properties: IPropertyFieldChoiceGroupWithCalloutPropsInternal | ||
) { | ||
this.targetProperty = _targetProperty; | ||
this.properties = _properties; | ||
|
||
this.properties.onRender = this._render.bind(this); | ||
this.properties.onDispose = this._dispose.bind(this); | ||
} | ||
this.properties.onRender = this._render.bind(this); | ||
this.properties.onDispose = this._dispose.bind(this); | ||
} | ||
|
||
private _render(elem: HTMLElement, context?: any, changeCallback?: (targetProperty?: string, newValue?: any) => void): void { // eslint-disable-line @typescript-eslint/no-explicit-any | ||
// IPropertyPaneChoiceGroupOption should be manually converted to IChoiceGroupOption | ||
const options: IChoiceGroupOption[] = 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, | ||
onChange: this._onChanged.bind(this) | ||
}); | ||
|
||
ReactDOM.render(element, elem); | ||
|
||
if (changeCallback) { | ||
this._onChangeCallback = changeCallback; | ||
} | ||
} | ||
private _render( | ||
elem: HTMLElement, | ||
context?: any, | ||
changeCallback?: (targetProperty?: string, newValue?: any) => void | ||
): void { | ||
// eslint-disable-line @typescript-eslint/no-explicit-any | ||
// IPropertyPaneChoiceGroupOption should be manually converted to IChoiceGroupOption | ||
|
||
const options: IChoiceGroupOption[] = []; | ||
let selectedKey: string | number | undefined = undefined; | ||
|
||
this.properties.options.forEach((o) => { | ||
options.push({ | ||
...omit(o, ['key', 'iconProps']), | ||
iconProps: o.iconProps && { | ||
iconName: o.iconProps.officeFabricIconFontName, | ||
}, | ||
key: o.key.toString(), | ||
}); | ||
|
||
if (o.checked) { | ||
selectedKey = o.key; | ||
} | ||
}); | ||
const props = this.properties as IPropertyFieldChoiceGroupWithCalloutProps; | ||
|
||
const element = React.createElement(PropertyFieldToggleWithCalloutHost, { | ||
...omit(props, ['options']), | ||
options: options, | ||
onChange: this._onChanged.bind(this), | ||
selectedKey: selectedKey, | ||
}); | ||
|
||
private _dispose(elem: HTMLElement): void { | ||
ReactDOM.unmountComponentAtNode(elem); | ||
ReactDOM.render(element, elem); | ||
|
||
if (changeCallback) { | ||
this._onChangeCallback = changeCallback; | ||
} | ||
} | ||
|
||
private _dispose(elem: HTMLElement): void { | ||
ReactDOM.unmountComponentAtNode(elem); | ||
} | ||
|
||
private _onChanged(option: IChoiceGroupOption): void { | ||
if (this._onChangeCallback) { | ||
this._onChangeCallback(this.targetProperty, option.key); | ||
} | ||
private _onChanged( | ||
ev?: React.FormEvent<HTMLElement | HTMLInputElement>, | ||
option?: IChoiceGroupOption | ||
): void { | ||
if (this._onChangeCallback && option) { | ||
this._onChangeCallback(this.targetProperty, option.key); | ||
} | ||
} | ||
} | ||
|
||
export function PropertyFieldChoiceGroupWithCallout(targetProperty: string, properties: IPropertyFieldChoiceGroupWithCalloutProps): IPropertyPaneField<IPropertyFieldChoiceGroupWithCalloutPropsInternal> { | ||
return new PropertyFieldChoiceGroupWithCalloutBuilder(targetProperty, { | ||
...properties, | ||
onRender: null, | ||
onDispose: null | ||
}); | ||
export function PropertyFieldChoiceGroupWithCallout( | ||
targetProperty: string, | ||
properties: IPropertyFieldChoiceGroupWithCalloutProps | ||
): IPropertyPaneField<IPropertyFieldChoiceGroupWithCalloutPropsInternal> { | ||
return new PropertyFieldChoiceGroupWithCalloutBuilder(targetProperty, { | ||
...properties, | ||
onRender: null, | ||
onDispose: null, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters