1
0
Fork 0
mirror of synced 2024-06-26 10:00:41 +12:00
budibase/packages/builder/src/components/backend/DataTable/popovers/RecordFieldControl.svelte

65 lines
1.6 KiB
Svelte
Raw Normal View History

<script>
import { Input, Select, Label, DatePicker, Toggle } from "@budibase/bbui"
2020-09-12 02:09:56 +12:00
import Dropzone from "components/common/Dropzone.svelte"
2020-08-08 03:13:57 +12:00
export let meta
2020-08-25 02:48:34 +12:00
export let value = meta.type === "boolean" ? false : ""
export let originalValue
2020-08-25 02:48:34 +12:00
let isSelect =
meta.type === "string" &&
meta.constraints &&
meta.constraints.inclusion &&
meta.constraints.inclusion.length > 0
let type = determineInputType(meta)
function determineInputType(meta) {
if (meta.type === "datetime") return "date"
if (meta.type === "number") return "number"
if (meta.type === "boolean") return "checkbox"
2020-09-12 02:09:56 +12:00
if (meta.type === "attachment") return "file"
2020-08-25 02:48:34 +12:00
if (isSelect) return "select"
return "text"
}
</script>
2020-06-01 23:15:44 +12:00
{#if type === 'select'}
<Select
thin
secondary
label={meta.name}
data-cy="{meta.name}-select"
bind:value>
<option value="">Choose an option</option>
2020-08-25 02:48:34 +12:00
{#each meta.constraints.inclusion as opt}
2020-06-01 23:15:44 +12:00
<option value={opt}>{opt}</option>
{/each}
2020-08-08 03:13:57 +12:00
</Select>
{:else if type === 'date'}
<DatePicker label={meta.name} bind:value />
2020-09-12 02:09:56 +12:00
{:else if type === 'file'}
<div>
<Label extraSmall grey forAttr={'dropzone-label'}>{meta.name}</Label>
<Dropzone bind:files={value} />
</div>
{:else if type === 'checkbox'}
<Toggle text={meta.name} bind:checked={value} data-cy="{meta.name}-input" />
{:else}
<Input thin label={meta.name} data-cy="{meta.name}-input" {type} bind:value />
2020-08-11 22:23:07 +12:00
{/if}
2020-08-12 04:58:01 +12:00
<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);
2020-08-12 04:58:01 +12:00
}
</style>