|
|
@ -1,64 +1,40 @@ |
|
|
<script> |
|
|
<script> |
|
|
import { Input, Select, Label, DatePicker, Toggle } from "@budibase/bbui" |
|
|
import { Input, Select, Label, DatePicker, Toggle } from "@budibase/bbui" |
|
|
import Dropzone from "components/common/Dropzone.svelte" |
|
|
import Dropzone from "components/common/Dropzone.svelte" |
|
|
|
|
|
import { capitalise } from "../../../../helpers" |
|
|
|
|
|
|
|
|
export let meta |
|
|
export let meta |
|
|
export let value = meta.type === "boolean" ? false : "" |
|
|
export let value = meta.type === "boolean" ? false : "" |
|
|
export let originalValue |
|
|
|
|
|
|
|
|
|
|
|
let isSelect = |
|
|
const type = determineInputType(meta) |
|
|
meta.type === "string" && |
|
|
const label = capitalise(meta.name) |
|
|
meta.constraints && |
|
|
|
|
|
meta.constraints.inclusion && |
|
|
|
|
|
meta.constraints.inclusion.length > 0 |
|
|
|
|
|
|
|
|
|
|
|
let type = determineInputType(meta) |
|
|
|
|
|
|
|
|
|
|
|
function determineInputType(meta) { |
|
|
function determineInputType(meta) { |
|
|
if (meta.type === "datetime") return "date" |
|
|
if (meta.type === "datetime") return "date" |
|
|
if (meta.type === "number") return "number" |
|
|
if (meta.type === "number") return "number" |
|
|
if (meta.type === "boolean") return "checkbox" |
|
|
if (meta.type === "boolean") return "checkbox" |
|
|
if (meta.type === "attachment") return "file" |
|
|
if (meta.type === "attachment") return "file" |
|
|
if (isSelect) return "select" |
|
|
if (meta.type === "options") return "select" |
|
|
|
|
|
|
|
|
return "text" |
|
|
return "text" |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
{#if type === 'select'} |
|
|
{#if type === 'select'} |
|
|
<Select |
|
|
<Select thin secondary {label} data-cy="{meta.name}-select" bind:value> |
|
|
thin |
|
|
|
|
|
secondary |
|
|
|
|
|
label={meta.name} |
|
|
|
|
|
data-cy="{meta.name}-select" |
|
|
|
|
|
bind:value> |
|
|
|
|
|
<option value="">Choose an option</option> |
|
|
<option value="">Choose an option</option> |
|
|
{#each meta.constraints.inclusion as opt} |
|
|
{#each meta.constraints.inclusion as opt} |
|
|
<option value={opt}>{opt}</option> |
|
|
<option value={opt}>{opt}</option> |
|
|
{/each} |
|
|
{/each} |
|
|
</Select> |
|
|
</Select> |
|
|
{:else if type === 'date'} |
|
|
{:else if type === 'date'} |
|
|
<DatePicker label={meta.name} bind:value /> |
|
|
<DatePicker {label} bind:value /> |
|
|
{:else if type === 'file'} |
|
|
{:else if type === 'file'} |
|
|
<div> |
|
|
<div> |
|
|
<Label extraSmall grey forAttr={'dropzone-label'}>{meta.name}</Label> |
|
|
<Label extraSmall grey forAttr={'dropzone-label'}>{label}</Label> |
|
|
<Dropzone bind:files={value} /> |
|
|
<Dropzone bind:files={value} /> |
|
|
</div> |
|
|
</div> |
|
|
{:else if type === 'checkbox'} |
|
|
{:else if type === 'checkbox'} |
|
|
<Toggle text={meta.name} bind:checked={value} data-cy="{meta.name}-input" /> |
|
|
<Toggle text={label} bind:checked={value} data-cy="{meta.name}-input" /> |
|
|
{:else} |
|
|
{:else} |
|
|
<Input thin label={meta.name} data-cy="{meta.name}-input" {type} bind:value /> |
|
|
<Input thin {label} data-cy="{meta.name}-input" {type} bind:value /> |
|
|
{/if} |
|
|
{/if} |
|
|
|
|
|
|
|
|
<style> |
|
|
|
|
|
.checkbox { |
|
|
|
|
|
display: flex; |
|
|
|
|
|
flex-direction: row; |
|
|
|
|
|
justify-content: flex-start; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
} |
|
|
|
|
|
.checkbox :global(label) { |
|
|
|
|
|
margin-bottom: 0; |
|
|
|
|
|
margin-right: var(--spacing-xs); |
|
|
|
|
|
} |
|
|
|
|
|
</style> |
|
|
|
|
|
|