Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/Common/cashtabAmountKeypadScroll.ts
| Show All 18 Lines | |||||
| export const CASHTAB_FIXED_CTA_OFFSET_VAR = '--cashtab-fixed-cta-offset'; | export const CASHTAB_FIXED_CTA_OFFSET_VAR = '--cashtab-fixed-cta-offset'; | ||||
| /** Host screens mark the fixed bottom CTA with this attribute for measurement. */ | /** Host screens mark the fixed bottom CTA with this attribute for measurement. */ | ||||
| export const CASHTAB_FIXED_CTA_ATTR = 'data-cashtab-fixed-cta'; | export const CASHTAB_FIXED_CTA_ATTR = 'data-cashtab-fixed-cta'; | ||||
| /** Cashtab bottom nav height on narrow viewports (see Footer / SendButtonContainer). */ | /** Cashtab bottom nav height on narrow viewports (see Footer / SendButtonContainer). */ | ||||
| export const CASHTAB_MOBILE_FOOTER_OFFSET_PX = 70; | export const CASHTAB_MOBILE_FOOTER_OFFSET_PX = 70; | ||||
| /** Live footer height; 0px while the OS keyboard is open (see cashtabOsKeyboard). */ | |||||
| export const CASHTAB_MOBILE_FOOTER_OFFSET_VAR = | |||||
| '--cashtab-mobile-footer-offset'; | |||||
| /** Extra gap so the amount field is not flush against the keypad top edge. */ | /** Extra gap so the amount field is not flush against the keypad top edge. */ | ||||
| export const CASHTAB_AMOUNT_KEYPAD_SCROLL_PAD_PX = 12; | export const CASHTAB_AMOUNT_KEYPAD_SCROLL_PAD_PX = 12; | ||||
| /** | /** | ||||
| * Parse a CSS pixel custom property, falling back when unset or invalid. | * Parse a CSS pixel custom property, falling back when unset or invalid. | ||||
| */ | */ | ||||
| export const parseCssPxProperty = ( | export const parseCssPxProperty = ( | ||||
| styles: CSSStyleDeclaration, | styles: CSSStyleDeclaration, | ||||
| property: string, | property: string, | ||||
| fallback: number, | fallback: number, | ||||
| ): number => { | ): number => { | ||||
| const n = parseFloat(styles.getPropertyValue(property)); | const n = parseFloat(styles.getPropertyValue(property)); | ||||
| return Number.isFinite(n) ? n : fallback; | return Number.isFinite(n) ? n : fallback; | ||||
| }; | }; | ||||
| /** | /** | ||||
| * Mobile footer clearance; desktop Send layouts dock the keypad above the CTA only. | * Mobile footer clearance; desktop Send layouts dock the keypad above the CTA only. | ||||
| */ | */ | ||||
| export const getMobileFooterOffsetPx = ( | export const getMobileFooterOffsetPx = ( | ||||
| matchMediaFn: typeof window.matchMedia | undefined = typeof window !== | matchMediaFn: typeof window.matchMedia | undefined = typeof window !== | ||||
| 'undefined' | 'undefined' | ||||
| ? window.matchMedia | ? window.matchMedia | ||||
| : undefined, | : undefined, | ||||
| root: HTMLElement | undefined = typeof document !== 'undefined' | |||||
| ? document.documentElement | |||||
| : undefined, | |||||
| ): number => { | ): number => { | ||||
| if ( | if ( | ||||
| typeof matchMediaFn === 'function' && | typeof matchMediaFn === 'function' && | ||||
| matchMediaFn('(min-width: 769px)').matches | matchMediaFn('(min-width: 769px)').matches | ||||
| ) { | ) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| if (root) { | |||||
| return parseCssPxProperty( | |||||
| getComputedStyle(root), | |||||
| CASHTAB_MOBILE_FOOTER_OFFSET_VAR, | |||||
| CASHTAB_MOBILE_FOOTER_OFFSET_PX, | |||||
| ); | |||||
| } | |||||
| return CASHTAB_MOBILE_FOOTER_OFFSET_PX; | return CASHTAB_MOBILE_FOOTER_OFFSET_PX; | ||||
| }; | }; | ||||
| /** | /** | ||||
| * Measure the fixed CTA height from the DOM (preferred) or the CSS variable. | * Measure the fixed CTA height from the DOM (preferred) or the CSS variable. | ||||
| */ | */ | ||||
| export const measureFixedCtaOffsetPx = ( | export const measureFixedCtaOffsetPx = ( | ||||
| doc: Document = typeof document !== 'undefined' | doc: Document = typeof document !== 'undefined' | ||||
| ▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines | |||||