-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ProgressIndicator: convert to mergeStyles - part 1 (#4592)
* Scaffold styles file * Split to base file. * Scaffold types file. * Export base
- Loading branch information
1 parent
9cc47f5
commit 1b45279
Showing
5 changed files
with
178 additions
and
75 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.base.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as React from 'react'; | ||
import { | ||
BaseComponent, | ||
css | ||
} from '../../Utilities'; | ||
import { IProgressIndicatorProps } from './ProgressIndicator.types'; | ||
import * as stylesImport from './ProgressIndicator.scss'; | ||
const styles: any = stylesImport; | ||
|
||
// if the percentComplete is near 0, don't animate it. | ||
// This prevents animations on reset to 0 scenarios | ||
const ZERO_THRESHOLD = 0.01; | ||
|
||
export class ProgressIndicatorBase extends BaseComponent<IProgressIndicatorProps, {}> { | ||
public static defaultProps = { | ||
label: '', | ||
description: '', | ||
width: 180 | ||
}; | ||
|
||
constructor(props: IProgressIndicatorProps) { | ||
super(props); | ||
|
||
this._warnDeprecations({ | ||
title: 'label' | ||
}); | ||
|
||
} | ||
|
||
public render() { | ||
const { title, description, className, ariaValueText } = this.props; | ||
let { label, percentComplete } = this.props; | ||
|
||
// Handle deprecated value. | ||
if (title) { | ||
label = title; | ||
} | ||
|
||
if (this.props.percentComplete !== undefined) { | ||
percentComplete = Math.min(100, Math.max(0, percentComplete! * 100)); | ||
} | ||
|
||
return ( | ||
<div className={ css('ms-ProgressIndicator', styles.root, className) }> | ||
<div className={ css('ms-ProgressIndicator-itemName', styles.itemName) }>{ label }</div> | ||
<div className={ css('ms-ProgressIndicator-itemProgress', styles.itemProgress) }> | ||
<div className={ css('ms-ProgressIndicator-progressTrack', styles.progressTrack) } /> | ||
<div | ||
className={ css( | ||
'ms-ProgressIndicator-progressBar', | ||
styles.progressBar, | ||
percentComplete && percentComplete > ZERO_THRESHOLD && 'smoothTransition', | ||
percentComplete === undefined && styles.indeterminate | ||
) } | ||
style={ percentComplete !== undefined ? { width: percentComplete + '%' } : undefined } | ||
role='progressbar' | ||
aria-valuemin={ 0 } | ||
aria-valuemax={ 100 } | ||
aria-valuenow={ percentComplete } | ||
aria-valuetext={ ariaValueText } | ||
/> | ||
</div> | ||
<div className={ css('ms-ProgressIndicator-itemDescription', styles.itemDescription) }>{ description }</div> | ||
</div> | ||
); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { IStyle, keyframes } from '../../Styling'; | ||
import { IProgressIndicatorStyleProps, IProgressIndicatorStyles } from './ProgressIndicator.types'; | ||
|
||
export const getStyles = ( | ||
props: IProgressIndicatorStyleProps | ||
): IProgressIndicatorStyles => { | ||
const { | ||
className, | ||
theme, | ||
indeterminate, | ||
smoothTransition, | ||
} = props; | ||
|
||
const { palette, semanticColors } = theme; | ||
|
||
return ({ | ||
root: [ | ||
'ms-ProgressIndicator', | ||
{}, | ||
className | ||
], | ||
|
||
itemName: [ | ||
'ms-ProgressIndicator-itemName', | ||
{} | ||
], | ||
|
||
itemDescription: [ | ||
'ms-ProgressIndicator-itemDescription', | ||
{} | ||
], | ||
|
||
itemProgress: [ | ||
'ms-ProgressIndicator-itemProgress', | ||
{} | ||
], | ||
|
||
progressTrack: [ | ||
'ms-ProgressIndicator-progressTrack', | ||
{} | ||
], | ||
|
||
progressBar: [ | ||
'ms-ProgressIndicator-progressBar', | ||
{}, | ||
], | ||
}); | ||
}; |
84 changes: 15 additions & 69 deletions
84
packages/office-ui-fabric-react/src/components/ProgressIndicator/ProgressIndicator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,16 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
import * as React from 'react'; | ||
/* tslint:enable:no-unused-variable */ | ||
|
||
import { styled } from '../../Utilities'; | ||
import { | ||
BaseComponent, | ||
css | ||
} from '../../Utilities'; | ||
import { IProgressIndicatorProps } from './ProgressIndicator.types'; | ||
import * as stylesImport from './ProgressIndicator.scss'; | ||
const styles: any = stylesImport; | ||
|
||
// if the percentComplete is near 0, don't animate it. | ||
// This prevents animations on reset to 0 scenarios | ||
const ZERO_THRESHOLD = 0.01; | ||
|
||
export class ProgressIndicator extends BaseComponent<IProgressIndicatorProps, {}> { | ||
public static defaultProps = { | ||
label: '', | ||
description: '', | ||
width: 180 | ||
}; | ||
|
||
constructor(props: IProgressIndicatorProps) { | ||
super(props); | ||
|
||
this._warnDeprecations({ | ||
title: 'label' | ||
}); | ||
|
||
} | ||
|
||
public render() { | ||
const { title, description, className, ariaValueText } = this.props; | ||
let { label, percentComplete } = this.props; | ||
|
||
// Handle deprecated value. | ||
if (title) { | ||
label = title; | ||
} | ||
|
||
if (this.props.percentComplete !== undefined) { | ||
percentComplete = Math.min(100, Math.max(0, percentComplete! * 100)); | ||
} | ||
|
||
return ( | ||
<div className={ css('ms-ProgressIndicator', styles.root, className) }> | ||
<div className={ css('ms-ProgressIndicator-itemName', styles.itemName) }>{ label }</div> | ||
<div className={ css('ms-ProgressIndicator-itemProgress', styles.itemProgress) }> | ||
<div className={ css('ms-ProgressIndicator-progressTrack', styles.progressTrack) } /> | ||
<div | ||
className={ css( | ||
'ms-ProgressIndicator-progressBar', | ||
styles.progressBar, | ||
percentComplete && percentComplete > ZERO_THRESHOLD && 'smoothTransition', | ||
percentComplete === undefined && styles.indeterminate | ||
) } | ||
style={ percentComplete !== undefined ? { width: percentComplete + '%' } : undefined } | ||
role='progressbar' | ||
aria-valuemin={ 0 } | ||
aria-valuemax={ 100 } | ||
aria-valuenow={ percentComplete } | ||
aria-valuetext={ ariaValueText } | ||
/> | ||
</div> | ||
<div className={ css('ms-ProgressIndicator-itemDescription', styles.itemDescription) }>{ description }</div> | ||
</div> | ||
); | ||
} | ||
} | ||
IProgressIndicatorProps, | ||
IProgressIndicatorStyleProps, | ||
IProgressIndicatorStyles | ||
} from './ProgressIndicator.types'; | ||
import { ProgressIndicatorBase } from './ProgressIndicator.base'; | ||
import { getStyles } from './ProgressIndicator.styles'; | ||
|
||
/** | ||
* ProgressIndicator description | ||
*/ | ||
export const ProgressIndicator = styled<IProgressIndicatorProps, IProgressIndicatorStyleProps, IProgressIndicatorStyles>( | ||
ProgressIndicatorBase, | ||
getStyles | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/office-ui-fabric-react/src/components/ProgressIndicator/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './ProgressIndicator'; | ||
export * from './ProgressIndicator.base'; | ||
export * from './ProgressIndicator.types'; |