index.d.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import type { Options as Options_2 } from 'compute-scroll-into-view'
  2. import type { ScrollAction } from 'compute-scroll-into-view'
  3. /** @public */
  4. export declare interface CustomBehaviorOptions<T = unknown> extends Options_2 {
  5. behavior: CustomScrollBehaviorCallback<T>
  6. }
  7. /** @public */
  8. export declare type CustomScrollBehaviorCallback<T = unknown> = (
  9. actions: ScrollAction[]
  10. ) => T
  11. /** @public */
  12. export declare type Options<T = unknown> =
  13. | StandardBehaviorOptions
  14. | CustomBehaviorOptions<T>
  15. /**
  16. * Scrolls the given element into view, with options for when, and how.
  17. * Supports the same `options` as [`Element.prototype.scrollIntoView`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) with additions such as `scrollMode`, `behavior: Function` and `skipOverflowHiddenElements`.
  18. * @public
  19. */
  20. declare function scrollIntoView(
  21. target: Element,
  22. options?: StandardBehaviorOptions | boolean
  23. ): void
  24. /**
  25. * Scrolls the given element into view, with options for when, and how.
  26. * Supports the same `options` as [`Element.prototype.scrollIntoView`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) with additions such as `scrollMode`, `behavior: Function` and `skipOverflowHiddenElements`.
  27. *
  28. * You can set the expected return type for `behavior: Function`:
  29. * ```ts
  30. * await scrollIntoView<Promise<boolean[]>>(node, {
  31. * behavior: async actions => {
  32. * return Promise.all(actions.map(
  33. * // animate() resolves to `true` if anything was animated, `false` if the element already were in the end state
  34. * ({ el, left, top }) => animate(el, {scroll: {left, top}})
  35. * ))
  36. * }
  37. * })
  38. * ```
  39. * @public
  40. */
  41. declare function scrollIntoView<T>(
  42. target: Element,
  43. options: CustomBehaviorOptions<T>
  44. ): T
  45. export default scrollIntoView
  46. /**
  47. * Only scrolls if the `node` is partially out of view:
  48. * ```ts
  49. * scrollIntoView(node, { scrollMode: 'if-needed' })
  50. * ```
  51. * Skips scrolling `overflow: hidden` elements:
  52. * ```ts
  53. * scrollIntoView(node, { skipOverflowHiddenElements: true })
  54. * ```
  55. * When scrolling is needed do the least and smoothest scrolling possible:
  56. * ```ts
  57. * scrollIntoView(node, {
  58. * behavior: 'smooth',
  59. * scrollMode: 'if-needed',
  60. * block: 'nearest',
  61. * inline: 'nearest',
  62. * })
  63. * ```
  64. * @public
  65. */
  66. export declare interface StandardBehaviorOptions extends Options_2 {
  67. /**
  68. * @defaultValue 'auto
  69. */
  70. behavior?: ScrollBehavior
  71. }
  72. export {}