-
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.
Only display featured image UI when theme supports it too (#6541)
* Only display featured image UI when theme supports it too * JSX formatting style
- Loading branch information
1 parent
9870e81
commit dc7ee12
Showing
4 changed files
with
77 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { get, some, castArray } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
export function ThemeSupportCheck( { themeSupports, children, supportKeys } ) { | ||
const isSupported = some( | ||
castArray( supportKeys ), ( key ) => get( themeSupports, [ key ], false ) | ||
); | ||
|
||
if ( ! isSupported ) { | ||
return null; | ||
} | ||
|
||
return children; | ||
} | ||
|
||
export default withSelect( ( select ) => { | ||
const { getThemeSupports } = select( 'core' ); | ||
return { | ||
themeSupports: getThemeSupports(), | ||
}; | ||
} )( ThemeSupportCheck ); |
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,38 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ThemeSupportCheck } from '../index'; | ||
|
||
describe( 'ThemeSupportCheck', () => { | ||
it( 'should not render if there\'s no support check provided', () => { | ||
const wrapper = shallow( <ThemeSupportCheck>foobar</ThemeSupportCheck> ); | ||
expect( wrapper.type() ).toBe( null ); | ||
} ); | ||
|
||
it( 'should render if post-thumbnails are supported', () => { | ||
const themeSupports = { | ||
'post-thumbnails': true, | ||
}; | ||
const supportKeys = 'post-thumbnails'; | ||
const wrapper = shallow( <ThemeSupportCheck | ||
supportKeys={ supportKeys } | ||
themeSupports={ themeSupports }>foobar</ThemeSupportCheck> ); | ||
expect( wrapper.type() ).not.toBe( null ); | ||
} ); | ||
|
||
it( 'should not render if theme doesn\'t support post-thumbnails', () => { | ||
const themeSupports = { | ||
'post-thumbnails': false, | ||
}; | ||
const supportKeys = 'post-thumbnails'; | ||
const wrapper = shallow( <ThemeSupportCheck | ||
supportKeys={ supportKeys } | ||
themeSupports={ themeSupports }>foobar</ThemeSupportCheck> ); | ||
expect( wrapper.type() ).toBe( null ); | ||
} ); | ||
} ); |
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