Skip to content

Commit c124c2a

Browse files
committed
Updated Shad / Added forms
1 parent 9a47fae commit c124c2a

File tree

9 files changed

+180
-0
lines changed

9 files changed

+180
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script lang="ts">
2+
import * as Button from '$comp/ui/button/index.js';
3+
4+
type $$Props = Button.Props;
5+
type $$Events = Button.Events;
6+
</script>
7+
8+
<Button.Root type="submit" on:click on:keydown {...$$restProps}>
9+
<slot />
10+
</Button.Root>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script lang="ts">
2+
import * as FormPrimitive from 'formsnap';
3+
import { cn } from '$lib/utils.js';
4+
5+
type $$Props = FormPrimitive.DescriptionProps;
6+
let className: $$Props['class'] = undefined;
7+
export { className as class };
8+
</script>
9+
10+
<FormPrimitive.Description class={cn('text-[0.8rem] text-muted-foreground', className)} {...$$restProps} let:descriptionAttrs>
11+
<slot {descriptionAttrs} />
12+
</FormPrimitive.Description>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script lang="ts" context="module">
2+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3+
import type { FormPathLeaves, SuperForm } from 'sveltekit-superforms';
4+
type T = Record<string, unknown>;
5+
type U = unknown;
6+
</script>
7+
8+
<script lang="ts" generics="T extends Record<string, unknown>, U extends FormPathLeaves<T>">
9+
import type { HTMLAttributes } from 'svelte/elements';
10+
import * as FormPrimitive from 'formsnap';
11+
import { cn } from '$lib/utils.js';
12+
13+
type $$Props = FormPrimitive.ElementFieldProps<T, U> & HTMLAttributes<HTMLDivElement>;
14+
15+
export let form: SuperForm<T>;
16+
export let name: U;
17+
18+
let className: $$Props['class'] = undefined;
19+
export { className as class };
20+
</script>
21+
22+
<FormPrimitive.ElementField {form} {name} let:constraints let:errors let:tainted let:value>
23+
<div class={cn('space-y-2', className)}>
24+
<slot {constraints} {errors} {tainted} {value} />
25+
</div>
26+
</FormPrimitive.ElementField>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script lang="ts">
2+
import * as FormPrimitive from 'formsnap';
3+
import { cn } from '$lib/utils.js';
4+
5+
type $$Props = FormPrimitive.FieldErrorsProps & {
6+
errorClasses?: string | undefined | null;
7+
};
8+
9+
let className: $$Props['class'] = undefined;
10+
export { className as class };
11+
export let errorClasses: $$Props['class'] = undefined;
12+
</script>
13+
14+
<FormPrimitive.FieldErrors class={cn('text-[0.8rem] font-medium text-destructive', className)} {...$$restProps} let:errors let:fieldErrorsAttrs let:errorAttrs>
15+
<slot {errors} {fieldErrorsAttrs} {errorAttrs}>
16+
{#each errors as error}
17+
<div {...errorAttrs} class={cn(errorClasses)}>{error}</div>
18+
{/each}
19+
</slot>
20+
</FormPrimitive.FieldErrors>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script lang="ts" context="module">
2+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3+
import type { FormPath, SuperForm } from 'sveltekit-superforms';
4+
type T = Record<string, unknown>;
5+
type U = unknown;
6+
</script>
7+
8+
<script lang="ts" generics="T extends Record<string, unknown>, U extends FormPath<T>">
9+
import type { HTMLAttributes } from 'svelte/elements';
10+
import * as FormPrimitive from 'formsnap';
11+
import { cn } from '$lib/utils.js';
12+
13+
type $$Props = FormPrimitive.FieldProps<T, U> & HTMLAttributes<HTMLElement>;
14+
15+
export let form: SuperForm<T>;
16+
export let name: U;
17+
18+
let className: $$Props['class'] = undefined;
19+
export { className as class };
20+
</script>
21+
22+
<FormPrimitive.Field {form} {name} let:constraints let:errors let:tainted let:value>
23+
<div class={cn('space-y-2', className)}>
24+
<slot {constraints} {errors} {tainted} {value} />
25+
</div>
26+
</FormPrimitive.Field>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script lang="ts" context="module">
2+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3+
import type { FormPath, SuperForm } from 'sveltekit-superforms';
4+
type T = Record<string, unknown>;
5+
type U = unknown;
6+
</script>
7+
8+
<script lang="ts" generics="T extends Record<string, unknown>, U extends FormPath<T>">
9+
import * as FormPrimitive from 'formsnap';
10+
import { cn } from '$lib/utils.js';
11+
12+
type $$Props = FormPrimitive.FieldsetProps<T, U>;
13+
14+
export let form: SuperForm<T>;
15+
export let name: U;
16+
17+
let className: $$Props['class'] = undefined;
18+
export { className as class };
19+
</script>
20+
21+
<FormPrimitive.Fieldset {form} {name} let:constraints let:errors let:tainted let:value class={cn('space-y-2', className)}>
22+
<slot {constraints} {errors} {tainted} {value} />
23+
</FormPrimitive.Fieldset>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script lang="ts">
2+
import type { Label as LabelPrimitive } from 'bits-ui';
3+
import { getFormControl } from 'formsnap';
4+
import { Label } from '$comp/ui/label/index.js';
5+
import { cn } from '$lib/utils.js';
6+
7+
type $$Props = LabelPrimitive.Props;
8+
9+
let className: $$Props['class'] = undefined;
10+
export { className as class };
11+
12+
const { labelAttrs } = getFormControl();
13+
</script>
14+
15+
<Label {...$labelAttrs} class={cn('data-[fs-error]:text-destructive', className)} {...$$restProps}>
16+
<slot {labelAttrs} />
17+
</Label>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script lang="ts">
2+
import * as FormPrimitive from 'formsnap';
3+
import { cn } from '$lib/utils.js';
4+
5+
type $$Props = FormPrimitive.LegendProps;
6+
7+
let className: $$Props['class'] = undefined;
8+
export { className as class };
9+
</script>
10+
11+
<FormPrimitive.Legend {...$$restProps} class={cn('text-sm font-medium leading-none data-[fs-error]:text-destructive', className)} let:legendAttrs>
12+
<slot {legendAttrs} />
13+
</FormPrimitive.Legend>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as FormPrimitive from 'formsnap';
2+
import Description from './form-description.svelte';
3+
import Label from './form-label.svelte';
4+
import FieldErrors from './form-field-errors.svelte';
5+
import Field from './form-field.svelte';
6+
import Button from './form-button.svelte';
7+
import Fieldset from './form-fieldset.svelte';
8+
import Legend from './form-legend.svelte';
9+
import ElementField from './form-element-field.svelte';
10+
11+
const Control = FormPrimitive.Control;
12+
13+
export {
14+
Field,
15+
Control,
16+
Label,
17+
FieldErrors,
18+
Description,
19+
Fieldset,
20+
Legend,
21+
ElementField,
22+
Button,
23+
//
24+
Field as FormField,
25+
Control as FormControl,
26+
Description as FormDescription,
27+
Label as FormLabel,
28+
FieldErrors as FormFieldErrors,
29+
Fieldset as FormFieldset,
30+
Legend as FormLegend,
31+
ElementField as FormElementField,
32+
Button as FormButton
33+
};

0 commit comments

Comments
 (0)