mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: dynamically show inputs
This commit is contained in:
1 parent
f546ceb2b8
commit
bf6e9a4b80
2 files changed
+91
-15
No files matched your search
@@ -1,14 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher, onMount } from 'svelte';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { fly, type FlyParams } from 'svelte/transition';
|
||||
|
||||
export let show = false;
|
||||
export let title: string;
|
||||
let browser = false;
|
||||
//TODO: explore other solutions compatible with testing library
|
||||
onMount(() => {
|
||||
browser = true;
|
||||
});
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const transitionFly: FlyParams = {
|
||||
@@ -27,14 +22,6 @@
|
||||
show = false;
|
||||
dispatch('close');
|
||||
};
|
||||
|
||||
$: if (browser) {
|
||||
if (show) {
|
||||
document.body.classList.add('u-overflow-hidden');
|
||||
} else {
|
||||
document.body.classList.remove('u-overflow-hidden');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
|
||||
+90
-1
@@ -1,6 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { Wizard } from '$lib/layout';
|
||||
import { Step, Steps } from '$lib/components';
|
||||
import {
|
||||
Form,
|
||||
FormList,
|
||||
InputCheckbox,
|
||||
InputText,
|
||||
InputEmail,
|
||||
InputNumber,
|
||||
Button
|
||||
} from '$lib/elements/forms';
|
||||
import { collection } from './store';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
|
||||
export let showCreate = false;
|
||||
|
||||
@@ -8,6 +19,52 @@
|
||||
{ title: 'Create data', current: true, completed: false },
|
||||
{ title: 'Set permissions', current: false, completed: false }
|
||||
];
|
||||
|
||||
let currentStep = 0;
|
||||
|
||||
const comp = (type: string) => {
|
||||
switch (type) {
|
||||
case 'boolean':
|
||||
return InputCheckbox;
|
||||
case 'email':
|
||||
return InputEmail;
|
||||
case 'float':
|
||||
return InputNumber;
|
||||
case 'integer':
|
||||
return InputNumber;
|
||||
|
||||
default:
|
||||
return InputText;
|
||||
}
|
||||
};
|
||||
|
||||
let newDocument = {};
|
||||
let read: string[];
|
||||
let write: string[];
|
||||
|
||||
const create = async () => {
|
||||
await sdkForProject.databases.createDocument(
|
||||
$collection.$id,
|
||||
'unique()',
|
||||
newDocument,
|
||||
read,
|
||||
write
|
||||
);
|
||||
};
|
||||
|
||||
const nextStep = () => {
|
||||
steps[currentStep].current = false;
|
||||
steps[currentStep].completed = true;
|
||||
currentStep++;
|
||||
steps[currentStep].current = true;
|
||||
};
|
||||
const prevStep = () => {
|
||||
steps[currentStep].current = false;
|
||||
|
||||
currentStep--;
|
||||
steps[currentStep].current = true;
|
||||
steps[currentStep].completed = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<Wizard title="Create document" bind:show={showCreate}>
|
||||
@@ -20,5 +77,37 @@
|
||||
{/each}
|
||||
</Steps>
|
||||
</svelte:fragment>
|
||||
test
|
||||
<Form on:submit={create}>
|
||||
<header class="form-header">
|
||||
<h1 class="heading-level-6">Create document data</h1>
|
||||
<p>Provide document data based on attributes you created earlier.</p>
|
||||
</header>
|
||||
<div class="form-content">
|
||||
<FormList>
|
||||
{#each $collection.attributes as attribute}
|
||||
<svelte:component
|
||||
this={comp(attribute.type)}
|
||||
label={attribute.key}
|
||||
id={attribute.key}
|
||||
required={attribute.required}
|
||||
bind:value={newDocument[attribute.key]} />
|
||||
{/each}
|
||||
</FormList>
|
||||
</div>
|
||||
|
||||
<div class="form-footer">
|
||||
<div class="u-flex u-main-end u-gap-12">
|
||||
{#if currentStep === 0}
|
||||
<Button secondary on:click={() => (showCreate = false)}>Cancel</Button>
|
||||
<Button on:click={nextStep}>Next</Button>
|
||||
{:else if currentStep === steps.length - 1}
|
||||
<Button secondary on:click={prevStep}>Back</Button>
|
||||
<Button submit>Create</Button>
|
||||
{:else}
|
||||
<Button secondary on:click={prevStep}>Back</Button>
|
||||
<Button on:click={nextStep}>Next</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</Wizard>
|
||||
Reference in new issue
Block a user