Type RadioGroup with $$Props
This commit is contained in:
@@ -43,6 +43,14 @@
|
|||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TRadioGroupProps<
|
||||||
|
TSlotProps extends {},
|
||||||
|
TAsProp extends SupportedAs
|
||||||
|
> = TPassThroughProps<TSlotProps, TAsProp> & {
|
||||||
|
value: StateDefinition["value"];
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -51,25 +59,31 @@
|
|||||||
import { get_current_component } from "svelte/internal";
|
import { get_current_component } from "svelte/internal";
|
||||||
import type { SupportedAs } from "$lib/internal/elements";
|
import type { SupportedAs } from "$lib/internal/elements";
|
||||||
import type { HTMLActionArray } from "$lib/hooks/use-actions";
|
import type { HTMLActionArray } from "$lib/hooks/use-actions";
|
||||||
import Render from "$lib/utils/Render.svelte";
|
import Render, { type TPassThroughProps } from "$lib/utils/Render.svelte";
|
||||||
const forwardEvents = forwardEventsBuilder(get_current_component(), [
|
|
||||||
"change",
|
/***** Props *****/
|
||||||
]);
|
type TAsProp = $$Generic<SupportedAs>;
|
||||||
|
type $$Props = TRadioGroupProps<typeof slotProps, TAsProp>;
|
||||||
|
|
||||||
export let as: SupportedAs = "div";
|
export let as: SupportedAs = "div";
|
||||||
export let use: HTMLActionArray = [];
|
export let use: HTMLActionArray = [];
|
||||||
|
|
||||||
export let disabled = false;
|
|
||||||
export let value: StateDefinition["value"];
|
export let value: StateDefinition["value"];
|
||||||
|
export let disabled = false;
|
||||||
|
|
||||||
|
/***** Events *****/
|
||||||
|
const forwardEvents = forwardEventsBuilder(get_current_component(), [
|
||||||
|
"change",
|
||||||
|
]);
|
||||||
|
const dispatch = createEventDispatcher<{
|
||||||
|
change: any;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
/***** Component *****/
|
||||||
let radioGroupRef: HTMLElement | null = null;
|
let radioGroupRef: HTMLElement | null = null;
|
||||||
let options: StateDefinition["options"] = [];
|
let options: StateDefinition["options"] = [];
|
||||||
|
|
||||||
let id = `headlessui-radiogroup-${useId()}`;
|
let id = `headlessui-radiogroup-${useId()}`;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{
|
|
||||||
change: any;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
let api = writable<StateDefinition>({
|
let api = writable<StateDefinition>({
|
||||||
options,
|
options,
|
||||||
value,
|
value,
|
||||||
@@ -200,6 +214,8 @@
|
|||||||
id,
|
id,
|
||||||
role: "radiogroup",
|
role: "radiogroup",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$: slotProps = {};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<DescriptionProvider name="RadioGroupDescription" let:describedby>
|
<DescriptionProvider name="RadioGroupDescription" let:describedby>
|
||||||
@@ -208,14 +224,14 @@
|
|||||||
{...{ ...$$restProps, ...propsWeControl }}
|
{...{ ...$$restProps, ...propsWeControl }}
|
||||||
{as}
|
{as}
|
||||||
use={[...use, forwardEvents]}
|
use={[...use, forwardEvents]}
|
||||||
slotProps={{}}
|
{slotProps}
|
||||||
name={"RadioGroup"}
|
name={"RadioGroup"}
|
||||||
bind:el={radioGroupRef}
|
bind:el={radioGroupRef}
|
||||||
aria-labelledby={labelledby}
|
aria-labelledby={labelledby}
|
||||||
aria-describedby={describedby}
|
aria-describedby={describedby}
|
||||||
on:keydown={handleKeyDown}
|
on:keydown={handleKeyDown}
|
||||||
>
|
>
|
||||||
<slot />
|
<slot {...slotProps} />
|
||||||
</Render>
|
</Render>
|
||||||
</LabelProvider>
|
</LabelProvider>
|
||||||
</DescriptionProvider>
|
</DescriptionProvider>
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
|
<script lang="ts" context="module">
|
||||||
|
type TRadioGroupOptionProps<
|
||||||
|
TSlotProps extends {},
|
||||||
|
TAsProp extends SupportedAs
|
||||||
|
> = TPassThroughProps<TSlotProps, TAsProp> & {
|
||||||
|
value: unknown;
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onDestroy } from "svelte";
|
import { onDestroy } from "svelte";
|
||||||
import DescriptionProvider from "$lib/components/description/DescriptionProvider.svelte";
|
import DescriptionProvider from "$lib/components/description/DescriptionProvider.svelte";
|
||||||
@@ -9,19 +19,26 @@
|
|||||||
import { get_current_component } from "svelte/internal";
|
import { get_current_component } from "svelte/internal";
|
||||||
import type { SupportedAs } from "$lib/internal/elements";
|
import type { SupportedAs } from "$lib/internal/elements";
|
||||||
import type { HTMLActionArray } from "$lib/hooks/use-actions";
|
import type { HTMLActionArray } from "$lib/hooks/use-actions";
|
||||||
import Render from "$lib/utils/Render.svelte";
|
import Render, { type TPassThroughProps } from "$lib/utils/Render.svelte";
|
||||||
const forwardEvents = forwardEventsBuilder(get_current_component());
|
|
||||||
|
/***** Props *****/
|
||||||
|
type TAsProp = $$Generic<SupportedAs>;
|
||||||
|
type $$Props = TRadioGroupOptionProps<typeof slotProps, TAsProp>;
|
||||||
|
|
||||||
export let as: SupportedAs = "div";
|
export let as: SupportedAs = "div";
|
||||||
export let use: HTMLActionArray = [];
|
export let use: HTMLActionArray = [];
|
||||||
|
export let value: unknown;
|
||||||
|
export let disabled: boolean = false;
|
||||||
|
|
||||||
|
/***** Events *****/
|
||||||
|
const forwardEvents = forwardEventsBuilder(get_current_component());
|
||||||
|
|
||||||
|
/***** Component *****/
|
||||||
enum OptionState {
|
enum OptionState {
|
||||||
Empty = 1 << 0,
|
Empty = 1 << 0,
|
||||||
Active = 1 << 1,
|
Active = 1 << 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
export let value: unknown;
|
|
||||||
export let disabled: boolean = false;
|
|
||||||
let api = useRadioGroupContext("RadioGroupOption");
|
let api = useRadioGroupContext("RadioGroupOption");
|
||||||
let id = `headlessui-radiogroup-option-${useId()}`;
|
let id = `headlessui-radiogroup-option-${useId()}`;
|
||||||
let optionRef: HTMLElement | null = null;
|
let optionRef: HTMLElement | null = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user