-
Notifications
You must be signed in to change notification settings - Fork 0
Updated the fade-in effect on reveal of enhanced text and fix other issues on feedback #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
2a78f5a
25fd7d4
a806363
54b30fa
93abf97
4f0739b
da29cc8
4be85cd
fbfc2df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import React, { useEffect, useState, useRef } from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import classnames from 'classnames' | ||
|
|
||
| function TextRevealOverlay({ | ||
| text, | ||
|
|
@@ -25,6 +26,7 @@ function TextRevealOverlay({ | |
| } | ||
| }, [text]) | ||
|
|
||
| // Handle animation completion when the last paragraph finishes animating | ||
| useEffect(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add some short comments to all useEffect hooks in this component?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would be good to move all those useEffects to a separate hook?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some comments to the useEffect but did not move into a separate hook since it's only being used by this component. |
||
| if (isAnimatingLastParagraph && lastParagraphIndex === paragraphs.length - 1) { | ||
| const timer = setTimeout(() => { | ||
|
|
@@ -38,14 +40,14 @@ function TextRevealOverlay({ | |
| } | ||
| }, [isAnimatingLastParagraph, lastParagraphIndex, paragraphs.length, onAnimationComplete]) | ||
|
|
||
|
|
||
| // Detect when the last paragraph appears and mark it for animation | ||
| useEffect(() => { | ||
| if (lastParagraphIndex === paragraphs.length - 1 && paragraphs.length > 0) { | ||
| setIsAnimatingLastParagraph(true) | ||
| } | ||
| }, [lastParagraphIndex, paragraphs.length]) | ||
|
|
||
|
|
||
| // Sync overlay dimensions, positioning and scrolling with the textarea | ||
| useEffect(() => { | ||
| if (!textareaRef || !textareaRef.current || !overlayRef.current || !isRevealing) return | ||
|
|
||
|
|
@@ -84,7 +86,8 @@ function TextRevealOverlay({ | |
| overlay.style.position = 'absolute' | ||
| overlay.style.top = paddingTop | ||
| overlay.style.left = paddingLeft | ||
| overlay.style.width = 'calc(100% - ' + (parseInt(paddingLeft) * 2) + 'px)' | ||
| overlay.style.width = `calc(100% - ${parseInt(paddingLeft) * 2}px)` | ||
|
|
||
|
|
||
| // Set max-height to match textarea max-height | ||
| overlay.style.maxHeight = textareaStyles.maxHeight | ||
|
|
@@ -143,15 +146,21 @@ function TextRevealOverlay({ | |
| return ( | ||
| <div | ||
| ref={overlayRef} | ||
| className={`ds-prompt-input__text-reveal-overlay ${className || ''}`} | ||
| className={classnames( | ||
| 'ds-prompt-input__text-reveal-overlay', | ||
| className | ||
| )} | ||
| aria-hidden="true" | ||
| > | ||
| {paragraphs.map((paragraph, index) => ( | ||
| <p | ||
| key={index} | ||
| className={`ds-prompt-input__text-reveal-paragraph ${ | ||
| index === lastParagraphIndex ? 'ds-prompt-input__text-reveal-paragraph--animating' : '' | ||
| }`} | ||
| className={classnames( | ||
| 'ds-prompt-input__text-reveal-paragraph', | ||
| { | ||
| 'ds-prompt-input__text-reveal-paragraph--animating': index === lastParagraphIndex | ||
| } | ||
| )} | ||
| > | ||
| {paragraph} | ||
| </p> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.