-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Layer SCSS to MergeStyles #3979
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
Merged
oengusmacinog-zz
merged 10 commits into
microsoft:master
from
oengusmacinog-zz:layer-scss2ms
Feb 21, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fa130ec
initial commit
oengusmacinog-zz 58531b6
Theme decorater causing bug with static classes
oengusmacinog-zz 848f05c
disable theme props
oengusmacinog-zz 0865bf8
fixed contextualmenu test import of Layer-LayerBase
oengusmacinog-zz 12b8d61
applied classNames
oengusmacinog-zz 1a4b677
removed comments
oengusmacinog-zz a7b39b3
fixed styles for default host functionality
oengusmacinog-zz dbc609a
fixed component prop className, and added usage to example
oengusmacinog-zz 0be6aee
cleaned up imports in example files
oengusmacinog-zz 657117b
merge tslint changes
oengusmacinog-zz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/changes/office-ui-fabric-react/layer-scss2ms_2018-02-14-22-55.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "office-ui-fabric-react", | ||
| "comment": "Convert Layer component to mergeStyles", | ||
| "type": "minor" | ||
| } | ||
| ], | ||
| "packageName": "office-ui-fabric-react", | ||
| "email": "v-brgarl@microsoft.com" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
packages/office-ui-fabric-react/src/components/Layer/Layer.base.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| /* tslint:disable:no-unused-variable */ | ||
| import * as React from 'react'; | ||
| import * as ReactDOM from 'react-dom'; | ||
| /* tslint:enable:no-unused-variable */ | ||
|
|
||
| import { Fabric } from '../../Fabric'; | ||
| import { | ||
| ILayerProps, | ||
| ILayerStyleProps, | ||
| ILayerStyles, | ||
| } from './Layer.types'; | ||
| import { | ||
| css, | ||
| BaseComponent, | ||
| classNamesFunction, | ||
| customizable, | ||
| getDocument, | ||
| setVirtualParent | ||
| } from '../../Utilities'; | ||
|
|
||
| const _layersByHostId: { [hostId: string]: LayerBase[] } = {}; | ||
| let _defaultHostSelector: string | undefined; | ||
|
|
||
| const getClassNames = classNamesFunction<ILayerStyleProps, ILayerStyles>(); | ||
|
|
||
| // @customizable('Layer', ['theme']) | ||
| export class LayerBase extends BaseComponent<ILayerProps, {}> { | ||
|
|
||
| public static defaultProps: ILayerProps = { | ||
| onLayerDidMount: () => undefined, | ||
| onLayerWillUnmount: () => undefined | ||
| }; | ||
|
|
||
| private _rootElement: HTMLElement; | ||
| private _host: Node; | ||
| private _layerElement: HTMLElement | undefined; | ||
| private _hasMounted: boolean; | ||
| /** | ||
| * Used for notifying applicable Layers that a host is available/unavailable and to re-evaluate Layers that | ||
| * care about the specific host. | ||
| */ | ||
| public static notifyHostChanged(id: string) { | ||
| if (_layersByHostId[id]) { | ||
| _layersByHostId[id].forEach(layer => layer.forceUpdate()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sets the default target selector to use when determining the host in which | ||
| * Layered content will be injected into. If not provided, an element will be | ||
| * created at the end of the document body. | ||
| * | ||
| * Passing in a falsey value will clear the default target and reset back to | ||
| * using a created element at the end of document body. | ||
| */ | ||
| public static setDefaultTarget(selector?: string) { | ||
| _defaultHostSelector = selector; | ||
| } | ||
|
|
||
| constructor(props: ILayerProps) { | ||
| super(props); | ||
|
|
||
| this._warnDeprecations({ | ||
| onLayerMounted: 'onLayerDidMount' | ||
| }); | ||
|
|
||
| if (this.props.hostId) { | ||
| if (!_layersByHostId[this.props.hostId]) { | ||
| _layersByHostId[this.props.hostId] = []; | ||
| } | ||
|
|
||
| _layersByHostId[this.props.hostId].push(this); | ||
| } | ||
| } | ||
|
|
||
| public componentDidMount() { | ||
| this.componentDidUpdate(); | ||
| } | ||
|
|
||
| public componentWillUnmount() { | ||
| this._removeLayerElement(); | ||
|
|
||
| if (this.props.hostId) { | ||
| _layersByHostId[this.props.hostId] = _layersByHostId[this.props.hostId].filter(layer => layer !== this); | ||
| if (!_layersByHostId[this.props.hostId].length) { | ||
| delete _layersByHostId[this.props.hostId]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public componentDidUpdate() { | ||
| const host = this._getHost(); | ||
|
|
||
| const { className, getStyles, theme } = this.props; | ||
| const classNames = getClassNames(getStyles!, | ||
| { | ||
| theme: theme!, | ||
| className, | ||
| isNotHost: !this.props.hostId | ||
| } | ||
| ); | ||
|
|
||
| if (host !== this._host) { | ||
| this._removeLayerElement(); | ||
| } | ||
|
|
||
| if (host) { | ||
| this._host = host; | ||
|
|
||
| if (!this._layerElement) { | ||
| const doc = getDocument(this._rootElement) as Document; | ||
|
|
||
| this._layerElement = doc.createElement('div'); | ||
| this._layerElement.className = classNames.root; | ||
|
|
||
| host.appendChild(this._layerElement); | ||
| setVirtualParent(this._layerElement, this._rootElement); | ||
| } | ||
|
|
||
| // Using this 'unstable' method allows us to retain the React context across the layer projection. | ||
| ReactDOM.unstable_renderSubtreeIntoContainer( | ||
| this, | ||
| ( | ||
| <Fabric className={ classNames.content }> | ||
| { this.props.children } | ||
| </Fabric> | ||
| ), | ||
| this._layerElement, | ||
| () => { | ||
| if (!this._hasMounted) { | ||
| this._hasMounted = true; | ||
|
|
||
| // TODO: @deprecated cleanup required. | ||
| if (this.props.onLayerMounted) { | ||
| this.props.onLayerMounted(); | ||
| } | ||
|
|
||
| this.props.onLayerDidMount!(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public render() { | ||
| return ( | ||
| <span | ||
| className='ms-Layer' | ||
| ref={ this._resolveRef('_rootElement') } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| private _removeLayerElement() { | ||
| if (this._layerElement) { | ||
| this.props.onLayerWillUnmount!(); | ||
|
|
||
| ReactDOM.unmountComponentAtNode(this._layerElement); | ||
| const parentNode = this._layerElement.parentNode; | ||
| if (parentNode) { | ||
| parentNode.removeChild(this._layerElement); | ||
| } | ||
| this._layerElement = undefined; | ||
| this._hasMounted = false; | ||
| } | ||
| } | ||
|
|
||
| private _getHost(): Node { | ||
| const { hostId } = this.props; | ||
| const doc = getDocument(this._rootElement) as Document; | ||
|
|
||
| if (hostId) { | ||
| return doc.getElementById(hostId) as Node; | ||
| } else { | ||
| return _defaultHostSelector ? doc.querySelector(_defaultHostSelector) as Node : doc.body; | ||
| } | ||
| } | ||
|
|
||
| } | ||
13 changes: 0 additions & 13 deletions
13
packages/office-ui-fabric-react/src/components/Layer/Layer.scss
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
packages/office-ui-fabric-react/src/components/Layer/Layer.styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { ILayerStyleProps, ILayerStyles } from './Layer.types'; | ||
| import { | ||
| IStyle, | ||
| ITheme, | ||
| } from '../../Styling'; | ||
|
|
||
| export const getStyles = ( | ||
| props: ILayerStyleProps | ||
| ): ILayerStyles => { | ||
| const { | ||
| className, | ||
| theme, | ||
| isNotHost | ||
| } = props; | ||
|
|
||
| // const { palette, semanticColors } = theme; | ||
|
|
||
| return ({ | ||
| root: [ | ||
| 'ms-Layer', | ||
| isNotHost && [ | ||
| 'ms-Layer--fixed', | ||
| { | ||
| position: 'fixed', | ||
| zIndex: 1000000, | ||
| top: 0, | ||
| left: 0, | ||
| width: '100vw', | ||
| height: '100vh', | ||
| visibility: 'hidden' | ||
| } | ||
| ], | ||
| className | ||
| ], | ||
| content: [ | ||
| 'ms-Layer-content', | ||
| { | ||
| visibility: 'visible' | ||
| } | ||
| ] | ||
| }); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to uncomment this before checkin, maybe there is something we can do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the old one didn't have it. I'm ok omitting it for now if we can't figure it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is commented out due to a bug, #3988. I'm leaving this commented out so it can be turned on later easily, but it's not blocking for this specific component because at least currently it does not need to use the theme.