useTextSelection
Tracking content, size, position of user text selection.
Overview
Tracking content, size, position of user text selection.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTextSelection.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTextSelection.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTextSelection.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTextSelection.jsonTracking content, size, position of user text selection.
Examples
Default usage
Listen for specified area
Translate user text selection
API
const state = useTextSelection(target?);Params
| Property | Description | Type | Default |
| -- | | | - | - |
| state | Content, size, position of user text selection | State |
State
| Property | Description | Type |
| -- | ----- |
| text | Selected text | string |
| left | The left coordinate value of text | number |
| right | The right coordinate value of text | number |
| top | The top coordinate value of text | number |
| bottom | The bottom coordinate value of text | number |
| height | The height of text | number |
| width | The width of text | number |