-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:twilio-labs/paste into docs-icons
- Loading branch information
Showing
24 changed files
with
1,073 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@twilio-paste/ai-chat-log": minor | ||
"@twilio-paste/core": minor | ||
--- | ||
|
||
[AI Chat Log] added optional typewriter animation to AIChatMessageBody |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,6 @@ | |
"db:reset": "yarn supabase db reset" | ||
}, | ||
"devDependencies": { | ||
"supabase": "^1.204.3" | ||
"supabase": "^2.6.8" | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
apps/backend/supabase/migrations/20230928013336_initial_schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
// Hook to animate text content of React elements | ||
export const useAnimatedText = ( | ||
children: React.ReactNode, | ||
speed = 10, | ||
enabled = true, | ||
): { animatedChildren: React.ReactNode; isAnimating: boolean } => { | ||
const [animatedChildren, setAnimatedChildren] = useState<React.ReactNode>(); | ||
const [textIndex, setTextIndex] = useState(0); | ||
|
||
// Effect to increment textIndex at a specified speed | ||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setTextIndex((prevIndex) => prevIndex + 1); | ||
}, speed); | ||
|
||
return () => clearInterval(interval); | ||
}, [speed]); | ||
|
||
// Function to calculate the total length of text within nested elements | ||
const calculateTotalTextLength = (nodes: React.ReactNode): number => { | ||
let length = 0; | ||
React.Children.forEach(nodes, (child) => { | ||
if (typeof child === "string") { | ||
length += child.length; | ||
} else if (React.isValidElement(child)) { | ||
length += calculateTotalTextLength(child.props.children); | ||
} | ||
}); | ||
return length; | ||
}; | ||
|
||
// Function to recursively clone children and apply text animation | ||
const cloneChildren = (nodes: React.ReactNode, currentIndex: number): React.ReactNode => { | ||
let currentTextIndex = currentIndex; | ||
return React.Children.map(nodes, (child) => { | ||
if (typeof child === "string") { | ||
// Only include text nodes if their animation has started | ||
if (currentTextIndex > 0) { | ||
const visibleText = child.slice(0, currentTextIndex); | ||
currentTextIndex -= child.length; | ||
return visibleText; | ||
} | ||
return null; | ||
} else if (React.isValidElement(child)) { | ||
const totalChildTextLength = calculateTotalTextLength(child.props.children); | ||
// Only include elements if their text animation has started | ||
if (currentTextIndex > 0) { | ||
const clonedChild = React.cloneElement(child, {}, cloneChildren(child.props.children, currentTextIndex)); | ||
currentTextIndex -= totalChildTextLength; | ||
return clonedChild; | ||
} else if (currentTextIndex === 0 && totalChildTextLength === 0) { | ||
return child; | ||
} | ||
return null; | ||
} | ||
|
||
return child; | ||
}); | ||
}; | ||
|
||
// Effect to update animated children based on the current text index | ||
useEffect(() => { | ||
if (enabled) { | ||
const totaLength = calculateTotalTextLength(children); | ||
if (textIndex <= totaLength) { | ||
setAnimatedChildren(cloneChildren(children, textIndex)); | ||
} | ||
} | ||
}, [children, textIndex, enabled]); | ||
|
||
return { | ||
animatedChildren: enabled ? animatedChildren : children, | ||
isAnimating: enabled && textIndex < calculateTotalTextLength(children), | ||
}; | ||
}; | ||
|
||
export default useAnimatedText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.