@wikimedia/codex
Version:
Codex Design System for Wikimedia
17 lines (16 loc) • 839 B
TypeScript
import { Ref } from 'vue';
/**
* Composable for detecting the language of the context surrounding a component.
* For example, if the component is wrapped in <div lang="ar">...</div>, this composable
* detects that and returns 'ar'.
*
* The value returned by this composable will initially be null, and will then
* update to the detected language later, when the component mounts. This is
* because detecting the language is not possible until the component has been
* mounted. Code using this composable should anticipate this, and check whether
* the value is null.
*
* @param root Template ref for the root element of the component
* @return The detected language code, or null if the component hasn't been mounted yet.
*/
export default function useComputedLanguage(root: Ref<HTMLElement | undefined>): Ref<string | null>;