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; descriptionIds?: string;
} }
const DESCRIPTION_CONTEXT_NAME = "DescriptionContext"; const DESCRIPTION_CONTEXT_NAME = "headlessui-description-context";
export function useDescriptionContext(): export function useDescriptionContext():
| Writable<DescriptionContext> | Writable<DescriptionContext>
| undefined { | undefined {

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import { getContext, setContext } from "svelte"; 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 { export function usePanelContext(): string | undefined {
return getContext(DISCLOSURE_PANEL_CONTEXT_NAME); return getContext(DISCLOSURE_PANEL_CONTEXT_NAME);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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