📄 useTextDirection¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 2 |
| 📦 Imports | 7 |
| 🟢 Vue Composition API | 1 |
| 📐 Interfaces | 1 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/core/useTextDirection/index.ts
📦 Imports¶
| Name | Source |
|---|---|
ConfigurableDocument |
../_configurable |
MaybeElement |
../unrefElement |
tryOnMounted |
@vueuse/shared |
computed |
vue |
shallowRef |
vue |
defaultDocument |
../_configurable |
useMutationObserver |
../useMutationObserver |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
computed |
computed | none | none |
Functions¶
useTextDirection(options: UseTextDirectionOptions): any¶
Reactive dir of the element's text.
See: https://vueuse.org/useTextDirection
Tags: @__NO_SIDE_EFFECTS__
Raw JSDoc
Calls:
document?.querySelector(selector)?.getAttributeshallowRef (from vue)getValuetryOnMounted (from @vueuse/shared)useMutationObserver (from ../useMutationObserver)document.querySelectorcomputed (from vue)document.querySelector(selector)?.setAttributedocument.querySelector(selector)?.removeAttribute
Code
export function useTextDirection(options: UseTextDirectionOptions = {}) {
const {
document = defaultDocument,
selector = 'html',
observe = false,
initialValue = 'ltr',
} = options
function getValue() {
return document?.querySelector(selector)?.getAttribute('dir') as UseTextDirectionValue ?? initialValue
}
const dir = shallowRef<UseTextDirectionValue>(getValue())
tryOnMounted(() => dir.value = getValue())
if (observe && document) {
useMutationObserver(
document.querySelector(selector) as MaybeElement,
() => dir.value = getValue(),
{ attributes: true },
)
}
return computed<UseTextDirectionValue>({
get() {
return dir.value
},
set(v) {
dir.value = v
if (!document)
return
if (dir.value)
document.querySelector(selector)?.setAttribute('dir', dir.value)
else
document.querySelector(selector)?.removeAttribute('dir')
},
})
}
Internal helpers¶
Declared inside another function in this file.
getValue(): UseTextDirectionValue¶
Returns: UseTextDirectionValue
Calls:
document?.querySelector(selector)?.getAttribute
Code
Interfaces¶
UseTextDirectionOptions¶
Interface Code
export interface UseTextDirectionOptions extends ConfigurableDocument {
/**
* CSS Selector for the target element applying to
*
* @default 'html'
*/
selector?: string
/**
* Observe `document.querySelector(selector)` changes using MutationObserve
*
* @default false
*/
observe?: boolean
/**
* Initial value
*
* @default 'ltr'
*/
initialValue?: UseTextDirectionValue
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
selector |
string |
✓ | not shown |
observe |
boolean |
✓ | not shown |
initialValue |
UseTextDirectionValue |
✓ | not shown |
Type Aliases¶
UseTextDirectionValue¶
Generated by Syntax Scribe