-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
187 additions
and
152 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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Context } from 'react'; | ||
|
||
declare const ListContext: Context<{ dense?: boolean }>; | ||
export default ListContext; |
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,5 @@ | ||
import React from 'react'; | ||
|
||
const ListContext = React.createContext({}); | ||
|
||
export default ListContext; |
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 { default } from './List'; | ||
export * from './List'; | ||
export { default as ListContext } from './ListContext'; |
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 +1,2 @@ | ||
export { default } from './List'; | ||
export { default as ListContext } from './ListContext'; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from 'react'; | ||
|
||
export interface MergeWithListContextProps { | ||
dense?: boolean; | ||
} | ||
|
||
declare const MergeWithListContext: React.ComponentType<MergeWithListContextProps>; | ||
|
||
export default MergeWithListContext; |
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,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ListContext } from '../List'; | ||
|
||
/** | ||
* Consumes a context and passes that context merged with its props | ||
* @param props | ||
*/ | ||
function MergeWithListContext(props) { | ||
const { children, dense } = props; | ||
return ( | ||
<ListContext.Consumer> | ||
{context => { | ||
const isDense = dense || context.dense || false; | ||
const childContext = { dense: isDense }; | ||
|
||
return ( | ||
<ListContext.Provider value={childContext}>{children(childContext)}</ListContext.Provider> | ||
); | ||
}} | ||
</ListContext.Consumer> | ||
); | ||
} | ||
|
||
MergeWithListContext.propTypes = { | ||
children: PropTypes.func.isRequired, | ||
dense: PropTypes.bool, | ||
}; | ||
|
||
export default MergeWithListContext; |
Oops, something went wrong.