2020-03-28 00:28:30 +13:00
|
|
|
<script>
|
2020-04-21 03:17:11 +12:00
|
|
|
export let type = "text"
|
|
|
|
export let value = ""
|
|
|
|
export let label
|
|
|
|
export let errors = []
|
2020-05-29 09:26:32 +12:00
|
|
|
export let options = []
|
2020-06-01 23:15:44 +12:00
|
|
|
|
2020-05-07 21:53:34 +12:00
|
|
|
let checked = type === "checkbox" ? value : false
|
2020-06-01 23:15:44 +12:00
|
|
|
|
2020-05-29 09:26:32 +12:00
|
|
|
const determineClassName = type => {
|
|
|
|
if (type === "checkbox") return "uk-checkbox"
|
|
|
|
if (type === "select") return "uk-select"
|
|
|
|
return "uk-input"
|
|
|
|
}
|
2020-06-01 23:15:44 +12:00
|
|
|
|
2020-04-21 03:17:11 +12:00
|
|
|
const handleInput = event => {
|
|
|
|
if (event.target.type === "checkbox") {
|
2020-05-07 21:53:34 +12:00
|
|
|
value = event.target.checked
|
|
|
|
return
|
2020-04-21 03:17:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event.target.type === "number") {
|
2020-05-07 21:53:34 +12:00
|
|
|
value = parseInt(event.target.value)
|
|
|
|
return
|
2020-04-21 03:17:11 +12:00
|
|
|
}
|
|
|
|
|
2020-05-07 21:53:34 +12:00
|
|
|
value = event.target.value
|
2020-04-21 03:17:11 +12:00
|
|
|
}
|
2020-03-28 00:28:30 +13:00
|
|
|
</script>
|
|
|
|
|
2020-04-21 03:17:11 +12:00
|
|
|
<label>{label}</label>
|
2020-05-29 09:26:32 +12:00
|
|
|
|
2020-06-01 23:15:44 +12:00
|
|
|
{#if type === 'select'}
|
|
|
|
<select
|
2020-06-12 03:10:26 +12:00
|
|
|
data-cy="{label}-select"
|
2020-06-01 23:15:44 +12:00
|
|
|
class={determineClassName(type)}
|
|
|
|
bind:value
|
|
|
|
class:uk-form-danger={errors.length > 0}>
|
2020-07-01 20:48:53 +12:00
|
|
|
<option></option>
|
2020-06-01 23:15:44 +12:00
|
|
|
{#each options as opt}
|
|
|
|
<option value={opt}>{opt}</option>
|
|
|
|
{/each}
|
|
|
|
</select>
|
2020-05-29 09:26:32 +12:00
|
|
|
{:else}
|
2020-06-01 23:15:44 +12:00
|
|
|
<input
|
2020-06-12 03:10:26 +12:00
|
|
|
data-cy="{label}-input"
|
2020-06-01 23:15:44 +12:00
|
|
|
class={determineClassName(type)}
|
|
|
|
class:uk-form-danger={errors.length > 0}
|
|
|
|
{checked}
|
|
|
|
{type}
|
|
|
|
{value}
|
|
|
|
on:input={handleInput}
|
|
|
|
on:change={handleInput} />
|
2020-05-29 09:26:32 +12:00
|
|
|
{/if}
|
2020-06-24 00:50:45 +12:00
|
|
|
|
|
|
|
<style>
|
|
|
|
label {
|
|
|
|
display: block;
|
|
|
|
font-size: 18px;
|
|
|
|
font-weight: 500;
|
|
|
|
margin-bottom: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
input {
|
|
|
|
color: var(--dark-grey);
|
|
|
|
}
|
2020-06-24 03:20:06 +12:00
|
|
|
</style>
|