@veracity/vui
Version:
Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.
67 lines (66 loc) • 2.77 kB
JavaScript
//#region src/notification/utils.ts
/** Canonical hierarchy keys recognised by the two-prop API. */
const HIERARCHY_KEYS = /* @__PURE__ */ new Set(["inline", "banner"]);
/** The banner hierarchy key. */
const BANNER_HIERARCHY = "banner";
/** Default intent applied when none is specified. */
const DEFAULT_INTENT = "info";
/** Default variant hierarchy applied when none is specified. */
const DEFAULT_VARIANT = "inline";
/**
* Capitalises the first character of a string.
* Mirrors button/utils.ts — used to compose theme keys the same way theme.ts generates them.
*/
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
/**
* Converts a two-prop variant+intent pair into the combined theme key used internally
* (e.g. `resolveNotificationVariant('inline', 'info') => { themeKey: 'inlineInfo', isBanner: false }`).
* When `intent` is omitted, `DEFAULT_INTENT` ('info') is used.
*
* If `variant` is already a fully-qualified legacy key (e.g. `'inlineBlue'`, `'bannerRed'`)
* it is returned unchanged so the new API is backward-compatible.
*
* Returns `{ themeKey: 'inlineInfo', isBanner: false }` (the default) when `variant` is absent.
*/
const resolveNotificationVariant = (variant = DEFAULT_VARIANT, intent = DEFAULT_INTENT) => {
const themeKey = !variant ? `${DEFAULT_VARIANT}${capitalize(DEFAULT_INTENT)}` : !HIERARCHY_KEYS.has(variant) ? variant : `${variant}${capitalize(intent)}`;
return {
themeKey,
isBanner: themeKey.startsWith(BANNER_HIERARCHY)
};
};
/**
* Q2 — Infers the layout from content composition. No `layout` prop exists; this
* is the single source of truth for visual layout.
*
* - `action` present → `'button-down'`
* - both `title` and `text` present → `'multiline'`
* - otherwise → `'one-line'`
*/
const inferNotificationLayout = (args) => {
if (args.hasStatus) return "one-line";
if (args.action != null && args.action !== false && args.action !== "") return "button-down";
if (args.title != null && args.title !== "" && args.text != null && args.text !== "") return "multiline";
return "one-line";
};
/**
* Q4 — Auto-maps intent to the appropriate ARIA role / aria-live politeness.
* `isLoading` forces `role="status"` / `aria-live="polite"` regardless of intent.
*/
const resolveNotificationAria = (args) => {
if (args.isLoading) return {
role: "status",
ariaLive: "polite"
};
return args.intent === "warning" || args.intent === "danger" ? {
role: "alert",
ariaLive: "assertive"
} : {
role: "status",
ariaLive: "polite"
};
};
//#endregion
export { DEFAULT_INTENT, DEFAULT_VARIANT, inferNotificationLayout, resolveNotificationAria, resolveNotificationVariant };
globalThis.__vuiVersion__ = "5.3.1"
//# sourceMappingURL=utils.js.map