-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(context): Switch to new context API
- Loading branch information
Oscar Bartra
committed
Feb 25, 2018
1 parent
3eb2eee
commit 8f6db08
Showing
18 changed files
with
425 additions
and
319 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -34,9 +34,6 @@ | |
] | ||
], | ||
"env": { | ||
"development": { | ||
"plugins": ["flow-react-proptypes"] | ||
}, | ||
"test": { | ||
"plugins": [ | ||
[ | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,47 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import { compact } from 'lodash' | ||
import type { | ||
OneResolutionLayout, | ||
ConfigProviderContext, | ||
LayoutProps, | ||
} from '../types' | ||
import type { OneResolutionLayout, LayoutProps } from '../types' | ||
import getStyles from './layout.styles' | ||
import asCore from '../core/asCore' | ||
import { getValues } from '../utils/index' | ||
import { configProviderContext } from '../configProvider' | ||
|
||
const resolutionProperties = ['fixed', 'height', 'overflow'] | ||
|
||
export default function asLayout( | ||
Component: React.ComponentType<*> | string | ||
): React.ComponentType<LayoutProps> { | ||
function Layout( | ||
{ | ||
className, | ||
fixed, | ||
height, | ||
overflow, | ||
innerRef, | ||
...props | ||
}: OneResolutionLayout, | ||
context: ConfigProviderContext | ||
) { | ||
const styles = getStyles(getValues(context, props)) | ||
const classes = compact([ | ||
className, | ||
fixed && styles[`${fixed}Fixed`], | ||
height ? styles[`${height}Height`] : styles.fitHeight, | ||
overflow && styles.overflow, | ||
styles.layout, | ||
]) | ||
function Layout({ | ||
className, | ||
fixed, | ||
height, | ||
overflow, | ||
innerRef, | ||
...props | ||
}: OneResolutionLayout) { | ||
return ( | ||
<configProviderContext.Consumer> | ||
{context => { | ||
const styles = getStyles(getValues(context, props)) | ||
const classes = compact([ | ||
className, | ||
fixed && styles[`${fixed}Fixed`], | ||
height ? styles[`${height}Height`] : styles.fitHeight, | ||
overflow && styles.overflow, | ||
styles.layout, | ||
]) | ||
|
||
return <Component ref={innerRef} {...props} className={classes.join(' ')} /> | ||
return ( | ||
<Component | ||
ref={innerRef} | ||
{...props} | ||
className={classes.join(' ')} | ||
/> | ||
) | ||
}} | ||
</configProviderContext.Consumer> | ||
) | ||
} | ||
return asCore(Layout, resolutionProperties) | ||
} |
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
Oops, something went wrong.