Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "DatePicker MergeStyles step 2 - Converts scss to js styles",
"type": "minor"
}
],
"packageName": "office-ui-fabric-react",
"email": "v-jescla@microsoft.com"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import * as React from 'react';
import { IDatePicker, IDatePickerProps, IDatePickerStrings } from './DatePicker.types';
import {
IDatePicker,
IDatePickerProps,
IDatePickerStrings,
IDatePickerStyleProps,
IDatePickerStyles
} from './DatePicker.types';
import { BaseComponent, KeyCodes, createRef, classNamesFunction } from '../../Utilities';
import { Calendar, ICalendar, DayOfWeek } from '../../Calendar';
import { FirstWeekOfYear } from '../../utilities/dateValues/DateValues';
import { Callout } from '../../Callout';
import { DirectionalHint } from '../../common/DirectionalHint';
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';
import { FocusTrapZone } from '../../FocusTrapZone';
const styles: any = stylesImport;

const getClassNames = classNamesFunction<IDatePickerStyleProps, IDatePickerStyles>();

export interface IDatePickerState {
selectedDate?: Date;
Expand Down Expand Up @@ -145,6 +151,9 @@ export class DatePickerBase extends BaseComponent<IDatePickerProps, IDatePickerS
firstDayOfWeek,
strings,
label,
theme,
className,
styles,
initialPickerDate,
isRequired,
disabled,
Expand All @@ -153,19 +162,25 @@ export class DatePickerBase extends BaseComponent<IDatePickerProps, IDatePickerS
placeholder,
allowTextInput,
borderless,
className,
minDate,
maxDate,
calendarProps
} = this.props;
const { isDatePickerShown, formattedDate, selectedDate, errorMessage } = this.state;

const classNames = getClassNames(styles, {
theme: theme!,
className,
disabled,
label: !!label,
isDatePickerShown
});

return (
<div className={css('ms-DatePicker', styles.root, isDatePickerShown && 'is-open', className)}>
<div className={classNames.root}>
<div ref={this._datePickerDiv}>
<TextField
label={label}
className={styles.textField}
ariaLabel={ariaLabel}
aria-haspopup="true"
aria-expanded={isDatePickerShown}
Expand All @@ -182,11 +197,7 @@ export class DatePickerBase extends BaseComponent<IDatePickerProps, IDatePickerS
iconProps={{
iconName: 'Calendar',
onClick: this._onIconClick,
className: css(
disabled && styles.msDatePickerDisabled,
label ? 'ms-DatePicker-event--with-label' : 'ms-DatePicker-event--without-label',
label ? styles.eventWithLabel : styles.eventWithoutLabel
)
className: classNames.icon
}}
readOnly={!allowTextInput}
value={formattedDate}
Expand All @@ -199,7 +210,7 @@ export class DatePickerBase extends BaseComponent<IDatePickerProps, IDatePickerS
role="dialog"
ariaLabel={pickerAriaLabel}
isBeakVisible={false}
className={css('ms-DatePicker-callout')}
className={classNames.callout}
gapSpace={0}
doNotLayer={false}
target={this._datePickerDiv.current}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,59 @@
import { IDatePickerStyleProps, IDatePickerStyles } from './DatePicker.types';
import { IStyle, normalize, getGlobalClassNames, FontSizes } from '../../Styling';

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.

👍

callout: 'ms-DatePicker-callout',
withLabel: 'ms-DatePicker-event--with-label',
withoutLabel: 'ms-DatePicker-event--without-label',
disabled: 'msDatePickerDisabled '
};

