@codecademy/gamut-styles

17.13.117.13.2-alpha.955544.0
dist/utilities/elementDir.d.ts
+dist/utilities/elementDir.d.tsNew file
+22
Index: package/dist/utilities/elementDir.d.ts
===================================================================
--- package/dist/utilities/elementDir.d.ts
+++ package/dist/utilities/elementDir.d.ts
@@ -0,0 +1,22 @@
+import type { RefObject } from 'react';
+/** Resolved HTML `dir` keyword: effective writing direction after `dir`, then CSS `direction`, then document root. */
+export type DirValue = 'rtl' | 'ltr';
+/**
+ * Resolves the effective `dir` for an element (`rtl` or `ltr`), including JSDOM where
+ * `getComputedStyle(el).direction` is often empty while `dir` is set on the root.
+ */
+export declare function elementDir(el: Element): DirValue;
+/**
+ * Ref whose `current` may be any DOM {@link Element} subclass (`HTMLElement`, `SVGElement`,
+ * `HTMLButtonElement`, etc.). For structural/minimal types (e.g. tests), intersect with
+ * `Element` so `current` is still typed as an `Element` (e.g. `Pick<HTMLAnchorElement, 'id'> & Element`).
+ */
+export type ElementDirRef<T extends Element = Element> = RefObject<T | null>;
+/**
+ * Returns the effective `dir` for the resolved element (`rtl` or `ltr`), and updates when `dir`
+ * changes on the document subtree or after layout (so `ref.current` is current).
+ * Resolution uses {@link elementDir}.
+ *
+ * @param elementRef - Optional ref; when missing or `current` is not an `Element`, uses `document.documentElement`.
+ */
+export declare function useElementDir<T extends Element = Element>(elementRef?: ElementDirRef<T>): DirValue;