Facebook-Events-iCal-Converter/lib/frontend/components/Input.svelte

75 lines
1.3 KiB
Svelte
Raw Normal View History

<style>
#form {
2020-12-25 10:03:50 +01:00
box-sizing: border-box;
flex: 1;
display: flex;
min-width: 300px;
}
#form input {
margin: 5px;
}
input#url {
flex: 1;
font-size: 1rem;
}
2020-12-25 10:03:50 +01:00
.input--error {
border: 1px solid firebrick;
}
</style>
<script>
import { createEvent } from '../actions'
import logger from '../services/logger'
export let error
export let pending
let value
2020-12-25 10:15:28 +01:00
let form
const onChange = (e) => {
value = e.currentTarget.value
}
2020-12-25 10:03:50 +01:00
let inputClasses = ''
$: inputClasses = [
error ? 'input--error' : '',
pending ? 'input--pending': '',
].join(' ')
console.log(inputClasses)
const handleSubmit = async (e) => {
2020-12-25 10:15:28 +01:00
if (!form.reportValidity()) {
return
}
e.preventDefault()
createEvent(value, { logger })
}
</script>
2020-12-25 10:15:28 +01:00
<form id="form" bind:this={form}>
<input
required
pattern="^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?|\d+$"
id="url"
name="url"
2020-12-25 10:03:50 +01:00
class={inputClasses}
bind:value={value}
disabled={pending}
placeholder="Paste / type FB event URL or event number..."
title="Please insert Facebook Event URL / Number"
/>
<input
id="submit"
2020-12-25 10:03:50 +01:00
class={inputClasses}
type='submit'
value='Submit'
disabled={pending}
on:click={handleSubmit}
/>
</form>