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/util | |
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/util')
-rw-r--r-- | src/alf/util/useGutterStyles.ts | 21 | ||||
-rw-r--r-- | src/alf/util/useGutters.ts | 66 |
2 files changed, 66 insertions, 21 deletions
diff --git a/src/alf/util/useGutterStyles.ts b/src/alf/util/useGutterStyles.ts deleted file mode 100644 index 64b246fdd..000000000 --- a/src/alf/util/useGutterStyles.ts +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react' - -import {atoms as a, useBreakpoints, ViewStyleProp} from '#/alf' - -export function useGutterStyles({ - top, - bottom, -}: { - top?: boolean - bottom?: boolean -} = {}) { - const {gtMobile} = useBreakpoints() - return React.useMemo<ViewStyleProp['style']>(() => { - return [ - a.px_lg, - top && a.pt_md, - bottom && a.pb_md, - gtMobile && [a.px_xl, top && a.pt_lg, bottom && a.pb_lg], - ] - }, [gtMobile, top, bottom]) -} diff --git a/src/alf/util/useGutters.ts b/src/alf/util/useGutters.ts new file mode 100644 index 000000000..57dd4e80b --- /dev/null +++ b/src/alf/util/useGutters.ts @@ -0,0 +1,66 @@ +import React from 'react' + +import {Breakpoint, useBreakpoints} from '#/alf/breakpoints' +import * as tokens from '#/alf/tokens' + +type Gutter = 'compact' | 'base' | 'wide' | 0 + +const gutters: Record< + Exclude<Gutter, 0>, + Record<Breakpoint | 'default', number> +> = { + compact: { + default: tokens.space.sm, + gtPhone: tokens.space.sm, + gtMobile: tokens.space.md, + gtTablet: tokens.space.md, + }, + base: { + default: tokens.space.lg, + gtPhone: tokens.space.lg, + gtMobile: tokens.space.xl, + gtTablet: tokens.space.xl, + }, + wide: { + default: tokens.space.xl, + gtPhone: tokens.space.xl, + gtMobile: tokens.space._3xl, + gtTablet: tokens.space._3xl, + }, +} + +type Gutters = { + paddingTop: number + paddingRight: number + paddingBottom: number + paddingLeft: number +} + +export function useGutters([all]: [Gutter]): Gutters +export function useGutters([vertical, horizontal]: [Gutter, Gutter]): Gutters +export function useGutters([top, right, bottom, left]: [ + Gutter, + Gutter, + Gutter, + Gutter, +]): Gutters +export function useGutters([top, right, bottom, left]: Gutter[]) { + const {activeBreakpoint} = useBreakpoints() + if (right === undefined) { + right = bottom = left = top + } else if (bottom === undefined) { + bottom = top + left = right + } + return React.useMemo(() => { + return { + paddingTop: top === 0 ? 0 : gutters[top][activeBreakpoint || 'default'], + paddingRight: + right === 0 ? 0 : gutters[right][activeBreakpoint || 'default'], + paddingBottom: + bottom === 0 ? 0 : gutters[bottom][activeBreakpoint || 'default'], + paddingLeft: + left === 0 ? 0 : gutters[left][activeBreakpoint || 'default'], + } + }, [activeBreakpoint, top, right, bottom, left]) +} |