-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Framework: Add viewport module (data module experiments, proof-of-con…
…cept) (#5206) * Testing: Fix typo in post editor source lint rule * Components: Add ifCondition higher-order component * Data: Add registerStore convenience registration * Framework: Add viewport module * Post Editor: Port editor to use viewport module * Viewport: Split withViewportMatch from ifViewportMatches * Edit Post: Remove unused viewportType preference
- Loading branch information
Showing
37 changed files
with
612 additions
and
264 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,20 @@ | ||
If Condition | ||
============ | ||
|
||
`ifCondition` is a higher-order component creator, used for creating a new component which renders if the given condition is satisfied. | ||
|
||
## Usage | ||
|
||
`ifCondition`, passed with a predicate function, will render the underlying component only if the predicate returns a truthy value. The predicate is passed the component's own original props as an argument. | ||
|
||
```jsx | ||
function MyEvenNumber( { number } ) { | ||
// This is only reached if the `number` prop is even. Otherwise, nothing | ||
// will be rendered. | ||
return <strong>{ number }</strong>; | ||
} | ||
|
||
MyEvenNumber = ifCondition( | ||
( { number } ) => number % 2 === 0 | ||
)( MyEvenNumber ); | ||
``` |
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,28 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getWrapperDisplayName } from '@wordpress/element'; | ||
|
||
/** | ||
* Higher-order component creator, creating a new component which renders if | ||
* the given condition is satisfied or with the given optional prop name. | ||
* | ||
* @param {Function} predicate Function to test condition. | ||
* | ||
* @return {Function} Higher-order component. | ||
*/ | ||
const ifCondition = ( predicate ) => ( WrappedComponent ) => { | ||
const EnhancedComponent = ( props ) => { | ||
if ( ! predicate( props ) ) { | ||
return null; | ||
} | ||
|
||
return <WrappedComponent { ...props } />; | ||
}; | ||
|
||
EnhancedComponent.displayName = getWrapperDisplayName( WrappedComponent, 'ifCondition' ); | ||
|
||
return EnhancedComponent; | ||
}; | ||
|
||
export default ifCondition; |
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
40 changes: 16 additions & 24 deletions
40
edit-post/components/header/fixed-toolbar-toggle/index.js
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,49 +1,41 @@ | ||
/** | ||
* External Dependencies | ||
* WordPress Dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { compose } from '@wordpress/element'; | ||
import { MenuItemsGroup, MenuItemsToggle, withInstanceId } from '@wordpress/components'; | ||
import { ifViewportMatches } from '@wordpress/viewport'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import { hasFixedToolbar, isMobile } from '../../../store/selectors'; | ||
import { toggleFeature } from '../../../store/actions'; | ||
|
||
function FeatureToggle( { onToggle, active, onMobile } ) { | ||
if ( onMobile ) { | ||
return null; | ||
} | ||
function FeatureToggle( { onToggle, isActive } ) { | ||
return ( | ||
<MenuItemsGroup | ||
label={ __( 'Settings' ) } | ||
filterName="editPost.MoreMenu.settings" | ||
> | ||
<MenuItemsToggle | ||
label={ __( 'Fix Toolbar to Top' ) } | ||
isSelected={ active } | ||
isSelected={ isActive } | ||
onClick={ onToggle } | ||
/> | ||
</MenuItemsGroup> | ||
); | ||
} | ||
|
||
export default connect( | ||
( state ) => ( { | ||
active: hasFixedToolbar( state ), | ||
onMobile: isMobile( state ), | ||
} ), | ||
( dispatch, ownProps ) => ( { | ||
export default compose( [ | ||
withSelect( ( select ) => ( { | ||
isActive: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ), | ||
} ) ), | ||
withDispatch( ( dispatch, ownProps ) => ( { | ||
onToggle() { | ||
dispatch( toggleFeature( 'fixedToolbar' ) ); | ||
dispatch( 'core/edit-post' ).toggleFeature( 'fixedToolbar' ); | ||
ownProps.onToggle(); | ||
}, | ||
} ), | ||
undefined, | ||
{ storeKey: 'edit-post' } | ||
)( withInstanceId( FeatureToggle ) ); | ||
} ) ), | ||
ifViewportMatches( 'medium' ), | ||
withInstanceId, | ||
] )( FeatureToggle ); |
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 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
Oops, something went wrong.