11import type { CallbackFn } from '../types' ;
22
33/**
4- * @private
5- *
64 * @param t: time (elapsed)
75 * @param b: initial value
86 * @param c: amount of change
97 * @param d: duration
108 */
11- function easeOutCubic ( t : number , b : number , c : number , d : number ) : number {
9+ const easeOutCubic = (
10+ t : number ,
11+ b : number ,
12+ c : number ,
13+ d : number
14+ ) : number => {
1215 return c * ( ( t = t / d - 1 ) * t * t + 1 ) + b ;
13- }
16+ } ;
1417
15- /**
16- * @private
17- */
18- function getScrollTop ( el : HTMLElement ) : number {
18+ const getScrollTop = ( el : HTMLElement ) : number => {
1919 return isDocumentElement ( el ) ? window . pageYOffset : el . scrollTop ;
20- }
20+ } ;
2121
22- /**
23- * @private
24- */
25- function scrollTo ( el : HTMLElement , top : number ) : void {
22+ const scrollTo = ( el : HTMLElement , top : number ) : void => {
2623 isDocumentElement ( el ) ? window . scrollTo ( 0 , top ) : ( el . scrollTop = top ) ;
27- }
24+ } ;
2825
29- /**
30- * @private
31- */
32- function isDocumentElement ( el : HTMLElement | typeof window ) : boolean {
26+ const isDocumentElement = ( el : HTMLElement | typeof window ) : boolean => {
3327 return el === document . body || el === document . documentElement || el === window ;
34- }
28+ } ;
3529
36- /**
37- * @private
38- */
39- function getScrollParent ( el : HTMLElement ) : HTMLElement {
30+ const getScrollParent = ( el : HTMLElement ) : HTMLElement => {
4031 let style = getComputedStyle ( el ) ;
4132
4233 if ( style . position === 'fixed' ) {
@@ -57,34 +48,31 @@ function getScrollParent(el: HTMLElement): HTMLElement {
5748 }
5849
5950 return document . documentElement ;
60- }
51+ } ;
6152
62- /**
63- * @private
64- */
65- function smoothScrollTo (
53+ const smoothScrollTo = (
6654 el : HTMLElement ,
6755 to : number ,
6856 duration : number = 300 ,
6957 callback ?: CallbackFn
70- ) : void {
58+ ) : void => {
7159 let currentTime = 0 ;
7260 const start = getScrollTop ( el ) ;
7361 const change = to - start ;
7462
75- function scrollFn ( ) {
63+ const scrollFn = ( ) => {
7664 currentTime += 5 ;
7765 const calcScrollTop = easeOutCubic ( currentTime , start , change , duration ) ;
7866 scrollTo ( el , calcScrollTop ) ;
7967 ( currentTime < duration ) ? requestAnimationFrame ( scrollFn ) : callback ?.( ) ;
80- }
68+ } ;
8169
8270 requestAnimationFrame ( scrollFn ) ;
83- }
71+ } ;
8472
8573/**
86- * Calculates the top property value for the MenuWrapper <div />.
87- * This property is only generated when the position of the menu is above the control.
74+ * Calculates the top property value for the MenuWrapper element
75+ * This property is only generated when the position of the menu is above the control
8876 */
8977export const calculateMenuTop = (
9078 menuHeight : number ,
@@ -110,7 +98,7 @@ export const menuFitsBelowControl = (el: HTMLElement | null): boolean => {
11098
11199/**
112100 * Calculate space around the control and menu to determine if an animated
113- * scroll can performed to show the menu in full view. Also, execute a callback if defined.
101+ * scroll can performed to show the menu in full view. Also, execute a callback if defined
114102 */
115103export const scrollMenuIntoViewOnOpen = (
116104 menuEl : HTMLElement | null ,
@@ -138,8 +126,8 @@ export const scrollMenuIntoViewOnOpen = (
138126 const spaceBelow = scrollParent . getBoundingClientRect ( ) . height - scrollTop - top ;
139127 const notEnoughSpaceBelow = spaceBelow < height ;
140128
141- // Sufficient space does not exist to scroll menu fully into view.
142- // Calculate available space and use that as the the new menuHeight (use scrollSpaceBelow for now).
129+ // Sufficient space does not exist to scroll menu fully into view
130+ // Calculate available space and use that as the the new menuHeight (use scrollSpaceBelow for now)
143131 // OR scrollMenuIntoView = false
144132 if ( notEnoughSpaceBelow || ! scrollMenuIntoView ) {
145133 const condensedMenuHeight = notEnoughSpaceBelow ? spaceBelow : undefined ;
0 commit comments