-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
botonic-react: WebchatReplies and Reply with typescript (#2952)
## Description Using typescript in Reply and WebchatReplies components In the WebchatReplies component I have to put a @ts-ignore because replies is of type Reply[] but typescript does not detect that the component is already “rendered with the props” (TODO investigate in the future how to pass the props and render Reply components at this point).
- Loading branch information
Showing
15 changed files
with
360 additions
and
116 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
import React, { useContext } from 'react' | ||
|
||
import { WEBCHAT } from '../../constants' | ||
import { WebchatContext } from '../../contexts' | ||
import { BotonicContainerId } from '../constants' | ||
import { RepliesContainer, ReplyContainer, ScrollableReplies } from './styles' | ||
|
||
const options = { | ||
left: 'flex-start', | ||
center: 'center', | ||
right: 'flex-end', | ||
} | ||
|
||
export const WebchatReplies = () => { | ||
const { webchatState, getThemeProperty, repliesRef } = | ||
useContext(WebchatContext) | ||
|
||
let justifyContent = 'center' | ||
const flexWrap = getThemeProperty( | ||
WEBCHAT.CUSTOM_PROPERTIES.wrapReplies, | ||
'wrap' | ||
) | ||
|
||
if (flexWrap === 'nowrap') { | ||
justifyContent = 'flex-start' | ||
} else if (getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.alignReplies)) { | ||
justifyContent = | ||
options[getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.alignReplies)] | ||
} | ||
|
||
return ( | ||
<ScrollableReplies> | ||
<RepliesContainer | ||
id={BotonicContainerId.RepliesContainer} | ||
ref={repliesRef} | ||
className='replies-container' | ||
justify={justifyContent} | ||
wrap={flexWrap} | ||
> | ||
{webchatState.replies?.map((reply, i) => ( | ||
// @ts-ignore TODO: In this point reply is the the component to render | ||
<ReplyContainer key={`reply-${i}`}>{reply}</ReplyContainer> | ||
))} | ||
</RepliesContainer> | ||
</ScrollableReplies> | ||
) | ||
} |
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,28 @@ | ||
import styled from 'styled-components' | ||
|
||
export const ScrollableReplies = styled.div` | ||
overscroll-behavior: contain; | ||
-webkit-overflow-scrolling: touch; | ||
` | ||
|
||
interface RepliesContainerProps { | ||
justify: string | ||
wrap: string | ||
} | ||
|
||
export const RepliesContainer = styled.div<RepliesContainerProps>` | ||
display: flex; | ||
text-align: center; | ||
justify-content: ${props => props.justify}; | ||
flex-wrap: ${props => props.wrap}; | ||
padding-bottom: 10px; | ||
margin-left: 5px; | ||
margin-right: 5px; | ||
overflow-x: auto; | ||
` | ||
|
||
export const ReplyContainer = styled.div` | ||
flex: none; | ||
display: inline-block; | ||
margin: 3px; | ||
` |
Oops, something went wrong.