From 1cfdcea8d5aafdaed44a5b9e7f5f123f83bd1215 Mon Sep 17 00:00:00 2001 From: Abigaila Ekiert <44117299+sharlotta93@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:16:18 +0200 Subject: [PATCH] TP-2543-change-where-the-button-is-on-forms (#162) --- package.json | 2 +- .../activities/form/TraditionalForm.tsx | 69 ++++++++++++------- .../activities/form/form.module.scss | 19 +++++ 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 232db14..c0e502a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@awell-health/ui-library", - "version": "0.1.71", + "version": "0.1.72", "description": "UI components to integrate with Awell Health", "repository": { "type": "git", diff --git a/src/hostedPages/activities/form/TraditionalForm.tsx b/src/hostedPages/activities/form/TraditionalForm.tsx index 756fe3d..7e463f3 100644 --- a/src/hostedPages/activities/form/TraditionalForm.tsx +++ b/src/hostedPages/activities/form/TraditionalForm.tsx @@ -1,11 +1,10 @@ -import React, { useEffect } from 'react' +import React, { useEffect, useRef } from 'react' import { Button, Text } from '../../../atoms' import classes from './form.module.scss' import { Question } from '../../../molecules' import { useTraditionalForm } from '../../../hooks/useForm' import layoutClasses from '../../layouts/HostedPageLayout/hostedPageLayout.module.scss' import { FormProps } from '../../../types/form' -import { UserQuestionType } from '../../../types' import { useTheme } from '../../../atoms/themeProvider/ThemeProvider' import { LoadActivityPlaceholder, @@ -23,6 +22,21 @@ export const TraditionalForm = ({ autosaveAnswers = true, questionLabels, }: FormProps) => { + const scrollHintOverlayRef = useRef(null) + + useEffect(() => { + const handleScroll = () => { + if (scrollHintOverlayRef.current) { + const { scrollTop, scrollHeight, clientHeight } = + document.documentElement + const isAtBottom = scrollTop + clientHeight >= scrollHeight + scrollHintOverlayRef.current.style.top = isAtBottom ? '100%' : 'auto' + } + } + + window.addEventListener('scroll', handleScroll) + return () => window.removeEventListener('scroll', handleScroll) + }, []) const { updateLayoutMode, resetLayoutMode } = useTheme() const { @@ -45,7 +59,6 @@ export const TraditionalForm = ({ useEffect(() => { updateLayoutMode('flexible') - return () => { // Reset to default mode on unmount resetLayoutMode() @@ -53,7 +66,7 @@ export const TraditionalForm = ({ }, []) return ( - <> +
- -
- {formHasErrors && ( -
- - {errorLabels.formHasErrors} - -
- )} -
- -
-
- +
+
+ +
+ {formHasErrors && ( +
+ + {errorLabels.formHasErrors} + +
+ )} +
+ +
+
+
+
) } diff --git a/src/hostedPages/activities/form/form.module.scss b/src/hostedPages/activities/form/form.module.scss index 8639cf9..13f8291 100644 --- a/src/hostedPages/activities/form/form.module.scss +++ b/src/hostedPages/activities/form/form.module.scss @@ -97,3 +97,22 @@ padding-top: var(--awell-spacing-4); } } + +/* Overlay for the opacity gradient */ +.scroll_hint_overlay { + position: fixed; + bottom: 50px; + left: 0; + width: 100%; + height: 70px; + background: linear-gradient(to bottom, transparent, var(--awell-neutralLight10) 100%); + pointer-events: none; /* Prevent interaction */ + transition: top 0.5s ease-in-out; +} + +.footer_for_traditional_form { + width: 100%; + position: fixed; + bottom: 0; + left: 0; +}