From 34a8651652513a8ee3b4988b8b3ab55de23ba5c8 Mon Sep 17 00:00:00 2001 From: Stauffer Taylor Date: Fri, 16 Feb 2018 14:50:05 -0800 Subject: [PATCH 1/7] Add errorAs callback to Icon --- .../src/components/Breadcrumb/Breadcrumb.tsx | 8 +- .../src/components/Button/BaseButton.tsx | 8 +- .../src/components/Check/Check.tsx | 16 +- .../src/components/CommandBar/CommandBar.tsx | 2 +- .../src/components/Icon/Icon.tsx | 164 ++++++++++-------- .../src/components/Icon/Icon.types.ts | 6 + 6 files changed, 117 insertions(+), 87 deletions(-) diff --git a/packages/office-ui-fabric-react/src/components/Breadcrumb/Breadcrumb.tsx b/packages/office-ui-fabric-react/src/components/Breadcrumb/Breadcrumb.tsx index 1b3b682702215d..7a9f105e9660f9 100644 --- a/packages/office-ui-fabric-react/src/components/Breadcrumb/Breadcrumb.tsx +++ b/packages/office-ui-fabric-react/src/components/Breadcrumb/Breadcrumb.tsx @@ -102,10 +102,10 @@ export class Breadcrumb extends BaseComponent { directionalHint: DirectionalHint.bottomLeftEdge } } /> - { Icon({ - className: css('ms-Breadcrumb-chevron', styles.chevron), - iconName: getRTL() ? 'ChevronLeft' : 'ChevronRight' - }) } + { } ) } { renderedItems.map( diff --git a/packages/office-ui-fabric-react/src/components/Button/BaseButton.tsx b/packages/office-ui-fabric-react/src/components/Button/BaseButton.tsx index 7c0ec7e68e7253..6f854abb1e3858 100644 --- a/packages/office-ui-fabric-react/src/components/Button/BaseButton.tsx +++ b/packages/office-ui-fabric-react/src/components/Button/BaseButton.tsx @@ -254,10 +254,10 @@ export class BaseButton extends BaseComponent } return null; } diff --git a/packages/office-ui-fabric-react/src/components/Check/Check.tsx b/packages/office-ui-fabric-react/src/components/Check/Check.tsx index 0141ca290999de..8df86293c35459 100644 --- a/packages/office-ui-fabric-react/src/components/Check/Check.tsx +++ b/packages/office-ui-fabric-react/src/components/Check/Check.tsx @@ -48,14 +48,14 @@ export class Check extends BaseComponent { } ) } > - { Icon({ - className: 'ms-Check-circle ' + styles.circle, - iconName: 'CircleRing' - }) } - { Icon({ - className: 'ms-Check-check ' + styles.check, - iconName: 'StatusCircleCheckmark' - }) } + { } + { } ); } diff --git a/packages/office-ui-fabric-react/src/components/CommandBar/CommandBar.tsx b/packages/office-ui-fabric-react/src/components/CommandBar/CommandBar.tsx index 380c19195a352c..e5dbfbca6b880d 100644 --- a/packages/office-ui-fabric-react/src/components/CommandBar/CommandBar.tsx +++ b/packages/office-ui-fabric-react/src/components/CommandBar/CommandBar.tsx @@ -95,7 +95,7 @@ export class CommandBar extends BaseComponent - { Icon({ iconName: 'Search' }) } + { }
{ - let { - ariaLabel, - className, - styles, - iconName - } = props; - let classNames = getClassNames( - styles - ); +export interface IIconState { + imageLoadError: boolean; +} - if (props.iconType === IconType.image || props.iconType === IconType.Image) { - let containerClassName = css( - 'ms-Icon-imageContainer', - classNames.root, - classNames.imageContainer, - className - ); +export class Icon extends React.Component { + constructor(props: IIconProps) { + super(props); + this.state = { + imageLoadError: false, + } + } - return ( -
- -
- ); - } else if (typeof iconName === 'string' && iconName.length === 0) { - return ( - - ); - } else { - let iconDefinition = getIcon(iconName) || { - subset: { - className: undefined - }, - code: undefined - }; + private onImageLoadingStateChange = (state: ImageLoadState): void => { + if (this.props.imageProps && this.props.imageProps.onLoadingStateChange) { + this.props.imageProps.onLoadingStateChange(state); + } + if (state == ImageLoadState.error) { + this.setState({ imageLoadError: true }); + } + } - return ( - - { iconDefinition.code } - + render() { + let { + ariaLabel, + className, + styles, + iconName, + errorAs, + } = this.props; + let classNames = getClassNames( + styles ); + + const containerProps = ariaLabel ? { 'aria-label': ariaLabel, 'data-icon-name': iconName, } : { + role: 'presentation', + 'aria-hidden': true, + 'data-icon-name': iconName, + } + + if (this.props.iconType === IconType.image || this.props.iconType === IconType.Image) { + let containerClassName = css( + 'ms-Icon-imageContainer', + classNames.root, + classNames.imageContainer, + className + ); + let { imageLoadError } = this.state; + let imageProps = { ...this.props.imageProps, onLoadingStateChange: this.onImageLoadingStateChange } + let ImageType = imageLoadError && errorAs || Image; + return ( +
+ +
+ ); + } else if (typeof iconName === 'string' && iconName.length === 0) { + return ( + + ); + } else { + let iconDefinition = getIcon(iconName) || { + subset: { + className: undefined + }, + code: undefined + }; + + return ( + + { iconDefinition.code } + + ); + } } }; diff --git a/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts b/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts index c776f1cfcee22f..0b51d779b143c0 100644 --- a/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts +++ b/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts @@ -1,6 +1,7 @@ import * as React from 'react'; import { IImageProps } from '../Image/Image.types'; import { IStyle } from '../../Styling'; +import { Icon } from './Icon'; // Please keep alphabetized export enum IconType { @@ -65,4 +66,9 @@ export interface IIconProps extends React.HTMLAttributes { * @memberOf IIconProps */ imageProps?: IImageProps; + + /** + * If rendering an image icon, this function callback will be invoked in the event loading the image errors. + */ + errorAs?: (image: IImageProps) => any; } \ No newline at end of file From d7761f3fa453971db0da7e5f622024cba72616a1 Mon Sep 17 00:00:00 2001 From: Stauffer Taylor Date: Fri, 16 Feb 2018 14:52:01 -0800 Subject: [PATCH 2/7] change name --- packages/office-ui-fabric-react/src/components/Icon/Icon.tsx | 4 ++-- .../office-ui-fabric-react/src/components/Icon/Icon.types.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx b/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx index f2bc455f6e4ab5..20f97bd67e01e8 100644 --- a/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx +++ b/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx @@ -39,7 +39,7 @@ export class Icon extends React.Component { className, styles, iconName, - errorAs, + imageErrorAs, } = this.props; let classNames = getClassNames( styles @@ -60,7 +60,7 @@ export class Icon extends React.Component { ); let { imageLoadError } = this.state; let imageProps = { ...this.props.imageProps, onLoadingStateChange: this.onImageLoadingStateChange } - let ImageType = imageLoadError && errorAs || Image; + let ImageType = imageLoadError && imageErrorAs || Image; return (
{ /** * If rendering an image icon, this function callback will be invoked in the event loading the image errors. */ - errorAs?: (image: IImageProps) => any; + imageErrorAs?: (image: IImageProps) => any; } \ No newline at end of file From 583e8841720ffd81b1a1bff11518fa12b5d81920 Mon Sep 17 00:00:00 2001 From: Stauffer Taylor Date: Fri, 16 Feb 2018 14:54:46 -0800 Subject: [PATCH 3/7] add change file --- .../staylo-AddErrorAsToIcon_2018-02-16-22-54.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 common/changes/office-ui-fabric-react/staylo-AddErrorAsToIcon_2018-02-16-22-54.json diff --git a/common/changes/office-ui-fabric-react/staylo-AddErrorAsToIcon_2018-02-16-22-54.json b/common/changes/office-ui-fabric-react/staylo-AddErrorAsToIcon_2018-02-16-22-54.json new file mode 100644 index 00000000000000..e86b4124bafa32 --- /dev/null +++ b/common/changes/office-ui-fabric-react/staylo-AddErrorAsToIcon_2018-02-16-22-54.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "office-ui-fabric-react", + "comment": "Add imageErrorAs to IIconProps", + "type": "minor" + } + ], + "packageName": "office-ui-fabric-react", + "email": "staylo@microsoft.com" +} \ No newline at end of file From 37ec03652914050c7be129b5d64bf27f1eaa9ff7 Mon Sep 17 00:00:00 2001 From: Stauffer Taylor Date: Tue, 20 Feb 2018 10:39:14 -0800 Subject: [PATCH 4/7] Fix Build Errors --- .../__snapshots__/ActivityItem.test.tsx.snap | 2 -- .../__snapshots__/Breadcrumb.test.tsx.snap | 8 ------ .../src/components/Button/BaseButton.tsx | 10 ++++--- .../Button/__snapshots__/Button.test.tsx.snap | 3 -- .../__snapshots__/Calendar.test.tsx.snap | 4 --- .../__snapshots__/Checkbox.test.tsx.snap | 1 - .../__snapshots__/ComboBox.test.tsx.snap | 1 - .../__snapshots__/CommandBar.test.tsx.snap | 1 - .../__snapshots__/DatePicker.test.tsx.snap | 1 - .../__snapshots__/DocumentCard.test.tsx.snap | 1 - .../__snapshots__/Dropdown.test.tsx.snap | 2 -- .../src/components/Icon/Icon.tsx | 28 +++++++++---------- .../Icon/__snapshots__/Icon.test.tsx.snap | 1 - .../__snapshots__/MessageBar.test.tsx.snap | 1 - .../Nav/__snapshots__/Nav.test.tsx.snap | 2 +- .../Rating/__snapshots__/Rating.test.tsx.snap | 10 ------- .../__snapshots__/SearchBox.test.tsx.snap | 1 - .../__snapshots__/SpinButton.test.tsx.snap | 2 -- 18 files changed, 21 insertions(+), 58 deletions(-) diff --git a/packages/office-ui-fabric-react/src/components/ActivityItem/__snapshots__/ActivityItem.test.tsx.snap b/packages/office-ui-fabric-react/src/components/ActivityItem/__snapshots__/ActivityItem.test.tsx.snap index b3acb36fff522c..e861f560710775 100644 --- a/packages/office-ui-fabric-react/src/components/ActivityItem/__snapshots__/ActivityItem.test.tsx.snap +++ b/packages/office-ui-fabric-react/src/components/ActivityItem/__snapshots__/ActivityItem.test.tsx.snap @@ -173,7 +173,6 @@ exports[`ActivityItem renders compact with an icon correctly 1`] = ` > + return ( + + ); } return null; } diff --git a/packages/office-ui-fabric-react/src/components/Button/__snapshots__/Button.test.tsx.snap b/packages/office-ui-fabric-react/src/components/Button/__snapshots__/Button.test.tsx.snap index 0fbc1378c8cfc1..c2803b1370a6ba 100644 --- a/packages/office-ui-fabric-react/src/components/Button/__snapshots__/Button.test.tsx.snap +++ b/packages/office-ui-fabric-react/src/components/Button/__snapshots__/Button.test.tsx.snap @@ -180,7 +180,6 @@ exports[`Button renders CommandBarButton correctly 1`] = ` > { super(props); this.state = { imageLoadError: false, - } - } - - private onImageLoadingStateChange = (state: ImageLoadState): void => { - if (this.props.imageProps && this.props.imageProps.onLoadingStateChange) { - this.props.imageProps.onLoadingStateChange(state); - } - if (state == ImageLoadState.error) { - this.setState({ imageLoadError: true }); - } + }; } - render() { + public render() { let { ariaLabel, className, @@ -49,7 +40,7 @@ export class Icon extends React.Component { role: 'presentation', 'aria-hidden': true, 'data-icon-name': iconName, - } + }; if (this.props.iconType === IconType.image || this.props.iconType === IconType.Image) { let containerClassName = css( @@ -59,7 +50,7 @@ export class Icon extends React.Component { className ); let { imageLoadError } = this.state; - let imageProps = { ...this.props.imageProps, onLoadingStateChange: this.onImageLoadingStateChange } + let imageProps = { ...this.props.imageProps, onLoadingStateChange: this.onImageLoadingStateChange }; let ImageType = imageLoadError && imageErrorAs || Image; return (
{ ); } } -}; + + private onImageLoadingStateChange = (state: ImageLoadState): void => { + if (this.props.imageProps && this.props.imageProps.onLoadingStateChange) { + this.props.imageProps.onLoadingStateChange(state); + } + if (state === ImageLoadState.error) { + this.setState({ imageLoadError: true }); + } + } +} diff --git a/packages/office-ui-fabric-react/src/components/Icon/__snapshots__/Icon.test.tsx.snap b/packages/office-ui-fabric-react/src/components/Icon/__snapshots__/Icon.test.tsx.snap index 3b1bc246f97218..ab530ac055dbe0 100644 --- a/packages/office-ui-fabric-react/src/components/Icon/__snapshots__/Icon.test.tsx.snap +++ b/packages/office-ui-fabric-react/src/components/Icon/__snapshots__/Icon.test.tsx.snap @@ -3,7 +3,6 @@ exports[`Icon renders Icon correctly 1`] = `
Date: Tue, 20 Feb 2018 11:48:50 -0800 Subject: [PATCH 5/7] Fix build errors --- packages/office-ui-fabric-react/src/components/Icon/Icon.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx b/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx index eca8e2b6e3493b..9cffb032aaa6ba 100644 --- a/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx +++ b/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx @@ -50,8 +50,8 @@ export class Icon extends React.Component { className ); const { imageLoadError } = this.state; - let imageProps = { ...this.props.imageProps, onLoadingStateChange: this.onImageLoadingStateChange }; - let ImageType = imageLoadError && imageErrorAs || Image; + const imageProps = { ...this.props.imageProps, onLoadingStateChange: this.onImageLoadingStateChange }; + const ImageType = imageLoadError && imageErrorAs || Image; return (
Date: Tue, 20 Feb 2018 14:34:02 -0800 Subject: [PATCH 6/7] fix bundle error WITH PERMISSION. And extend base component and props --- packages/office-ui-fabric-react/src/components/Icon/Icon.tsx | 5 +++-- .../office-ui-fabric-react/src/components/Icon/Icon.types.ts | 3 ++- scripts/package.json | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx b/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx index 9cffb032aaa6ba..c85f56289bd8f0 100644 --- a/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx +++ b/packages/office-ui-fabric-react/src/components/Icon/Icon.tsx @@ -7,7 +7,8 @@ import { ImageLoadState } from '../Image/Image.types'; import { css, getNativeProps, - htmlElementProperties + htmlElementProperties, + BaseComponent } from '../../Utilities'; import { getIcon, IIconRecord } from '../../Styling'; import { getClassNames } from './Icon.classNames'; @@ -16,7 +17,7 @@ export interface IIconState { imageLoadError: boolean; } -export class Icon extends React.Component { +export class Icon extends BaseComponent { constructor(props: IIconProps) { super(props); this.state = { diff --git a/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts b/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts index 5e571cbbff9545..92b63affea2cc1 100644 --- a/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts +++ b/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts @@ -2,6 +2,7 @@ import * as React from 'react'; import { IImageProps } from '../Image/Image.types'; import { IStyle } from '../../Styling'; import { Icon } from './Icon'; +import { IBaseProps } from '../../Utilities'; // Please keep alphabetized export enum IconType { @@ -35,7 +36,7 @@ export interface IIconStyles { imageContainer?: IStyle; } -export interface IIconProps extends React.HTMLAttributes { +export interface IIconProps extends IBaseProps, React.HTMLAttributes { /** * The name of the icon to use from the icon font. If string is empty, a placeholder icon will be rendered the same width as an icon */ diff --git a/scripts/package.json b/scripts/package.json index 8ee991768cd7a4..79442affc8b343 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -49,7 +49,7 @@ "bundlesize": [ { "path": "../apps/test-bundle-button/dist/main.min.js", - "maxSize": "43.1 kB" + "maxSize": "43.2 kB" } ] } \ No newline at end of file From dee7769132853e4d1cc33b3172cc696d2a1dea4d Mon Sep 17 00:00:00 2001 From: Stauffer Taylor Date: Wed, 21 Feb 2018 15:23:12 -0800 Subject: [PATCH 7/7] Make imageErrorAs type safe --- .../office-ui-fabric-react/src/components/Icon/Icon.types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts b/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts index 92b63affea2cc1..378e791046a087 100644 --- a/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts +++ b/packages/office-ui-fabric-react/src/components/Icon/Icon.types.ts @@ -71,5 +71,5 @@ export interface IIconProps extends IBaseProps, React.HTMLAttributes any; + imageErrorAs?: React.StatelessComponent | React.ComponentClass; } \ No newline at end of file