dap-design-system
Version:
Official design system for the DÁP (dap.gov.hu)
85 lines (84 loc) • 3.42 kB
TypeScript
export declare const isReducedMotion: boolean;
export declare function isMobileView(): boolean;
export declare function setFromParentSize(element: HTMLElement): void;
export declare function numberRange(start: number, end: number): number[];
export declare const JSONAttributeParser: (value: string | null) => {};
/**
* Normalizes a string value that might be null, undefined, or the string "null"/"undefined".
* This is useful for handling values from React/Next.js object spreads where null props
* can be serialized as the string "null".
*
* @param value - The value to normalize
* @returns An empty string if the value is null, undefined, or the string "null"/"undefined", otherwise the value
*
* @example
* ```typescript
* protected updated(changedProperties: Map<PropertyKey, unknown>): void {
* super.updated(changedProperties)
* if (changedProperties.has('title')) {
* this.title = normalizeStringProperty(this.title)
* }
* }
* ```
*/
export declare function normalizeStringProperty(value: string | null | undefined): string;
/**
* Lit property converter that handles null/undefined values from React/Next.js object spreads.
*
* When React serializes null props (e.g., from object spreads like {...props} where props.title = null),
* it can become the string "null" in HTML attributes. This converter normalizes these cases.
*
* @example
* ```typescript
* @property({
* converter: stringPropertyConverter
* })
* title: string
* ```
*
* This prevents the string "null" from appearing in the rendered output when:
* - Props come from object spreads with null values
* - React/Next.js serializes null as the string "null"
* - Properties are set directly (bypassing attribute conversion)
*
* Note: For direct property assignments (e.g., `element.title = null`), also use
* `normalizeStringProperty` in the `updated` lifecycle method.
*/
export declare const stringPropertyConverter: {
fromAttribute: (value: string | null) => string;
toAttribute: (value: string | null | undefined) => string | null;
};
/**
* Finds the nearest scrollable ancestor of an element, crossing shadow DOM and
* slot boundaries. Returns null if none is found before the document root.
*/
export declare function getScrollParent(element: Element): HTMLElement | null;
/**
* Reveals an element by scrolling only its nearest scrollable ancestor, without
* bubbling the scroll to outer ancestors. Unlike `Element.scrollIntoView`, which
* scrolls every scrollable ancestor up to the window, this keeps outer containers
* (e.g. a modal body or the page) still. That matters for an option deep inside a
* dropdown: revealing it must not scroll the trigger out of the viewport, which
* would otherwise fire the popup's viewport auto-close and snap the dropdown shut.
*/
export declare function scrollIntoContainer(element: HTMLElement): void;
export declare function getValidityStateObject(state: Partial<ValidityState>): {
badInput: boolean;
customError: boolean;
patternMismatch: boolean;
rangeOverflow: boolean;
rangeUnderflow: boolean;
stepMismatch: boolean;
tooLong: boolean;
tooShort: boolean;
typeMismatch: boolean;
valid: boolean;
valueMissing: boolean;
};
/**
* Converts a string to kebab-case.
*
* @param str - The string to convert
* @returns The kebab-cased string
*/
export declare function kebabCase(str: string): string;