Skip to content

Commit

Permalink
Improve types (huntabyte#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Oct 24, 2023
1 parent e645ad2 commit 2c406b2
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-tomatoes-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

Improve prop and `onChange` types
4 changes: 2 additions & 2 deletions src/lib/bits/alert-dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import type { CustomEventHandler } from "$lib/index.js";

type Props = Expand<
OmitOpen<Omit<CreateDialogProps, "role">> & {
open?: CreateDialogProps["defaultOpen"] & {};
onOpenChange?: OnChangeFn<CreateDialogProps["defaultOpen"]>;
open?: boolean & {};
onOpenChange?: OnChangeFn<boolean>;
}
>;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/checkbox/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { HTMLButtonAttributes, HTMLInputAttributes } from "svelte/elements"

type Props = Expand<
OmitChecked<CreateCheckboxProps> & {
checked?: CreateCheckboxProps["defaultChecked"] & {};
onCheckedChange?: OnChangeFn<CreateCheckboxProps["defaultChecked"]>;
checked?: boolean | "indeterminate";
onCheckedChange?: OnChangeFn<boolean | "indeterminate">;
} & AsChild
> &
HTMLButtonAttributes;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/collapsible/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { HTMLButtonAttributes } from "svelte/elements";

type Props = Expand<
OmitOpen<CreateCollapsibleProps> & {
open?: CreateCollapsibleProps["defaultOpen"] & {};
onOpenChange?: OnChangeFn<CreateCollapsibleProps["defaultOpen"]> & {};
open?: boolean;
onOpenChange?: OnChangeFn<boolean>;
}
> &
AsChild &
Expand Down
8 changes: 4 additions & 4 deletions src/lib/bits/context-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import type {

type Props = Expand<
OmitOpen<CreateContextMenuProps> & {
open?: CreateContextMenuProps["defaultOpen"] & {};
onOpenChange?: OnChangeFn<CreateContextMenuProps["defaultOpen"]>;
open?: boolean;
onOpenChange?: OnChangeFn<boolean>;
}
>;

type CheckboxItemProps = Expand<
OmitChecked<CreateContextMenuCheckboxItemProps> & {
checked?: CreateContextMenuCheckboxItemProps["defaultChecked"] & {};
onCheckedChange?: OnChangeFn<CreateContextMenuCheckboxItemProps["defaultChecked"]>;
checked?: boolean | "indeterminate";
onCheckedChange?: OnChangeFn<boolean | "indeterminate">;
} & AsChild
> &
HTMLDivAttributes;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bits/dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { CustomEventHandler } from "$lib/index.js";
type Props = Expand<
OmitOpen<Omit<CreateDialogProps, "role">> & {
open?: CreateDialogProps["defaultOpen"] & {};
onOpenChange?: OnChangeFn<boolean | undefined>;
onOpenChange?: OnChangeFn<boolean>;
}
>;

Expand Down
8 changes: 4 additions & 4 deletions src/lib/bits/dropdown-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import type { HTMLAnchorAttributes, HTMLButtonAttributes } from "svelte/elements

type Props = Expand<
OmitOpen<CreateDropdownMenuProps> & {
open?: CreateDropdownMenuProps["defaultOpen"] & {};
onOpenChange?: OnChangeFn<CreateDropdownMenuProps["defaultOpen"]>;
open?: boolean;
onOpenChange?: OnChangeFn<boolean>;
}
>;

type CheckboxItemProps = Expand<
OmitChecked<CreateDropdownMenuCheckboxItemProps> & {
checked?: CreateDropdownMenuCheckboxItemProps["defaultChecked"] & {};
onCheckedChange?: OnChangeFn<CreateDropdownMenuCheckboxItemProps["defaultChecked"]>;
checked?: boolean | "indeterminate";
onCheckedChange?: OnChangeFn<boolean | "indeterminate">;
} & AsChild
> &
HTMLDivAttributes;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/link-preview/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { HTMLAnchorAttributes } from "svelte/elements";

type Props = Expand<
OmitOpen<CreateLinkPreviewProps> & {
open?: CreateLinkPreviewProps["defaultOpen"];
onOpenChange?: OnChangeFn<CreateLinkPreviewProps["defaultOpen"]>;
open?: boolean;
onOpenChange?: OnChangeFn<boolean>;
}
>;

Expand Down
8 changes: 4 additions & 4 deletions src/lib/bits/menubar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ type Props = Expand<CreateMenubarProps & AsChild> & HTMLDivAttributes;

type MenuProps = Expand<
OmitOpen<CreateMenubarMenuProps> & {
open?: CreateMenubarMenuProps["defaultOpen"] & {};
onOpenChange?: OnChangeFn<CreateMenubarMenuProps["defaultOpen"]>;
open?: boolean;
onOpenChange?: OnChangeFn<boolean>;
}
>;

type CheckboxItemProps = Expand<
OmitChecked<CreateMenuCheckboxItemProps> & {
checked?: CreateMenuCheckboxItemProps["defaultChecked"] & {};
onCheckedChange?: OnChangeFn<CreateMenuCheckboxItemProps["defaultChecked"]>;
checked?: boolean | "indeterminate";
onCheckedChange?: OnChangeFn<boolean | "indeterminate">;
disabled?: boolean;
} & AsChild
> &
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/popover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { HTMLButtonAttributes } from "svelte/elements";

type Props = Expand<
OmitOpen<CreatePopoverProps> & {
open?: CreatePopoverProps["defaultOpen"];
onOpenChange?: OnChangeFn<CreatePopoverProps["defaultOpen"]>;
open?: boolean;
onOpenChange?: OnChangeFn<boolean>;
}
>;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Props = Expand<
OmitOpen<Omit<CreateSelectProps, "selected" | "defaultSelected" | "onSelectedChange">> & {
selected?: CreateSelectProps["defaultSelected"] & {};
onSelectedChange?: OnChangeFn<CreateSelectProps["defaultSelected"]>;
open?: CreateSelectProps["defaultOpen"] & {};
onOpenChange?: OnChangeFn<CreateSelectProps["defaultOpen"]>;
open?: boolean & {};
onOpenChange?: OnChangeFn<boolean>;
}
>;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/switch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { CustomEventHandler } from "$lib/index.js";

type Props = Expand<
OmitChecked<CreateSwitchProps> & {
checked?: CreateSwitchProps["defaultChecked"] & {};
onCheckedChange?: OnChangeFn<CreateSwitchProps["defaultChecked"]>;
checked?: boolean;
onCheckedChange?: OnChangeFn<boolean>;
} & AsChild
> &
HTMLButtonAttributes;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/toggle/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { CustomEventHandler } from "$lib/index.js";

type Props = Expand<
OmitPressed<CreateToggleProps> & {
pressed?: CreateToggleProps["defaultPressed"];
onPressedChange?: OnChangeFn<CreateToggleProps["defaultPressed"]>;
pressed?: boolean;
onPressedChange?: OnChangeFn<boolean>;
} & AsChild
> &
HTMLButtonAttributes;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/tooltip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { CustomEventHandler } from "$lib";

type Props = Expand<
OmitOpen<CreateTooltipProps> & {
open?: CreateTooltipProps["defaultOpen"] & {};
onOpenChange?: OnChangeFn<CreateTooltipProps["defaultOpen"]>;
open?: boolean & {};
onOpenChange?: OnChangeFn<boolean>;
}
>;

Expand Down

0 comments on commit 2c406b2

Please sign in to comment.