mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 05:03:57 +00:00
form provider
This commit is contained in:
@@ -35,6 +35,27 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.col-9 {
|
||||||
|
flex-basis: 75%;
|
||||||
|
max-width: 75%;
|
||||||
|
}
|
||||||
|
.col-8 {
|
||||||
|
flex-basis: 66.6667%;
|
||||||
|
max-width: 66.6667%;
|
||||||
|
}
|
||||||
|
.col-6 {
|
||||||
|
flex-basis: 50%;
|
||||||
|
max-width: 50%;
|
||||||
|
}
|
||||||
|
.col-4 {
|
||||||
|
flex-basis: 33.3333%;
|
||||||
|
max-width: 33.3333%;
|
||||||
|
}
|
||||||
|
.col-3 {
|
||||||
|
flex-basis: 25%;
|
||||||
|
max-width: 25%;
|
||||||
|
}
|
||||||
|
|
||||||
/* html, body {
|
/* html, body {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
12
packages/web/src/forms/FormProvider.svelte
Normal file
12
packages/web/src/forms/FormProvider.svelte
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
import FormProviderCore from './FormProviderCore.svelte';
|
||||||
|
|
||||||
|
export let initivalValues = {};
|
||||||
|
|
||||||
|
const values = writable(initivalValues);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<FormProviderCore {values}>
|
||||||
|
<slot />
|
||||||
|
</FormProviderCore>
|
||||||
32
packages/web/src/forms/FormProviderCore.svelte
Normal file
32
packages/web/src/forms/FormProviderCore.svelte
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<script lang="ts" context="module">
|
||||||
|
import { getContext, setContext } from 'svelte';
|
||||||
|
const contextKey = 'formProviderContextKey';
|
||||||
|
|
||||||
|
export function getFormContext(): any {
|
||||||
|
return getContext(contextKey);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import keycodes from '../utility/keycodes';
|
||||||
|
|
||||||
|
export let values;
|
||||||
|
|
||||||
|
const context = {
|
||||||
|
values,
|
||||||
|
submitActionRef: { current: null },
|
||||||
|
};
|
||||||
|
|
||||||
|
setContext(contextKey, context);
|
||||||
|
|
||||||
|
function handleEnter(e) {
|
||||||
|
if (e.keyCode == keycodes.enter && context.submitActionRef.current) {
|
||||||
|
e.preventDefault();
|
||||||
|
context.submitActionRef.current(values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot />
|
||||||
|
|
||||||
|
<svelte:window on:keydown={handleEnter} />
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
import FormStyledButton from '../widgets/FormStyledButton.svelte';
|
import FormStyledButton from '../widgets/FormStyledButton.svelte';
|
||||||
|
import { getFormContext } from './FormProviderCore.svelte';
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
const { submitActionRef } = getFormContext();
|
||||||
|
|
||||||
|
submitActionRef.current = () => {
|
||||||
|
dispatch('click');
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormStyledButton type="submit" on:click {...$$props} />
|
<FormStyledButton type="submit" on:click {...$$props} />
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
import FormButton from '../forms/FormButton.svelte';
|
import FormButton from '../forms/FormButton.svelte';
|
||||||
|
import FormProvider from '../forms/FormProvider.svelte';
|
||||||
import FormSubmit from '../forms/FormSubmit.svelte';
|
import FormSubmit from '../forms/FormSubmit.svelte';
|
||||||
|
|
||||||
import ModalBase from './ModalBase.svelte';
|
import ModalBase from './ModalBase.svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ModalBase {...$$restProps}>
|
<FormProvider>
|
||||||
|
<ModalBase {...$$restProps}>
|
||||||
<div slot="header">Add connection</div>
|
<div slot="header">Add connection</div>
|
||||||
xxx
|
xxx
|
||||||
<div slot="footer" class="flex">
|
<div slot="footer" class="flex">
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<FormButton value="Test" />
|
<FormButton value="Test" />
|
||||||
<FormSubmit value="Save" />
|
<FormSubmit value="Save" on:click={() => console.log('SAVE')} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ModalBase>
|
</ModalBase>
|
||||||
|
</FormProvider>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.buttons {
|
.buttons {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import { closeModal } from './modalTools';
|
import { closeModal } from './modalTools';
|
||||||
import clickOutside from '../utility/clickOutside';
|
import clickOutside from '../utility/clickOutside';
|
||||||
|
import keycodes from '../utility/keycodes';
|
||||||
|
|
||||||
export let fullScreen;
|
export let fullScreen;
|
||||||
export let noPadding;
|
export let noPadding;
|
||||||
@@ -10,6 +11,12 @@
|
|||||||
function handleCloseModal() {
|
function handleCloseModal() {
|
||||||
closeModal(modalId);
|
closeModal(modalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleEscape(e) {
|
||||||
|
if (e.keyCode == keycodes.escape) {
|
||||||
|
closeModal(modalId);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- The Modal -->
|
<!-- The Modal -->
|
||||||
@@ -31,6 +38,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<svelte:window on:keydown={handleEscape} />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.bglayer {
|
.bglayer {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
export let value;
|
export let value;
|
||||||
|
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
if (disabled) dispatch('click');
|
if (!disabled) dispatch('click');
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user