ComponentCSS.js
59 lines
| 1 | import { memo } from '@wordpress/element'; |
| 2 | import { useSelect } from '@wordpress/data'; |
| 3 | import DesktopCSS from '../css/desktop'; |
| 4 | import TabletCSS from '../css/tablet'; |
| 5 | import TabletOnlyCSS from '../css/tablet-only'; |
| 6 | import MobileCSS from '../css/mobile'; |
| 7 | import MainCSS from '../css/main'; |
| 8 | import shouldRebuildCSS from '../../../utils/should-rebuild-css'; |
| 9 | |
| 10 | function ComponentCSS( props ) { |
| 11 | const deviceType = useSelect( ( select ) => { |
| 12 | if ( ! select( 'core/edit-post' ) ) { |
| 13 | return 'Desktop'; |
| 14 | } |
| 15 | |
| 16 | const { |
| 17 | __experimentalGetPreviewDeviceType: experimentalGetPreviewDeviceType = () => 'Desktop', |
| 18 | } = select( 'core/edit-post' ); |
| 19 | |
| 20 | return experimentalGetPreviewDeviceType(); |
| 21 | }, [] ); |
| 22 | |
| 23 | const { |
| 24 | isBlockPreview = false, |
| 25 | } = props?.attributes; |
| 26 | |
| 27 | if ( isBlockPreview ) { |
| 28 | return null; |
| 29 | } |
| 30 | |
| 31 | return ( |
| 32 | <> |
| 33 | <MainCSS { ...props } /> |
| 34 | |
| 35 | { deviceType && |
| 36 | <> |
| 37 | { 'Desktop' === deviceType && |
| 38 | <DesktopCSS { ...props } /> |
| 39 | } |
| 40 | |
| 41 | { ( 'Tablet' === deviceType || 'Mobile' === deviceType ) && |
| 42 | <TabletCSS { ...props } /> |
| 43 | } |
| 44 | |
| 45 | { 'Tablet' === deviceType && |
| 46 | <TabletOnlyCSS { ...props } /> |
| 47 | } |
| 48 | |
| 49 | { 'Mobile' === deviceType && |
| 50 | <MobileCSS { ...props } /> |
| 51 | } |
| 52 | </> |
| 53 | } |
| 54 | </> |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | export default memo( ComponentCSS, shouldRebuildCSS ); |
| 59 |