-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Convert Check to mergeStyles #3880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6a250b7
b35ac65
fe0a2cc
077aec6
653e516
7043de2
90edfb0
45ccb3a
b0ae601
1726d5b
456a308
047428e
b3ac3fa
98377dc
5a03aa5
21832aa
e68c604
def08c6
3872a95
d0d9590
babf3ba
04a146c
e531bbc
6dd8473
d8b8504
1d6604c
e0ed9c0
a04339d
4920468
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "office-ui-fabric-react", | ||
| "comment": "Convert Check to mergeStyles", | ||
| "type": "patch" | ||
| } | ||
| ], | ||
| "packageName": "office-ui-fabric-react", | ||
| "email": "[email protected]" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| BaseComponent, | ||
| classNamesFunction, | ||
| customizable, | ||
| } from '@uifabric/utilities'; | ||
| import { | ||
| ICheckProps, | ||
| ICheckStyleProps, | ||
| ICheckStyles | ||
| } from './Check.types'; | ||
| import { Icon } from '../../Icon'; | ||
| import { getStyles } from './Check.styles'; | ||
|
|
||
| const getClassNames = classNamesFunction<ICheckStyleProps, ICheckStyles>(); | ||
|
|
||
| @customizable('Check', ['theme']) | ||
| export class CheckBase extends BaseComponent<ICheckProps, {}> { | ||
| public static defaultProps: ICheckProps = { | ||
| checked: false | ||
| }; | ||
|
|
||
| public shouldComponentUpdate(newProps: ICheckProps) { | ||
| return this.props.checked !== newProps.checked; | ||
| } | ||
|
|
||
| public render(): JSX.Element { | ||
| const { | ||
| checked, | ||
| className, | ||
| theme | ||
| } = this.props; | ||
|
|
||
| const classNames = getClassNames(getStyles!, { theme: theme!, className, checked }); | ||
|
|
||
| return ( | ||
| <div className={ classNames.root } > | ||
| <Icon iconName='CircleRing' className={ classNames.circle } /> | ||
| <Icon iconName='StatusCircleCheckmark' className={ classNames.check } /> | ||
| </div> | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { ICheckStyleProps, ICheckStyles } from './Check.types'; | ||
| import { | ||
| getTheme, | ||
| HighContrastSelector, | ||
| IStyle, | ||
| ITheme, | ||
| } from '@uifabric/styling'; | ||
| import { memoizeFunction } from '@uifabric/utilities'; | ||
|
|
||
| export const getStyles = ( | ||
| props: ICheckStyleProps | ||
| ): ICheckStyles => { | ||
| const { | ||
| checkBoxHeight = '18px', | ||
| checked, | ||
| className, | ||
| theme, | ||
| } = props; | ||
|
|
||
| const { palette, semanticColors } = theme; | ||
|
|
||
| const sharedCircleCheck: IStyle = { | ||
| fontSize: checkBoxHeight, | ||
| position: 'absolute', | ||
| left: 0, | ||
| top: 0, | ||
| width: checkBoxHeight, | ||
| height: checkBoxHeight, | ||
| textAlign: 'center', | ||
| verticalAlign: 'middle' | ||
| }; | ||
|
|
||
| return ({ | ||
| root: [ | ||
| 'ms-Check', | ||
|
|
||
| { | ||
| // lineHeight currently needs to be a string to output without 'px' | ||
| lineHeight: '1', | ||
| width: checkBoxHeight, | ||
| height: checkBoxHeight, | ||
| verticalAlign: 'top', | ||
| position: 'relative', | ||
| userSelect: 'none', | ||
|
|
||
| selectors: { | ||
| ':before': { | ||
| content: '""', | ||
| position: 'absolute', | ||
| top: '1px', | ||
| right: '1px', | ||
| bottom: '1px', | ||
| left: '1px', | ||
| borderRadius: '50%', | ||
| opacity: 1, | ||
| background: semanticColors.bodyBackground, | ||
| }, | ||
|
|
||
| /** | ||
| * TODO: Come back to this once .checkHost has been | ||
| * converted to mergeStyles | ||
| */ | ||
| '.checkHost:hover &, .checkHost:focus &, &:hover, &:focus': { | ||
| opacity: 1 | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| checked && [ | ||
| 'is-checked', | ||
| { | ||
| selectors: { | ||
| ':before': { | ||
| background: palette.themePrimary, | ||
| opacity: 1, | ||
| selectors: { | ||
| [HighContrastSelector]: { | ||
| background: 'Window' | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| ], | ||
| className | ||
| ], | ||
|
|
||
| circle: [ | ||
| 'ms-Check-circle', | ||
| sharedCircleCheck, | ||
|
|
||
| { | ||
| color: palette.neutralTertiaryAlt, | ||
|
|
||
| selectors: { | ||
| [HighContrastSelector]: { | ||
| color: 'WindowText' | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| checked && { | ||
| color: palette.white | ||
| } | ||
| ], | ||
|
|
||
| check: [ | ||
| 'ms-Check-check', | ||
| sharedCircleCheck, | ||
|
|
||
| { | ||
| opacity: 0, | ||
| color: palette.neutralTertiaryAlt, | ||
| fontSize: '16px', | ||
| left: '.5px', | ||
|
|
||
| selectors: { | ||
| ':hover': { | ||
| opacity: 1 | ||
| }, | ||
|
|
||
| [HighContrastSelector]: { | ||
| MsHighContrastAdjust: 'none' | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| checked && { | ||
| opacity: 1, | ||
| color: palette.white, | ||
| fontWeight: 900, | ||
|
|
||
| selectors: { | ||
| [HighContrastSelector]: { | ||
| border: 'none', | ||
| color: 'WindowText' | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1,13 @@ | ||
| import * as React from 'react'; | ||
| import { BaseComponent, css } from '../../Utilities'; | ||
| import { Icon } from '../../Icon'; | ||
| import * as stylesImport from './Check.scss'; | ||
| const styles: any = stylesImport; | ||
|
|
||
| export interface ICheckProps extends React.Props<Check> { | ||
| /** | ||
| * Gets the component ref. | ||
| */ | ||
| componentRef?: () => void; | ||
|
|
||
| /** | ||
| * Whether or not this menu item is currently checked. | ||
| * @defaultvalue false | ||
| */ | ||
| checked?: boolean; | ||
| /** | ||
| * Deprecated at v0.65.1 and will be removed by v 1.0. Use 'checked' instead. | ||
| * @deprecated | ||
| */ | ||
| isChecked?: boolean; | ||
|
|
||
| alwaysShowCheck?: boolean; | ||
| } | ||
|
|
||
| export class Check extends BaseComponent<ICheckProps, {}> { | ||
| public static defaultProps = { | ||
| isChecked: false | ||
| }; | ||
|
|
||
| public shouldComponentUpdate(newProps: ICheckProps) { | ||
| return this.props.isChecked !== newProps.isChecked || this.props.checked !== newProps.checked; | ||
| } | ||
|
|
||
| public render() { | ||
| let { isChecked } = this.props; | ||
| const { checked } = this.props; | ||
|
|
||
| isChecked = isChecked || checked; | ||
|
|
||
| return ( | ||
| <div | ||
| className={ css( | ||
| 'ms-Check', | ||
| styles.root, | ||
| { | ||
| [`is-checked ${styles.rootIsChecked}`]: isChecked | ||
| } | ||
| ) } | ||
| > | ||
| { <Icon | ||
| className={ 'ms-Check-circle ' + styles.circle } | ||
| iconName={ 'CircleRing' } | ||
| /> } | ||
| { <Icon | ||
| className={ 'ms-Check-check ' + styles.check } | ||
| iconName={ 'StatusCircleCheckmark' } | ||
| /> } | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
| import { styled } from '@uifabric/utilities'; | ||
| import { | ||
| ICheckProps, | ||
| ICheckStyleProps, | ||
| ICheckStyles | ||
| } from './Check.types'; | ||
| import { CheckBase } from './Check.base'; | ||
| import { getStyles } from './Check.styles'; | ||
|
|
||
| export const Check = styled<ICheckProps, ICheckStyleProps, ICheckStyles>( | ||
| CheckBase, | ||
| getStyles | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import * as React from 'react'; | ||
| import { CheckBase } from './Check.base'; | ||
| import { IStyle, ITheme } from '@uifabric/styling'; | ||
| import { IStyleFunction } from '@uifabric/utilities'; | ||
|
|
||
| export interface ICheckProps extends React.Props<CheckBase> { | ||
| /** | ||
| * Gets the component ref. | ||
| */ | ||
| componentRef?: (component: ICheckProps) => void; | ||
|
|
||
| /** | ||
| * Whether or not this menu item is currently checked. | ||
| * @defaultvalue false | ||
| */ | ||
| checked?: boolean; | ||
|
|
||
| /** | ||
| * Call to provide customized styling that will layer on top of the variant rules | ||
| */ | ||
| getStyles?: IStyleFunction<ICheckStyleProps, ICheckStyles>; | ||
|
|
||
| /** | ||
| * Flag to always show the check icon. Not currently working. | ||
| */ | ||
| alwaysShowCheck?: boolean; | ||
|
|
||
| /** | ||
| * Theme provided by HOC. | ||
| */ | ||
| theme?: ITheme; | ||
|
|
||
| /** | ||
| * Additional css class to apply to the Check | ||
| * @defaultvalue undefined | ||
| */ | ||
| className?: string; | ||
| } | ||
|
|
||
| export interface ICheckStyleProps { | ||
| /** | ||
| * Accept theme prop. | ||
| */ | ||
| theme: ITheme; | ||
|
|
||
| /** | ||
| * Accept custom classNames | ||
| */ | ||
| className?: string; | ||
|
|
||
| /** | ||
| * Accept custom checkBox size in pixels. | ||
| * @defaultvalue '18px' | ||
| */ | ||
| checkBoxHeight?: string; | ||
|
|
||
| checked?: boolean; | ||
| } | ||
|
|
||
| export interface ICheckStyles { | ||
| /** | ||
| * Style for the root element. | ||
| */ | ||
| root: IStyle; | ||
|
|
||
| /** | ||
| * The 'check' icon styles. | ||
| */ | ||
| check: IStyle; | ||
|
|
||
| /** | ||
| * The 'circle' icon styles. | ||
| */ | ||
| circle: IStyle; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| export * from './Check'; | ||
| export * from './Check'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export Also did you want to delete the scss file?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright. Not yet, there are some rogue components importing it directly. I'll come back to delete once those are converted (namely DetailsList... lol). |
||
| export * from './Check.base'; | ||
| export * from './Check.types'; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. I'm not sure this will work. Is "checkHost" a global? Where is this coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkHost is coming from the Check.scss file but only used in DetailsRowCheck.tsx.