This repository was archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Khatchig - CEM2662 - Typing animation #440
Open
Khachig
wants to merge
4
commits into
master
Choose a base branch
from
textbubble
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,53 @@ | ||
| import React from 'react'; | ||
| import { Meta, Story } from '@storybook/react'; | ||
| import TextBubble, { ITextBubbleProps } from './TextBubble'; | ||
| import TypingDots from '../../Text/TypingDots/TypingDots'; | ||
| import { Robot } from '@styled-icons/remix-fill/Robot'; | ||
|
|
||
| export default { | ||
| title: 'Components/Text Bubble', | ||
| component: TextBubble, | ||
| } as Meta; | ||
|
|
||
| const Template: Story<ITextBubbleProps> = (args) => ( | ||
| <TextBubble {...args} /> | ||
| ); | ||
|
|
||
| export const Basic = Template.bind({}); | ||
| Basic.args = { | ||
| content: <p>Basic text bubble (other generated)</p>, | ||
| fromBot: true | ||
| } | ||
|
|
||
| export const User = Template.bind({}); | ||
| User.args = { | ||
| content: <p>Basic text bubble (user generated)</p>, | ||
| fromBot: false | ||
| } | ||
|
|
||
| export const NoText = Template.bind({}); | ||
| NoText.args = { | ||
| content: <p> </p>, | ||
| fromBot: true | ||
| } | ||
|
|
||
| export const Typing = Template.bind({}); | ||
| Typing.args = { | ||
| content: <TypingDots num={3} delayStep={0.1} />, | ||
| fromBot: true, | ||
| icon: Robot | ||
| } | ||
|
|
||
| export const CustomStyled = Template.bind({}); | ||
| CustomStyled.args = { | ||
| content: <p>Text bubble with custom styles</p>, | ||
| fromBot: true, | ||
| bubbleStyle: { | ||
| backgroundColor: 'yellow', | ||
| borderRadius: '15px' | ||
| }, | ||
| iconStyle: { | ||
| borderRadius: '5px' | ||
| }, | ||
| icon: Robot | ||
| } | ||
This file contains hidden or 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,81 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
| import { Robot, User } from '@styled-icons/fa-solid/'; | ||
|
|
||
| export interface ITextBubbleProps { | ||
| content: React.ReactElement; | ||
| fromBot: boolean; | ||
|
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. bubbleProps: React.HTMLAttrs(ReactDivElemet) |
||
| icon: React.ReactElement; | ||
| iconSize: number; | ||
| iconStyle: React.HTMLAttrs; | ||
| bubbleStyle: React.HTMLAttrs; | ||
| } | ||
|
|
||
| export const TextBubble = ({content, fromBot, icon, iconSize, iconStyle, bubbleStyle, ...props}: ITextBubbleProps): React.ReactElement => { | ||
| if (!icon) | ||
| icon = fromBot ? Robot : User; | ||
|
|
||
| if (!iconSize) | ||
| iconSize = 25; | ||
|
|
||
| return ( | ||
| <BubbleContainer> | ||
| { fromBot && | ||
| <StyledImg as={ icon } imgSize={ iconSize } style={ iconStyle } /> | ||
| } | ||
|
|
||
| <Bubble fromBot={ fromBot } style={ bubbleStyle }> | ||
| { content } | ||
| </Bubble> | ||
|
|
||
| { !fromBot && | ||
| <StyledImg as={ icon } imgSize={ iconSize } style={ iconStyle } /> | ||
| } | ||
| </BubbleContainer> | ||
| ); | ||
| } | ||
|
|
||
| const StyledImg = styled.svg<{ imgSize: number }>` | ||
| ${({ imgSize }) => ` | ||
| width: ${imgSize}px; | ||
| height: ${imgSize}px; | ||
| `} | ||
| margin: 0 10px; | ||
| border-radius: 999px; | ||
| border-style: solid; | ||
| padding: 10px; | ||
| ` | ||
|
|
||
| const BubbleContainer = styled.div` | ||
| display: inline-block; | ||
| ` | ||
|
|
||
| const Bubble = styled.div<{ fromBot: boolean }>` | ||
| display: inline-block; | ||
| border: 1.5px solid rgba(0, 0, 0, 0.1); | ||
| padding: 0 10px; | ||
|
|
||
| ${({ theme, fromBot }): string => | ||
| fromBot | ||
| ? ` | ||
| border-radius: 20px 20px 20px 5px; | ||
| background-color: ${theme.colors["background"]}; | ||
| ` | ||
| : ` | ||
| border-radius: 20px 20px 5px 20px; | ||
| background-color: ${theme.colors["primary"]}; | ||
| ` | ||
| } | ||
|
|
||
| animation: appear 0.5s ease-in 1; | ||
| @keyframes appear { | ||
| from { | ||
| opacity: 0; | ||
| } | ||
| to { | ||
| opacity: 100; | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| export default TextBubble; | ||
This file contains hidden or 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,12 @@ | ||
| import React from 'react'; | ||
| import { Meta, Story } from '@storybook/react'; | ||
| import TypingDots, { ITypingDotsProps } from './TypingDots'; | ||
|
|
||
| export default { | ||
| title: 'Components/Typing Indicator Dots', | ||
| component: TypingDots | ||
| } as Meta; | ||
|
|
||
| export const Basic: Story<ITypingDotsProps> = () => ( | ||
| <TypingDots num={3} delayStep={0.1}/> | ||
| ); |
This file contains hidden or 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,54 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| export interface ITypingDotsProps { | ||
| num: number; | ||
| delayStep: number; | ||
| } | ||
|
|
||
| export const TypingDots = ({ num, delayStep, ...props }: ITypingDotsProps): React.ReactElement => { | ||
|
|
||
| let dots = []; | ||
|
|
||
| for (let i = 0; i < num; i ++) { | ||
| dots.push(<Dot delay={i * delayStep} />); | ||
| } | ||
|
Comment on lines
+11
to
+15
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. Somethings wrong here |
||
|
|
||
| return ( | ||
| <DotContainer> | ||
| { dots } | ||
| </DotContainer> | ||
| ); | ||
| } | ||
|
|
||
| const DotContainer = styled.div` | ||
| margin: 10px; | ||
| display: flex; | ||
| flex-direction: row; | ||
| ` | ||
|
|
||
| const Dot = styled.div<{ delay: number }>` | ||
| width: 10px; | ||
| height: 10px; | ||
| border-radius: 50%; | ||
| margin: 10px 5px 10px 5px; | ||
| ${({ theme }): string => ` | ||
| background-color: ${theme.colors.border}; | ||
| `} | ||
| animation: bounce 0.5s ease-in-out infinite; | ||
| animation-delay: ${p => p.delay}s; | ||
|
|
||
| @keyframes bounce { | ||
| 10% { | ||
| transform: translateY(0); | ||
| } | ||
| 50% { | ||
| transform: translateY(-25%); | ||
| } | ||
| 90% { | ||
| transform: translateY(25%); | ||
| } | ||
| } | ||
| ` | ||
|
|
||
| export default TypingDots; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frombot