Run prettier over everything and fix some imports

This commit is contained in:
Ryan Gossiaux
2021-12-13 18:22:16 -08:00
parent 3bf974a654
commit 82b138f0ae
63 changed files with 3317 additions and 3319 deletions

View File

@@ -1,91 +1,91 @@
<script lang="ts">
import { onDestroy } from "svelte";
import DescriptionProvider from "./DescriptionProvider.svelte";
import LabelProvider from "./LabelProvider.svelte";
import { onDestroy } from "svelte";
import DescriptionProvider from "./DescriptionProvider.svelte";
import LabelProvider from "./LabelProvider.svelte";
import { useRadioGroupContext, Option } from "./RadioGroup.svelte";
import { useId } from "./use-id";
import { useRadioGroupContext, Option } from "./RadioGroup.svelte";
import { useId } from "$lib/hooks/use-id";
enum OptionState {
Empty = 1 << 0,
Active = 1 << 1,
}
enum OptionState {
Empty = 1 << 0,
Active = 1 << 1,
}
export let value: any;
export let disabled: boolean = false;
let api = useRadioGroupContext("RadioGroupOption");
let id = `headlessui-radiogroup-option-${useId()}`;
let optionRef: HTMLElement | null = null;
$: propsRef = { value, disabled };
let state = OptionState.Empty;
export let value: any;
export let disabled: boolean = false;
let api = useRadioGroupContext("RadioGroupOption");
let id = `headlessui-radiogroup-option-${useId()}`;
let optionRef: HTMLElement | null = null;
$: propsRef = { value, disabled };
let state = OptionState.Empty;
function updateOption(option: Option) {
$api?.unregisterOption(option.id);
$api?.registerOption(option);
}
$: updateOption({ id, element: optionRef, propsRef });
onDestroy(() => $api?.unregisterOption(id));
function updateOption(option: Option) {
$api?.unregisterOption(option.id);
$api?.registerOption(option);
}
$: updateOption({ id, element: optionRef, propsRef });
onDestroy(() => $api?.unregisterOption(id));
$: isFirstOption = $api?.firstOption?.id === id;
$: isDisabled = $api?.disabled || disabled;
$: checked = $api?.value === value;
$: isFirstOption = $api?.firstOption?.id === id;
$: isDisabled = $api?.disabled || disabled;
$: checked = $api?.value === value;
$: tabIndex = (() => {
if (isDisabled) return -1;
if (checked) return 0;
if (!$api.containsCheckedOption && isFirstOption) return 0;
return -1;
})();
$: tabIndex = (() => {
if (isDisabled) return -1;
if (checked) return 0;
if (!$api.containsCheckedOption && isFirstOption) return 0;
return -1;
})();
function handleClick() {
if (!$api.change(value)) return;
function handleClick() {
if (!$api.change(value)) return;
state |= OptionState.Active;
optionRef?.focus();
}
function handleFocus() {
state |= OptionState.Active;
}
function handleBlur() {
state &= ~OptionState.Active;
}
state |= OptionState.Active;
optionRef?.focus();
}
function handleFocus() {
state |= OptionState.Active;
}
function handleBlur() {
state &= ~OptionState.Active;
}
$: classStyle = $$props.class
? typeof $$props.class === "function"
? $$props.class({
active: state & OptionState.Active,
checked,
disabled: isDisabled,
})
: $$props.class
: "";
$: classStyle = $$props.class
? typeof $$props.class === "function"
? $$props.class({
active: state & OptionState.Active,
checked,
disabled: isDisabled,
})
: $$props.class
: "";
$: propsWeControl = {
id,
class: classStyle,
role: "radio",
"aria-checked": checked ? ("true" as const) : ("false" as const),
"aria-disabled": isDisabled ? true : undefined,
tabIndex: tabIndex,
};
$: propsWeControl = {
id,
class: classStyle,
role: "radio",
"aria-checked": checked ? ("true" as const) : ("false" as const),
"aria-disabled": isDisabled ? true : undefined,
tabIndex: tabIndex,
};
</script>
<DescriptionProvider name="RadioGroup.Description" let:describedby>
<LabelProvider name="RadioGroup.Label" let:labelledby>
<div
{...{ ...$$restProps, ...propsWeControl }}
bind:this={optionRef}
aria-labelledby={labelledby}
aria-describedby={describedby}
on:click={isDisabled ? undefined : handleClick}
on:focus={isDisabled ? undefined : handleFocus}
on:blur={isDisabled ? undefined : handleBlur}
>
<slot
{checked}
disabled={isDisabled}
active={state & OptionState.Active}
/>
</div>
</LabelProvider>
<LabelProvider name="RadioGroup.Label" let:labelledby>
<div
{...{ ...$$restProps, ...propsWeControl }}
bind:this={optionRef}
aria-labelledby={labelledby}
aria-describedby={describedby}
on:click={isDisabled ? undefined : handleClick}
on:focus={isDisabled ? undefined : handleFocus}
on:blur={isDisabled ? undefined : handleBlur}
>
<slot
{checked}
disabled={isDisabled}
active={state & OptionState.Active}
/>
</div>
</LabelProvider>
</DescriptionProvider>