@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
89 lines (88 loc) • 2.68 kB
TypeScript
/**
* header.ts
*
* Type definitions for header-related domain models.
* These represent user, organization, and menu item data structures.
*/
/**
* User object containing information about the logged-in user
*/
export interface User {
/** Full name of the user */
name: string;
/** Short name or initials (deprecated) */
shortname?: string;
/** Last login timestamp (ISO string or Date) */
lastLoggedIn?: Date | string;
}
/**
* Representation object containing information about the organization/entity being represented
*/
export interface Representing {
/** Name of the organization or entity */
name: string;
/** Short name or initials (deprecated) */
shortname?: string;
/** Organization number */
orgNumber?: string | number;
}
/**
* Menu item in the user menu
* The iconName will be typed as PktIconName in package-specific implementations
*/
export interface UserMenuItem<IconType = string> {
/** Icon name to display */
iconName?: IconType;
/** Text for the menu item */
title: string;
/** Link URL or click handler function */
target: string | (() => void);
}
/**
* Internal type for rendering links/buttons (supports both href and onClick)
* Base interface for discriminated union
*/
export interface InternalMenuItemBase<IconType = string> {
title: string;
iconName?: IconType;
}
/**
* Internal menu item that is a link
*/
export interface InternalMenuLink<IconType = string> extends InternalMenuItemBase<IconType> {
href: string;
}
/**
* Internal menu item that is a button
*/
export interface InternalMenuButton<IconType = string> extends InternalMenuItemBase<IconType> {
onClick: () => void;
}
/**
* Union type for internal menu items (discriminated by href vs onClick)
*/
export type TInternalMenuItem<IconType = string> = InternalMenuLink<IconType> | InternalMenuButton<IconType>;
/**
* Helper to convert UserMenuItem (with target) to internal format
*/
export declare const convertUserMenuItem: <IconType = string>(item: UserMenuItem<IconType>) => TInternalMenuItem<IconType>;
/**
* Variant for the slot menu button in tablet/mobile mode
*/
export type TSlotMenuVariant = 'icon-only' | 'icon-right';
/**
* Type for which menu is currently open in the header
*/
export type THeaderMenu = 'none' | 'slot' | 'search' | 'user';
/**
* Placement options for the logout button
*/
export type TLogOutButtonPlacement = 'userMenu' | 'header' | 'both' | 'none';
/**
* Position options for the header
*/
export type THeaderPosition = 'fixed' | 'relative';
/**
* Scroll behavior options for the header
*/
export type THeaderScrollBehavior = 'hide' | 'none';