Skip to content
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

Convert Check to mergeStyles #3880

Merged
merged 29 commits into from
Feb 23, 2018

Conversation

jordandrako
Copy link
Contributor

@jordandrako jordandrako commented Feb 3, 2018

Pull request checklist

  • Include a change request file using $ npm run change

Description of changes

  • Move ICheckProps to Check.types.ts file.
  • Add ICheckStyleProps and ICheckStyles
  • Convert Check.scss to Check.styles.ts
  • Remove rootIsChecked class, add checked boolean for conditionals.
  • Rename Check.tsx to Check.base.tsx and made Check.tsx return a styled CheckBase.
  • Check can be themed.
  • Check.scss remains until other components no longer require it as a dependency.

Focus areas to test

Check still looks a behaves the same. Try theming the Check.


return (
<div
className={ css(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

css doesn't need to be used and should be removed. Can you move all of the logic to getStyles so that we have it in one place?


const { palette, semanticColors } = theme;

const _sharedCircleCheck: IStyle = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We typically only prepend the _ when it's a private member of a class but not a local variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit pushed

} from '@uifabric/styling';
import { memoizeFunction } from '@uifabric/utilities';

const DEFAULT_CHECKBOX_HEIGHT: string = '18px';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't "hard code" this value unless the consumer will never need to change it. It seems like in this case we should expose this as a public prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const {
    checkBoxHeight = DEFAULT_CHECKBOX_HEIGHT,
    checked,
    className,
    theme,
  } = props;

Setting checkBoxHeight to equal that variable is just the way to set it as default and is overridden by what the user set in props. To be honest, I didn't need DEFAULT_CHECKBOX_HEIGHT, but I thought it'd be a nice easy way to see/change the default later down the road.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@battletoilet Could you take another look at this review?

root: [
{
// lineHeight currently needs to be a string to output without 'px'
lineHeight: '1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dzearing apparently this is a bug where providing the type number automatically converts the value into a string with 'px' appended.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, there was a PR to fix it by Micheal but had to be reverted as some people are using lineHeight: 20 intending for it to output line-height: 20px.

@dzearing dzearing closed this Feb 7, 2018
@dzearing dzearing reopened this Feb 7, 2018
@dzearing
Copy link
Member

dzearing commented Feb 7, 2018

im curious if there are any significant performance changes in details list with this change. Check is a high traffic component there.

@jordandrako
Copy link
Contributor Author

It seems the performance impact is minimal, but not sure if these performance tests in dev tools are sufficient.
image
image
image
image

@jordandrako
Copy link
Contributor Author

jordandrako commented Feb 9, 2018

@dzearing So I rendered like 5000 Checks with sass and with mergeStyles, and couldn't see any noticeable difference in page load speed or anything. I think perf is fine.

@dzearing
Copy link
Member

dzearing commented Feb 9, 2018

@jordandrako woot, thanks!

* TODO: Come back to this once .checkHost has been
* converted to mergeStyles
*/
'.checkHost:hover &, .checkHost:focus &, &:hover, &:focus': {
Copy link
Member

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?

Copy link
Contributor Author

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.

<div
  { ...buttonProps }
  role='checkbox'
  className={
    css(className, 'ms-DetailsRow-check', DetailsRowCheckStyles.check, CheckStyles.checkHost, {
      [`ms-DetailsRow-check--isDisabled ${DetailsRowCheckStyles.isDisabled}`]: !props.canSelect,
      [`ms-DetailsRow-check--isHeader ${DetailsRowCheckStyles.isHeader}`]: props.isHeader
    })
  }
  aria-checked={ isPressed }
  data-selection-toggle={ true }
  data-automationid='DetailsRowCheck'
>
  <Check
    checked={ isPressed }
  />
</div>

<div
className={ classNames.root }
>
{ Icon({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused why this isn't JSX.

<Icon className={ ... } iconName={ ... } />

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was how it was written before, I was trying to keep the number of logic changes unrelated to mergeStyles to a minimum.

@@ -0,0 +1,145 @@
import { ICheckStyleProps, ICheckStyles } from './Check.types';
import {
concatStyleSets,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these imports aren't needed. Not sure why no-unused-imports isn't picking this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, me either. I'll take the unused ones out.

export * from './Check';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export CheckBase as well perhaps.

Also did you want to delete the scss file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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).

Copy link
Member

@dzearing dzearing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor feedback.

@jordandrako jordandrako dismissed stale reviews from gokunymbus and dzearing February 13, 2018 19:04

Addressed the issue

@jordandrako
Copy link
Contributor Author

@dzearing @battletoilet Could I get approval on this?

@dzearing
Copy link
Member

I've approved, @jordandrako sorry it got buried in too many PRs. There is a conflict. Can you double check what changed?

Copy link
Member

@dzearing dzearing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix conflicts.

@dzearing dzearing self-assigned this Feb 22, 2018
@jordandrako jordandrako merged commit b2177a5 into microsoft:master Feb 23, 2018
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Feb 27, 2018
* master: (28 commits)
  Scrollable pane sort stickies (microsoft#4111)
  Allow ScrollablePane to accept native properties. (microsoft#4095)
  Sticky (microsoft#4091)
  Applying package updates.
  [ColorRectangle, Sticky] Fixed null root refs (microsoft#4099)
  DatePicker: order of callbacks for onSelectDate and onAfterMenuDismiss (microsoft#4092)
  Applying package updates.
  Alhenry fix split button props (microsoft#4090)
  Fixing ComboBox styling by reverting button classname move (microsoft#4088)
  Update CODEOWNERS
  Undoing terrible change.
  [DetailsList] Fixed focus test (microsoft#4087)
  Added icons package screener test (microsoft#4082)
  ContextualMenu: Fix ContextualMenuUtility imports (microsoft#4085)
  [ContextualMenu] Made disabled buttons focusable (microsoft#4074)
  Convert Check to mergeStyles (microsoft#3880)
  [DetailsList] Add public focusIndex function (microsoft#3852)
  ComboBox button should have data-is-focusable="false" (microsoft#4070)
  Applying package updates.
  Focus Zone: Allow Tab to Skip Selection (microsoft#4061)
  ...
chrismohr pushed a commit to chrismohr/office-ui-fabric-react that referenced this pull request Apr 17, 2018
* Separate types to types.ts file.
Start converting check to mergeStyles

* Convert bulk scss to mergeStyles. Needs to be reviewed, this is rough.

* Add comments for style types.

* Convert Check to mergeStyle pattern

* Add more props and types

* Fix most style conversions.

* Remove setUserSelect related lines. Rename rootIsChecked to just checked state.

* Remove setUserSelect related lines. Rename rootIsChecked to just checked state.

* Fix line-height

* Export types in index.

* npm run change output

* Fix import for Travis

* Move className logic to styles file.

* nit, remove _ in _sharedCircleCheck

* Combine checked conditionals into array.

* Make ICheckStyles required, remove checkHost

* Export base component

* Remove unused import

* Make icons jsx

* Remove uneeded const
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants