Skip to content

Commit

Permalink
feat(wrap.svelte): add Wrap.svelte component
Browse files Browse the repository at this point in the history
  • Loading branch information
pyoner committed Jul 16, 2020
1 parent 075e8a5 commit 1b94b94
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
35 changes: 19 additions & 16 deletions packages/lib/src/components/fields/NumberField.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<script lang="ts">
import { createProps, defaultValue, getComponent, getComponentProps } from '../../helpers'
import { createProps, defaultValue, getComponent, getComponentProps } from "../../helpers";
import Wrap from "../helpers/Wrap.svelte";
type T = number
const p = createProps<T>()
export let value = p.value
export let errors = p.errors
export let schema = p.schema
export let components = p.components
export let props = p.props
type T = number;
const p = createProps<T>();
export let value = p.value;
export let errors = p.errors;
export let schema = p.schema;
export let components = p.components;
export let props = p.props;
/* recalc a default value */
$: if (schema && value == null) {
value = defaultValue<T>(schema, value)
value = defaultValue<T>(schema, value);
}
</script>

{#if schema && components}
<svelte:component
this={getComponent(components.wrapper)}
{...getComponentProps(components.wrapper)}
{schema}
{errors}>
<input {...props} type="number" step={props.step || 'any'} bind:value />
</svelte:component>
<Wrap {schema} {errors} component={components.wrapper}>
<svelte:component
this={getComponent(components.wrapper)}
{...getComponentProps(components.wrapper)}
{schema}
{errors}>
<input {...props} type="number" step={props.step || 'any'} bind:value />
</svelte:component>
</Wrap>
{/if}
16 changes: 16 additions & 0 deletions packages/lib/src/components/helpers/Wrap.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { getComponent, getComponentProps } from "../../helpers";
import type { SvelteSchema, TSvelteComponent } from "../../types";
export let errors: Error[] | null = null;
export let schema: SvelteSchema;
export let component: TSvelteComponent;
</script>

<svelte:component
this={getComponent(component)}
{...getComponentProps(component)}
{schema}
{errors}>
<slot />
</svelte:component>

0 comments on commit 1b94b94

Please sign in to comment.