-
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): replace wrapper boilerplate code
- Loading branch information
Showing
7 changed files
with
57 additions
and
86 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
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,23 @@ | ||
<script lang="ts"> | ||
import { createProps, defaultValue, getComponent, getComponentProps } from '../../helpers' | ||
import { createProps, defaultValue } from "../../helpers"; | ||
import Wrap from "../helpers/Wrap.svelte"; | ||
type T = boolean | ||
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 = boolean; | ||
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}> | ||
<Wrap {schema} {errors} component={components.wrapper}> | ||
<input {...props} type="checkbox" bind:checked={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 |
---|---|---|
@@ -1,22 +1,19 @@ | ||
<script lang="ts"> | ||
import { createProps, getComponent, getComponentProps } from '../../helpers' | ||
import { createProps, defaultValue } from "../../helpers"; | ||
import Wrap from "../helpers/Wrap.svelte"; | ||
const p = createProps<null>() | ||
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 | ||
const p = createProps<null>(); | ||
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; | ||
let checked = false | ||
let checked = false; | ||
</script> | ||
|
||
{#if schema && components} | ||
<svelte:component | ||
this={getComponent(components.wrapper)} | ||
{...getComponentProps(components.wrapper)} | ||
{schema} | ||
{errors}> | ||
<Wrap {schema} {errors} component={components.wrapper}> | ||
<input {...props} type="checkbox" bind:checked /> | ||
</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
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
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
27 changes: 12 additions & 15 deletions
27
packages/lib/src/components/fields/extra/TextareaField.svelte
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,23 @@ | ||
<script lang="ts"> | ||
import { createProps, defaultValue, getComponent, getComponentProps } from '../../../helpers' | ||
import { createProps, defaultValue } from "../../../helpers"; | ||
import Wrap from "../../helpers/Wrap.svelte"; | ||
type T = string | ||
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 = string; | ||
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}> | ||
<Wrap {schema} {errors} component={components.wrapper}> | ||
<textarea {...props} bind:value /> | ||
</svelte:component> | ||
</Wrap> | ||
{/if} |