index.js
46 lines
| 1 | export default function isFlexItem( props ) { |
| 2 | const { |
| 3 | device, |
| 4 | display, |
| 5 | displayTablet, |
| 6 | displayMobile, |
| 7 | computedStyles = { display: '' }, |
| 8 | } = props; |
| 9 | |
| 10 | // Check for a computed value if one is provided |
| 11 | const { display: computedValue = '' } = computedStyles; |
| 12 | |
| 13 | // If the computed style is flex, we can assume it's a flex item. |
| 14 | if ( 'flex' === computedValue ) { |
| 15 | return true; |
| 16 | } |
| 17 | |
| 18 | // Check local attributes to determine if a flex item |
| 19 | let flexItem = false; |
| 20 | |
| 21 | if ( 'Desktop' === device && display.includes( 'flex' ) ) { |
| 22 | flexItem = true; |
| 23 | } |
| 24 | |
| 25 | if ( 'Tablet' === device ) { |
| 26 | if ( |
| 27 | ( displayTablet && displayTablet.includes( 'flex' ) ) || |
| 28 | ( ! displayTablet && display.includes( 'flex' ) ) |
| 29 | ) { |
| 30 | flexItem = true; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | if ( 'Mobile' === device ) { |
| 35 | if ( |
| 36 | ( displayMobile && displayMobile.includes( 'flex' ) ) || |
| 37 | ( ! displayMobile && displayTablet && displayTablet.includes( 'flex' ) ) || |
| 38 | ( ! displayMobile && ! displayTablet && display.includes( 'flex' ) ) |
| 39 | ) { |
| 40 | flexItem = true; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return flexItem; |
| 45 | } |
| 46 |