Container queries!

This commit is contained in:
Gregory Schier
2023-03-20 01:08:41 -07:00
parent 9e1771c5ec
commit b6f53d059e
14 changed files with 212 additions and 245 deletions

View File

@@ -0,0 +1,22 @@
import { useCallback } from 'react';
import { clamp } from '../lib/clamp';
import { useKeyValue } from './useKeyValue';
const INITIAL_WIDTH = 200;
const MIN_WIDTH = 110;
const MAX_WIDTH = 500;
export function useSidebarWidth() {
const width = useKeyValue<number>({ key: 'sidebar_width', defaultValue: INITIAL_WIDTH });
const setWidth = useCallback((v: number) => {
width.set(clamp(v, MIN_WIDTH, MAX_WIDTH));
}, []);
const resetWidth = useCallback(() => {
width.set(INITIAL_WIDTH);
}, []);
return { value: width.value ?? INITIAL_WIDTH, set: setWidth, reset: resetWidth };
}