File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Get the breakpoint value from a CSS custom property.
3+ *
4+ * @param {string } breakpointVar CSS custom property name for the breakpoint.
5+ * @return {string } The breakpoint value.
6+ * @example getBreakpoint('--breakpoint-mobile-to-desktop-nav') => '1200'
7+ */
8+ export default function getBreakpoint ( breakpointVar = '--breakpoint-mobile-to-desktop-nav' ) {
9+ return getComputedStyle ( document . documentElement ) . getPropertyValue ( breakpointVar ) . trim ( )
10+ }
Original file line number Diff line number Diff line change 1+ import getBreakpoint from './getBreakpoint'
2+
3+ /**
4+ * Check if the current viewport is mobile based on a CSS breakpoint.
5+ *
6+ * @param {string } breakpointVar CSS custom property name for the breakpoint.
7+ * @return {boolean } True if viewport is mobile, false otherwise.
8+ * @example isMobileNav() => true; !isMobileNav() => false
9+ */
10+ export default function isMobileNav ( breakpointVar = '--breakpoint-mobile-to-desktop-nav' ) {
11+ const breakpoint = parseInt ( getBreakpoint ( breakpointVar ) , 10 )
12+ return window . matchMedia ( `(max-width: ${ breakpoint - 1 } px)` ) . matches
13+ }
Original file line number Diff line number Diff line change 55
66:root {
77 /*
8+ * Breakpoints
9+ */
10+ --breakpoint-mobile-to-desktop-nav : #{map-get ($breakpoints , mobile-to-desktop-nav )} ; // Used by JavaScript
11+
12+ /*
813 * Heading
914 */
1015 // Font size
You can’t perform that action at this time.
0 commit comments