diff options
author | Eric Bailey <git@esb.lol> | 2024-12-10 14:52:30 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-10 20:52:30 +0000 |
commit | e052f5e198603246cb031e00d9cadc2ae4bb140d (patch) | |
tree | aceffa2b71bfdc9c632ff8eaa84d68c807fd5655 /src/alf/breakpoints.ts | |
parent | f34e8d8cdfcab16165c94d8c96084e9cd4338d91 (diff) | |
download | voidsky-e052f5e198603246cb031e00d9cadc2ae4bb140d.tar.zst |
Refactor sidebar (#6971)
* Refactor RightNav (cherry picked from commit 96bb02acfd2d7452df18a0e7410e6a7169a583ed) * Better gutter handling * Clean up styles * Memoize breakpoints * Format * Comment * Loosen spacing, handle overflow, smaller text to match prod * Fix circular imports on native * Return 0 instead of undefined for easier calculations * Re-assign * Fix * Port over fix from subs/base * Space out right nav feeds, widen sidebar to match prod * Fix lost padding on home header * Fix perf by not actually linking to new URL * Remove underline on focus * Foramt --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src/alf/breakpoints.ts')
-rw-r--r-- | src/alf/breakpoints.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/alf/breakpoints.ts b/src/alf/breakpoints.ts new file mode 100644 index 000000000..934585644 --- /dev/null +++ b/src/alf/breakpoints.ts @@ -0,0 +1,28 @@ +import {useMemo} from 'react' +import {useMediaQuery} from 'react-responsive' + +export type Breakpoint = 'gtPhone' | 'gtMobile' | 'gtTablet' + +export function useBreakpoints(): Record<Breakpoint, boolean> & { + activeBreakpoint: Breakpoint | undefined +} { + const gtPhone = useMediaQuery({minWidth: 500}) + const gtMobile = useMediaQuery({minWidth: 800}) + const gtTablet = useMediaQuery({minWidth: 1300}) + return useMemo(() => { + let active: Breakpoint | undefined + if (gtTablet) { + active = 'gtTablet' + } else if (gtMobile) { + active = 'gtMobile' + } else if (gtPhone) { + active = 'gtPhone' + } + return { + activeBreakpoint: active, + gtPhone, + gtMobile, + gtTablet, + } + }, [gtPhone, gtMobile, gtTablet]) +} |