Skip to content

Commit

Permalink
feat(engine): 💄 Better long text input
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 30, 2022
1 parent cff5ec6 commit e339cc1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
9 changes: 8 additions & 1 deletion packages/bot-engine/src/components/ChatBlock/ChatBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export const ChatBlock = ({
isEnabled: typebot.theme.chat.hostAvatar?.isEnabled ?? true,
src: avatarSrc && parseVariables(typebot.variables)(avatarSrc),
}}
hasGuestAvatar={typebot.theme.chat.guestAvatar?.isEnabled ?? false}
onDisplayNextStep={displayNextStep}
/>
))}
Expand All @@ -197,11 +198,13 @@ export const ChatBlock = ({
type Props = {
displayChunk: ChatDisplayChunk
hostAvatar: { isEnabled: boolean; src?: string }
hasGuestAvatar: boolean
onDisplayNextStep: (answerContent?: string, isRetry?: boolean) => void
}
const ChatChunks = ({
displayChunk: { bubbles, input },
hostAvatar,
hasGuestAvatar,
onDisplayNextStep,
}: Props) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -223,7 +226,10 @@ const ChatChunks = ({
hostAvatarSrc={hostAvatar.src}
/>
)}
<div className="flex-1" style={{ marginRight: '50px' }}>
<div
className="flex-1"
style={{ marginRight: hasGuestAvatar ? '50px' : '0.5rem' }}
>
<TransitionGroup>
{bubbles.map((step) => (
<CSSTransition
Expand Down Expand Up @@ -255,6 +261,7 @@ const ChatChunks = ({
step={input}
onTransitionEnd={onDisplayNextStep}
hasAvatar={hostAvatar.isEnabled}
hasGuestAvatar={hasGuestAvatar}
/>
)}
</CSSTransition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { isInputValid } from 'services/inputs'
export const InputChatStep = ({
step,
hasAvatar,
hasGuestAvatar,
onTransitionEnd,
}: {
step: InputStep
hasGuestAvatar: boolean
hasAvatar: boolean
onTransitionEnd: (answerContent?: string, isRetry?: boolean) => void
}) => {
Expand Down Expand Up @@ -70,6 +72,7 @@ export const InputChatStep = ({
step={step}
onSubmit={handleSubmit}
defaultValue={defaultValue?.toString()}
hasGuestAvatar={hasGuestAvatar}
/>
</div>
)
Expand All @@ -79,10 +82,12 @@ const Input = ({
step,
onSubmit,
defaultValue,
hasGuestAvatar,
}: {
step: InputStep
onSubmit: (value: string) => void
defaultValue?: string
hasGuestAvatar: boolean
}) => {
switch (step.type) {
case InputStepType.TEXT:
Expand All @@ -91,7 +96,12 @@ const Input = ({
case InputStepType.URL:
case InputStepType.PHONE:
return (
<TextForm step={step} onSubmit={onSubmit} defaultValue={defaultValue} />
<TextForm
step={step}
onSubmit={onSubmit}
defaultValue={defaultValue}
hasGuestAvatar={hasGuestAvatar}
/>
)
case InputStepType.DATE:
return <DateForm options={step.options} onSubmit={onSubmit} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ type TextFormProps = {
| PhoneNumberInputStep
onSubmit: (value: string) => void
defaultValue?: string
hasGuestAvatar: boolean
}

export const TextForm = ({ step, onSubmit, defaultValue }: TextFormProps) => {
export const TextForm = ({
step,
onSubmit,
defaultValue,
hasGuestAvatar,
}: TextFormProps) => {
const [inputValue, setInputValue] = useState(defaultValue ?? '')

const isLongText = step.type === InputStepType.TEXT && step.options?.isLong

const handleChange = (inputValue: string) => {
if (step.type === InputStepType.URL && !inputValue.startsWith('https://'))
return inputValue === 'https:/'
Expand All @@ -40,21 +48,21 @@ export const TextForm = ({ step, onSubmit, defaultValue }: TextFormProps) => {
}

return (
<div className="flex flex-col w-full lg:w-4/6 mb-2">
<div className="flex items-center">
<form
className="flex items-end justify-between rounded-lg pr-2 typebot-input"
onSubmit={handleSubmit}
data-testid="input"
>
<TextInput step={step} onChange={handleChange} value={inputValue} />
<SendButton
label={step.options?.labels?.button ?? 'Send'}
isDisabled={inputValue === ''}
className="my-2 ml-2"
/>
</form>
</div>
</div>
<form
className="flex items-end justify-between rounded-lg pr-2 typebot-input w-full"
onSubmit={handleSubmit}
data-testid="input"
style={{
marginRight: hasGuestAvatar ? '50px' : '0.5rem',
maxWidth: isLongText ? undefined : '350px',
}}
>
<TextInput step={step} onChange={handleChange} value={inputValue} />
<SendButton
label={step.options?.labels?.button ?? 'Send'}
isDisabled={inputValue === ''}
className="my-2 ml-2"
/>
</form>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const LongTextInput = React.forwardRef(
<textarea
ref={ref}
className="focus:outline-none bg-transparent px-4 py-4 flex-1 w-full text-input"
rows={4}
rows={6}
data-testid="textarea"
required
style={{ fontSize: '16px' }}
Expand Down

4 comments on commit e339cc1

@vercel
Copy link

@vercel vercel bot commented on e339cc1 Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on e339cc1 Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on e339cc1 Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.