Move to using writable<T> syntax
This commit is contained in:
@@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext, setContext } from "svelte";
|
import { getContext, setContext } from "svelte";
|
||||||
import type { Readable, Writable } from "svelte/store";
|
import type { Readable } from "svelte/store";
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
export let name: string;
|
export let name: string;
|
||||||
export let slotProps = {};
|
export let slotProps = {};
|
||||||
let descriptionIds: string[] = [];
|
let descriptionIds: string[] = [];
|
||||||
let contextStore: Writable<DescriptionContext> = writable({
|
let contextStore = writable<DescriptionContext>({
|
||||||
name,
|
name,
|
||||||
slotProps,
|
slotProps,
|
||||||
props: $$restProps,
|
props: $$restProps,
|
||||||
|
|||||||
@@ -128,7 +128,7 @@
|
|||||||
|
|
||||||
let titleId: StateDefinition["titleId"];
|
let titleId: StateDefinition["titleId"];
|
||||||
|
|
||||||
let api: Writable<StateDefinition> = writable({
|
let api = writable<StateDefinition>({
|
||||||
titleId,
|
titleId,
|
||||||
dialogState,
|
dialogState,
|
||||||
setTitleId(id?: string) {
|
setTitleId(id?: string) {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
let panelStore: StateDefinition["panelStore"] = writable(null);
|
let panelStore: StateDefinition["panelStore"] = writable(null);
|
||||||
let buttonStore: StateDefinition["buttonStore"] = writable(null);
|
let buttonStore: StateDefinition["buttonStore"] = writable(null);
|
||||||
|
|
||||||
let api: Writable<StateDefinition> = writable({
|
let api = writable<StateDefinition>({
|
||||||
buttonId,
|
buttonId,
|
||||||
panelId,
|
panelId,
|
||||||
disclosureState,
|
disclosureState,
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let openClosedState: Writable<State> = writable(
|
let openClosedState = writable<State>(
|
||||||
computeOpenClosedState(disclosureState)
|
computeOpenClosedState(disclosureState)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
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 from "$lib/utils/Render.svelte";
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
import { resolveButtonType } from "$lib/utils/resolve-button-type";
|
import { resolveButtonType } from "$lib/utils/resolve-button-type";
|
||||||
const forwardEvents = forwardEventsBuilder(get_current_component());
|
const forwardEvents = forwardEventsBuilder(get_current_component());
|
||||||
@@ -25,7 +24,7 @@
|
|||||||
$: isWithinPanel =
|
$: isWithinPanel =
|
||||||
panelContext === null ? false : panelContext === $api.panelId;
|
panelContext === null ? false : panelContext === $api.panelId;
|
||||||
|
|
||||||
let ourStore: Writable<HTMLElement | null> = writable(null);
|
let ourStore = writable<HTMLElement | null>(null);
|
||||||
$: if (!isWithinPanel) ourStore = buttonStore;
|
$: if (!isWithinPanel) ourStore = buttonStore;
|
||||||
|
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
export let name: string;
|
export let name: string;
|
||||||
export let slotProps = {};
|
export let slotProps = {};
|
||||||
let labelIds: string[] = [];
|
let labelIds: string[] = [];
|
||||||
let contextStore: Writable<LabelContext> = writable({
|
let contextStore = writable<LabelContext>({
|
||||||
name,
|
name,
|
||||||
slotProps,
|
slotProps,
|
||||||
props: $$restProps,
|
props: $$restProps,
|
||||||
|
|||||||
2
src/lib/components/label/label.test.ts
vendored
2
src/lib/components/label/label.test.ts
vendored
@@ -138,7 +138,7 @@ it("should be possible to render a Label with an `as` prop", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should be possible to change the props of a Label", async () => {
|
it("should be possible to change the props of a Label", async () => {
|
||||||
let classStore: Writable<string | null> = writable(null);
|
let classStore = writable<string | null>(null);
|
||||||
let { container } = render(svelte`
|
let { container } = render(svelte`
|
||||||
<LabelProvider name={"test"} let:labelledby>
|
<LabelProvider name={"test"} let:labelledby>
|
||||||
<div aria-labelledby={labelledby}>
|
<div aria-labelledby={labelledby}>
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
let searchQuery: StateDefinition["searchQuery"] = "";
|
let searchQuery: StateDefinition["searchQuery"] = "";
|
||||||
let activeOptionIndex: StateDefinition["activeOptionIndex"] = null;
|
let activeOptionIndex: StateDefinition["activeOptionIndex"] = null;
|
||||||
|
|
||||||
let api: Writable<StateDefinition> = writable({
|
let api = writable<StateDefinition>({
|
||||||
listboxState,
|
listboxState,
|
||||||
value,
|
value,
|
||||||
labelRef,
|
labelRef,
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
let searchQuery: StateDefinition["searchQuery"] = "";
|
let searchQuery: StateDefinition["searchQuery"] = "";
|
||||||
let activeItemIndex: StateDefinition["activeItemIndex"] = null;
|
let activeItemIndex: StateDefinition["activeItemIndex"] = null;
|
||||||
|
|
||||||
let api: Writable<StateDefinition> = writable({
|
let api = writable<StateDefinition>({
|
||||||
menuState,
|
menuState,
|
||||||
buttonStore,
|
buttonStore,
|
||||||
itemsStore: itemsStore,
|
itemsStore: itemsStore,
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
if (!event.defaultPrevented) $buttonStore?.focus({ preventScroll: true });
|
if (!event.defaultPrevented) $buttonStore?.focus({ preventScroll: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
let openClosedState: Writable<State> | undefined = writable(State.Closed);
|
let openClosedState = writable<State>(State.Closed);
|
||||||
useOpenClosedProvider(openClosedState);
|
useOpenClosedProvider(openClosedState);
|
||||||
|
|
||||||
$: $openClosedState = match(menuState, {
|
$: $openClosedState = match(menuState, {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
let panel: StateDefinition["panel"] = writable(null);
|
let panel: StateDefinition["panel"] = writable(null);
|
||||||
let button: StateDefinition["button"] = writable(null);
|
let button: StateDefinition["button"] = writable(null);
|
||||||
|
|
||||||
let api: Writable<StateDefinition> = writable({
|
let api = writable<StateDefinition>({
|
||||||
popoverState,
|
popoverState,
|
||||||
buttonId,
|
buttonId,
|
||||||
panelId,
|
panelId,
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
});
|
});
|
||||||
setContext(POPOVER_CONTEXT_NAME, api);
|
setContext(POPOVER_CONTEXT_NAME, api);
|
||||||
|
|
||||||
let openClosedState: Writable<State> = writable(State.Closed);
|
let openClosedState = writable<State>(State.Closed);
|
||||||
useOpenClosedProvider(openClosedState);
|
useOpenClosedProvider(openClosedState);
|
||||||
|
|
||||||
$: $openClosedState = match(popoverState, {
|
$: $openClosedState = match(popoverState, {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
change: any;
|
change: any;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
let api: Writable<StateDefinition> = writable({
|
let api = writable<StateDefinition>({
|
||||||
options,
|
options,
|
||||||
value,
|
value,
|
||||||
disabled,
|
disabled,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
let switchStore: StateDefinition["switchStore"] = writable(null);
|
let switchStore: StateDefinition["switchStore"] = writable(null);
|
||||||
|
|
||||||
let api: Writable<StateDefinition> = writable({
|
let api = writable<StateDefinition>({
|
||||||
switchStore,
|
switchStore,
|
||||||
});
|
});
|
||||||
setContext(SWITCH_CONTEXT_NAME, api);
|
setContext(SWITCH_CONTEXT_NAME, api);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
let api: Writable<StateDefinition> = writable({
|
let api = writable<StateDefinition>({
|
||||||
selectedIndex,
|
selectedIndex,
|
||||||
orientation: vertical ? "vertical" : "horizontal",
|
orientation: vertical ? "vertical" : "horizontal",
|
||||||
activation: manual ? "manual" : "auto",
|
activation: manual ? "manual" : "auto",
|
||||||
|
|||||||
@@ -7,14 +7,13 @@
|
|||||||
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, { Features } from "$lib/utils/Render.svelte";
|
import Render, { Features } from "$lib/utils/Render.svelte";
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
const forwardEvents = forwardEventsBuilder(get_current_component());
|
const forwardEvents = forwardEventsBuilder(get_current_component());
|
||||||
|
|
||||||
export let as: SupportedAs = "div";
|
export let as: SupportedAs = "div";
|
||||||
export let use: HTMLActionArray = [];
|
export let use: HTMLActionArray = [];
|
||||||
|
|
||||||
let elementRef: Writable<HTMLElement | null> = writable(null);
|
let elementRef = writable<HTMLElement | null>(null);
|
||||||
let api = useTabsContext("TabPanel");
|
let api = useTabsContext("TabPanel");
|
||||||
let id = `headlessui-tabs-panel-${useId()}`;
|
let id = `headlessui-tabs-panel-${useId()}`;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher, onMount, setContext } from "svelte";
|
import { createEventDispatcher, onMount, setContext } from "svelte";
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
import { match } from "$lib/utils/match";
|
import { match } from "$lib/utils/match";
|
||||||
import { State, useOpenClosedProvider } from "$lib/internal/open-closed";
|
import { State, useOpenClosedProvider } from "$lib/internal/open-closed";
|
||||||
@@ -60,7 +59,7 @@
|
|||||||
$: strategy =
|
$: strategy =
|
||||||
$$props.unmount === false ? RenderStrategy.Hidden : RenderStrategy.Unmount;
|
$$props.unmount === false ? RenderStrategy.Hidden : RenderStrategy.Unmount;
|
||||||
|
|
||||||
let nesting: Writable<NestingContextValues> = writable(
|
let nesting = writable<NestingContextValues>(
|
||||||
useNesting(() => {
|
useNesting(() => {
|
||||||
// When all children have been unmounted we can only hide ourselves if and only if we are not
|
// When all children have been unmounted we can only hide ourselves if and only if we are not
|
||||||
// transitioning ourselves. Otherwise we would unmount before the transitions are finished.
|
// transitioning ourselves. Otherwise we would unmount before the transitions are finished.
|
||||||
@@ -174,7 +173,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContext(NESTING_CONTEXT_NAME, nesting);
|
setContext(NESTING_CONTEXT_NAME, nesting);
|
||||||
let openClosedState: Writable<State> = writable(State.Closed);
|
let openClosedState = writable<State>(State.Closed);
|
||||||
useOpenClosedProvider(openClosedState);
|
useOpenClosedProvider(openClosedState);
|
||||||
|
|
||||||
$: openClosedState.set(
|
$: openClosedState.set(
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount, setContext } from "svelte";
|
import { onMount, setContext } from "svelte";
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
import { match } from "$lib/utils/match";
|
import { match } from "$lib/utils/match";
|
||||||
import { State, useOpenClosed } from "$lib/internal/open-closed";
|
import { State, useOpenClosed } from "$lib/internal/open-closed";
|
||||||
@@ -69,14 +68,14 @@
|
|||||||
}
|
}
|
||||||
let state = shouldShow ? TreeStates.Visible : TreeStates.Hidden;
|
let state = shouldShow ? TreeStates.Visible : TreeStates.Hidden;
|
||||||
|
|
||||||
let nestingBag: Writable<NestingContextValues> = writable(
|
let nestingBag = writable<NestingContextValues>(
|
||||||
useNesting(() => {
|
useNesting(() => {
|
||||||
state = TreeStates.Hidden;
|
state = TreeStates.Hidden;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
let initial = true;
|
let initial = true;
|
||||||
let transitionBag: Writable<TransitionContextValues> = writable();
|
let transitionBag = writable<TransitionContextValues>();
|
||||||
$: transitionBag.set({
|
$: transitionBag.set({
|
||||||
show: !!shouldShow,
|
show: !!shouldShow,
|
||||||
appear: appear || !initial,
|
appear: appear || !initial,
|
||||||
|
|||||||
Reference in New Issue
Block a user