@eldrajs/ui 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ import { Component } from 'vue';
2
+ import { UiMessages } from '../../composables/useMessages.js';
3
+ import { NavMenuItem, NavMenuLink, NavMenuPart, NavMenuVariant } from './types.js';
4
+ type __VLS_Props = {
5
+ item: NavMenuItem;
6
+ idPrefix: string;
7
+ placement: 'bar' | 'drawer';
8
+ variant: NavMenuVariant;
9
+ messages: UiMessages;
10
+ linkAs?: string | Component;
11
+ classes?: Partial<Record<NavMenuPart, string>>;
12
+ };
13
+ type __VLS_Slots = {
14
+ panelItem?: (props: {
15
+ link: NavMenuLink;
16
+ item: NavMenuItem;
17
+ }) => unknown;
18
+ groupHeading?: (props: {
19
+ group: string;
20
+ links: NavMenuLink[];
21
+ item: NavMenuItem;
22
+ }) => unknown;
23
+ };
24
+ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
25
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
26
+ declare const _default: typeof __VLS_export;
27
+ export default _default;
28
+ type __VLS_WithSlots<T, S> = T & {
29
+ new (): {
30
+ $slots: S;
31
+ };
32
+ };
@@ -0,0 +1,27 @@
1
+ import { Component } from 'vue';
2
+ import { NavMenuItem, NavMenuLink, NavMenuPanelLayout } from './types.js';
3
+ /** How the page the visitor is on is marked, on every kind of link the menu draws. */
4
+ export declare const CURRENT_PAGE = "aria-[current=page]:underline aria-[current=page]:decoration-2 aria-[current=page]:underline-offset-[0.2em]";
5
+ /** A run of panel entries under one column heading; `group` is `null` for entries without one. */
6
+ export interface NavMenuGroup {
7
+ group: string | null;
8
+ links: NavMenuLink[];
9
+ }
10
+ /** Whether an entry has visible text to render. */
11
+ export declare function isRenderableLink(link: NavMenuLink): boolean;
12
+ /** The entries a panel draws, without the ones that have nothing to show. */
13
+ export declare function panelLinks(item: NavMenuItem): NavMenuLink[];
14
+ /** Whether a top-level entry opens a panel rather than being a plain link. */
15
+ export declare function hasPanel(item: NavMenuItem): boolean;
16
+ /** Groups entries by their `group`, keeping the order each group first appears in. */
17
+ export declare function groupLinks(links: readonly NavMenuLink[]): NavMenuGroup[];
18
+ /** The panel's layout: the item's own, else `mega` when its entries are grouped into columns. */
19
+ export declare function panelLayout(item: NavMenuItem): NavMenuPanelLayout;
20
+ /** Whether the item, or an entry in its panel, is the page the visitor is on. */
21
+ export declare function containsCurrent(item: NavMenuItem): boolean;
22
+ /** Whether an entry goes somewhere; one without a destination renders as plain text. */
23
+ export declare function hasHref(link: NavMenuLink): boolean;
24
+ /** The element an entry renders as: `linkAs` (or `a`) with a destination, else `span`. */
25
+ export declare function navLinkTag(link: NavMenuLink, linkAs?: string | Component): string | Component;
26
+ /** An entry's link attributes; a component `linkAs` takes the destination as `to`. */
27
+ export declare function navLinkAttrs(link: NavMenuLink, linkAs?: string | Component): Record<string, unknown>;
@@ -0,0 +1,17 @@
1
+ import { Ref } from 'vue';
2
+ export interface NavMenuKeysOptions {
3
+ /** The bar's `<ul>`, one `<li>` per rendered entry. */
4
+ list: Ref<HTMLElement | null>;
5
+ /** The `items` index of the entry rendered at `position` in the list. */
6
+ indexAt: (position: number) => number;
7
+ /** The entry's panel, or `null` when it has none. */
8
+ panel: (index: number) => HTMLElement | null;
9
+ openIndex: Ref<number | null>;
10
+ open: (index: number) => void;
11
+ close: () => void;
12
+ }
13
+ /**
14
+ * The arrow keys of the APG disclosure navigation pattern, over the bar's own DOM: Left/Right and
15
+ * Home/End along the bar, Down/Up into and through a panel. Clamped, never wrapping.
16
+ */
17
+ export declare function useNavMenuKeys(options: NavMenuKeysOptions): (event: KeyboardEvent) => void;
@@ -0,0 +1,62 @@
1
+ import { Component } from 'vue';
2
+ import { UiMessages } from '../../composables/useMessages.js';
3
+ import { DrawerSide } from '../drawer/types.js';
4
+ /** One entry; `@eldrajs/theme-core`'s `ResolvedLink` (a resolved Studio link tree) fits it as is. */
5
+ export interface NavMenuLink {
6
+ /** The visible text. An entry with no label (`null` or empty) is not rendered. */
7
+ label: string | null;
8
+ /** The destination. Without one the entry renders as plain text, never a dead link. */
9
+ href?: string | null;
10
+ /** Opens in a new tab, with the hidden "opens in a new tab" text. */
11
+ newTab?: boolean;
12
+ /** A second line under the label, for a mega panel. */
13
+ description?: string | null;
14
+ /** A short tag after the label, such as "Coming soon". */
15
+ badge?: string | null;
16
+ /** The column heading this entry sits under; entries sharing one form a column. */
17
+ group?: string | null;
18
+ /** Marks the page the visitor is on (`aria-current="page"`). */
19
+ current?: boolean;
20
+ }
21
+ /** `dropdown` hangs a compact panel under its trigger; `mega` spans the menu's positioning box. */
22
+ export type NavMenuPanelLayout = 'dropdown' | 'mega';
23
+ /** One top-level entry: a link when it has no children, a button opening a panel when it has. */
24
+ export interface NavMenuItem extends NavMenuLink {
25
+ /** The panel's entries, one level deep. */
26
+ children?: readonly NavMenuLink[];
27
+ /** Default `mega` when any child has a `group`, else `dropdown`. */
28
+ layout?: NavMenuPanelLayout;
29
+ }
30
+ /** Below which viewport (`md`…) or nearest-container (`@tablet`…) breakpoint the bar becomes a menu button. */
31
+ export type NavMenuCollapse = 'md' | 'lg' | 'xl' | '@tablet' | '@content' | '@wide' | 'never' | 'always';
32
+ /** `ghost` fills an entry on hover, as `Button`'s ghost variant does; `muted` is `Link`'s muted tone. */
33
+ export type NavMenuVariant = 'ghost' | 'muted';
34
+ /** The parts a consumer can restyle through `classes`. */
35
+ export type NavMenuPart = 'root' | 'nav' | 'list' | 'item' | 'link' | 'trigger' | 'triggerIcon' | 'panel' | 'content' | 'overview' | 'columns' | 'group' | 'groupHeading' | 'panelList' | 'panelItem' | 'panelLink' | 'panelLabel' | 'description' | 'badge' | 'footer' | 'toggle' | 'toggleIcon' | 'drawer' | 'drawerList' | 'drawerItem' | 'drawerLink' | 'drawerTrigger' | 'drawerPanel' | 'drawerFooter';
36
+ export interface NavMenuProps {
37
+ /** The top-level entries, in order. */
38
+ items: readonly NavMenuItem[];
39
+ /** The bar's and its panels' look: `ghost` (default) fills on hover and while open, `muted` is quiet text. */
40
+ variant?: NavMenuVariant;
41
+ /** The open panel's index in `items` (two-way); `null` when none is open. */
42
+ modelValue?: number | null;
43
+ /** Whether the narrow-screen drawer is open (two-way, `update:drawerOpen`). */
44
+ drawerOpen?: boolean;
45
+ /** The navigation landmark's accessible name. Defaults to `messages.navMenuLabel`. */
46
+ ariaLabel?: string;
47
+ /** Below this breakpoint the bar collapses into the drawer. Default `lg`. */
48
+ collapseBelow?: NavMenuCollapse;
49
+ /** The edge the drawer slides in from. Default `left`. */
50
+ drawerSide?: DrawerSide;
51
+ /** Also open a panel when a mouse pointer rests 150ms on its trigger; leaving closes it again. */
52
+ openOnHover?: boolean;
53
+ /**
54
+ * Render every link as a different tag or component, such as a router link. A string is used as
55
+ * the tag and keeps `href`; a component receives the destination as `to`.
56
+ */
57
+ linkAs?: string | Component;
58
+ /** Message overrides. See `useMessages`. */
59
+ messages?: Partial<UiMessages>;
60
+ /** Per-part class overrides, merged with `tailwind-merge`. */
61
+ classes?: Partial<Record<NavMenuPart, string>>;
62
+ }