Skip to content

Commit 06bb4f9

Browse files
committed
Changes to import IFrameDialog correctly from the library
1 parent f004a95 commit 06bb4f9

File tree

7 files changed

+44
-12
lines changed

7 files changed

+44
-12
lines changed

docs/documentation/docs/controls/IFrameDialog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Here is an example of the control in action:
1515
import { IFrameDialog } from "@pnp/spfx-controls-react/lib/IFrameDialog";
1616
```
1717

18-
- Use the `IFrameDialog` control in your code as follows:
18+
- Use the `IFrameDialog` control in your code as follows (`this._onIframeLoaded` and `this._onDialogDismiss` are methods that should be implemented if you want to execute some actions when the iframe content is loaded and dialog should be closed respectively):
1919

2020
```TypeScript
2121
<IFrameDialog

src/common/utilities/FieldRendererHelper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { SPField } from '@microsoft/sp-page-context';
99
import { IContext } from '../Interfaces';
1010
import { GeneralHelper } from './GeneralHelper';
1111
import { FieldLookupRenderer, IFieldLookupClickEventArgs } from '../../controls/fields/fieldLookupRenderer/FieldLookupRenderer';
12-
import IFrameDialog from '../../controls/iFrameDialog/IFrameDialog';
1312
import { FieldUrlRenderer } from '../../controls/fields/fieldUrlRenderer/FieldUrlRenderer';
1413
import { FieldTaxonomyRenderer } from '../../controls/fields/fieldTaxonomyRenderer/FieldTaxonomyRenderer';
1514
import { IFieldRendererProps } from '../../controls/fields/fieldCommon/IFieldRendererProps';

src/controls/fields/fieldLookupRenderer/FieldLookupRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IFieldRendererProps } from '../fieldCommon/IFieldRendererProps';
77
import * as appInsights from '../../../common/appInsights';
88

99
import styles from './FieldLookupRenderer.module.scss';
10-
import IFrameDialog from '../../iFrameDialog/IFrameDialog';
10+
import { IFrameDialog } from '../../iFrameDialog/IFrameDialog';
1111
import { SPHelper } from '../../../Utilities';
1212
import { IContext } from '../../../Common';
1313

src/controls/iFrameDialog/IFrameDialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import * as ReactDOM from "react-dom";
33
import { Dialog, IDialogProps } from 'office-ui-fabric-react';
4-
import IFrameDialogContent from './IFrameDialogContent';
4+
import { IFrameDialogContent } from './IFrameDialogContent';
55
import * as appInsights from '../../common/appInsights';
66

