Skip to content

Commit 34f318a

Browse files
FileTypeIcon enhancements (#1789)
* Added onClick support to FileTypeIcon * Added various events to FileTypeIcon * Updated documentation * Update docs/documentation/docs/controls/FileTypeIcon.md Co-authored-by: Michaël Maillot <[email protected]> * Update docs/documentation/docs/controls/FileTypeIcon.md Co-authored-by: Michaël Maillot <[email protected]> * Update docs/documentation/docs/controls/FileTypeIcon.md Co-authored-by: Michaël Maillot <[email protected]> * Update docs/documentation/docs/controls/FileTypeIcon.md Co-authored-by: Michaël Maillot <[email protected]> * Update docs/documentation/docs/controls/FileTypeIcon.md Co-authored-by: Michaël Maillot <[email protected]> * Update docs/documentation/docs/controls/FileTypeIcon.md Co-authored-by: Michaël Maillot <[email protected]> * Removed unused imports in IFileTypeIcon.ts --------- Co-authored-by: Michaël Maillot <[email protected]>
1 parent 6be67f9 commit 34f318a

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

docs/documentation/docs/controls/FileTypeIcon.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,11 @@ The FileTypeIcon component can be configured with the following properties:
4242
| path | string | no | Path to the document. If this is provided, the control will use the file extension to display the corresponding icon. |
4343
| size | ImageSize | no | This is a property that only needs to be used when the type is set to image. It allows you to specify the image size. small (16px), normal (20px), medium (48px) and large (96px) are possible. Use the **ImageSize** enum to get the list of available images sizes. |
4444
| type | IconType | yes | This property specifies is you want to use the icon font or image. Use the **IconType** enum to get the list of available icon types. |
45+
| onClick | React.MouseEvent&lt;HTMLElement&gt; | no | Event triggered when the icon is clicked. |
46+
| onDoubleClick | React.MouseEvent&lt;HTMLElement&gt; | no | Event triggered when the icon is double clicked. |
47+
| onMouseEnter | React.MouseEvent&lt;HTMLElement&gt; | no | Event triggered when the mouse cursor enters the icon (without event bubbling). |
48+
| onMouseLeave | React.MouseEvent&lt;HTMLElement&gt; | no | Event triggered when the mouse cursor leaves the icon. |
49+
| onMouseOver | React.MouseEvent&lt;HTMLElement&gt; | no | Event triggered when the mouse cursor enters the icon (with event bubbling). |
50+
| onMouseUp | React.MouseEvent&lt;HTMLElement&gt; | no | Event triggered when the mouse button is released after clicked on the icon. |
4551

4652
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/FileTypeIcon)

src/controls/fileTypeIcon/FileTypeIcon.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ export class FileTypeIcon extends React.Component<IFileTypeIconProps, {}> {
264264
iconElm = <Icon iconName={iconClass} />;
265265
}
266266

267+
// Bind events
268+
iconElm.props.onClick = this.props.onClick;
269+
iconElm.props.onDoubleClick = this.props.onDoubleClick;
270+
iconElm.props.onMouseEnter = this.props.onMouseEnter;
271+
iconElm.props.onMouseLeave = this.props.onMouseLeave;
272+
iconElm.props.onMouseOver = this.props.onMouseOver;
273+
iconElm.props.onMouseUp = this.props.onMouseUp;
274+
267275
// Return the icon element
268276
return iconElm;
269277
}

src/controls/fileTypeIcon/IFileTypeIcon.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { MouseEventHandler } from "react";
2+
13
/**
24
* Available icon types
35
*/
@@ -225,11 +227,16 @@ export interface ImageInformation {
225227
* Interface for the FileTypeIcon component properties
226228
*/
227229
export interface IFileTypeIconProps {
228-
229230
type: IconType;
230231
application?: ApplicationType;
231232
path?: string;
232233
size?: ImageSize;
234+
onClick?: MouseEventHandler<HTMLElement> | undefined;
235+
onDoubleClick?: MouseEventHandler<HTMLElement> | undefined;
236+
onMouseEnter?: MouseEventHandler<HTMLElement> | undefined;
237+
onMouseLeave?: MouseEventHandler<HTMLElement> | undefined;
238+
onMouseOver?: MouseEventHandler<HTMLElement> | undefined;
239+
onMouseUp?: MouseEventHandler<HTMLElement> | undefined;
233240
}
234241

235242
/**

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,17 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
15301530
<FileTypeIcon type={IconType.image} application={ApplicationType.PDF} />
15311531
<FileTypeIcon type={IconType.image} path="https://contoso.sharepoint.com/documents/filename.pdf" />
15321532
</div>
1533+
<div className="ms-font-m">
1534+
Image icons with support to events:
1535+
<FileTypeIcon type={IconType.image} application={ApplicationType.PowerApps} size={ImageSize.medium}
1536+
onClick={(e) => console.log("onClick on FileTypeIcon!")}
1537+
onDoubleClick={(e) => console.log("onDoubleClick on FileTypeIcon!")}
1538+
onMouseEnter={(e) => console.log("onMouseEnter on FileTypeIcon!")}
1539+
onMouseLeave={(e) => console.log("onMouseLeave on FileTypeIcon!")}
1540+
onMouseOver={(e) => console.log("onMouseOver on FileTypeIcon!")}
1541+
onMouseUp={(e) => console.log("onMouseUp on FileTypeIcon!")}
1542+
/>
1543+
</div>
15331544
<div className="ms-font-m">Icon size tester:
15341545
<Dropdown options={sizeOptions} onChanged={this._onIconSizeChange} />
15351546
<FileTypeIcon type={IconType.image} size={this.state.imgSize} application={ApplicationType.Excel} />

0 commit comments

Comments
 (0)