-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wrap.svelte): add Wrap.svelte component
- Loading branch information
Showing
2 changed files
with
35 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |