@vectoriox/iox-ui 5.125.0 → 5.127.0

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.
@@ -1,5 +1,5 @@
1
1
  import { AccountRole, ShopRole } from '@vectoriox/iox-ui/composite-core';
2
- import { LinkType } from '@vectoriox/iox-ui/design-core';
2
+ import { LinkType, MenuButtonKind, menuButtonOf, menuButtonProps, menuDialogProps, MenuLook, MenuTrait } from '@vectoriox/iox-ui/design-core';
3
3
 
4
4
  import { PatternGlobalPosition } from './patterns';
5
5
  import { createSerializedNode, SerializedNode, walkSerialized } from './serialized-node';
@@ -90,6 +90,12 @@ export interface NavShapeOptions {
90
90
  /** HI-D15: the menu button at the start or the end of the bar (or of the side cell there). Default: where it already
91
91
  * is, else the end. */
92
92
  menuSide?: MenuSide | `${MenuSide}`;
93
+ /** HI2a: the menu's look — its form, how it opens, its button, what the mouse does in it, its phone form. Written as
94
+ * traits on the drawer, the menu button and the drawer's Close; a default writes nothing (R-H4). Absent: the parts
95
+ * keep what they have. */
96
+ look?: Partial<MenuLook>;
97
+ /** The site's language, for the words a menu button shows (`word`: Menu ⇄ Close). Default English. */
98
+ locale?: string;
93
99
  }
94
100
 
