diff --git a/common/changes/office-ui-fabric-react/progress-indicator_2018-04-16-14-56.json b/common/changes/office-ui-fabric-react/progress-indicator_2018-04-16-14-56.json new file mode 100644 index 00000000000000..447ffb33ba791c --- /dev/null +++ b/common/changes/office-ui-fabric-react/progress-indicator_2018-04-16-14-56.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "office-ui-fabric-react", + "comment": "Add more customization hooks to ProgressIndicator", + "type": "minor" + } + ], + "packageName": "office-ui-fabric-react", + "email": "tmichon@microsoft.com" +} \ No newline at end of file diff --git a/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.base.tsx b/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.base.tsx index 7cec1918ea7c90..488a9bea385ba6 100644 --- a/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.base.tsx +++ b/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.base.tsx @@ -38,16 +38,19 @@ export class ProgressIndicatorBase extends BaseComponent + { + label ? ( +
{ label }
+ ) : null + } + { + !progressHidden ? onRenderProgress({ + ...(this.props as IProgressIndicatorProps), + percentComplete: percentComplete + }, this._onRenderProgress) : null + } + { + description ? ( +
{ description }
+ ) : null + } + + ); + } + + private _onRenderProgress = (props: IProgressIndicatorProps): JSX.Element => { + const { + ariaValueText, + barHeight, + className, + getStyles, + theme, + } = this.props; + + const percentComplete = typeof this.props.percentComplete === 'number' ? + Math.min(100, Math.max(0, this.props.percentComplete * 100)) : + undefined; - if (this.props.percentComplete !== undefined) { - percentComplete = Math.min(100, Math.max(0, percentComplete! * 100)); - } + const classNames = getClassNames(getStyles, { + theme: theme!, + className, + barHeight, + indeterminate: percentComplete === undefined ? true : false, + }); const progressBarStyles = { width: percentComplete !== undefined ? percentComplete + '%' : undefined, @@ -71,21 +107,17 @@ export class ProgressIndicatorBase extends BaseComponent -
{ label }
-
-
-
-
-
{ description }
+
+
+
); } diff --git a/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.test.tsx b/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.test.tsx index 3b5ad5c04f39e2..d032e947532159 100644 --- a/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.test.tsx +++ b/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.test.tsx @@ -5,14 +5,32 @@ import { ProgressIndicator } from './ProgressIndicator'; describe('ProgressIndicator', () => { it('renders ProgressIndicator correctly', () => { - const component = renderer.create(); + const component = renderer.create(); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); it('renders indeterminate ProgressIndicator correctly', () => { + const component = renderer.create(); + const tree = component.toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('renders with no progress', () => { + const component = renderer.create(); + const tree = component.toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('renders with no label or description', () => { const component = renderer.create(); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); -}); \ No newline at end of file + + it('renders React content', () => { + const component = renderer.create(Test } description={ Test } />); + const tree = component.toJSON(); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.types.ts b/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.types.ts index f2227ba3314123..9b9d3c6a093269 100644 --- a/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.types.ts +++ b/packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.types.ts @@ -1,7 +1,7 @@ import * as React from 'react'; import { ProgressIndicatorBase } from './ProgressIndicator.base'; import { IStyle, ITheme } from '../../Styling'; -import { IStyleFunction } from '../../Utilities'; +import { IStyleFunction, IRenderFunction } from '../../Utilities'; export interface IProgressIndicator { focus: () => void; @@ -30,20 +30,30 @@ export interface IProgressIndicatorProps extends React.Props; + /** * Text alternative of the progress status, used by screen readers for reading the value of the progress. */ @@ -86,4 +96,4 @@ export interface IProgressIndicatorStyles { itemProgress: IStyle; progressTrack: IStyle; progressBar: IStyle; -} \ No newline at end of file +} diff --git a/packages/office-ui-fabric-react/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap b/packages/office-ui-fabric-react/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap index 8e71ec1d2f80d1..b2562b107eb616 100644 --- a/packages/office-ui-fabric-react/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +++ b/packages/office-ui-fabric-react/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap @@ -21,7 +21,7 @@ exports[`ProgressIndicator renders ProgressIndicator correctly 1`] = ` white-space: nowrap; } > - + Test
- + Test +
+
+`; + +exports[`ProgressIndicator renders React content 1`] = ` +
+
+ + Test + +
+
+
+
+
+
+ + Test +
`; @@ -110,8 +206,85 @@ exports[`ProgressIndicator renders indeterminate ProgressIndicator correctly 1`] white-space: nowrap; } > - + Test +
+
+
+
+
+
+ Test
+
+`; + +exports[`ProgressIndicator renders with no label or description 1`] = ` +
+
+`; + +exports[`ProgressIndicator renders with no progress 1`] = ` +
+
+ Test +
- + Test
`;