-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
ResizeGroup SCSS to MergeStyles Part 2: Style Conversion #4072
Merged
oengusmacinog-zz
merged 17 commits into
microsoft:master
from
oengusmacinog-zz:resizegroup-scss2ms-pt2
Mar 1, 2018
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6766f11
convert scss to mergeStyles
oengusmacinog-zz 2320f81
rush change
oengusmacinog-zz 1c3a3a8
updated snapshots
oengusmacinog-zz 62109bf
update experiments snapshots
oengusmacinog-zz 2438eb4
temp fix for shallow test with decorator usage
oengusmacinog-zz 4944214
added shallowUntilTarget function to Utilities for use with decorated…
oengusmacinog-zz e7825b0
cleanup
oengusmacinog-zz d3cfa7b
moved shallowUntilTarget into fabrics common folder
oengusmacinog-zz 6559ee6
clean up imports
oengusmacinog-zz 1e8dd14
remove scss
oengusmacinog-zz 125adcd
added base to index
oengusmacinog-zz a0e687d
shallowUntilTarget default shallow functionality
oengusmacinog-zz 0779d03
removing base from index so styles are not optional
oengusmacinog-zz 912cf74
moved measured styles to inline
oengusmacinog-zz 5b6268f
updated snapshots
oengusmacinog-zz 186ed05
missing semicolon
oengusmacinog-zz b7a8756
updated experiments snapshots
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/resizegroup-scss2ms-pt2_2018-02-22-21-19.json
This file contains 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": "Converting ResizeGroup SCSS to MergeStyles step 2 - style converstion", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "office-ui-fabric-react", | ||
"email": "[email protected]" | ||
} |
This file contains 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
65 changes: 65 additions & 0 deletions
65
packages/office-ui-fabric-react/src/common/shallowUntilTarget.ts
This file contains 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,65 @@ | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
|
||
/** | ||
* Duplicated enzyme's ShallowRendererProps | ||
* | ||
* @internal | ||
*/ | ||
export interface IShallowRendererProps { | ||
lifecycleExperimental?: boolean; | ||
disableLifecycleMethods?: boolean; | ||
} | ||
|
||
/** | ||
* ShallowUntilTarget Interface | ||
* | ||
* @internal | ||
*/ | ||
export interface IShallowUntilTarget { | ||
maxTries: number; | ||
shallowOptions: IShallowRendererProps; | ||
} | ||
|
||
/** | ||
* An extention of enzyme's shallow function which will fail to work | ||
* with decorated components and/or components using the styled() function. | ||
* This function allows you to pass a 'target' component (e.g. ComponentBase) | ||
* and keep running shallow on each child component till a match is found. | ||
* | ||
* @public | ||
*/ | ||
export function shallowUntilTarget<P, S>( | ||
componentInstance: React.ReactElement<P>, | ||
TargetComponent: string, | ||
options: IShallowUntilTarget = { | ||
maxTries: 10, | ||
shallowOptions: {} | ||
} | ||
): ShallowWrapper { | ||
const { maxTries, shallowOptions } = options; | ||
|
||
let root = shallow<P, S>(componentInstance, shallowOptions); | ||
|
||
if (typeof root.type() === 'string' || root.type().toString().includes(TargetComponent)) { | ||
// Default shallow() | ||
// If type() is a string then it's a DOM Node. | ||
// If it were wrapped, it would be a React component. | ||
return root; | ||
} | ||
|
||
for (let tries = 1; tries <= maxTries; tries++) { | ||
// Check for target as a string to avoid conflicts | ||
// with decoratored components name | ||
if (root.type().toString().includes(TargetComponent)) { | ||
// Now that we found the target component, render it. | ||
return root.first().shallow(shallowOptions); | ||
} | ||
// Unwrap the next component in the hierarchy. | ||
root = root.first().shallow(shallowOptions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I don't think that any decorators we currently have render multiple siblings, it is possible that this will miss a component that isn't the first child. |
||
} | ||
|
||
throw new Error( | ||
`Could not find ${TargetComponent} in React instance: ${componentInstance}; | ||
gave up after ${maxTries} tries` | ||
); | ||
} |
This file contains 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
This file contains 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
11 changes: 0 additions & 11 deletions
11
packages/office-ui-fabric-react/src/components/ResizeGroup/ResizeGroup.scss
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
1 change: 1 addition & 0 deletions
1
packages/office-ui-fabric-react/src/components/ResizeGroup/index.ts
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './ResizeGroup'; | ||
export * from './ResizeGroup.base' | ||
export * from './ResizeGroup.types'; |
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.
You could have target component be type of
Function
, and then users could pass in the actual class that they care about. You could then access the string by callingTargetComponent.name
and it would work out fine. That way it keeps things a bit more type safe since they would need to import the actual class they care about. This is just a suggestion, if you feel like trying it out that would be cool, otherwise no worries.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 was the original way that I had implemented this, but specifically for decorated functions like ResizeGroupBase, the name becomes 'ComponentWithInjectedProps' so it returns before it should. Passing a string name into the function was a way to avoid this.