95
101
  export interface NavShapeResult {
@@ -122,10 +128,23 @@ const COMPOSED = { releaseLayoutDefaults: true };
122
128
  export const NAV_SHAPE_COPY = {
123
129
  menu: 'Menu',
124
130
  closeMenu: 'Close menu',
131
+ /** HI2a: the word a `word` menu button turns into while its menu is open. */
132
+ close: 'Close',
125
133
  more: 'More',
126
134
  home: 'Home',
127
135
  } as const;
128
136
 
137
+ /** The words a `word` menu button SHOWS, in the site's language (HI2a — visible words; the other parts' copy is still
138
+ * English and editable, as it always was). */
139
+ const MENU_WORDS: Readonly<Record<string, { menu: string; close: string }>> = {
140
+ en: { menu: NAV_SHAPE_COPY.menu, close: NAV_SHAPE_COPY.close },
141
+ he: { menu: 'תפריט', close: 'סגירה' },
142
+ };
143
+
144
+ export function menuWords(locale: string | undefined): { menu: string; close: string } {
145
+ return MENU_WORDS[locale ?? ''] ?? MENU_WORDS['en'];
146
+ }
147
+
129
148
  /** The layer names of the parts (R2: the tree, the breadcrumb and the toolbar read them). */
130
149
  export const NAV_PART_LABELS: Readonly<Record<string, string>> = {
131
150
  [NavRole.Root]: 'Navigation bar',
@@ -156,6 +175,9 @@ const ROUTE_ICONS: ReadonlyArray<[RegExp, string]> = [
156
175
  const FALLBACK_ICON = 'ph-thin ph-file';
157
176
  const MENU_ICON = 'ph-thin ph-list';
158
177
  const CLOSE_ICON = 'ph-thin ph-x';
178
+ /** A `dots` button's icon — what a renderer without the shared CSS shows; the shared CSS draws the nine dots and their
179
+ * cross itself (iox-design.css "the menu's buttons"). */
180
+ const DOTS_ICON = 'ph-thin ph-dots-nine';
159
181
  const MORE_ICON = 'ph-thin ph-dots-three';
160
182
 
161
183
  export function barIconForRoute(route: string): string {
@@ -420,6 +442,61 @@ function drawer(kit: Kit, root: SerializedNode, pages: NavPage[], at: string): S
420
442
  return dr;
421
443
  }
422
444
 
445
+ // ── HI2a: the menu's look ───────────────────────────────────────────────────────────────────
446
+
447
+ /** The menu's own traits (on the drawer); its button's trait is on the menu button and the drawer's Close. */
448
+ const MENU_DIALOG_TRAITS: ReadonlyArray<[keyof MenuLook, MenuTrait]> = [
449
+ ['form', MenuTrait.Form], ['reveal', MenuTrait.Reveal], ['hover', MenuTrait.Hover], ['phone', MenuTrait.Phone],
450
+ ];
451
+
452
+ /** Write the look's menu traits on the drawer: each one the look names is replaced (a default writes nothing — R-H4);
453
+ * what it does not name is kept. */
454
+ function dressDrawer(dr: SerializedNode, look: Partial<MenuLook>): void {
455
+ const props = { ...(dr.props ?? {}) };
456
+ for (const [key, trait] of MENU_DIALOG_TRAITS) if (look[key] !== undefined) delete props[trait];
457
+ dr.props = { ...props, ...menuDialogProps(look) };
458
+ }
459
+
460
+ /** A `word` button is as wide as its word (never narrower than the icon button it replaces). */
461
+ const WORD_BUTTON_LAY = { width: 'auto', minWidth: '48px' };
462
+
463
+ /** What a menu button shows for its kind — closed (the menu button) or open (the drawer's Close, which lands where the
464
+ * menu button is): the list icon and an X, the nine dots and an X (the shared CSS draws both as dots), or the word. */
465
+ function buttonFace(kit: Kit, suffix: string, kind: MenuButtonKind, open: boolean, locale: string | undefined): SerializedNode[] {
466
+ switch (kind) {
467
+ case MenuButtonKind.Word: {
468
+ const words = menuWords(locale);
469
+ return [labelText(kit, `${suffix}-word`, open ? words.close : words.menu)];
470
+ }
471
+ case MenuButtonKind.Dots: return [iconNode(kit, `${suffix}-dots`, open ? CLOSE_ICON : DOTS_ICON)];
472
+ default: return [iconNode(kit, `${suffix}-icon`, open ? CLOSE_ICON : MENU_ICON)];
473
+ }
474
+ }
475
+
476
+ /** Give a menu button (or the drawer's Close) a kind. The same kind keeps the author's children; another kind gets that
477
+ * kind's face and size. */
478
+ function dressButton(kit: Kit, btn: SerializedNode, suffix: string, kind: MenuButtonKind, open: boolean, locale: string | undefined): void {
479
+ const was = menuButtonOf(btn.props?.[MenuTrait.Button]);
480
+ const { [MenuTrait.Button]: _drop, ...props } = btn.props ?? {};
481
+ btn.props = { ...props, ...menuButtonProps(kind) };
482
+ if (was === kind) return;
483
+ btn.children = buttonFace(kit, suffix, kind, open, locale);
484
+ if (kind === MenuButtonKind.Word) Object.assign(btn.styleProps, WORD_BUTTON_LAY);
485
+ else if (was === MenuButtonKind.Word) Object.assign(btn.styleProps, { width: MENU_BUTTON_LAY.width, minWidth: ICON_BUTTON_MIN_WIDTH });
486
+ }
487
+
488
+ /** An icon menu button's own min-width (its type's, as `part` stamps it) — what a `word` button gives back. */
489
+ const ICON_BUTTON_MIN_WIDTH = String(createSerializedNode('min-width', BUTTON, { tag: 'button' }, 'button-ghost', COMPOSED).styleProps['minWidth'] ?? '0px');
490
+
491
+ /** Put a look on a header's menu: the drawer's traits, and the menu button's and the Close's kind. */
492
+ function dressMenu(kit: Kit, dr: SerializedNode | null, menu: SerializedNode | null, look: Partial<MenuLook>, locale: string | undefined): void {
493
+ if (dr) dressDrawer(dr, look);
494
+ if (!look.button) return;
495
+ if (menu) dressButton(kit, menu, 'menu', look.button, false, locale);
496
+ const close = dr ? find([dr], NavRole.DrawerClose) : null;
497
+ if (close) dressButton(kit, close, 'drawer-close', look.button, true, locale);
498
+ }
499
+
423
500
  function barItem(kit: Kit, i: number, page: NavPage): SerializedNode {
424
501
  const item = part(kit, `bar-item-${i}`, LINKED, { linkType: LinkType.Page, pageRoute: page.route, target: '_self' }, 'bottom-bar-item', NavRole.BarItem, BAR_ITEM_LAY);
425
502
  item.label = page.label;
@@ -620,6 +697,8 @@ export function planNavShape(globals: ReadonlyArray<SerializedNode>, shape: NavS
620
697
  }
621
698
  placeMenu(root, menu, (options.menuSide as MenuSide | undefined) ?? null, was);
622
699
  }
700
+ // HI2a: the menu's look, when one is asked (the composer's header recipe; the Header studio later).
701
+ if (options.look) dressMenu(kit, dr, menu, options.look, options.locale);
623
702
  if (dr && shape === NavShape.Drawer) kids.push(dr);
624
703
  if (dr && shape === NavShape.Both) {
625
704
  dr.isGlobal = true;