export const styles = (props: IDatePickerStyleProps): IDatePickerStyles => {
const { className, theme, disabled, label, isDatePickerShown } = props;
const { palette } = theme;
const classNames = getGlobalClassNames(GlobalClassNames, theme);

const DatePickerEvent: IStyle = {
color: palette.neutralSecondary,
fontSize: FontSizes.icon,
lineHeight: '18px',
pointerEvents: 'none',
position: 'absolute',
right: '9px'
};

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

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.

Shouldn't need the empty object here

textField: [
{
// Insert css properties
},
className
position: 'relative',
selectors: {
'& input[readonly]': {
cursor: 'pointer'
},
input: {
selectors: {
'::-ms-clear': {
display: 'none'
}
}
}
}
}
],
callout: [classNames.callout],
icon: [
DatePickerEvent,
!label && [classNames.withoutLabel, { top: '7px' }],
label && [classNames.withLabel, { bottom: '5px' }],
!disabled && [
classNames.disabled,
{
pointerEvents: 'initial',
cursor: 'pointer'
}
]
]

// Insert className styles
};
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { styled } from '../../Utilities';
import { IDatePickerProps, IDatePickerStyleProps, IDatePickerStyles } from './DatePicker.types';
import { DatePickerBase } from './DatePicker.base';
import { getStyles } from './DatePicker.styles';
import { styles } from './DatePicker.styles';

/**
* DatePicker description
*/
export const DatePicker = styled<IDatePickerProps, IDatePickerStyleProps, IDatePickerStyles>(
DatePickerBase,
getStyles,
styles,
undefined,
{ scope: 'DatePicker' }
);
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,17 @@ export interface IDatePickerStyleProps {
className?: string;

// Insert DatePicker style props below
disabled?: boolean;
label?: boolean;
isDatePickerShown?: boolean;
}

export interface IDatePickerStyles {
/**
* Style for the root element.
*/
root: IStyle;

// Insert DatePicker classNames below
textField: IStyle;
callout: IStyle;
icon: IStyle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

@JasonGore JasonGore Jun 29, 2018

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.

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

>
<div>
<div
Expand Down Expand Up @@ -39,7 +39,7 @@ exports[`DatePicker renders default DatePicker correctly 1`] = `
<i
aria-hidden={true}
className=
ms-DatePicker-event--without-label

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.

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

{
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ exports[`Component Examples renders DatePicker.Basic.Example.tsx correctly 1`] =
className="docs-DatePickerExample"
>
<div
className="ms-DatePicker"
className=
ms-DatePicker
{
box-shadow: none;
box-sizing: border-box;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
}
>
<div>
<div
Expand Down Expand Up @@ -43,14 +56,23 @@ exports[`Component Examples renders DatePicker.Basic.Example.tsx correctly 1`] =
aria-hidden={true}
className=
ms-DatePicker-event--without-label
msDatePickerDisabled
{
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
color: #666666;
cursor: pointer;
display: inline-block;
font-family: "FabricMDL2Icons";
font-size: 16px;
font-style: normal;
font-weight: normal;
line-height: 18px;
pointer-events: initial;
position: absolute;
right: 9px;
speak: none;
top: 7px;
}
data-icon-name="Calendar"
onClick={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ exports[`Component Examples renders DatePicker.Bounded.Example.tsx correctly 1`]
When date boundaries are set (via minDate and maxDate props) the DatePicker will not allow out-of-bounds dates to be picked or entered. In this example, the allowed dates are 2018-5-13-2018-5-13
</p>
<div
className="ms-DatePicker"
className=
ms-DatePicker
{
box-shadow: none;
box-sizing: border-box;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
}
>
<div>
<div
Expand Down Expand Up @@ -46,14 +59,23 @@ exports[`Component Examples renders DatePicker.Bounded.Example.tsx correctly 1`]
aria-hidden={true}
className=
ms-DatePicker-event--without-label
msDatePickerDisabled
{
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
color: #666666;
cursor: pointer;
display: inline-block;
font-family: "FabricMDL2Icons";
font-size: 16px;
font-style: normal;
font-weight: normal;
line-height: 18px;
pointer-events: initial;
position: absolute;
right: 9px;
speak: none;
top: 7px;
}
data-icon-name="Calendar"
onClick={[Function]}
Expand Down
Loading