-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eea522f
commit f712c7a
Showing
16 changed files
with
356 additions
and
75 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
40 changes: 40 additions & 0 deletions
40
...mponents/board/graph/BlockNode/StepNode/SettingsPopoverContent/SettingsPopoverContent.tsx
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,40 @@ | ||
import { PopoverContent, PopoverArrow, PopoverBody } from '@chakra-ui/react' | ||
import { useTypebot } from 'contexts/TypebotContext/TypebotContext' | ||
import { Step, StepType, TextInputOptions } from 'models' | ||
import { TextInputSettingsBody } from './TextInputSettingsBody' | ||
|
||
type Props = { | ||
step: Step | ||
} | ||
export const SettingsPopoverContent = ({ step }: Props) => { | ||
const handleMouseDown = (e: React.MouseEvent) => e.stopPropagation() | ||
|
||
return ( | ||
<PopoverContent onMouseDown={handleMouseDown}> | ||
<PopoverArrow /> | ||
<PopoverBody p="6"> | ||
<SettingsPopoverBodyContent step={step} /> | ||
</PopoverBody> | ||
</PopoverContent> | ||
) | ||
} | ||
|
||
const SettingsPopoverBodyContent = ({ step }: Props) => { | ||
const { updateStep } = useTypebot() | ||
const handleOptionsChange = (options: TextInputOptions) => | ||
updateStep(step.id, { options } as Partial<Step>) | ||
|
||
switch (step.type) { | ||
case StepType.TEXT_INPUT: { | ||
return ( | ||
<TextInputSettingsBody | ||
options={step.options} | ||
onOptionsChange={handleOptionsChange} | ||
/> | ||
) | ||
} | ||
default: { | ||
return <></> | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...omponents/board/graph/BlockNode/StepNode/SettingsPopoverContent/TextInputSettingsBody.tsx
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,55 @@ | ||
import { FormLabel, Stack } from '@chakra-ui/react' | ||
import { DebouncedInput } from 'components/shared/DebouncedInput' | ||
import { SwitchWithLabel } from 'components/shared/SwitchWithLabel' | ||
import { TextInputOptions } from 'models' | ||
import React from 'react' | ||
|
||
type TextInputSettingsBodyProps = { | ||
options?: TextInputOptions | ||
onOptionsChange: (options: TextInputOptions) => void | ||
} | ||
|
||
export const TextInputSettingsBody = ({ | ||
options, | ||
onOptionsChange, | ||
}: TextInputSettingsBodyProps) => { | ||
const handlePlaceholderChange = (placeholder: string) => | ||
onOptionsChange({ ...options, labels: { ...options?.labels, placeholder } }) | ||
const handleButtonLabelChange = (button: string) => | ||
onOptionsChange({ ...options, labels: { ...options?.labels, button } }) | ||
const handleLongChange = (isLong: boolean) => | ||
onOptionsChange({ ...options, isLong }) | ||
|
||
return ( | ||
<Stack spacing={4}> | ||
<SwitchWithLabel | ||
id="switch" | ||
label="Long text?" | ||
initialValue={options?.isLong ?? false} | ||
onCheckChange={handleLongChange} | ||
/> | ||
<Stack> | ||
<FormLabel mb="0" htmlFor="placeholder"> | ||
Placeholder: | ||
</FormLabel> | ||
<DebouncedInput | ||
id="placeholder" | ||
initialValue={options?.labels?.placeholder ?? 'Type your answer...'} | ||
delay={100} | ||
onChange={handlePlaceholderChange} | ||
/> | ||
</Stack> | ||
<Stack> | ||
<FormLabel mb="0" htmlFor="button"> | ||
Button label: | ||
</FormLabel> | ||
<DebouncedInput | ||
id="button" | ||
initialValue={options?.labels?.button ?? 'Send'} | ||
delay={100} | ||
onChange={handleButtonLabelChange} | ||
/> | ||
</Stack> | ||
</Stack> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
apps/builder/components/board/graph/BlockNode/StepNode/SettingsPopoverContent/index.ts
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 @@ | ||
export { SettingsPopoverContent } from './SettingsPopoverContent' |
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,31 @@ | ||
import { Input, InputProps } from '@chakra-ui/react' | ||
import { ChangeEvent, useEffect, useState } from 'react' | ||
import { useDebounce } from 'use-debounce' | ||
|
||
type Props = Omit<InputProps, 'onChange' | 'value'> & { | ||
delay: number | ||
initialValue: string | ||
onChange: (debouncedValue: string) => void | ||
} | ||
|
||
export const DebouncedInput = ({ | ||
delay, | ||
onChange, | ||
initialValue, | ||
...props | ||
}: Props) => { | ||
const [currentValue, setCurrentValue] = useState(initialValue) | ||
const [currentValueDebounced] = useDebounce(currentValue, delay) | ||
|
||
useEffect(() => { | ||
if (currentValueDebounced === initialValue) return | ||
onChange(currentValueDebounced) | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [currentValueDebounced]) | ||
|
||
const handleChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setCurrentValue(e.target.value) | ||
} | ||
|
||
return <Input {...props} value={currentValue} onChange={handleChange} /> | ||
} |
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,30 @@ | ||
import { FormLabel, HStack, Switch, SwitchProps } from '@chakra-ui/react' | ||
import React, { useState } from 'react' | ||
|
||
type SwitchWithLabelProps = { | ||
label: string | ||
initialValue: boolean | ||
onCheckChange: (isChecked: boolean) => void | ||
} & SwitchProps | ||
|
||
export const SwitchWithLabel = ({ | ||
label, | ||
initialValue, | ||
onCheckChange, | ||
...props | ||
}: SwitchWithLabelProps) => { | ||
const [isChecked, setIsChecked] = useState(initialValue) | ||
|
||
const handleChange = () => { | ||
setIsChecked(!isChecked) | ||
onCheckChange(!isChecked) | ||
} | ||
return ( | ||
<HStack justifyContent="space-between"> | ||
<FormLabel htmlFor={props.id} mb="0"> | ||
{label} | ||
</FormLabel> | ||
<Switch isChecked={isChecked} onChange={handleChange} {...props} /> | ||
</HStack> | ||
) | ||
} |
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
Oops, something went wrong.
f712c7a
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.
Successfully deployed to the following URLs:
viewer-v2 – ./apps/viewer
viewer-v2-git-main-typebot-io.vercel.app
typebot-io.vercel.app
viewer-v2-typebot-io.vercel.app
f712c7a
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.
Successfully deployed to the following URLs:
builder-v2 – ./apps/builder
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
next.typebot.io