@casinogate/ui 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/css/root.css +183 -5
- package/dist/components/button-group/button-group.stories.svelte +59 -0
- package/dist/components/button-group/button-group.stories.svelte.d.ts +19 -0
- package/dist/components/button-group/components/button-group.root.svelte +35 -0
- package/dist/components/button-group/components/button-group.root.svelte.d.ts +8 -0
- package/dist/components/button-group/components/button-group.separator.svelte +24 -0
- package/dist/components/button-group/components/button-group.separator.svelte.d.ts +13 -0
- package/dist/components/button-group/index.d.ts +16 -0
- package/dist/components/button-group/index.js +6 -0
- package/dist/components/button-group/styles.d.ts +47 -0
- package/dist/components/button-group/styles.js +27 -0
- package/dist/components/data-table/components/data-table.svelte.js +1 -1
- package/dist/components/field/components/field.control.svelte +24 -0
- package/dist/components/field/components/field.control.svelte.d.ts +10 -0
- package/dist/components/field/components/field.description.svelte +47 -0
- package/dist/components/field/components/field.description.svelte.d.ts +7 -0
- package/dist/components/field/components/field.error.svelte +49 -0
- package/dist/components/field/components/field.error.svelte.d.ts +7 -0
- package/dist/components/field/components/field.label.svelte +49 -0
- package/dist/components/field/components/field.label.svelte.d.ts +7 -0
- package/dist/components/field/components/field.root.svelte +63 -0
- package/dist/components/field/components/field.root.svelte.d.ts +12 -0
- package/dist/components/field/components/field.svelte.d.ts +83 -0
- package/dist/components/field/components/field.svelte.js +121 -0
- package/dist/components/field/field.stories.svelte +51 -0
- package/dist/components/field/field.stories.svelte.d.ts +19 -0
- package/dist/components/field/field.svelte +47 -0
- package/dist/components/field/field.svelte.d.ts +14 -0
- package/dist/components/field/index.d.ts +14 -0
- package/dist/components/field/index.js +14 -0
- package/dist/components/field/styles.d.ts +50 -0
- package/dist/components/field/styles.js +12 -0
- package/dist/components/input/input.svelte +1 -1
- package/dist/components/separator/index.d.ts +5 -0
- package/dist/components/separator/index.js +4 -0
- package/dist/components/separator/separator.stories.svelte +44 -0
- package/dist/components/separator/separator.stories.svelte.d.ts +19 -0
- package/dist/components/separator/separator.svelte +21 -0
- package/dist/components/separator/separator.svelte.d.ts +5 -0
- package/dist/components/skeleton/skeleton.stories.svelte +9 -1
- package/dist/components/skeleton/skeleton.svelte +8 -2
- package/dist/components/skeleton/skeleton.svelte.d.ts +3 -1
- package/dist/components/toast/index.d.ts +1 -0
- package/dist/components/toast/index.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/internal/constants/attrs.d.ts +1 -0
- package/dist/internal/constants/attrs.js +1 -0
- package/dist/internal/types/html-attributes.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
type FieldDescriptionPropsWithoutHTML = WithElementRef<WithChild<{}>>;
|
|
3
|
+
|
|
4
|
+
export type FieldDescriptionProps = FieldDescriptionPropsWithoutHTML &
|
|
5
|
+
Without<PrimitiveSpanAttributes, FieldDescriptionPropsWithoutHTML>;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import type { PrimitiveSpanAttributes } from '../../../internal/types/html-attributes.js';
|
|
10
|
+
import { cn } from '../../../internal/utils/common.js';
|
|
11
|
+
import { useId } from 'bits-ui';
|
|
12
|
+
|
|
13
|
+
import { box, mergeProps, type WithChild, type WithElementRef, type Without } from 'svelte-toolbelt';
|
|
14
|
+
import { FieldStylesContext } from '../styles.js';
|
|
15
|
+
import { FieldDescriptionState } from './field.svelte.js';
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
children,
|
|
19
|
+
child,
|
|
20
|
+
ref = $bindable(null),
|
|
21
|
+
id = useId(),
|
|
22
|
+
class: className,
|
|
23
|
+
...restProps
|
|
24
|
+
}: FieldDescriptionProps = $props();
|
|
25
|
+
|
|
26
|
+
const styles = FieldStylesContext.get();
|
|
27
|
+
|
|
28
|
+
const descriptionState = FieldDescriptionState.create({
|
|
29
|
+
ref: box.with(
|
|
30
|
+
() => ref,
|
|
31
|
+
(v) => (ref = v)
|
|
32
|
+
),
|
|
33
|
+
id: box.with(() => id),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const mergedProps = $derived(
|
|
37
|
+
mergeProps(restProps, descriptionState.props, { class: cn(styles.current.description(), className) })
|
|
38
|
+
);
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
{#if child}
|
|
42
|
+
{@render child({ props: mergedProps })}
|
|
43
|
+
{:else}
|
|
44
|
+
<span {...mergedProps}>
|
|
45
|
+
{@render children?.()}
|
|
46
|
+
</span>
|
|
47
|
+
{/if}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type FieldDescriptionPropsWithoutHTML = WithElementRef<WithChild<{}>>;
|
|
2
|
+
export type FieldDescriptionProps = FieldDescriptionPropsWithoutHTML & Without<PrimitiveSpanAttributes, FieldDescriptionPropsWithoutHTML>;
|
|
3
|
+
import type { PrimitiveSpanAttributes } from '../../../internal/types/html-attributes.js';
|
|
4
|
+
import { type WithChild, type WithElementRef, type Without } from 'svelte-toolbelt';
|
|
5
|
+
declare const Field: import("svelte").Component<FieldDescriptionProps, {}, "ref">;
|
|
6
|
+
type Field = ReturnType<typeof Field>;
|
|
7
|
+
export default Field;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
type FieldErrorPropsWithoutHTML = WithElementRef<WithChild<{}>>;
|
|
3
|
+
|
|
4
|
+
export type FieldErrorProps = FieldErrorPropsWithoutHTML &
|
|
5
|
+
Without<PrimitiveSpanAttributes, FieldErrorPropsWithoutHTML>;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import type { PrimitiveSpanAttributes } from '../../../internal/types/html-attributes.js';
|
|
10
|
+
import { cn } from '../../../internal/utils/common.js';
|
|
11
|
+
import { useId } from 'bits-ui';
|
|
12
|
+
import { FieldStylesContext } from '../styles.js';
|
|
13
|
+
import { FieldErrorState } from './field.svelte.js';
|
|
14
|
+
|
|
15
|
+
import { box, mergeProps, type WithChild, type WithElementRef, type Without } from 'svelte-toolbelt';
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
children,
|
|
19
|
+
child,
|
|
20
|
+
ref = $bindable(null),
|
|
21
|
+
id = useId(),
|
|
22
|
+
class: className,
|
|
23
|
+
...restProps
|
|
24
|
+
}: FieldErrorProps = $props();
|
|
25
|
+
|
|
26
|
+
const styles = FieldStylesContext.get();
|
|
27
|
+
|
|
28
|
+
const errorState = FieldErrorState.create({
|
|
29
|
+
ref: box.with(
|
|
30
|
+
() => ref,
|
|
31
|
+
(v) => (ref = v)
|
|
32
|
+
),
|
|
33
|
+
id: box.with(() => id),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const mergedProps = $derived(
|
|
37
|
+
mergeProps(restProps, errorState.props, { class: cn(styles.current.error(), className) })
|
|
38
|
+
);
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
{#if errorState.root.opts.invalid.current}
|
|
42
|
+
{#if child}
|
|
43
|
+
{@render child({ props: mergedProps })}
|
|
44
|
+
{:else}
|
|
45
|
+
<span {...mergedProps}>
|
|
46
|
+
{@render children?.()}
|
|
47
|
+
</span>
|
|
48
|
+
{/if}
|
|
49
|
+
{/if}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type FieldErrorPropsWithoutHTML = WithElementRef<WithChild<{}>>;
|
|
2
|
+
export type FieldErrorProps = FieldErrorPropsWithoutHTML & Without<PrimitiveSpanAttributes, FieldErrorPropsWithoutHTML>;
|
|
3
|
+
import type { PrimitiveSpanAttributes } from '../../../internal/types/html-attributes.js';
|
|
4
|
+
import { type WithChild, type WithElementRef, type Without } from 'svelte-toolbelt';
|
|
5
|
+
declare const Field: import("svelte").Component<FieldErrorProps, {}, "ref">;
|
|
6
|
+
type Field = ReturnType<typeof Field>;
|
|
7
|
+
export default Field;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
type FieldLabelPropsWithoutHTML = WithElementRef<WithChild<{}>>;
|
|
3
|
+
|
|
4
|
+
export type FieldLabelProps = FieldLabelPropsWithoutHTML &
|
|
5
|
+
Without<PrimitiveLabelAttributes, FieldLabelPropsWithoutHTML>;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { FieldLabelState } from './field.svelte.js';
|
|
10
|
+
|
|
11
|
+
import { FieldStylesContext } from '../styles.js';
|
|
12
|
+
|
|
13
|
+
import type { PrimitiveLabelAttributes } from '../../../internal/types/html-attributes.js';
|
|
14
|
+
import { cn } from '../../../internal/utils/common.js';
|
|
15
|
+
import { useId } from 'bits-ui';
|
|
16
|
+
|
|
17
|
+
import { box, mergeProps, type WithChild, type WithElementRef, type Without } from 'svelte-toolbelt';
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
children,
|
|
21
|
+
child,
|
|
22
|
+
ref = $bindable(null),
|
|
23
|
+
id = useId(),
|
|
24
|
+
class: className,
|
|
25
|
+
...restProps
|
|
26
|
+
}: FieldLabelProps = $props();
|
|
27
|
+
|
|
28
|
+
const styles = FieldStylesContext.get();
|
|
29
|
+
|
|
30
|
+
const labelState = FieldLabelState.create({
|
|
31
|
+
ref: box.with(
|
|
32
|
+
() => ref,
|
|
33
|
+
(v) => (ref = v)
|
|
34
|
+
),
|
|
35
|
+
id: box.with(() => id),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const mergedProps = $derived(
|
|
39
|
+
mergeProps(restProps, labelState.props, { class: cn(styles.current.label(), className) })
|
|
40
|
+
);
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
{#if child}
|
|
44
|
+
{@render child({ props: mergedProps })}
|
|
45
|
+
{:else}
|
|
46
|
+
<label {...mergedProps}>
|
|
47
|
+
{@render children?.()}
|
|
48
|
+
</label>
|
|
49
|
+
{/if}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type FieldLabelPropsWithoutHTML = WithElementRef<WithChild<{}>>;
|
|
2
|
+
export type FieldLabelProps = FieldLabelPropsWithoutHTML & Without<PrimitiveLabelAttributes, FieldLabelPropsWithoutHTML>;
|
|
3
|
+
import type { PrimitiveLabelAttributes } from '../../../internal/types/html-attributes.js';
|
|
4
|
+
import { type WithChild, type WithElementRef, type Without } from 'svelte-toolbelt';
|
|
5
|
+
declare const Field: import("svelte").Component<FieldLabelProps, {}, "ref">;
|
|
6
|
+
type Field = ReturnType<typeof Field>;
|
|
7
|
+
export default Field;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
type FieldRootPropsWithoutHTML = WithElementRef<
|
|
3
|
+
WithChild<{
|
|
4
|
+
invalid?: boolean;
|
|
5
|
+
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
|
|
8
|
+
readOnly?: boolean;
|
|
9
|
+
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}>
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export type FieldRootProps = FieldRootPropsWithoutHTML & Without<PrimitiveDivAttributes, FieldRootPropsWithoutHTML>;
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import type { PrimitiveDivAttributes } from '../../../internal/types/html-attributes.js';
|
|
19
|
+
import { cn } from '../../../internal/utils/common.js';
|
|
20
|
+
import { useId } from 'bits-ui';
|
|
21
|
+
import { box, mergeProps, type WithChild, type WithElementRef, type Without } from 'svelte-toolbelt';
|
|
22
|
+
import { fieldStyles, FieldStylesContext } from '../styles.js';
|
|
23
|
+
import { FieldRootState } from './field.svelte.js';
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
children,
|
|
27
|
+
child,
|
|
28
|
+
class: className,
|
|
29
|
+
ref = $bindable(null),
|
|
30
|
+
id = useId(),
|
|
31
|
+
invalid = false,
|
|
32
|
+
disabled = false,
|
|
33
|
+
readOnly = false,
|
|
34
|
+
required = false,
|
|
35
|
+
...restProps
|
|
36
|
+
}: FieldRootProps = $props();
|
|
37
|
+
|
|
38
|
+
const rootState = FieldRootState.create({
|
|
39
|
+
ref: box.with(
|
|
40
|
+
() => ref,
|
|
41
|
+
(v) => (ref = v)
|
|
42
|
+
),
|
|
43
|
+
id: box.with(() => id),
|
|
44
|
+
invalid: box.with(() => invalid),
|
|
45
|
+
disabled: box.with(() => disabled),
|
|
46
|
+
readOnly: box.with(() => readOnly),
|
|
47
|
+
required: box.with(() => required),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const variants = $derived(fieldStyles());
|
|
51
|
+
|
|
52
|
+
FieldStylesContext.set(box.with(() => variants));
|
|
53
|
+
|
|
54
|
+
const mergedProps = $derived(mergeProps(restProps, rootState.props, { class: cn(variants.root(), className) }));
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
{#if child}
|
|
58
|
+
{@render child({ props: mergedProps })}
|
|
59
|
+
{:else}
|
|
60
|
+
<div {...mergedProps}>
|
|
61
|
+
{@render children?.()}
|
|
62
|
+
</div>
|
|
63
|
+
{/if}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type FieldRootPropsWithoutHTML = WithElementRef<WithChild<{
|
|
2
|
+
invalid?: boolean;
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
readOnly?: boolean;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
}>>;
|
|
7
|
+
export type FieldRootProps = FieldRootPropsWithoutHTML & Without<PrimitiveDivAttributes, FieldRootPropsWithoutHTML>;
|
|
8
|
+
import type { PrimitiveDivAttributes } from '../../../internal/types/html-attributes.js';
|
|
9
|
+
import { type WithChild, type WithElementRef, type Without } from 'svelte-toolbelt';
|
|
10
|
+
declare const Field: import("svelte").Component<FieldRootProps, {}, "ref">;
|
|
11
|
+
type Field = ReturnType<typeof Field>;
|
|
12
|
+
export default Field;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { RefAttachment } from '../../../internal/types/common.js';
|
|
2
|
+
import { type ReadableBoxedValues, type WithRefProps } from 'svelte-toolbelt';
|
|
3
|
+
type FieldRootStateOpts = WithRefProps<ReadableBoxedValues<{
|
|
4
|
+
invalid: boolean;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
readOnly: boolean;
|
|
7
|
+
required: boolean;
|
|
8
|
+
}>>;
|
|
9
|
+
type Ids = {
|
|
10
|
+
control?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
error?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare class FieldRootState {
|
|
16
|
+
#private;
|
|
17
|
+
static create(opts: FieldRootStateOpts): FieldRootState;
|
|
18
|
+
readonly opts: FieldRootStateOpts;
|
|
19
|
+
readonly attachment: RefAttachment;
|
|
20
|
+
constructor(opts: FieldRootStateOpts);
|
|
21
|
+
setId(key: keyof Ids, id: string): void;
|
|
22
|
+
getId(key: keyof Ids): string | undefined;
|
|
23
|
+
readonly props: {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly 'data-invalid': "" | undefined;
|
|
26
|
+
readonly 'data-disabled': "" | undefined;
|
|
27
|
+
readonly 'data-read-only': "" | undefined;
|
|
28
|
+
readonly 'data-required': "" | undefined;
|
|
29
|
+
readonly "data-slot": "field-root";
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
type FieldLabelStateOpts = WithRefProps<ReadableBoxedValues<{}>>;
|
|
33
|
+
export declare class FieldLabelState {
|
|
34
|
+
static create(opts: FieldLabelStateOpts): FieldLabelState;
|
|
35
|
+
readonly opts: FieldLabelStateOpts;
|
|
36
|
+
readonly attachment: RefAttachment;
|
|
37
|
+
readonly root: FieldRootState;
|
|
38
|
+
constructor(opts: FieldLabelStateOpts, root: FieldRootState);
|
|
39
|
+
readonly props: {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly for: string | undefined;
|
|
42
|
+
readonly 'data-invalid': "" | undefined;
|
|
43
|
+
readonly "data-slot": "field-label";
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
type FieldErrorStateOpts = WithRefProps<ReadableBoxedValues<{}>>;
|
|
47
|
+
export declare class FieldErrorState {
|
|
48
|
+
static create(opts: FieldErrorStateOpts): FieldErrorState;
|
|
49
|
+
readonly opts: FieldErrorStateOpts;
|
|
50
|
+
readonly attachment: RefAttachment;
|
|
51
|
+
readonly root: FieldRootState;
|
|
52
|
+
constructor(opts: FieldErrorStateOpts, root: FieldRootState);
|
|
53
|
+
readonly props: {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly "data-slot": "field-error";
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
type FieldDescriptionStateOpts = WithRefProps<ReadableBoxedValues<{}>>;
|
|
59
|
+
export declare class FieldDescriptionState {
|
|
60
|
+
static create(opts: FieldDescriptionStateOpts): FieldDescriptionState;
|
|
61
|
+
readonly opts: FieldDescriptionStateOpts;
|
|
62
|
+
readonly attachment: RefAttachment;
|
|
63
|
+
readonly root: FieldRootState;
|
|
64
|
+
constructor(opts: FieldDescriptionStateOpts, root: FieldRootState);
|
|
65
|
+
readonly props: {
|
|
66
|
+
readonly id: string;
|
|
67
|
+
readonly "data-slot": "field-description";
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
type FieldControlStateOpts = ReadableBoxedValues<{
|
|
71
|
+
id: string;
|
|
72
|
+
}>;
|
|
73
|
+
export declare class FieldControlState {
|
|
74
|
+
static create(opts: FieldControlStateOpts): FieldControlState;
|
|
75
|
+
readonly opts: FieldControlStateOpts;
|
|
76
|
+
readonly root: FieldRootState;
|
|
77
|
+
constructor(opts: FieldControlStateOpts, root: FieldRootState);
|
|
78
|
+
readonly props: {
|
|
79
|
+
readonly id: string;
|
|
80
|
+
readonly 'aria-invalid': boolean;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { SLOT_ATTR_NAME } from '../../../internal/constants/attrs.js';
|
|
2
|
+
import { getDataActive, getDataDisabled } from '../../../internal/utils/attrs.js';
|
|
3
|
+
import { Context } from 'runed';
|
|
4
|
+
import { attachRef } from 'svelte-toolbelt';
|
|
5
|
+
const SLOT_ATTR_VALUES = {
|
|
6
|
+
root: 'field-root',
|
|
7
|
+
label: 'field-label',
|
|
8
|
+
error: 'field-error',
|
|
9
|
+
description: 'field-description',
|
|
10
|
+
};
|
|
11
|
+
const FieldRootStateContext = new Context('field-root-state');
|
|
12
|
+
export class FieldRootState {
|
|
13
|
+
static create(opts) {
|
|
14
|
+
return FieldRootStateContext.set(new FieldRootState(opts));
|
|
15
|
+
}
|
|
16
|
+
opts;
|
|
17
|
+
attachment;
|
|
18
|
+
#ids = $state({});
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
this.opts = opts;
|
|
21
|
+
this.attachment = attachRef(opts.ref);
|
|
22
|
+
}
|
|
23
|
+
setId(key, id) {
|
|
24
|
+
this.#ids = { ...this.#ids, [key]: id };
|
|
25
|
+
}
|
|
26
|
+
getId(key) {
|
|
27
|
+
return this.#ids[key];
|
|
28
|
+
}
|
|
29
|
+
props = $derived.by(() => ({
|
|
30
|
+
id: this.opts.id.current,
|
|
31
|
+
'data-invalid': getDataActive(this.opts.invalid.current),
|
|
32
|
+
'data-disabled': getDataDisabled(this.opts.disabled.current),
|
|
33
|
+
'data-read-only': getDataActive(this.opts.readOnly.current),
|
|
34
|
+
'data-required': getDataActive(this.opts.required.current),
|
|
35
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.root,
|
|
36
|
+
...this.attachment,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
export class FieldLabelState {
|
|
40
|
+
static create(opts) {
|
|
41
|
+
return new FieldLabelState(opts, FieldRootStateContext.get());
|
|
42
|
+
}
|
|
43
|
+
opts;
|
|
44
|
+
attachment;
|
|
45
|
+
root;
|
|
46
|
+
constructor(opts, root) {
|
|
47
|
+
this.opts = opts;
|
|
48
|
+
this.root = root;
|
|
49
|
+
this.attachment = attachRef(opts.ref);
|
|
50
|
+
$effect.pre(() => {
|
|
51
|
+
this.root.setId('label', this.opts.id.current);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
props = $derived.by(() => ({
|
|
55
|
+
id: this.opts.id.current,
|
|
56
|
+
for: this.root.getId('control'),
|
|
57
|
+
'data-invalid': getDataActive(this.root.opts.invalid.current),
|
|
58
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.label,
|
|
59
|
+
...this.attachment,
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
export class FieldErrorState {
|
|
63
|
+
static create(opts) {
|
|
64
|
+
return new FieldErrorState(opts, FieldRootStateContext.get());
|
|
65
|
+
}
|
|
66
|
+
opts;
|
|
67
|
+
attachment;
|
|
68
|
+
root;
|
|
69
|
+
constructor(opts, root) {
|
|
70
|
+
this.opts = opts;
|
|
71
|
+
this.root = root;
|
|
72
|
+
this.attachment = attachRef(opts.ref);
|
|
73
|
+
$effect.pre(() => {
|
|
74
|
+
this.root.setId('error', this.opts.id.current);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
props = $derived.by(() => ({
|
|
78
|
+
id: this.opts.id.current,
|
|
79
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.error,
|
|
80
|
+
...this.attachment,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
export class FieldDescriptionState {
|
|
84
|
+
static create(opts) {
|
|
85
|
+
return new FieldDescriptionState(opts, FieldRootStateContext.get());
|
|
86
|
+
}
|
|
87
|
+
opts;
|
|
88
|
+
attachment;
|
|
89
|
+
root;
|
|
90
|
+
constructor(opts, root) {
|
|
91
|
+
this.opts = opts;
|
|
92
|
+
this.root = root;
|
|
93
|
+
this.attachment = attachRef(opts.ref);
|
|
94
|
+
$effect.pre(() => {
|
|
95
|
+
this.root.setId('description', this.opts.id.current);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
props = $derived.by(() => ({
|
|
99
|
+
id: this.opts.id.current,
|
|
100
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.description,
|
|
101
|
+
...this.attachment,
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
export class FieldControlState {
|
|
105
|
+
static create(opts) {
|
|
106
|
+
return new FieldControlState(opts, FieldRootStateContext.get());
|
|
107
|
+
}
|
|
108
|
+
opts;
|
|
109
|
+
root;
|
|
110
|
+
constructor(opts, root) {
|
|
111
|
+
this.opts = opts;
|
|
112
|
+
this.root = root;
|
|
113
|
+
$effect.pre(() => {
|
|
114
|
+
this.root.setId('control', this.opts.id.current);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
props = $derived.by(() => ({
|
|
118
|
+
id: this.opts.id.current,
|
|
119
|
+
'aria-invalid': this.root.opts.invalid.current,
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { Input } from '../input/index.js';
|
|
3
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
4
|
+
import type { Parameters } from '@storybook/sveltekit';
|
|
5
|
+
import type { ComponentProps } from 'svelte';
|
|
6
|
+
import { Field, FieldPrimitive } from './index.js';
|
|
7
|
+
|
|
8
|
+
const parameters: Parameters = {
|
|
9
|
+
controls: {
|
|
10
|
+
include: [],
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const { Story } = defineMeta({
|
|
15
|
+
title: 'UI Kit/Field',
|
|
16
|
+
component: FieldPrimitive.Root,
|
|
17
|
+
tags: ['autodocs'],
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
type Args = ComponentProps<typeof FieldPrimitive.Root>;
|
|
21
|
+
|
|
22
|
+
const args: Args = {};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<Story name="Basic" {args} {parameters}>
|
|
26
|
+
{#snippet template(args: Args)}
|
|
27
|
+
<Field {...args} label="Label" error="Sunt enim qui culpa qui cupidatat." description="Description" invalid>
|
|
28
|
+
{#snippet children({ props })}
|
|
29
|
+
<Input placeholder="Input" {...props} />
|
|
30
|
+
{/snippet}
|
|
31
|
+
</Field>
|
|
32
|
+
{/snippet}
|
|
33
|
+
</Story>
|
|
34
|
+
|
|
35
|
+
<Story name="Primitive" {args} {parameters}>
|
|
36
|
+
{#snippet template(args: Args)}
|
|
37
|
+
<FieldPrimitive.Root {...args} invalid>
|
|
38
|
+
<FieldPrimitive.Label>Label</FieldPrimitive.Label>
|
|
39
|
+
|
|
40
|
+
<FieldPrimitive.Control>
|
|
41
|
+
{#snippet children({ props })}
|
|
42
|
+
<Input placeholder="Input" {...props} />
|
|
43
|
+
{/snippet}
|
|
44
|
+
</FieldPrimitive.Control>
|
|
45
|
+
|
|
46
|
+
<FieldPrimitive.Error>Sunt enim qui culpa qui cupidatat.</FieldPrimitive.Error>
|
|
47
|
+
|
|
48
|
+
<FieldPrimitive.Description>Description</FieldPrimitive.Description>
|
|
49
|
+
</FieldPrimitive.Root>
|
|
50
|
+
{/snippet}
|
|
51
|
+
</Story>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Field } from './index.js';
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
declare const Field: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
}, {}, {}, string>;
|
|
18
|
+
type Field = InstanceType<typeof Field>;
|
|
19
|
+
export default Field;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export type FieldProps = WithoutChildrenOrChild<FieldRootProps> & {
|
|
5
|
+
label?: string | Snippet;
|
|
6
|
+
error?: string | Snippet;
|
|
7
|
+
description?: string | Snippet;
|
|
8
|
+
children?: Snippet<[{ props: Record<string, unknown> }]>;
|
|
9
|
+
};
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import type { WithoutChildrenOrChild } from 'svelte-toolbelt';
|
|
14
|
+
import FieldControl from './components/field.control.svelte';
|
|
15
|
+
import FieldDescription from './components/field.description.svelte';
|
|
16
|
+
import FieldError from './components/field.error.svelte';
|
|
17
|
+
import FieldLabel from './components/field.label.svelte';
|
|
18
|
+
import FieldRoot, { type FieldRootProps } from './components/field.root.svelte';
|
|
19
|
+
|
|
20
|
+
let { label, error, description, ref = $bindable(null), children, ...restProps }: FieldProps = $props();
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<FieldRoot bind:ref {...restProps}>
|
|
24
|
+
{#if typeof label === 'string'}
|
|
25
|
+
<FieldLabel>{label}</FieldLabel>
|
|
26
|
+
{:else}
|
|
27
|
+
{@render label?.()}
|
|
28
|
+
{/if}
|
|
29
|
+
|
|
30
|
+
<FieldControl>
|
|
31
|
+
{#snippet children({ props })}
|
|
32
|
+
{@render children?.({ props })}
|
|
33
|
+
{/snippet}
|
|
34
|
+
</FieldControl>
|
|
35
|
+
|
|
36
|
+
{#if typeof error === 'string'}
|
|
37
|
+
<FieldError>{error}</FieldError>
|
|
38
|
+
{:else}
|
|
39
|
+
{@render error?.()}
|
|
40
|
+
{/if}
|
|
41
|
+
|
|
42
|
+
{#if typeof description === 'string'}
|
|
43
|
+
<FieldDescription>{description}</FieldDescription>
|
|
44
|
+
{:else}
|
|
45
|
+
{@render description?.()}
|
|
46
|
+
{/if}
|
|
47
|
+
</FieldRoot>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type FieldProps = WithoutChildrenOrChild<FieldRootProps> & {
|
|
3
|
+
label?: string | Snippet;
|
|
4
|
+
error?: string | Snippet;
|
|
5
|
+
description?: string | Snippet;
|
|
6
|
+
children?: Snippet<[{
|
|
7
|
+
props: Record<string, unknown>;
|
|
8
|
+
}]>;
|
|
9
|
+
};
|
|
10
|
+
import type { WithoutChildrenOrChild } from 'svelte-toolbelt';
|
|
11
|
+
import { type FieldRootProps } from './components/field.root.svelte';
|
|
12
|
+
declare const Field: import("svelte").Component<FieldProps, {}, "ref">;
|
|
13
|
+
type Field = ReturnType<typeof Field>;
|
|
14
|
+
export default Field;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FieldDescriptionProps } from './components/field.description.svelte';
|
|
2
|
+
import { type FieldErrorProps } from './components/field.error.svelte';
|
|
3
|
+
import { type FieldLabelProps } from './components/field.label.svelte';
|
|
4
|
+
import { type FieldRootProps } from './components/field.root.svelte';
|
|
5
|
+
import Field from './field.svelte';
|
|
6
|
+
export declare const FieldPrimitive: {
|
|
7
|
+
readonly Root: import("svelte").Component<FieldRootProps, {}, "ref">;
|
|
8
|
+
readonly Label: import("svelte").Component<FieldLabelProps, {}, "ref">;
|
|
9
|
+
readonly Error: import("svelte").Component<FieldErrorProps, {}, "ref">;
|
|
10
|
+
readonly Description: import("svelte").Component<FieldDescriptionProps, {}, "ref">;
|
|
11
|
+
readonly Control: import("svelte").Component<import("./components/field.control.svelte").FieldControlProps, {}, "">;
|
|
12
|
+
};
|
|
13
|
+
export { Field };
|
|
14
|
+
export type { FieldDescriptionProps, FieldErrorProps, FieldLabelProps, FieldRootProps };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import FieldControl from './components/field.control.svelte';
|
|
2
|
+
import FieldDescription, {} from './components/field.description.svelte';
|
|
3
|
+
import FieldError, {} from './components/field.error.svelte';
|
|
4
|
+
import FieldLabel, {} from './components/field.label.svelte';
|
|
5
|
+
import FieldRoot, {} from './components/field.root.svelte';
|
|
6
|
+
import Field from './field.svelte';
|
|
7
|
+
export const FieldPrimitive = {
|
|
8
|
+
Root: FieldRoot,
|
|
9
|
+
Label: FieldLabel,
|
|
10
|
+
Error: FieldError,
|
|
11
|
+
Description: FieldDescription,
|
|
12
|
+
Control: FieldControl,
|
|
13
|
+
};
|
|
14
|
+
export { Field };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Context } from 'runed';
|
|
2
|
+
import type { ReadableBox } from 'svelte-toolbelt';
|
|
3
|
+
import type { VariantProps } from 'tailwind-variants';
|
|
4
|
+
export declare const fieldStyles: import("tailwind-variants").TVReturnType<{
|
|
5
|
+
[key: string]: {
|
|
6
|
+
[key: string]: import("tailwind-variants").ClassValue | {
|
|
7
|
+
label?: import("tailwind-variants").ClassValue;
|
|
8
|
+
root?: import("tailwind-variants").ClassValue;
|
|
9
|
+
error?: import("tailwind-variants").ClassValue;
|
|
10
|
+
description?: import("tailwind-variants").ClassValue;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
} | {
|
|
14
|
+
[x: string]: {
|
|
15
|
+
[x: string]: import("tailwind-variants").ClassValue | {
|
|
16
|
+
label?: import("tailwind-variants").ClassValue;
|
|
17
|
+
root?: import("tailwind-variants").ClassValue;
|
|
18
|
+
error?: import("tailwind-variants").ClassValue;
|
|
19
|
+
description?: import("tailwind-variants").ClassValue;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
} | {}, {
|
|
23
|
+
root: string;
|
|
24
|
+
label: string;
|
|
25
|
+
error: string;
|
|
26
|
+
description: string;
|
|
27
|
+
}, undefined, {
|
|
28
|
+
[key: string]: {
|
|
29
|
+
[key: string]: import("tailwind-variants").ClassValue | {
|
|
30
|
+
label?: import("tailwind-variants").ClassValue;
|
|
31
|
+
root?: import("tailwind-variants").ClassValue;
|
|
32
|
+
error?: import("tailwind-variants").ClassValue;
|
|
33
|
+
description?: import("tailwind-variants").ClassValue;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
} | {}, {
|
|
37
|
+
root: string;
|
|
38
|
+
label: string;
|
|
39
|
+
error: string;
|
|
40
|
+
description: string;
|
|
41
|
+
}, import("tailwind-variants").TVReturnType<unknown, {
|
|
42
|
+
root: string;
|
|
43
|
+
label: string;
|
|
44
|
+
error: string;
|
|
45
|
+
description: string;
|
|
46
|
+
}, undefined, unknown, unknown, undefined>>;
|
|
47
|
+
export type FieldVariantsProps = VariantProps<typeof fieldStyles>;
|
|
48
|
+
type FieldStylesContextValues = ReadableBox<ReturnType<typeof fieldStyles>>;
|
|
49
|
+
export declare const FieldStylesContext: Context<FieldStylesContextValues>;
|
|
50
|
+
export {};
|