Skip to content

Commit 8ba3cd6

Browse files
author
Piotr Siatka
committed
Add support for IconButton.
1 parent 55576bc commit 8ba3cd6

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/controls/filePicker/FilePicker.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IFilePickerProps } from './IFilePickerProps';
33
import { IFilePickerState } from './IFilePickerState';
44

55
// Office Fabric controls
6-
import { PrimaryButton } from 'office-ui-fabric-react/lib/components/Button';
6+
import { PrimaryButton, IconButton } from 'office-ui-fabric-react/lib/components/Button';
77
import { Panel, PanelType } from 'office-ui-fabric-react/lib/components/Panel';
88
import { Label } from 'office-ui-fabric-react/lib/components/Label';
99
import { Nav, INavLink, INavLinkGroup } from 'office-ui-fabric-react/lib/Nav';
@@ -70,13 +70,21 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
7070
onClose: () => this._handleClosePanel(),
7171
onSave: (value: IFilePickerResult) => { this._handleSave(value); }
7272
};
73+
const buttonProps = {
74+
disabled: this.props.disabled,
75+
onClick: this._handleOpenPanel
76+
}
7377

7478
return (
7579
<div >
76-
<Label required={this.props.required}>{this.props.label}</Label>
77-
<PrimaryButton text={this.props.buttonLabel}
78-
onClick={this._handleOpenPanel}
79-
disabled={this.props.disabled} />
80+
{
81+
this.props.label && <Label required={this.props.required}>{this.props.label}</Label>
82+
}
83+
{
84+
this.props.buttonIcon ?
85+
<IconButton iconProps={{ iconName: this.props.buttonIcon }} {...buttonProps} /> :
86+
<PrimaryButton text={this.props.buttonLabel} {...buttonProps}/>
87+
}
8088

8189
<Panel isOpen={this.state.panelOpen}
8290
isBlocking={true}

src/controls/filePicker/IFilePickerProps.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export interface IFilePickerProps {
99
/**
1010
* Specifies the label of the file picker button
1111
*/
12-
buttonLabel: string;
12+
buttonLabel?: string;
13+
14+
/**
15+
* Specifies the icon to be used to display Icon Button.
16+
*/
17+
buttonIcon?: string;
1318

1419
/**
1520
* Content of the file.

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
340340
<div className={styles.controlsTest}>
341341
<FilePicker
342342
bingAPIKey="D41D8CD98F00B204E9800998ECF8427E06193A4E"
343-
buttonLabel="Choose file"
344-
label="File picker"
343+
// buttonLabel="Choose file"
344+
// label="File picker"
345+
buttonIcon="FileImage"
345346
onSave={(filePickerResult: IFilePickerResult) => { this.setState({filePickerResult }) }}
346347
onChanged={(filePickerResult: IFilePickerResult) => { this.setState({filePickerResult }) }}
347348
filePickerResult={null}

0 commit comments

Comments
 (0)