@adriansyah/heroui-svelte 0.0.2 → 0.0.4
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/README.md +3 -3
- package/dist/components/autocomplete/autocomplete-popover.svelte +1 -1
- package/dist/components/autocomplete/autocomplete-trigger.svelte +45 -21
- package/dist/components/autocomplete/autocomplete-trigger.svelte.d.ts +8 -2
- package/dist/components/autocomplete/autocomplete.svelte +13 -7
- package/dist/components/autocomplete/index.svelte.d.ts +3 -3
- package/dist/components/autocomplete/index.svelte.js +10 -11
- package/dist/components/avatar/context.svelte.d.ts +1 -1
- package/dist/components/avatar/context.svelte.js +1 -1
- package/dist/components/button/button.svelte +1 -1
- package/dist/components/button/index.svelte.d.ts +1 -1
- package/dist/components/button/index.svelte.js +1 -1
- package/dist/components/button-group/context.svelte.d.ts +1 -1
- package/dist/components/button-group/context.svelte.js +1 -1
- package/dist/components/card/context.svelte.d.ts +1 -1
- package/dist/components/card/context.svelte.js +1 -1
- package/dist/components/checkbox/checkbox-content.svelte +7 -6
- package/dist/components/checkbox/checkbox-control.svelte +7 -6
- package/dist/components/checkbox/checkbox.svelte +7 -2
- package/dist/components/collection/collection.svelte +1 -1
- package/dist/components/collection/collection.svelte.d.ts +1 -1
- package/dist/components/filter/filter-provider.svelte +1 -1
- package/dist/components/filter/index.svelte.d.ts +3 -3
- package/dist/components/filter/index.svelte.js +3 -18
- package/dist/components/input/index.svelte.d.ts +1 -1
- package/dist/components/input/index.svelte.js +3 -3
- package/dist/components/input/input.svelte +1 -1
- package/dist/components/input-group/input-group-input.svelte +1 -1
- package/dist/components/input-group/input-group-textarea.svelte +1 -1
- package/dist/components/input-group/input-group.svelte +1 -1
- package/dist/components/list-box/index.svelte.d.ts +21 -1
- package/dist/components/list-box/index.svelte.js +56 -2
- package/dist/components/list-box/list-box-item-indicator.svelte +3 -9
- package/dist/components/list-box/list-box-item.svelte +23 -48
- package/dist/components/list-box/list-box-item.svelte.d.ts +4 -1
- package/dist/components/list-box/list-box.svelte +2 -3
- package/dist/components/modal/index.svelte.d.ts +1 -1
- package/dist/components/modal/index.svelte.js +1 -1
- package/dist/components/modal/modal-content.svelte +1 -1
- package/dist/components/modal/modal-trigger.svelte +18 -9
- package/dist/components/modal/modal-trigger.svelte.d.ts +5 -1
- package/dist/components/pagination/index.svelte.d.ts +1 -1
- package/dist/components/pagination/index.svelte.js +1 -1
- package/dist/components/pagination/pagination-content.svelte +17 -1
- package/dist/components/pagination/pagination-link.svelte +5 -1
- package/dist/components/pagination/pagination-next.svelte +7 -1
- package/dist/components/pagination/pagination-previous.svelte +7 -1
- package/dist/components/pagination/pagination-summary.svelte +7 -1
- package/dist/components/pagination/pagination.svelte +9 -2
- package/dist/components/popover/index.svelte.d.ts +1 -1
- package/dist/components/popover/index.svelte.js +1 -1
- package/dist/components/popover/popover-trigger.svelte +26 -9
- package/dist/components/popover/popover-trigger.svelte.d.ts +12 -7
- package/dist/components/popover/popover.svelte +3 -3
- package/dist/components/popover/popover.svelte.d.ts +2 -4
- package/dist/components/search-input/search-input.svelte +5 -4
- package/dist/components/table/index.svelte.d.ts +1 -1
- package/dist/components/table/index.svelte.js +1 -1
- package/dist/components/text-field/text-field.svelte +1 -1
- package/dist/components/textarea/textarea.svelte +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ A Svelte 5 wrapper for [HeroUI](https://heroui.com), bringing HeroUI's styling a
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
bun add
|
|
8
|
+
bun add @adriansyah/heroui-svelte @heroui/styles
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Setup
|
|
@@ -16,7 +16,7 @@ Import Tailwind CSS and HeroUI styles in your main CSS file:
|
|
|
16
16
|
@import "tailwindcss";
|
|
17
17
|
@import "@heroui/styles";
|
|
18
18
|
|
|
19
|
-
@source "../../node_modules/heroui-svelte/dist";
|
|
19
|
+
@source "../../node_modules/@adriansyah/heroui-svelte/dist";
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
Adjust the `@source` path to match your project structure.
|
|
@@ -27,7 +27,7 @@ Import components from `heroui-svelte` and use them in your Svelte 5 components.
|
|
|
27
27
|
|
|
28
28
|
```svelte
|
|
29
29
|
<script lang="ts">
|
|
30
|
-
import { Button } from "heroui-svelte";
|
|
30
|
+
import { Button } from "@adriansyah/heroui-svelte";
|
|
31
31
|
</script>
|
|
32
32
|
|
|
33
33
|
<Button>Get started</Button>
|
|
@@ -1,28 +1,52 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
-
import {
|
|
3
|
+
import { AutocompleteContext } from "../../index.js";
|
|
4
4
|
import { autocompleteVariants } from "@heroui/styles";
|
|
5
|
+
import AutocompleteClearButton from "./autocomplete-clear-button.svelte";
|
|
6
|
+
import AutocompleteIndicator from "./autocomplete-indicator.svelte";
|
|
7
|
+
import AutocompleteValue from "./autocomplete-value.svelte";
|
|
8
|
+
import type { Snippet } from "svelte";
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
11
|
+
child?: Snippet<[{ props: HTMLAttributes<any>; ctx: AutocompleteContext }]>;
|
|
12
|
+
};
|
|
7
13
|
|
|
8
|
-
const { children, ...props }: Props = $props();
|
|
9
|
-
const
|
|
14
|
+
const { children, child, ...props }: Props = $props();
|
|
15
|
+
const ctx = AutocompleteContext.get();
|
|
16
|
+
const popover = ctx.popover;
|
|
17
|
+
const merged: HTMLAttributes<any> = $derived({
|
|
18
|
+
...props,
|
|
19
|
+
tabindex: 0,
|
|
20
|
+
role: "button",
|
|
21
|
+
"data-open": popover.open,
|
|
22
|
+
"data-popover": popover.node?.popover,
|
|
23
|
+
onclick: (ev) => {
|
|
24
|
+
props.onclick?.(ev);
|
|
25
|
+
popover.toggle(undefined, ev.currentTarget);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
10
28
|
</script>
|
|
11
29
|
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
{#if child}
|
|
31
|
+
{@render child({ props: merged, ctx })}
|
|
32
|
+
{:else}
|
|
33
|
+
<div
|
|
34
|
+
{...merged}
|
|
35
|
+
data-slot="autocomplete-trigger"
|
|
36
|
+
class={autocompleteVariants().trigger({
|
|
37
|
+
...ctx.heroui,
|
|
38
|
+
class: [
|
|
39
|
+
props?.class?.toString(),
|
|
40
|
+
"data-[open=true]:[[data-popover=''],[data-popover='auto']]:pointer-events-none",
|
|
41
|
+
],
|
|
42
|
+
})}
|
|
43
|
+
>
|
|
44
|
+
{#if children}
|
|
45
|
+
{@render children()}
|
|
46
|
+
{:else}
|
|
47
|
+
<AutocompleteValue placeholder={props.placeholder ?? undefined} />
|
|
48
|
+
<AutocompleteIndicator />
|
|
49
|
+
<AutocompleteClearButton />
|
|
50
|
+
{/if}
|
|
51
|
+
</div>
|
|
52
|
+
{/if}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { HTMLAttributes } from "svelte/elements";
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
import { AutocompleteContext } from "../../index.js";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
5
|
+
child?: Snippet<[{
|
|
6
|
+
props: HTMLAttributes<any>;
|
|
7
|
+
ctx: AutocompleteContext;
|
|
8
|
+
}]>;
|
|
9
|
+
};
|
|
4
10
|
declare const AutocompleteTrigger: import("svelte").Component<Props, {}, "">;
|
|
5
11
|
type AutocompleteTrigger = ReturnType<typeof AutocompleteTrigger>;
|
|
6
12
|
export default AutocompleteTrigger;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type AutocompleteOpts,
|
|
7
|
-
} from "../../index.js";
|
|
8
|
-
import { box } from "svelte-utils";
|
|
3
|
+
import { Popover, AutocompleteContext, type AutocompleteOpts } from "../../index.js";
|
|
4
|
+
import { box } from "@adriansyah/svelte-utils";
|
|
5
|
+
import { autocompleteVariants } from "@heroui/styles";
|
|
9
6
|
|
|
10
7
|
type Props = HTMLAttributes<HTMLElement> &
|
|
11
8
|
Partial<AutocompleteOpts> & {
|
|
@@ -48,5 +45,14 @@
|
|
|
48
45
|
</script>
|
|
49
46
|
|
|
50
47
|
<Popover {offset} {placement}>
|
|
51
|
-
|
|
48
|
+
<div
|
|
49
|
+
{...props}
|
|
50
|
+
class={autocompleteVariants().base({
|
|
51
|
+
fullWidth,
|
|
52
|
+
variant,
|
|
53
|
+
class: props.class?.toString(),
|
|
54
|
+
})}
|
|
55
|
+
>
|
|
56
|
+
{@render props.children?.()}
|
|
57
|
+
</div>
|
|
52
58
|
</Popover>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AutocompleteVariants } from "@heroui/styles";
|
|
2
|
-
import { Context, type Box, type Getter } from "svelte-utils";
|
|
3
|
-
import { ListBoxContext,
|
|
2
|
+
import { Context, type Box, type Getter, PopoverState } from "@adriansyah/svelte-utils";
|
|
3
|
+
import { ListBoxContext, type ListBoxOpts, type PopoverContextOpts } from "../../index.js";
|
|
4
4
|
export type AutocompleteOpts = ListBoxOpts & AutocompleteVariants & PopoverContextOpts & {
|
|
5
5
|
invalid?: boolean;
|
|
6
6
|
};
|
|
7
7
|
export declare class AutocompleteContext extends Context {
|
|
8
8
|
opts: AutocompleteOpts;
|
|
9
|
-
|
|
9
|
+
popover: PopoverState;
|
|
10
10
|
listboxCtx: ListBoxContext;
|
|
11
11
|
constructor(opts: Getter<AutocompleteOpts>, selected: Box<string[]>);
|
|
12
12
|
autoCloseOnFocusLost(): () => void;
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { Context, isEventTargetInAny, watch } from "svelte-utils";
|
|
2
|
-
import { ListBoxContext
|
|
1
|
+
import { Context, isEventTargetInAny, watch, PopoverState } from "@adriansyah/svelte-utils";
|
|
2
|
+
import { ListBoxContext } from "../../index.js";
|
|
3
3
|
export class AutocompleteContext extends Context {
|
|
4
4
|
opts;
|
|
5
|
-
|
|
5
|
+
popover = new PopoverState();
|
|
6
6
|
listboxCtx;
|
|
7
7
|
constructor(opts, selected) {
|
|
8
8
|
super();
|
|
9
9
|
this.opts = $derived.by(opts);
|
|
10
|
-
this.popoverCtx = new PopoverContext(opts);
|
|
11
10
|
this.listboxCtx = new ListBoxContext(opts, selected);
|
|
12
11
|
this.autoCloseOnFocusLost();
|
|
13
12
|
this.autoCloseOnSingleSelect();
|
|
14
13
|
}
|
|
15
14
|
autoCloseOnFocusLost() {
|
|
16
15
|
const handleWindowClick = (ev) => {
|
|
17
|
-
if (!this.
|
|
16
|
+
if (!this.popover.node?.matches(":popover-open"))
|
|
18
17
|
return;
|
|
19
|
-
if (isEventTargetInAny(ev, this.
|
|
18
|
+
if (isEventTargetInAny(ev, this.popover.anchor, this.popover.node)) {
|
|
20
19
|
return;
|
|
21
20
|
}
|
|
22
21
|
this.close();
|
|
23
22
|
};
|
|
24
23
|
const handleEscapeKey = (ev) => {
|
|
25
|
-
const focused = this.
|
|
24
|
+
const focused = this.popover.node?.matches(":focus-within") || this.popover.anchor?.matches(":focus-within");
|
|
26
25
|
if (ev.code !== "Escape" || !focused)
|
|
27
26
|
return;
|
|
28
27
|
ev.preventDefault();
|
|
29
28
|
ev.stopImmediatePropagation();
|
|
30
29
|
this.close();
|
|
31
|
-
this.
|
|
30
|
+
this.popover.anchor?.focus();
|
|
32
31
|
};
|
|
33
32
|
window.addEventListener("click", handleWindowClick);
|
|
34
33
|
window.addEventListener("keydown", handleEscapeKey);
|
|
@@ -45,13 +44,13 @@ export class AutocompleteContext extends Context {
|
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
close() {
|
|
48
|
-
this.
|
|
47
|
+
this.popover.hide();
|
|
49
48
|
}
|
|
50
49
|
open(source) {
|
|
51
|
-
this.
|
|
50
|
+
this.popover.node?.showPopover({ source });
|
|
52
51
|
}
|
|
53
52
|
toggle(source) {
|
|
54
|
-
this.
|
|
53
|
+
this.popover.node?.togglePopover({ source });
|
|
55
54
|
}
|
|
56
55
|
get props() {
|
|
57
56
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AvatarVariants } from "@heroui/styles";
|
|
2
|
-
import { Context, type Getter } from "svelte-utils";
|
|
2
|
+
import { Context, type Getter } from "@adriansyah/svelte-utils";
|
|
3
3
|
export type AvatarOpts = AvatarVariants;
|
|
4
4
|
export declare class AvatarContext extends Context {
|
|
5
5
|
readonly opts: AvatarOpts;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { buttonVariants } from "@heroui/styles";
|
|
3
3
|
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
4
4
|
import { type ButtonOpts, ButtonContext, Spinner } from "../../index.js";
|
|
5
|
-
import { useRipples } from "svelte-utils";
|
|
5
|
+
import { useRipples } from "@adriansyah/svelte-utils";
|
|
6
6
|
|
|
7
7
|
const {
|
|
8
8
|
focused,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ButtonVariants } from "@heroui/styles";
|
|
2
|
-
import { Context, type Getter } from "svelte-utils";
|
|
2
|
+
import { Context, type Getter } from "@adriansyah/svelte-utils";
|
|
3
3
|
export type ButtonGroupOpts = ButtonVariants;
|
|
4
4
|
export declare class ButtonGroupContext extends Context {
|
|
5
5
|
readonly opts: ButtonGroupOpts;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CardVariants } from "@heroui/styles";
|
|
2
|
-
import { Context, type Getter } from "svelte-utils";
|
|
2
|
+
import { Context, type Getter } from "@adriansyah/svelte-utils";
|
|
3
3
|
export declare class CardContext extends Context {
|
|
4
4
|
opts: CardVariants;
|
|
5
5
|
constructor(opts: Getter<CardVariants>);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { checkboxVariants } from "@heroui/styles";
|
|
3
3
|
import type { HTMLLabelAttributes } from "svelte/elements";
|
|
4
4
|
import { InputContext, Input } from "../../index.js";
|
|
5
|
+
import CheckboxControl from "./checkbox-control.svelte";
|
|
5
6
|
|
|
6
7
|
type Props = HTMLLabelAttributes;
|
|
7
8
|
|
|
@@ -16,11 +17,11 @@
|
|
|
16
17
|
);
|
|
17
18
|
</script>
|
|
18
19
|
|
|
19
|
-
<label
|
|
20
|
-
{...props}
|
|
21
|
-
data-slot="checkbox-content"
|
|
22
|
-
class={contentClass}
|
|
23
|
-
>
|
|
20
|
+
<label {...props} data-slot="checkbox-content" class={contentClass}>
|
|
24
21
|
<Input headless hidden type="checkbox" />
|
|
25
|
-
{
|
|
22
|
+
{#if props.children}
|
|
23
|
+
{@render props.children()}
|
|
24
|
+
{:else}
|
|
25
|
+
<CheckboxControl />
|
|
26
|
+
{/if}
|
|
26
27
|
</label>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { checkboxVariants } from "@heroui/styles";
|
|
3
3
|
import type { HTMLAttributes } from "svelte/elements";
|
|
4
4
|
import { InputContext } from "../../index.js";
|
|
5
|
+
import CheckboxIndicator from "./checkbox-indicator.svelte";
|
|
5
6
|
|
|
6
7
|
type Props = HTMLAttributes<HTMLSpanElement>;
|
|
7
8
|
|
|
@@ -16,10 +17,10 @@
|
|
|
16
17
|
);
|
|
17
18
|
</script>
|
|
18
19
|
|
|
19
|
-
<span
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{
|
|
20
|
+
<span {...props} data-slot="checkbox-control" class={controlClass}>
|
|
21
|
+
{#if props.children}
|
|
22
|
+
{@render props.children()}
|
|
23
|
+
{:else}
|
|
24
|
+
<CheckboxIndicator />
|
|
25
|
+
{/if}
|
|
25
26
|
</span>
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { checkboxVariants } from "@heroui/styles";
|
|
3
3
|
import type { HTMLAttributes } from "svelte/elements";
|
|
4
4
|
import { type InputOpts, InputContext } from "../../index.js";
|
|
5
|
-
import { box } from "svelte-utils";
|
|
5
|
+
import { box } from "@adriansyah/svelte-utils";
|
|
6
|
+
import CheckboxContent from "./checkbox-content.svelte";
|
|
6
7
|
|
|
7
8
|
type Props = InputOpts &
|
|
8
9
|
HTMLAttributes<HTMLDivElement> & {
|
|
@@ -56,5 +57,9 @@
|
|
|
56
57
|
data-indeterminate={indeterminate}
|
|
57
58
|
class={checkboxClass}
|
|
58
59
|
>
|
|
59
|
-
{
|
|
60
|
+
{#if props.children}
|
|
61
|
+
{@render props.children()}
|
|
62
|
+
{:else}
|
|
63
|
+
<CheckboxContent />
|
|
64
|
+
{/if}
|
|
60
65
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Snippet } from "svelte";
|
|
2
|
-
import { type Fn, type MaybePromise } from "svelte-utils";
|
|
2
|
+
import { type Fn, type MaybePromise } from "@adriansyah/svelte-utils";
|
|
3
3
|
import type { Attachment } from "svelte/attachments";
|
|
4
4
|
declare function $$render<T>(): {
|
|
5
5
|
props: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Context, type Box, type Fn, type Getter } from "svelte-utils";
|
|
1
|
+
import { Context, type Box, type Fn, type Getter } from "@adriansyah/svelte-utils";
|
|
2
2
|
export type FilterOpts = {
|
|
3
3
|
caseSensitive?: boolean;
|
|
4
|
-
filter?: Fn<
|
|
4
|
+
filter?: Fn<[string, string], boolean>;
|
|
5
5
|
};
|
|
6
6
|
export declare class FilterContext extends Context {
|
|
7
7
|
#private;
|
|
@@ -13,5 +13,5 @@ export declare class FilterContext extends Context {
|
|
|
13
13
|
matches: (text: string) => boolean;
|
|
14
14
|
filter: (query: string, text: string) => boolean;
|
|
15
15
|
constructor(opts: Getter<FilterOpts>, query?: Box<string>);
|
|
16
|
-
sync(
|
|
16
|
+
sync(value: Box<string>): void;
|
|
17
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { untrack } from "svelte";
|
|
2
|
-
import { box, Context } from "svelte-utils";
|
|
2
|
+
import { box, Context } from "@adriansyah/svelte-utils";
|
|
3
3
|
export class FilterContext extends Context {
|
|
4
4
|
#opts;
|
|
5
5
|
#query;
|
|
@@ -31,22 +31,7 @@ export class FilterContext extends Context {
|
|
|
31
31
|
this.#opts = $derived.by(opts);
|
|
32
32
|
this.#query = query;
|
|
33
33
|
}
|
|
34
|
-
sync(
|
|
35
|
-
|
|
36
|
-
box.current;
|
|
37
|
-
untrack(() => {
|
|
38
|
-
if (box.current === this.query)
|
|
39
|
-
return;
|
|
40
|
-
this.query = box.current;
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
$effect(() => {
|
|
44
|
-
this.query;
|
|
45
|
-
untrack(() => {
|
|
46
|
-
if (box.current === this.query)
|
|
47
|
-
return;
|
|
48
|
-
box.current = this.query;
|
|
49
|
-
});
|
|
50
|
-
});
|
|
34
|
+
sync(value) {
|
|
35
|
+
box.link(value, this.#query);
|
|
51
36
|
}
|
|
52
37
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { InputVariants } from "@heroui/styles";
|
|
2
|
-
import { Context, type Box, type Getter } from "svelte-utils";
|
|
2
|
+
import { Context, type Box, type Getter } from "@adriansyah/svelte-utils";
|
|
3
3
|
export type InputValue = string | number | undefined;
|
|
4
4
|
export type InputOpts = InputVariants & {
|
|
5
5
|
disabled?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { box,
|
|
1
|
+
import { box, coalesce, Context } from "@adriansyah/svelte-utils";
|
|
2
2
|
export class InputContext extends Context {
|
|
3
3
|
opts;
|
|
4
4
|
#value;
|
|
@@ -23,8 +23,8 @@ export class InputContext extends Context {
|
|
|
23
23
|
this.#checked = checked;
|
|
24
24
|
if (!parent)
|
|
25
25
|
return;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
box.link(parent.#value, value);
|
|
27
|
+
box.link(parent.#checked, checked);
|
|
28
28
|
}
|
|
29
29
|
get props() {
|
|
30
30
|
return {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { inputVariants } from "@heroui/styles";
|
|
3
3
|
import type { HTMLInputAttributes } from "svelte/elements";
|
|
4
4
|
import { type InputOpts, InputContext } from "../../index.js";
|
|
5
|
-
import { box } from "svelte-utils";
|
|
5
|
+
import { box } from "@adriansyah/svelte-utils";
|
|
6
6
|
|
|
7
7
|
type Props = {
|
|
8
8
|
headless?: boolean;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { inputGroupVariants } from "@heroui/styles";
|
|
3
3
|
import type { ComponentProps } from "svelte";
|
|
4
4
|
import { Input, InputContext } from "../../index.js";
|
|
5
|
-
import { box } from "svelte-utils";
|
|
5
|
+
import { box } from "@adriansyah/svelte-utils";
|
|
6
6
|
|
|
7
7
|
let {
|
|
8
8
|
value = $bindable(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { inputGroupVariants } from "@heroui/styles";
|
|
3
3
|
import { InputContext, type InputOpts } from "../../index.js";
|
|
4
|
-
import { box, coalesce } from "svelte-utils";
|
|
4
|
+
import { box, coalesce } from "@adriansyah/svelte-utils";
|
|
5
5
|
import type { HTMLAttributes } from "svelte/elements";
|
|
6
6
|
|
|
7
7
|
let {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { inputGroupVariants } from "@heroui/styles";
|
|
3
3
|
import type { HTMLAttributes } from "svelte/elements";
|
|
4
4
|
import { type InputOpts, type InputValue, InputContext } from "../../index.js";
|
|
5
|
-
import { box } from "svelte-utils";
|
|
5
|
+
import { box } from "@adriansyah/svelte-utils";
|
|
6
6
|
|
|
7
7
|
type Props = InputOpts &
|
|
8
8
|
HTMLAttributes<HTMLDivElement> & {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Context, type Box, type Getter } from "svelte-utils";
|
|
1
|
+
import { Context, type Box, type Getter } from "@adriansyah/svelte-utils";
|
|
2
|
+
import { FilterContext } from "../filter";
|
|
3
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
2
4
|
export type ListBoxOpts = {
|
|
3
5
|
disabled?: boolean;
|
|
4
6
|
multiple?: boolean;
|
|
@@ -15,3 +17,21 @@ export declare class ListBoxContext extends Context {
|
|
|
15
17
|
setSelected(value: string, checked: boolean): void;
|
|
16
18
|
constructor(opts: Getter<ListBoxOpts>, selected?: Box<string[]>);
|
|
17
19
|
}
|
|
20
|
+
export type ListBoxItemOpts = {
|
|
21
|
+
value: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare class ListBoxItemContext extends Context {
|
|
25
|
+
#private;
|
|
26
|
+
readonly listbox: ListBoxContext;
|
|
27
|
+
readonly opts: ListBoxItemOpts;
|
|
28
|
+
readonly filter?: FilterContext;
|
|
29
|
+
get selected(): boolean;
|
|
30
|
+
set selected(value: boolean);
|
|
31
|
+
get value(): string;
|
|
32
|
+
constructor(opts: Getter<ListBoxItemOpts>, selected?: Box<boolean>);
|
|
33
|
+
toggle: () => void;
|
|
34
|
+
get visible(): boolean;
|
|
35
|
+
get disabled(): boolean | undefined;
|
|
36
|
+
props: (props?: HTMLAttributes<HTMLDivElement>) => HTMLAttributes<HTMLDivElement>;
|
|
37
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { box,
|
|
1
|
+
import { box, Context } from "@adriansyah/svelte-utils";
|
|
2
|
+
import { FilterContext } from "../filter";
|
|
3
|
+
import { onDestroy } from "svelte";
|
|
2
4
|
export class ListBoxContext extends Context {
|
|
3
5
|
#opts;
|
|
4
6
|
get opts() { return this.#opts; }
|
|
5
7
|
#selected;
|
|
6
|
-
get selected() { return
|
|
8
|
+
get selected() { return box.array(this.#selected); }
|
|
7
9
|
set selected(values) { this.#selected.current = values; }
|
|
8
10
|
get noSelected() { return this.selected.length === 0; }
|
|
9
11
|
isSelected(value) {
|
|
@@ -23,3 +25,55 @@ export class ListBoxContext extends Context {
|
|
|
23
25
|
this.#selected = selected;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
28
|
+
export class ListBoxItemContext extends Context {
|
|
29
|
+
listbox;
|
|
30
|
+
opts;
|
|
31
|
+
filter;
|
|
32
|
+
#selected;
|
|
33
|
+
get selected() { return this.#selected.current; }
|
|
34
|
+
set selected(value) { this.#selected.current = value; }
|
|
35
|
+
get value() { return this.opts.value; }
|
|
36
|
+
constructor(opts, selected = box(false)) {
|
|
37
|
+
super();
|
|
38
|
+
this.listbox = ListBoxContext.get();
|
|
39
|
+
this.filter = FilterContext.getOr();
|
|
40
|
+
this.opts = $derived.by(opts);
|
|
41
|
+
this.#selected = selected;
|
|
42
|
+
$effect(() => this.filter?.register(this.value));
|
|
43
|
+
onDestroy(() => {
|
|
44
|
+
this.listbox.setSelected(this.value, false);
|
|
45
|
+
});
|
|
46
|
+
box.link(box(() => this.listbox.isSelected(this.value), v => this.listbox.setSelected(this.value, v)), selected);
|
|
47
|
+
}
|
|
48
|
+
toggle = () => {
|
|
49
|
+
this.selected = !this.selected;
|
|
50
|
+
};
|
|
51
|
+
get visible() {
|
|
52
|
+
return this.filter === undefined || this.filter.matches(this.value);
|
|
53
|
+
}
|
|
54
|
+
get disabled() {
|
|
55
|
+
return this.opts.disabled || this.listbox.opts.disabled;
|
|
56
|
+
}
|
|
57
|
+
props = (props) => {
|
|
58
|
+
return {
|
|
59
|
+
onkeydown: ev => {
|
|
60
|
+
this.#onKeyDown(ev);
|
|
61
|
+
props?.onkeydown?.(ev);
|
|
62
|
+
},
|
|
63
|
+
onclick: ev => {
|
|
64
|
+
this.toggle();
|
|
65
|
+
props?.onclick?.(ev);
|
|
66
|
+
},
|
|
67
|
+
"data-disabled": this.disabled,
|
|
68
|
+
"aria-disabled": this.disabled,
|
|
69
|
+
tabindex: 0,
|
|
70
|
+
role: "checkbox"
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
#onKeyDown(ev) {
|
|
74
|
+
if (ev.code === "Space" ||
|
|
75
|
+
(ev.code === "Enter" && ev.target === ev.currentTarget)) {
|
|
76
|
+
this.toggle();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|