Standardize context naming

Fixes #7
This commit is contained in:
Ryan Gossiaux
2021-12-18 23:18:45 -08:00
parent 03399fc954
commit 70910c05b0
16 changed files with 20 additions and 18 deletions

View File

@@ -6,7 +6,7 @@
descriptionIds?: string;
}
const DESCRIPTION_CONTEXT_NAME = "DescriptionContext";
const DESCRIPTION_CONTEXT_NAME = "headlessui-description-context";
export function useDescriptionContext():
| Writable<DescriptionContext>
| undefined {

View File

@@ -22,7 +22,7 @@
close(): void;
}
const DIALOG_CONTEXT_NAME = "DialogContext";
const DIALOG_CONTEXT_NAME = "headlessui-dialog-context";
export function useDialogContext(
component: string

View File

@@ -22,7 +22,7 @@
close(focusableElement: HTMLElement | HTMLElement | null): void;
}
let DISCLOSURE_CONTEXT_NAME = "DisclosureContext";
let DISCLOSURE_CONTEXT_NAME = "headlessui-disclosure-context";
export function useDisclosureContext(
component: string

View File

@@ -1,6 +1,6 @@
<script lang="ts" context="module">
import { getContext, setContext } from "svelte";
let DISCLOSURE_PANEL_CONTEXT_NAME = "DisclosurePanelContext";
let DISCLOSURE_PANEL_CONTEXT_NAME = "headlessui-disclosure-panel-context";
export function usePanelContext(): string | undefined {
return getContext(DISCLOSURE_PANEL_CONTEXT_NAME);

View File

@@ -6,7 +6,7 @@
labelIds?: string;
}
const LABEL_CONTEXT_NAME = "LabelContext";
const LABEL_CONTEXT_NAME = "headlessui-label-context";
export function useLabelContext(): Writable<LabelContext> | undefined {
return getContext(LABEL_CONTEXT_NAME);
}

View File

@@ -35,7 +35,7 @@
select(value: unknown): void;
};
const LISTBOX_CONTEXT_NAME = "ListboxContext";
const LISTBOX_CONTEXT_NAME = "headlessui-listbox-context";
export function useListboxContext(
component: string
): Writable<StateDefinition> {

View File

@@ -32,7 +32,7 @@
unregisterItem(id: string): void;
};
const MENU_CONTEXT_NAME = "MenuContext";
const MENU_CONTEXT_NAME = "headlessui-menu-context";
export function useMenuContext(
componentName: string

View File

@@ -25,7 +25,7 @@
close(): void;
}
const POPOVER_CONTEXT_NAME = "PopoverContext";
const POPOVER_CONTEXT_NAME = "headlessui-popover-context";
export function usePopoverContext(
component: string
): Writable<StateDefinition> {

View File

@@ -6,7 +6,7 @@
closeOthers(buttonId: string): void;
}
const POPOVER_GROUP_CONTEXT_NAME = "PopoverGroupContext";
const POPOVER_GROUP_CONTEXT_NAME = "headlessui-popover-group-context";
export function usePopoverGroupContext(): PopoverGroupContext | undefined {
return getContext(POPOVER_GROUP_CONTEXT_NAME);
}

View File

@@ -1,7 +1,7 @@
<script lang="ts" context="module">
export type PopoverPanelContext = string | null;
const POPOVER_PANEL_CONTEXT_NAME = "PopoverPanelContext";
const POPOVER_PANEL_CONTEXT_NAME = "headlessui-popover-panel-context";
export function usePopoverPanelContext():
| StateDefinition["panelId"]
| undefined {

View File

@@ -26,7 +26,7 @@
unregisterOption(id: Option["id"]): void;
}
const RADIO_GROUP_CONTEXT_NAME = "RadioGroupContext";
const RADIO_GROUP_CONTEXT_NAME = "headlessui-radio-group-context";
export function useRadioGroupContext(
component: string
): Writable<StateDefinition> {

View File

@@ -3,7 +3,7 @@
switchStore: Writable<HTMLButtonElement | null>;
}
const SWITCH_CONTEXT_NAME = "SwitchContext";
const SWITCH_CONTEXT_NAME = "headlessui-switch-context";
export function useSwitchContext(): Writable<StateDefinition> | undefined {
return getContext(SWITCH_CONTEXT_NAME);
}

View File

@@ -25,7 +25,7 @@
unregisterPanel(panel: string): void;
};
const TABS_CONTEXT_NAME = "TabsContext";
const TABS_CONTEXT_NAME = "headlessui-tabs-context";
export function useTabsContext(component: string): Writable<StateDefinition> {
let context: Writable<StateDefinition> | undefined =

View File

@@ -17,8 +17,8 @@
appear: boolean;
}
const TRANSITION_CONTEXT_NAME = "TransitionContext";
export const NESTING_CONTEXT_NAME = "NestingContext";
const TRANSITION_CONTEXT_NAME = "headlessui-transition-context";
export const NESTING_CONTEXT_NAME = "headlessui-nesting-context";
export function hasTransitionContext() {
return getContext(TRANSITION_CONTEXT_NAME) !== undefined;
}

View File

@@ -3,6 +3,8 @@
Add,
Remove,
}
const STACK_CONTEXT_NAME = "headlessui-stack-context";
</script>
<script lang="ts">
@@ -14,9 +16,9 @@
export let element: HTMLElement | null;
let parentUpdateStore: Writable<OnUpdate> | undefined =
getContext("StackContext");
getContext(STACK_CONTEXT_NAME);
let notifyStore: Writable<OnUpdate> = writable(() => {});
setContext("StackContext", notifyStore);
setContext(STACK_CONTEXT_NAME, notifyStore);
$: notifyStore.set((...args: Parameters<OnUpdate>) => {
// Notify our layer

View File

@@ -6,7 +6,7 @@ export enum State {
Closed,
}
const OPEN_CLOSED_CONTEXT_NAME = "OpenClosed";
const OPEN_CLOSED_CONTEXT_NAME = "headlessui-open-closed-context";
export function hasOpenClosed() {
return useOpenClosed() !== undefined;
}