diff --git a/common/changes/@uifabric/utilities/customizable-hoisting_2018-03-07-21-58.json b/common/changes/@uifabric/utilities/customizable-hoisting_2018-03-07-21-58.json new file mode 100644 index 00000000000000..1103fda8a75cba --- /dev/null +++ b/common/changes/@uifabric/utilities/customizable-hoisting_2018-03-07-21-58.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@uifabric/utilities", + "comment": "Added hoistStatics function to @customizable decorator so static methods work properly", + "type": "minor" + } + ], + "packageName": "@uifabric/utilities", + "email": "v-brgarl@microsoft.com" +} \ No newline at end of file diff --git a/common/changes/office-ui-fabric-react/customizable-hoisting_2018-03-07-21-58.json b/common/changes/office-ui-fabric-react/customizable-hoisting_2018-03-07-21-58.json new file mode 100644 index 00000000000000..7af05007afefab --- /dev/null +++ b/common/changes/office-ui-fabric-react/customizable-hoisting_2018-03-07-21-58.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "office-ui-fabric-react", + "comment": "Added the @customizable decorator to Image and Layer to enable theme functionality", + "type": "minor" + } + ], + "packageName": "office-ui-fabric-react", + "email": "v-brgarl@microsoft.com" +} \ No newline at end of file diff --git a/packages/office-ui-fabric-react/src/components/Image/Image.base.tsx b/packages/office-ui-fabric-react/src/components/Image/Image.base.tsx index 1fe6bc5970c171..ce2ebe0699bc5d 100644 --- a/packages/office-ui-fabric-react/src/components/Image/Image.base.tsx +++ b/packages/office-ui-fabric-react/src/components/Image/Image.base.tsx @@ -5,7 +5,7 @@ import { autobind, BaseComponent, classNamesFunction, - // customizable, + customizable, getNativeProps, imageProperties } from '../../Utilities'; @@ -26,7 +26,7 @@ export interface IImageState { const KEY_PREFIX = 'fabricImage'; -// @customizable('Image', ['theme']) +@customizable('Image', ['theme']) export class ImageBase extends BaseComponent { public static defaultProps = { shouldFadeIn: true diff --git a/packages/office-ui-fabric-react/src/components/Layer/Layer.base.tsx b/packages/office-ui-fabric-react/src/components/Layer/Layer.base.tsx index 5b103565134f21..f241acbd411397 100644 --- a/packages/office-ui-fabric-react/src/components/Layer/Layer.base.tsx +++ b/packages/office-ui-fabric-react/src/components/Layer/Layer.base.tsx @@ -12,6 +12,7 @@ import { import { BaseComponent, classNamesFunction, + customizable, getDocument, setVirtualParent } from '../../Utilities'; @@ -21,6 +22,7 @@ let _defaultHostSelector: string | undefined; const getClassNames = classNamesFunction(); +@customizable('Layer', ['theme']) export class LayerBase extends BaseComponent { public static defaultProps: ILayerProps = { diff --git a/packages/utilities/src/customizable.tsx b/packages/utilities/src/customizable.tsx index 962bde6e14252b..a3a99e57167b5d 100644 --- a/packages/utilities/src/customizable.tsx +++ b/packages/utilities/src/customizable.tsx @@ -14,14 +14,14 @@ export function customizable( ComposedComponent: (new (props: P, ...args: any[]) => React.Component) // tslint:disable-next-line:no-any ): any { - return class ComponentWithInjectedProps extends React.Component { + const resultClass = class ComponentWithInjectedProps extends React.Component { public static displayName: string = 'Customized' + scope; public static contextTypes: { customizations: PropTypes.Requireable<{}>; } = { - customizations: PropTypes.object - }; + customizations: PropTypes.object + }; // tslint:disable-next-line:no-any constructor(props: P, context: any) { @@ -52,5 +52,18 @@ export function customizable( } }; + + return hoistStatics(ComposedComponent, resultClass); }; } + +function hoistStatics(source: TSource, dest: TDest): TDest { + for (const name in source) { + if (source.hasOwnProperty(name)) { + // tslint:disable-next-line:no-any + (dest as any)[name] = source[name]; + } + } + + return dest; +} \ No newline at end of file