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

Toggle: theme is now injectable. #1943

Merged
merged 3 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all 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": "Toggle: theme now injectable through Customizer.",
"type": "minor"
}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IButtonStyles } from '../Button.Props';
import {
ITheme,
getTheme,
mergeStyleSets
} from '../../../Styling';
import { memoizeFunction } from '../../../Utilities';
Expand All @@ -14,7 +13,7 @@ const DEFAULT_BUTTON_MINWIDTH = '80px';
const DEFAULT_PADDING = '0 16px';

export const getStyles = memoizeFunction((
theme: ITheme = getTheme(),
theme: ITheme,
customStyles?: IButtonStyles,
focusInset?: string,
focusColor?: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Toggle } from './Toggle';
import { IStyle } from '../../Styling';
import { IStyle, ITheme } from '../../Styling';

export interface IToggle {
focus: () => void;
Expand Down Expand Up @@ -61,6 +61,11 @@ export interface IToggleProps extends React.HTMLProps<HTMLElement | Toggle> {
*/
onChanged?: (checked: boolean) => void;

/**
* Theme provided by HOC.
*/
theme?: ITheme;

/**
* Custom styles for this component
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { IToggleStyles } from './Toggle.Props';
import {
ITheme,
getTheme,
mergeStyleSets,
getFocusStyle
} from '../../Styling';
import { memoizeFunction } from '../../Utilities';

export const getStyles = memoizeFunction((
theme: ITheme = getTheme(),
theme: ITheme,
customStyles?: IToggleStyles
): IToggleStyles => {
const { semanticColors } = theme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ describe('Toggle', () => {
let callback = (isToggled) => {
isToggledValue = isToggled;
};
let component = ReactTestUtils.renderIntoDocument<React.ReactInstance>(
let component;

ReactTestUtils.renderIntoDocument<React.ReactInstance>(
<Toggle
componentRef={ ref => component = ref }
label='Label'
onChanged={ callback }
/>
Expand All @@ -43,8 +46,11 @@ describe('Toggle', () => {
});

it(`doesn't update the state if the user provides checked`, () => {
let component = ReactTestUtils.renderIntoDocument(
let component;

ReactTestUtils.renderIntoDocument(
<Toggle
componentRef={ ref => component = ref }
label='Label'
checked={ false }
/>
Expand All @@ -66,6 +72,7 @@ describe('Toggle', () => {
let renderedDOM = ReactDOM.findDOMNode(component as React.ReactInstance);
let label = renderedDOM.querySelector('label');

// tslint:disable-next-line:no-unused-expression
expect(label).is.null;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
IToggleStyles
} from './Toggle.Props';
import { Label } from '../../Label';
import {
customizable
} from '../../Utilities';
import {
mergeStyles
} from '../../Styling';
Expand All @@ -32,6 +35,7 @@ interface IToggleClassNames {
text: string;
}

@customizable(['theme'])
export class Toggle extends BaseComponent<IToggleProps, IToggleState> implements IToggle {

private _id: string;
Expand Down Expand Up @@ -74,6 +78,7 @@ export class Toggle extends BaseComponent<IToggleProps, IToggleState> implements

let {
className,
theme,
styles: customStyles,
disabled,
label,
Expand All @@ -87,7 +92,7 @@ export class Toggle extends BaseComponent<IToggleProps, IToggleState> implements
const ariaLabel = isChecked ? onAriaLabel : offAriaLabel;
const toggleNativeProps = getNativeProps(this.props, inputProperties, ['defaultChecked']);
const classNames = this._getClassNames(
getStyles(undefined, customStyles),
getStyles(theme, customStyles),
className,
disabled,
isChecked
Expand Down