Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru89 committed Mar 18, 2023
1 parent 9bcb120 commit 498aff5
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 164 deletions.
136 changes: 118 additions & 18 deletions packages/botonic-react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 38 additions & 19 deletions packages/botonic-react/src/webchat/components/attachment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,51 @@ import React, { useContext } from 'react'
import AttachmentIcon from '../../assets/attachment-icon.svg'
import { ROLES, WEBCHAT } from '../../constants'
import { WebchatContext } from '../../contexts'
import { Icon, IconContainer } from './common'
import { ConditionalAnimation } from '../components/conditional-animation'
import { Icon } from './common'

export const Attachment = ({ onChange, accept, customAttacments }) => {
export const Attachment = ({ onChange, accept, enableAttachments }) => {
const { getThemeProperty } = useContext(WebchatContext)

const CustomAttachments = getThemeProperty(
WEBCHAT.CUSTOM_PROPERTIES.customAttachments,
undefined
)

const isAttachmentsEnabled = () => {
const hasCustomAttachments = !!CustomAttachments
return (
getThemeProperty(
WEBCHAT.CUSTOM_PROPERTIES.enableAttachments,
enableAttachments
) ?? hasCustomAttachments
)
}
const attachmentsEnabled = isAttachmentsEnabled()

return (
<IconContainer role={ROLES.ATTACHMENT_ICON}>
<label htmlFor='attachment' style={{ marginTop: 4 }}>
{CustomAttachments ? (
<CustomAttachments />
) : (
<Icon src={AttachmentIcon} />
)}
</label>
<input
type='file'
name='file'
id='attachment'
style={{ display: 'none' }}
onChange={onChange}
accept={accept}
/>
</IconContainer>
<>
{attachmentsEnabled ? (
<ConditionalAnimation>
<div role={ROLES.ATTACHMENT_ICON}>
<label htmlFor='attachment' style={{ marginTop: 4 }}>
{CustomAttachments ? (
<CustomAttachments />
) : (
<Icon src={AttachmentIcon} />
)}
</label>
<input
type='file'
name='file'
id='attachment'
style={{ display: 'none' }}
onChange={onChange}
accept={accept}
/>
</div>
</ConditionalAnimation>
) : null}
</>
)
}
6 changes: 0 additions & 6 deletions packages/botonic-react/src/webchat/components/common.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,3 @@ const PointerImage = styled.img`
cursor: pointer;
`
export const Icon = props => <PointerImage src={resolveImage(props.src)} />

export const IconContainer = styled.div`
display: flex;
align-items: center;
padding-right: 15px;
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { motion } from 'framer-motion'
import React, { useContext } from 'react'

import { WEBCHAT } from '../../constants'
import { WebchatContext } from '../../contexts'
import { ConditionalWrapper } from '../../util/react'

export const ConditionalAnimation = props => {
const { getThemeProperty } = useContext(WebchatContext)

const animationsEnabled = getThemeProperty(
WEBCHAT.CUSTOM_PROPERTIES.enableAnimations,
props.enableAnimations !== undefined ? props.enableAnimations : true
)
return (
<ConditionalWrapper
condition={animationsEnabled}
wrapper={children => (
<motion.div whileHover={{ scale: 1.2 }}>{children}</motion.div>
)}
>
{props.children}
</ConditionalWrapper>
)
}
Loading

0 comments on commit 498aff5

Please sign in to comment.