File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ /**
2+ * Get the value from a CSS custom property.
3+ *
4+ * @param {string } name CSS custom property name (ex: '--breakpoint-mobile-to-desktop-nav').
5+ * @param {HTMLElement } element The element to get the CSS custom property from.
6+ * @return {string } The value.
7+ * @example getCssVar('--breakpoint-mobile-to-desktop-nav') => '1200'
8+ */
9+ export default function getCssVar ( name , element = document . documentElement ) {
10+ if ( ! name ) {
11+ console . warn ( 'getCssVar: No name provided.' )
12+ return ''
13+ }
14+
15+ const propName = name . startsWith ( '--' ) ? name : `--${ name } `
16+
17+ return getComputedStyle ( element ) . getPropertyValue ( propName ) . trim ( )
18+ }
Original file line number Diff line number Diff line change 1- import getBreakpoint from './getBreakpoint '
1+ import getCssVar from './getCssVar '
22
33/**
44 * Check if the current viewport is mobile based on a CSS breakpoint.
@@ -8,6 +8,6 @@ import getBreakpoint from './getBreakpoint'
88 * @example isMobileNav() => true; !isMobileNav() => false
99 */
1010export default function isMobileNav ( breakpointVar = '--breakpoint-mobile-to-desktop-nav' ) {
11- const breakpoint = parseInt ( getBreakpoint ( breakpointVar ) , 10 )
11+ const breakpoint = parseInt ( getCssVar ( breakpointVar ) , 10 )
1212 return window . matchMedia ( `(max-width: ${ breakpoint - 1 } px)` ) . matches
1313}
You can’t perform that action at this time.
0 commit comments