import type { JSX, ValidComponent } from "@solidjs/web"; /** * `` — wrapper for the app's main UI that applies * `data-active` when any drawer within the nearest `` is * open. */ import { dynamic } from "@solidjs/web"; import { createMemo, omit, onCleanup } from "solid-js"; import { composeRefs, userRef } from "../../internals/compose-refs"; import { mergeRootProps } from "../../internals/merge-root-props"; import { resolveClassStyle } from "../../internals/resolve-class-style"; import type { BaseUIComponentProps } from "../../internals/types"; import { useIsoLayoutEffect } from "../../internals/use-iso-layout-effect"; import { DrawerBackdropCssVars } from "../backdrop/drawer-backdrop-css-vars"; import { DrawerPopupCssVars } from "../popup/drawer-popup-css-vars"; import { useDrawerProviderContext } from "../provider/drawer-provider-context"; export interface DrawerIndentState { active: boolean; } export interface DrawerIndentProps extends BaseUIComponentProps<"div", DrawerIndentState> { /** * Tag/component to render. Defaults to `"div"`. Replaces the * pre-spike `render` prop (axis G). */ as?: ValidComponent; } /** * App-shell wrapper that keys off drawer activity. Renders a `
`. */ export function DrawerIndent(props: DrawerIndentProps): JSX.Element { const providerContext = useDrawerProviderContext(true); const state = createMemo(() => ({ active: providerContext?.active() ?? false, })); let indentEl: HTMLDivElement | null = null; const setIndentRef = (el: HTMLDivElement | null): void => { indentEl = el; }; useIsoLayoutEffect( () => providerContext?.visualStateStore, (visualStateStore) => { const el = indentEl; if (!el || !visualStateStore) return undefined; const syncVisualState = (): void => { const { swipeProgress, frontmostHeight } = visualStateStore.getSnapshot(); if (swipeProgress <= 0) { el.style.setProperty(DrawerBackdropCssVars.swipeProgress, "0"); } else { el.style.setProperty( DrawerBackdropCssVars.swipeProgress, `${swipeProgress}`, ); } if (frontmostHeight <= 0) { el.style.removeProperty(DrawerPopupCssVars.height); } else { el.style.setProperty( DrawerPopupCssVars.height, `${frontmostHeight}px`, ); } }; syncVisualState(); const unsubscribe = visualStateStore.subscribe(syncVisualState); return () => { unsubscribe(); el.style.setProperty(DrawerBackdropCssVars.swipeProgress, "0"); el.style.removeProperty(DrawerPopupCssVars.height); }; }, ); onCleanup(() => { indentEl = null; }); const internal = { get style(): JSX.CSSProperties { return { [DrawerBackdropCssVars.swipeProgress]: "0", } as JSX.CSSProperties; }, get "data-active"() { return state().active ? "" : undefined; }, get "data-inactive"() { return state().active ? undefined : ""; }, }; const userClassStyle = resolveClassStyle(props, () => state()); const userProps = omit(props, "as", "class", "style", "attrs"); let merged: Record = mergeRootProps( internal, userClassStyle, ); merged = mergeRootProps(merged, userProps); const Tag = dynamic(() => props.as ?? "div"); return ; }