Skip to content

DatePicker MergeStyles step 2 - Converts scss to js styles#5362

Merged
lorejoh12 merged 14 commits intomicrosoft:masterfrom
bennettclark:datepicker-mergestyles-step-2
Jun 29, 2018
Merged

DatePicker MergeStyles step 2 - Converts scss to js styles#5362
lorejoh12 merged 14 commits intomicrosoft:masterfrom
bennettclark:datepicker-mergestyles-step-2

Conversation

@bennettclark
Copy link
Copy Markdown
Contributor

@bennettclark bennettclark commented Jun 27, 2018

Pull request checklist

Description of changes

Updates to DatePicker.base.tsx

  • adds import statements: classNamesFunction, customizable; IDatePickerStyleProps, IDatePickerStyles
  • adds getClassNames function to DatePicker.base.tsx
  • adds _classNames private function to DatePickerBase class
  • calls _classNames in public render() instead of styles

Removes DatePicker.scss file

Updates to DatePicker.styles.ts

  • adds import statements: Istyle (required by MergeStyles), normalize (to replace ms-normalize mixin from scss), getGlobalClassNames (required to apply classnames)
  • changes getStyles() to styles()
  • pulls { palette, fonts } from theme for semantic constants
  • replaces class name designations in the return statement with variables from classNames constant
  • converts all scss style rules from DatePicker.scss

Updates to DatePicker.tsx

  • changes getStyles() to styles()

Updates t DatePicker.types.ts

  • adds style type list from scss style rules to IDatePickerStyles for DatePicker.styles.ts to - the list must match between these two files (linter will complain if any of the list in types are not present in the styles file)

Updates snapshots

Microsoft Reviewers: Open in CodeFlow

}
}
},
className
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't className only be on root? I don't see it mixed in with other class names in old code

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, the standard className prop is a custom class name just for the root, not all elements.

aria-hidden={true}
className=
ms-DatePicker-event--without-label

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I feel like this className should still be here but I don't see any obvious issues with the code

className="ms-TextField"
className=
ms-TextField
ms-TextField
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's odd, I wonder why ms-TextField appears twice?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

coming from TextField root, see my comment in DatePicker.styles.ts for the fix

}
&:not(.msDatePickerDisabled) {
cursor: pointer;
pointer-events: initial;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do all of these styling changes match up with the new JS styling?

prevYearAriaLabel: 'Go to previous year',
nextYearAriaLabel: 'Go to next year'
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nitpicky as all hell I realize, but can you put this blank line before the back? Separating declarations like the class and this interface really help with scan-ability

@@ -184,8 +196,7 @@ export class DatePickerBase extends BaseComponent<IDatePickerProps, IDatePickerS
onClick: this._onIconClick,
className: css(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This concatination logic should be in the styles.ts file. There css() function should no longer be used.

IDatePickerStyleProps,
IDatePickerStyles
} from './DatePicker.types';
import { BaseComponent, KeyCodes, createRef, css, classNamesFunction } from '../../Utilities';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

css import should be removed - there's a completely redundant call on line 213 that shouldn't have been there in the first place (its 'concatenating' just one class with nothing else

}
}
},
className
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, the standard className prop is a custom class name just for the root, not all elements.

const { className } = props;
const GlobalClassNames = {
root: 'ms-DatePicker',
textField: 'ms-TextField',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

duplicate - 'ms-TextField' comes from the TextField component root, so when they combine you render two 'ms-TextField' s - the scss implementation didn't have a class for this element just styles.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, this className should be removed

exports[`DatePicker renders default DatePicker correctly 1`] = `
<div
className="ms-DatePicker"
className={undefined}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this should not be undefined

Copy link
Copy Markdown
Member

@JasonGore JasonGore Jun 29, 2018

Choose a reason for hiding this comment

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

Per our Teams chat, DatePicker.test.tsx snapshot test should be modified to use DatePicker instead of DatePickerBase.

className="ms-TextField"
className=
ms-TextField
ms-TextField
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

coming from TextField root, see my comment in DatePicker.styles.ts for the fix

import { TextField, ITextField } from '../../TextField';
import { BaseComponent, KeyCodes, css, createRef } from '../../Utilities';
import { compareDates, compareDatePart } from '../../utilities/dateMath/DateMath';
import * as stylesImport from './DatePicker.scss';
Copy link
Copy Markdown
Member

@JasonGore JasonGore Jun 28, 2018

Choose a reason for hiding this comment

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

I'm surprised stylesImport isn't causing an error since the file appears to have been removed

import { compareDates, compareDatePart } from '../../utilities/dateMath/DateMath';
import * as stylesImport from './DatePicker.scss';
import { FocusTrapZone } from '../../FocusTrapZone';
const styles: any = stylesImport;
Copy link
Copy Markdown
Member

@JasonGore JasonGore Jun 28, 2018

Choose a reason for hiding this comment

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

styles should no longer be used anywhere and removed

return {
root: [
'ms-DatePicker',
root: [classNames.root, isDatePickerShown && 'is-open', normalize, {}, className],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't need the empty object here

Copy link
Copy Markdown
Collaborator

@oengusmacinog-zz oengusmacinog-zz left a comment

Choose a reason for hiding this comment

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

Looks great

Copy link
Copy Markdown
Contributor

@cliffkoh cliffkoh left a comment

Choose a reason for hiding this comment

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

Could you please rename DatePicker.tsx to DatePicker.ts (it has no JSX in it)?

export const getStyles = (props: IDatePickerStyleProps): IDatePickerStyles => {
const { className } = props;
const GlobalClassNames = {
root: 'ms-DatePicker',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@lorejoh12 lorejoh12 merged commit 78c5cab into microsoft:master Jun 29, 2018
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Jul 1, 2018
* master: (151 commits)
  Css updates for card components (microsoft#5393)
  DatePicker MergeStyles step 2 - Converts scss to js styles (microsoft#5362)
  Update stale with 60 day comment and updated ignored label names. (microsoft#5388)
  replaced await for ie compat syntax - but still needs promise (microsoft#5387)
  Slider - mergestyle conversion (microsoft#5379)
  Applying package updates.
  Enabling publishing for charting and gridlayout. (microsoft#5378)
  TilesList: fadeOut overlay. (microsoft#5381)
  Pivot: JS Styling (microsoft#5324)
  ShimmeredDetailsList: wrapper for DetailsList with Shimmer. (microsoft#5374)
  dashboard-grid-layout improved example (microsoft#5373)
  Applying package updates.
  Addressing Issue microsoft#5165 - Using Customizer with Nav Component (microsoft#5361)
  Applying package updates.
  Address issue microsoft#5353 (microsoft#5359)
  Change log to trigger release (microsoft#5358)
  Fluent updates (microsoft#5357)
  TextField render value undefined as empty string (microsoft#5349)
  Applying package updates.
  DetailsColumn: css class changes to show gripper when hover on draggable columns (microsoft#5309)
  ...
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 30, 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.

Datepicker: Convert to css-in-js

7 participants