2
0
Files
bot/apps/builder/src/features/blocks/bubbles/embed/components/EmbedUploadContent.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Input, SmartNumberInput } from '@/components/inputs'
2022-03-23 12:01:35 +01:00
import { HStack, Stack, Text } from '@chakra-ui/react'
import { EmbedBubbleContent } from 'models'
import { sanitizeUrl } from 'utils'
type Props = {
content: EmbedBubbleContent
onSubmit: (content: EmbedBubbleContent) => void
}
export const EmbedUploadContent = ({ content, onSubmit }: Props) => {
const handleUrlChange = (url: string) => {
2022-03-24 10:12:49 +01:00
const iframeUrl = sanitizeUrl(
2022-03-23 12:01:35 +01:00
url.trim().startsWith('<iframe') ? extractUrlFromIframe(url) : url
)
onSubmit({ ...content, url: iframeUrl })
}
const handleHeightChange = (height?: EmbedBubbleContent['height']) =>
2022-03-23 12:01:35 +01:00
height && onSubmit({ ...content, height })
return (
<Stack p="2" spacing={6}>
<Stack>
<Input
placeholder="Paste the link or code..."
defaultValue={content?.url ?? ''}
onChange={handleUrlChange}
/>
<Text fontSize="sm" color="gray.400" textAlign="center">
Works with PDFs, iframes, websites...
</Text>
</Stack>
<HStack>
2022-03-23 12:01:35 +01:00
<SmartNumberInput
label="Height:"
defaultValue={content?.height}
2022-03-23 12:01:35 +01:00
onValueChange={handleHeightChange}
/>
<Text>px</Text>
2022-03-23 12:01:35 +01:00
</HStack>
</Stack>
)
}
const extractUrlFromIframe = (iframe: string) =>
[...iframe.matchAll(/src="([^"]+)"/g)][0][1]