77
export interface IFrameDialogProps extends IDialogProps {
@@ -12,7 +12,7 @@ export interface IFrameDialogProps extends IDialogProps {
1212
/**
1313
* iframe's onload event handler
1414
*/
15-
iframeOnLoad?: (iframe: any) => {};
15+
iframeOnLoad?: (iframe: any) => void;
1616
/**
1717
* iframe width
1818
*/
@@ -29,7 +29,7 @@ export interface IFrameDialogState {
2929
/**
3030
* Dialog component to display content in iframe
3131
*/
32-
export default class IFrameDialog extends React.Component<IFrameDialogProps, IFrameDialogState> {
32+
export class IFrameDialog extends React.Component<IFrameDialogProps, IFrameDialogState> {
3333

3434
public constructor(props: IFrameDialogProps, state: IFrameDialogState) {
3535
super(props, state);

src/controls/iFrameDialog/IFrameDialogContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import styles from './IFrameDialogContent.module.scss';
66
export interface IIFrameDialogContentProps {
77
url: string;
88
close: () => void;
9-
iframeOnLoad?: (iframe: any) => {};
9+
iframeOnLoad?: (iframe: any) => void;
1010
width: string;
1111
height: string;
1212
}
1313

1414
/**
1515
* IFrame Dialog content
1616
*/
17-
export default class IFrameDialogContent extends React.Component<IIFrameDialogContentProps, {}> {
17+
export class IFrameDialogContent extends React.Component<IIFrameDialogContentProps, {}> {
1818
private _iframe: any;
1919

2020
constructor(props: IIFrameDialogContentProps) {

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import { IControlsTestProps, IControlsTestState } from './IControlsTestProps';
44
import { escape } from '@microsoft/sp-lodash-subset';
55
import { FileTypeIcon, IconType, ApplicationType, ImageSize } from '../../../FileTypeIcon';
66
import { Dropdown, IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown';
7+
import { PrimaryButton } from 'office-ui-fabric-react/lib/components/Button';
8+
import { DialogType } from 'office-ui-fabric-react/lib/components/Dialog';
79
import { Placeholder } from '../../../Placeholder';
810
import { ListView, IViewField, SelectionMode, GroupOrder, IGrouping } from '../../../ListView';
911
import { SPHttpClient } from '@microsoft/sp-http';
1012
import { SiteBreadcrumb } from '../../../SiteBreadcrumb';
1113
import { WebPartTitle } from '../../../WebPartTitle';
14+
import { IFrameDialog } from '../../../IFrameDialog';
15+
import { Environment, EnvironmentType } from '@microsoft/sp-core-library';
1216

1317
/**
1418
* Component that can be used to test out the React controls from this project
@@ -19,7 +23,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
1923

2024
this.state = {
2125
imgSize: ImageSize.small,
22-
items: []
26+
items: [],
27+
iFrameDialogOpened: false
2328
};
2429

2530
this._onIconSizeChange = this._onIconSizeChange.bind(this);
@@ -120,13 +125,21 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
120125

121126
// Specify the fields on which you want to group your items
122127
// Grouping is takes the field order into account from the array
123-
const groupByFields: IGrouping[] = [{name: "ListItemAllFields.City", order: GroupOrder.ascending }, {name: "ListItemAllFields.Country.Label", order: GroupOrder.descending}];
128+
const groupByFields: IGrouping[] = [{ name: "ListItemAllFields.City", order: GroupOrder.ascending }, { name: "ListItemAllFields.Country.Label", order: GroupOrder.descending }];
129+
130+
let iframeUrl: string = '/temp/workbench.html';
131+
if (Environment.type === EnvironmentType.SharePoint) {
132+
iframeUrl = '/_layouts/15/sharepoint.aspx';
133+
}
134+
else if (Environment.type === EnvironmentType.ClassicSharePoint) {
135+
iframeUrl = this.context.pageContext.web.serverRelativeUrl;
136+
}
124137

125138
return (
126139
<div className={styles.controlsTest}>
127140
<WebPartTitle displayMode={this.props.displayMode}
128-
title={this.props.title}
129-
updateProperty={this.props.updateProperty} />
141+
title={this.props.title}
142+
updateProperty={this.props.updateProperty} />
130143

131144
<div className={styles.container}>
132145
<div className={`ms-Grid-row ms-bgColor-neutralLight ms-fontColor-neutralDark ${styles.row}`}>
@@ -157,6 +170,25 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
157170
<FileTypeIcon type={IconType.image} size={this.state.imgSize} application={ApplicationType.Excel} />
158171
<FileTypeIcon type={IconType.image} size={this.state.imgSize} />
159172
</div>
173+
<div className="ms-font-m">iframe dialog tester:
174+
<PrimaryButton
175+
text="Open iframe Dialog"
176+
onClick={() => { this.setState({ iFrameDialogOpened: true }); }} />
177+
<IFrameDialog
178+
url={iframeUrl}
179+
iframeOnLoad={(iframe: any) => { console.log('iframe loaded'); }}
180+
hidden={!this.state.iFrameDialogOpened}
181+
onDismiss={() => { this.setState({ iFrameDialogOpened: false }); }}
182+
modalProps={{
183+
isBlocking: true
184+
}}
185+
dialogContentProps={{
186+
type: DialogType.close,
187+
showCloseButton: true
188+
}}
189+
width={'570px'}
190+
height={'315px'} />
191+
</div>
160192
</div>
161193
</div>
162194
</div>

src/webparts/controlsTest/components/IControlsTestProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export interface IControlsTestProps {
1313
export interface IControlsTestState {
1414
imgSize: ImageSize;
1515
items: any[];
16+
iFrameDialogOpened?: boolean;
1617
}

0 commit comments

Comments
 (0)