Type Listbox with $$Props

This commit is contained in:
Ryan Gossiaux
2022-02-07 17:04:13 -08:00
parent 168f7f1e3d
commit 231775e60b
7 changed files with 98 additions and 19 deletions

View File

@@ -50,6 +50,14 @@
return context;
}
type TListboxProps<
TSlotProps extends {},
TAsProp extends SupportedAs
> = TPassThroughProps<TSlotProps, TAsProp> & {
disabled?: boolean;
horizontal?: boolean;
value?: StateDefinition["value"];
};
</script>
<script lang="ts">
@@ -66,24 +74,32 @@
import { get_current_component } from "svelte/internal";
import type { SupportedAs } from "$lib/internal/elements";
import type { HTMLActionArray } from "$lib/hooks/use-actions";
import Render from "$lib/utils/Render.svelte";
const forwardEvents = forwardEventsBuilder(get_current_component(), [
"change",
]);
import Render, { type TPassThroughProps } from "$lib/utils/Render.svelte";
/***** Props *****/
type TAsProp = $$Generic<SupportedAs>;
type $$Props = TListboxProps<typeof slotProps, TAsProp>;
export let as: SupportedAs = "div";
export let use: HTMLActionArray = [];
export let disabled = false;
export let horizontal = false;
export let value: StateDefinition["value"];
$: orientation = (
horizontal ? "horizontal" : "vertical"
) as StateDefinition["orientation"];
/***** Events *****/
const forwardEvents = forwardEventsBuilder(get_current_component(), [
"change",
]);
const dispatch = createEventDispatcher<{
change: any;
}>();
/***** Component *****/
$: orientation = (
horizontal ? "horizontal" : "vertical"
) as StateDefinition["orientation"];
let listboxState: StateDefinition["listboxState"] = ListboxStates.Closed;
let labelRef: StateDefinition["labelRef"] = writable(null);
let buttonRef: StateDefinition["buttonRef"] = writable(null);