Unified file link format

This commit is contained in:
He4eT 2021-02-19 04:17:47 +05:00
commit 19e051045d
5 changed files with 96 additions and 13 deletions

View file

@ -0,0 +1,15 @@
import { h } from 'preact'
export default function ({ emitName, emitURL }) {
const fileInputHandler = ({ target }) => {
const file = target.files[0]
emitName(file.name)
emitURL(URL.createObjectURL(file))
target.value = null
}
return (
<input
type='file'
onChange={fileInputHandler} />)
}

View file

@ -0,0 +1,23 @@
import { h } from 'preact'
export default function ({ emitName, emitURL }) {
const reURL = /^(http|https):\/\/[^ "]+$/
const emit = url => {
emitName(url)
emitURL(url)
}
const urlInputHandler = ({ target }) => {
const url = target.value
emit(reURL.test(url)
? url
: null)
}
return (
<input
type='text'
placeholder='https://...'
onInput={urlInputHandler} />)
}