colibri-ui 0.8.96 → 0.8.98

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.
Files changed (135) hide show
  1. package/ColorPicker/ColorPicker.d.ts +3 -0
  2. package/ColorPicker/ColorPicker.js +116 -0
  3. package/ColorPicker/ColorPicker.module.css +22 -0
  4. package/ColorPicker/assets/none.png +0 -0
  5. package/ColorPicker/components/ColorPreview/ColorPreview.module.css +23 -0
  6. package/ColorPicker/components/ColorPreview/index.d.ts +10 -0
  7. package/ColorPicker/components/ColorPreview/index.js +29 -0
  8. package/ColorPicker/components/CustomColorModal/CustomColorModal.module.css +18 -0
  9. package/ColorPicker/components/CustomColorModal/index.d.ts +15 -0
  10. package/ColorPicker/components/CustomColorModal/index.js +107 -0
  11. package/ColorPicker/components/HueSlider/HueSlider.module.css +31 -0
  12. package/ColorPicker/components/HueSlider/index.d.ts +10 -0
  13. package/ColorPicker/components/HueSlider/index.js +73 -0
  14. package/ColorPicker/components/Palette/Palette.module.css +12 -0
  15. package/ColorPicker/components/Palette/index.d.ts +19 -0
  16. package/ColorPicker/components/Palette/index.js +99 -0
  17. package/ColorPicker/components/SaturationPanel/SaturationPanel.module.css +26 -0
  18. package/ColorPicker/components/SaturationPanel/index.d.ts +13 -0
  19. package/ColorPicker/components/SaturationPanel/index.js +86 -0
  20. package/ColorPicker/components/Swatch/Swatch.module.css +36 -0
  21. package/ColorPicker/components/Swatch/index.d.ts +14 -0
  22. package/ColorPicker/components/Swatch/index.js +47 -0
  23. package/ColorPicker/hooks/useEyeDropper.d.ts +8 -0
  24. package/ColorPicker/hooks/useEyeDropper.js +38 -0
  25. package/ColorPicker/hooks/useHexDraft.d.ts +19 -0
  26. package/ColorPicker/hooks/useHexDraft.js +49 -0
  27. package/ColorPicker/hooks/usePointerDrag.d.ts +20 -0
  28. package/ColorPicker/hooks/usePointerDrag.js +55 -0
  29. package/ColorPicker/index.d.ts +3 -0
  30. package/ColorPicker/index.js +9 -0
  31. package/ColorPicker/index.props.d.ts +43 -0
  32. package/ColorPicker/package.json +9 -0
  33. package/ColorPicker/presets.d.ts +3 -0
  34. package/ColorPicker/presets.js +92 -0
  35. package/ColorPicker/utils/color.d.ts +25 -0
  36. package/ColorPicker/utils/color.js +162 -0
  37. package/Icons/Pipette.d.ts +3 -0
  38. package/Icons/Pipette.js +35 -0
  39. package/Icons/index.d.ts +1 -0
  40. package/Icons/index.js +2 -0
  41. package/NavigationMenu/NavigationMenu.d.ts +3 -0
  42. package/NavigationMenu/NavigationMenu.js +170 -0
  43. package/NavigationMenu/NavigationMenu.module.css +67 -0
  44. package/NavigationMenu/components/MoreMenu/MoreMenu.module.css +19 -0
  45. package/NavigationMenu/components/MoreMenu/index.d.ts +16 -0
  46. package/NavigationMenu/components/MoreMenu/index.js +155 -0
  47. package/NavigationMenu/components/NavigationLink/NavigationLink.module.css +59 -0
  48. package/NavigationMenu/components/NavigationLink/index.d.ts +16 -0
  49. package/NavigationMenu/components/NavigationLink/index.js +51 -0
  50. package/NavigationMenu/helpers.d.ts +9 -0
  51. package/NavigationMenu/helpers.js +20 -0
  52. package/NavigationMenu/index.d.ts +2 -0
  53. package/NavigationMenu/index.js +7 -0
  54. package/NavigationMenu/index.props.d.ts +40 -0
  55. package/NavigationMenu/package.json +9 -0
  56. package/NavigationMenu/splitItems.d.ts +30 -0
  57. package/NavigationMenu/splitItems.js +54 -0
  58. package/NavigationMenu/useOverflowSplit.d.ts +25 -0
  59. package/NavigationMenu/useOverflowSplit.js +63 -0
  60. package/Theme/index.d.ts +8 -0
  61. package/Theme/themes/buenos_aires.d.ts +4 -0
  62. package/Theme/themes/buenos_aires.js +4 -0
  63. package/Theme/themes/jaipur.d.ts +4 -0
  64. package/Theme/themes/jaipur.js +4 -0
  65. package/esm/ColorPicker/ColorPicker.d.ts +3 -0
  66. package/esm/ColorPicker/ColorPicker.js +108 -0
  67. package/esm/ColorPicker/ColorPicker.module.css +22 -0
  68. package/esm/ColorPicker/assets/none.png +0 -0
  69. package/esm/ColorPicker/components/ColorPreview/ColorPreview.module.css +23 -0
  70. package/esm/ColorPicker/components/ColorPreview/index.d.ts +10 -0
  71. package/esm/ColorPicker/components/ColorPreview/index.js +21 -0
  72. package/esm/ColorPicker/components/CustomColorModal/CustomColorModal.module.css +18 -0
  73. package/esm/ColorPicker/components/CustomColorModal/index.d.ts +15 -0
  74. package/esm/ColorPicker/components/CustomColorModal/index.js +100 -0
  75. package/esm/ColorPicker/components/HueSlider/HueSlider.module.css +31 -0
  76. package/esm/ColorPicker/components/HueSlider/index.d.ts +10 -0
  77. package/esm/ColorPicker/components/HueSlider/index.js +66 -0
  78. package/esm/ColorPicker/components/Palette/Palette.module.css +12 -0
  79. package/esm/ColorPicker/components/Palette/index.d.ts +19 -0
  80. package/esm/ColorPicker/components/Palette/index.js +92 -0
  81. package/esm/ColorPicker/components/SaturationPanel/SaturationPanel.module.css +26 -0
  82. package/esm/ColorPicker/components/SaturationPanel/index.d.ts +13 -0
  83. package/esm/ColorPicker/components/SaturationPanel/index.js +79 -0
  84. package/esm/ColorPicker/components/Swatch/Swatch.module.css +36 -0
  85. package/esm/ColorPicker/components/Swatch/index.d.ts +14 -0
  86. package/esm/ColorPicker/components/Swatch/index.js +38 -0
  87. package/esm/ColorPicker/hooks/useEyeDropper.d.ts +8 -0
  88. package/esm/ColorPicker/hooks/useEyeDropper.js +36 -0
  89. package/esm/ColorPicker/hooks/useHexDraft.d.ts +19 -0
  90. package/esm/ColorPicker/hooks/useHexDraft.js +47 -0
  91. package/esm/ColorPicker/hooks/usePointerDrag.d.ts +20 -0
  92. package/esm/ColorPicker/hooks/usePointerDrag.js +53 -0
  93. package/esm/ColorPicker/index.d.ts +3 -0
  94. package/esm/ColorPicker/index.js +2 -0
  95. package/esm/ColorPicker/index.props.d.ts +43 -0
  96. package/esm/ColorPicker/presets.d.ts +3 -0
  97. package/esm/ColorPicker/presets.js +89 -0
  98. package/esm/ColorPicker/utils/color.d.ts +25 -0
  99. package/esm/ColorPicker/utils/color.js +152 -0
  100. package/esm/Icons/Pipette.d.ts +3 -0
  101. package/esm/Icons/Pipette.js +29 -0
  102. package/esm/Icons/index.d.ts +1 -0
  103. package/esm/Icons/index.js +1 -0
  104. package/esm/NavigationMenu/NavigationMenu.d.ts +3 -0
  105. package/esm/NavigationMenu/NavigationMenu.js +162 -0
  106. package/esm/NavigationMenu/NavigationMenu.module.css +67 -0
  107. package/esm/NavigationMenu/components/MoreMenu/MoreMenu.module.css +19 -0
  108. package/esm/NavigationMenu/components/MoreMenu/index.d.ts +16 -0
  109. package/esm/NavigationMenu/components/MoreMenu/index.js +147 -0
  110. package/esm/NavigationMenu/components/NavigationLink/NavigationLink.module.css +59 -0
  111. package/esm/NavigationMenu/components/NavigationLink/index.d.ts +16 -0
  112. package/esm/NavigationMenu/components/NavigationLink/index.js +41 -0
  113. package/esm/NavigationMenu/helpers.d.ts +9 -0
  114. package/esm/NavigationMenu/helpers.js +15 -0
  115. package/esm/NavigationMenu/index.d.ts +2 -0
  116. package/esm/NavigationMenu/index.js +1 -0
  117. package/esm/NavigationMenu/index.props.d.ts +40 -0
  118. package/esm/NavigationMenu/splitItems.d.ts +30 -0
  119. package/esm/NavigationMenu/splitItems.js +51 -0
  120. package/esm/NavigationMenu/useOverflowSplit.d.ts +25 -0
  121. package/esm/NavigationMenu/useOverflowSplit.js +61 -0
  122. package/esm/Theme/index.d.ts +8 -0
  123. package/esm/Theme/themes/buenos_aires.d.ts +4 -0
  124. package/esm/Theme/themes/buenos_aires.js +4 -0
  125. package/esm/Theme/themes/jaipur.d.ts +4 -0
  126. package/esm/Theme/themes/jaipur.js +4 -0
  127. package/esm/index.d.ts +4 -0
  128. package/esm/index.js +4 -0
  129. package/esm/theme_ba_variables.css +4 -0
  130. package/esm/theme_jaipur_variables.css +4 -0
  131. package/index.d.ts +4 -0
  132. package/index.js +10 -0
  133. package/package.json +1 -1
  134. package/theme_ba_variables.css +4 -0
  135. package/theme_jaipur_variables.css +4 -0
@@ -0,0 +1,67 @@
1
+ .root {
2
+ font-family: var(--font-family-ui);
3
+ min-inline-size: 0;
4
+ }
5
+ .root.size_m {
6
+ --navigation-item-height: calc(var(--space-8) + var(--space-1));
7
+ --navigation-item-font-size: var(--font-size-text-md);
8
+ --navigation-item-line-height: var(--line-height-text-md);
9
+ --navigation-item-padding: var(--space-4);
10
+ --navigation-menu-gap: var(--space-2);
11
+ }
12
+ .root.size_s {
13
+ --navigation-item-height: var(--space-8);
14
+ --navigation-item-font-size: var(--font-size-text-sm);
15
+ --navigation-item-line-height: var(--line-height-text-sm);
16
+ --navigation-item-padding: var(--space-3);
17
+ --navigation-menu-gap: var(--space-1);
18
+ }
19
+
20
+ .list {
21
+ align-items: center;
22
+ display: flex;
23
+ gap: var(--navigation-menu-gap);
24
+ list-style: none;
25
+ margin: 0;
26
+ padding: 0;
27
+ }
28
+ .list_item {
29
+ display: flex;
30
+ flex-shrink: 0;
31
+ }
32
+
33
+ .overflow {
34
+ display: block;
35
+ position: relative;
36
+ }
37
+ .overflow_measuring {
38
+ overflow: hidden;
39
+ }
40
+
41
+ .more_hidden {
42
+ pointer-events: none;
43
+ position: absolute;
44
+ visibility: hidden;
45
+ }
46
+
47
+ .measurer {
48
+ block-size: 0;
49
+ display: flex;
50
+ inline-size: max-content;
51
+ inset-block-start: 0;
52
+ inset-inline-start: 0;
53
+ overflow: hidden;
54
+ pointer-events: none;
55
+ position: absolute;
56
+ visibility: hidden;
57
+ }
58
+
59
+ .scroll_area {
60
+ overflow: auto hidden;
61
+ overscroll-behavior-x: contain;
62
+ position: relative;
63
+ scrollbar-width: none;
64
+ }
65
+ .scroll_area::-webkit-scrollbar {
66
+ display: none;
67
+ }
@@ -0,0 +1,19 @@
1
+ .root {
2
+ display: contents;
3
+ }
4
+
5
+ .chevron {
6
+ flex-shrink: 0;
7
+ transition: transform 0.15s ease;
8
+ }
9
+ .chevron_open {
10
+ transform: rotate(180deg);
11
+ }
12
+
13
+ .options {
14
+ display: flex;
15
+ flex-direction: column;
16
+ font-family: var(--font-family-ui);
17
+ min-inline-size: calc(var(--space-32) + var(--space-16));
18
+ padding: var(--space-1);
19
+ }
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import type { ReactNode } from "react";
3
+ import type { NavigationMenuItem, NavigationMenuRenderLink } from "../../index.props";
4
+ interface MoreMenuProps {
5
+ items: NavigationMenuItem[];
6
+ label: ReactNode;
7
+ /** Nothing to show: the trigger stays in the DOM only to be measured. */
8
+ hidden: boolean;
9
+ onItemClick?: (item: NavigationMenuItem) => void;
10
+ renderLink?: NavigationMenuRenderLink;
11
+ /** The menu became hidden while this item had focus inside the dropdown. */
12
+ onFocusLost: (item: NavigationMenuItem) => void;
13
+ }
14
+ /** "More" trigger with a dropdown of the items that do not fit. */
15
+ export declare const MoreMenu: ({ items, label, hidden, onItemClick, renderLink, onFocusLost, }: MoreMenuProps) => React.JSX.Element;
16
+ export {};
@@ -0,0 +1,147 @@
1
+ import React, { useState, useRef } from 'react';
2
+ import clsx from 'clsx';
3
+ import { Dropdown } from '../../../Dropdown/index.js';
4
+ import 'tslib';
5
+ import { Chevron } from '../../../Icons/Chevron.js';
6
+ import { useIsomorphicLayoutEffect, getItemKey } from '../../helpers.js';
7
+ import { getLinkClassName, NavigationLink } from '../NavigationLink/index.js';
8
+ import styles from './MoreMenu.module.css';
9
+
10
+ const getLinkPosition = event => {
11
+ const links = Array.from(event.currentTarget.querySelectorAll('[role="menuitem"]'));
12
+ return {
13
+ links,
14
+ index: links.indexOf(event.target)
15
+ };
16
+ };
17
+ const MoreOptions = ({
18
+ items,
19
+ onItemClick,
20
+ renderLink,
21
+ rootRef,
22
+ onItemFocus,
23
+ onTabOut
24
+ }) => {
25
+ // The dropdown is portaled to the end of the document: move focus into it,
26
+ // to the current section or to the first link.
27
+ useIsomorphicLayoutEffect(() => {
28
+ var _a, _b;
29
+ const root = rootRef.current;
30
+ (_b = (_a = root === null || root === void 0 ? void 0 : root.querySelector('[aria-current="page"]')) !== null && _a !== void 0 ? _a : root === null || root === void 0 ? void 0 : root.querySelector('[role="menuitem"]')) === null || _b === void 0 ? void 0 : _b.focus();
31
+ }, [rootRef]);
32
+ // Focus events bubble from the links, whatever `renderLink` renders.
33
+ const handleFocus = event => {
34
+ const {
35
+ index
36
+ } = getLinkPosition(event);
37
+ if (index !== -1) onItemFocus(items[index]);
38
+ };
39
+ // Arrow keys move focus through the links, Home/End go to the first and the
40
+ // last one. Tab leaves through the trigger, so focus continues from it.
41
+ const handleKeyDown = event => {
42
+ var _a;
43
+ if (event.key === "Tab") {
44
+ onTabOut();
45
+ return;
46
+ }
47
+ const {
48
+ links,
49
+ index
50
+ } = getLinkPosition(event);
51
+ const last = links.length - 1;
52
+ const targets = {
53
+ ArrowDown: index === last ? 0 : index + 1,
54
+ ArrowUp: index === 0 ? last : index - 1,
55
+ Home: 0,
56
+ End: last
57
+ };
58
+ if (index === -1 || !(event.key in targets)) return;
59
+ event.preventDefault();
60
+ (_a = links[targets[event.key]]) === null || _a === void 0 ? void 0 : _a.focus();
61
+ };
62
+ return (
63
+ /*#__PURE__*/
64
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions -- events come from the focused links
65
+ React.createElement("div", {
66
+ ref: rootRef,
67
+ className: styles.options,
68
+ onKeyDown: handleKeyDown,
69
+ onFocus: handleFocus
70
+ }, items.map((item, index) => (/*#__PURE__*/React.createElement(NavigationLink, {
71
+ key: getItemKey(item, index),
72
+ item: item,
73
+ view: "option",
74
+ role: "menuitem",
75
+ onClick: onItemClick,
76
+ renderLink: renderLink
77
+ }))))
78
+ );
79
+ };
80
+ /** "More" trigger with a dropdown of the items that do not fit. */
81
+ const MoreMenu = ({
82
+ items,
83
+ label,
84
+ hidden,
85
+ onItemClick,
86
+ renderLink,
87
+ onFocusLost
88
+ }) => {
89
+ const [isOpen, setOpen] = useState(false);
90
+ const rootRef = useRef(null);
91
+ const overlayRef = useRef(null);
92
+ const focusedItemRef = useRef(null);
93
+ // A resize hides "More" and removes the dropdown with the focused link.
94
+ // Layout effect: focus moves before the browser paints the new row.
95
+ useIsomorphicLayoutEffect(() => {
96
+ if (!hidden) return;
97
+ const item = focusedItemRef.current;
98
+ const isFocusLost = !document.activeElement || document.activeElement === document.body;
99
+ focusedItemRef.current = null;
100
+ setOpen(false);
101
+ if (item && isFocusLost) onFocusLost(item);
102
+ }, [hidden]);
103
+ // Selection, Escape and Tab remove the focused link together with the
104
+ // dropdown: return focus to the trigger.
105
+ const close = () => {
106
+ var _a, _b;
107
+ const trigger = (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.firstElementChild;
108
+ if (((_b = overlayRef.current) === null || _b === void 0 ? void 0 : _b.contains(document.activeElement)) && trigger instanceof HTMLElement) {
109
+ trigger.focus();
110
+ }
111
+ focusedItemRef.current = null;
112
+ setOpen(false);
113
+ };
114
+ return /*#__PURE__*/React.createElement("span", {
115
+ ref: rootRef,
116
+ className: styles.root
117
+ }, /*#__PURE__*/React.createElement(Dropdown, {
118
+ trigger: ["click"],
119
+ placement: "bottom-end",
120
+ visible: isOpen,
121
+ disabled: hidden,
122
+ onVisibleChange: visible => visible ? setOpen(true) : close(),
123
+ overlay: /*#__PURE__*/React.createElement(MoreOptions, {
124
+ items: items,
125
+ onItemClick: onItemClick,
126
+ renderLink: renderLink,
127
+ rootRef: overlayRef,
128
+ onItemFocus: item => {
129
+ focusedItemRef.current = item;
130
+ },
131
+ onTabOut: close
132
+ })
133
+ }, /*#__PURE__*/React.createElement("button", {
134
+ type: "button",
135
+ className: getLinkClassName(),
136
+ tabIndex: hidden ? -1 : undefined
137
+ }, label, /*#__PURE__*/React.createElement(Chevron, {
138
+ width: 16,
139
+ height: 16,
140
+ "aria-hidden": "true",
141
+ className: clsx(styles.chevron, {
142
+ [styles.chevron_open]: isOpen
143
+ })
144
+ }))));
145
+ };
146
+
147
+ export { MoreMenu };
@@ -0,0 +1,59 @@
1
+ .item {
2
+ align-items: center;
3
+ background: transparent;
4
+ block-size: var(--navigation-item-height);
5
+ border: none;
6
+ border-radius: var(--radius-full);
7
+ box-sizing: border-box;
8
+ color: var(--component-navigation-item-text);
9
+ cursor: pointer;
10
+ display: inline-flex;
11
+ font: inherit;
12
+ font-size: var(--navigation-item-font-size);
13
+ gap: var(--space-2);
14
+ line-height: var(--navigation-item-line-height);
15
+ padding: 0 var(--navigation-item-padding);
16
+ text-decoration: none;
17
+ transition: background-color 0.15s ease;
18
+ white-space: nowrap;
19
+ }
20
+ .item:hover {
21
+ background: var(--component-navigation-item-bg-hover);
22
+ }
23
+ .item:focus-visible {
24
+ outline: var(--focus-ring-width) solid var(--component-navigation-item-focus-ring);
25
+ outline-offset: calc(var(--focus-ring-width) * -1);
26
+ }
27
+ .item_selected, .item_selected:hover {
28
+ background: var(--component-navigation-item-bg-selected);
29
+ color: var(--component-navigation-item-text-selected);
30
+ }
31
+
32
+ .option {
33
+ align-items: center;
34
+ border-radius: var(--radius-xs);
35
+ color: var(--component-menu-text);
36
+ display: flex;
37
+ font-size: var(--font-size-text-sm);
38
+ gap: var(--space-2);
39
+ line-height: var(--line-height-text-sm);
40
+ outline: none;
41
+ padding: var(--space-2) var(--space-3);
42
+ text-decoration: none;
43
+ }
44
+ .option:hover, .option:focus-visible {
45
+ background: var(--component-menu-item-bg-hover);
46
+ }
47
+ .option_selected, .option_selected:hover, .option_selected:focus-visible {
48
+ background: var(--component-navigation-item-bg-selected);
49
+ color: var(--component-navigation-item-text-selected);
50
+ }
51
+ .option_selected:focus-visible {
52
+ outline: var(--focus-ring-width) solid var(--component-navigation-item-focus-ring);
53
+ outline-offset: calc(var(--focus-ring-width) * -1);
54
+ }
55
+
56
+ .icon {
57
+ display: inline-flex;
58
+ flex-shrink: 0;
59
+ }
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import type { NavigationMenuItem, NavigationMenuRenderLink } from "../../index.props";
3
+ interface NavigationLinkProps {
4
+ item: NavigationMenuItem;
5
+ /** `item` is a pill in the row, `option` is a line inside "More". */
6
+ view?: "item" | "option";
7
+ role?: "menuitem";
8
+ onClick?: (item: NavigationMenuItem) => void;
9
+ renderLink?: NavigationMenuRenderLink;
10
+ }
11
+ export declare const getLinkClassName: (view?: NavigationLinkProps["view"], active?: boolean) => string;
12
+ export declare const LinkContent: ({ item }: {
13
+ item: NavigationMenuItem;
14
+ }) => React.JSX.Element;
15
+ export declare const NavigationLink: ({ item, view, role, onClick, renderLink, }: NavigationLinkProps) => React.JSX.Element;
16
+ export {};
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import clsx from 'clsx';
3
+ import styles from './NavigationLink.module.css';
4
+
5
+ const getLinkClassName = (view = "item", active) => clsx(styles[view], {
6
+ [styles[`${view}_selected`]]: active
7
+ });
8
+ const LinkContent = ({
9
+ item
10
+ }) => (/*#__PURE__*/React.createElement(React.Fragment, null, item.icon && (/*#__PURE__*/React.createElement("span", {
11
+ className: styles.icon,
12
+ "aria-hidden": "true"
13
+ }, item.icon)), /*#__PURE__*/React.createElement("span", null, item.label)));
14
+ const NavigationLink = ({
15
+ item,
16
+ view,
17
+ role,
18
+ onClick,
19
+ renderLink
20
+ }) => {
21
+ const props = {
22
+ item,
23
+ className: getLinkClassName(view, item.active),
24
+ children: /*#__PURE__*/React.createElement(LinkContent, {
25
+ item: item
26
+ }),
27
+ onClick: onClick ? () => onClick(item) : undefined,
28
+ role,
29
+ "aria-current": item.active ? "page" : undefined
30
+ };
31
+ if (renderLink) return /*#__PURE__*/React.createElement(React.Fragment, null, renderLink(props));
32
+ return /*#__PURE__*/React.createElement("a", {
33
+ href: item.href,
34
+ className: props.className,
35
+ onClick: props.onClick,
36
+ role: role,
37
+ "aria-current": props["aria-current"]
38
+ }, props.children);
39
+ };
40
+
41
+ export { LinkContent, NavigationLink, getLinkClassName };
@@ -0,0 +1,9 @@
1
+ import { useLayoutEffect } from "react";
2
+ import type { Ref } from "react";
3
+ import type { NavigationMenuItem } from "./index.props";
4
+ export declare const getItemKey: (item: NavigationMenuItem, index: number) => string;
5
+ /** Items are often recreated on every render: compare them by content. */
6
+ export declare const isSameItem: (a: NavigationMenuItem, b: NavigationMenuItem) => boolean;
7
+ /** `useLayoutEffect` without the server rendering warning. */
8
+ export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
9
+ export declare const assignRef: <T>(ref: Ref<T> | undefined, value: T | null) => void;
@@ -0,0 +1,15 @@
1
+ import { useLayoutEffect, useEffect } from 'react';
2
+
3
+ const getItemKey = (item, index) => {
4
+ var _a, _b;
5
+ return (_b = (_a = item.id) !== null && _a !== void 0 ? _a : item.href) !== null && _b !== void 0 ? _b : `${item.label}-${index}`;
6
+ };
7
+ /** Items are often recreated on every render: compare them by content. */
8
+ const isSameItem = (a, b) => getItemKey(a, 0) === getItemKey(b, 0);
9
+ /** `useLayoutEffect` without the server rendering warning. */
10
+ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
11
+ const assignRef = (ref, value) => {
12
+ if (typeof ref === "function") ref(value);else if (ref) ref.current = value;
13
+ };
14
+
15
+ export { assignRef, getItemKey, isSameItem, useIsomorphicLayoutEffect };
@@ -0,0 +1,2 @@
1
+ export { NavigationMenu } from "./NavigationMenu";
2
+ export type { NavigationMenuItem, NavigationMenuLayout, NavigationMenuLinkProps, NavigationMenuProps, NavigationMenuRenderLink, NavigationMenuSize, } from "./index.props";
@@ -0,0 +1 @@
1
+ export { NavigationMenu } from './NavigationMenu.js';
@@ -0,0 +1,40 @@
1
+ import type { HTMLAttributes, MouseEventHandler, ReactNode } from "react";
2
+ /** `overflow` keeps items in a row and moves the rest to "More", `scroll` is a horizontal strip. */
3
+ export type NavigationMenuLayout = "overflow" | "scroll";
4
+ export type NavigationMenuSize = "s" | "m";
5
+ export interface NavigationMenuItem {
6
+ /** Unique key. Defaults to `href`, then to `label`. */
7
+ id?: string;
8
+ label: string;
9
+ href?: string;
10
+ /** Current section: highlighted, gets `aria-current="page"` and never moves to "More". */
11
+ active?: boolean;
12
+ /** Icon before the label. */
13
+ icon?: ReactNode;
14
+ }
15
+ export interface NavigationMenuLinkProps {
16
+ item: NavigationMenuItem;
17
+ className: string;
18
+ children: ReactNode;
19
+ onClick?: MouseEventHandler<HTMLElement>;
20
+ tabIndex?: number;
21
+ /** Set for links inside the "More" dropdown. */
22
+ role?: "menuitem";
23
+ "aria-current"?: "page";
24
+ }
25
+ /** Renders an item link, for example a router `Link`. Pass every prop except `item` to the element. */
26
+ export type NavigationMenuRenderLink = (props: NavigationMenuLinkProps) => ReactNode;
27
+ export interface NavigationMenuProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
28
+ items: NavigationMenuItem[];
29
+ /** Always visible after `items`. */
30
+ pinnedItems?: NavigationMenuItem[];
31
+ /** Always inside "More", after the items that do not fit. In the `scroll` layout they end the strip. */
32
+ moreItems?: NavigationMenuItem[];
33
+ layout?: NavigationMenuLayout;
34
+ size?: NavigationMenuSize;
35
+ moreLabel?: ReactNode;
36
+ /** Called on a click on any item, including the ones inside "More". */
37
+ onItemClick?: (item: NavigationMenuItem) => void;
38
+ /** Custom link. Defaults to `<a href>`. */
39
+ renderLink?: NavigationMenuRenderLink;
40
+ }
@@ -0,0 +1,30 @@
1
+ export interface SplitInput {
2
+ itemWidths: number[];
3
+ /** Pinned items are always visible and go after the main items. */
4
+ pinnedWidths: number[];
5
+ moreWidth: number;
6
+ containerWidth: number;
7
+ /** CSS gap between items. */
8
+ gap: number;
9
+ /** Index of the active item or -1. */
10
+ activeIndex: number;
11
+ /** "More" is needed anyway, for example for `moreItems`. */
12
+ forceMore: boolean;
13
+ }
14
+ export interface SplitResult {
15
+ /** Indexes of the items left in the row, in the original order. */
16
+ visible: number[];
17
+ /** Indexes of the items moved to "More", in the original order. */
18
+ hidden: number[];
19
+ }
20
+ /**
21
+ * Splits items into the row and "More".
22
+ *
23
+ * Items go from left to right while they fit; the first one that does not fit
24
+ * and all after it move to "More". Space for the active item is reserved
25
+ * first, so it stays in the row and its neighbours move instead. Every element
26
+ * costs its width plus gap; the budget has one extra gap because N elements
27
+ * have N − 1 gaps.
28
+ */
29
+ export declare const splitItems: ({ itemWidths, pinnedWidths, moreWidth, containerWidth, gap, activeIndex, forceMore, }: SplitInput) => SplitResult;
30
+ export declare const isSameSplit: (a: SplitResult, b: SplitResult) => boolean;
@@ -0,0 +1,51 @@
1
+ const sum = list => list.reduce((acc, n) => acc + n, 0);
2
+ /**
3
+ * Splits items into the row and "More".
4
+ *
5
+ * Items go from left to right while they fit; the first one that does not fit
6
+ * and all after it move to "More". Space for the active item is reserved
7
+ * first, so it stays in the row and its neighbours move instead. Every element
8
+ * costs its width plus gap; the budget has one extra gap because N elements
9
+ * have N − 1 gaps.
10
+ */
11
+ const splitItems = ({
12
+ itemWidths,
13
+ pinnedWidths,
14
+ moreWidth,
15
+ containerWidth,
16
+ gap,
17
+ activeIndex,
18
+ forceMore
19
+ }) => {
20
+ const all = itemWidths.map((_, index) => index);
21
+ const cost = width => width + gap;
22
+ const pinnedCost = sum(pinnedWidths.map(cost));
23
+ if (!forceMore && sum(itemWidths.map(cost)) + pinnedCost <= containerWidth + gap) {
24
+ return {
25
+ visible: all,
26
+ hidden: []
27
+ };
28
+ }
29
+ const hasActive = activeIndex >= 0 && activeIndex < itemWidths.length;
30
+ let budget = containerWidth + gap - pinnedCost - cost(moreWidth);
31
+ if (hasActive) budget -= cost(itemWidths[activeIndex]);
32
+ const visible = [];
33
+ for (let index = 0; index < itemWidths.length; index++) {
34
+ if (index === activeIndex) continue;
35
+ if (cost(itemWidths[index]) > budget) break;
36
+ budget -= cost(itemWidths[index]);
37
+ visible.push(index);
38
+ }
39
+ if (hasActive) {
40
+ visible.push(activeIndex);
41
+ visible.sort((a, b) => a - b);
42
+ }
43
+ return {
44
+ visible,
45
+ hidden: all.filter(index => !visible.includes(index))
46
+ };
47
+ };
48
+ const isSameList = (a, b) => a.length === b.length && a.every((index, position) => index === b[position]);
49
+ const isSameSplit = (a, b) => isSameList(a.visible, b.visible) && isSameList(a.hidden, b.hidden);
50
+
51
+ export { isSameSplit, splitItems };
@@ -0,0 +1,25 @@
1
+ import type { SplitResult } from "./splitItems";
2
+ interface Options {
3
+ itemCount: number;
4
+ pinnedCount: number;
5
+ activeIndex: number;
6
+ forceMore: boolean;
7
+ /** Changes with the item labels to recalculate. */
8
+ contentKey: string;
9
+ }
10
+ /**
11
+ * Measures the items and splits them into the row and "More".
12
+ *
13
+ * Widths come from a hidden measurer that always renders every item, so the
14
+ * items inside "More" are measured too, for example after a web font loads.
15
+ * ResizeObserver watches the container, the measurer and the "More" trigger.
16
+ * Before the first measurement, and on the server, `split` is `null`.
17
+ */
18
+ export declare const useOverflowSplit: ({ itemCount, pinnedCount, activeIndex, forceMore, contentKey, }: Options) => {
19
+ split: SplitResult | null;
20
+ containerRef: import("react").RefObject<HTMLElement | null>;
21
+ listRef: import("react").RefObject<HTMLUListElement | null>;
22
+ measurerRef: import("react").RefObject<HTMLDivElement | null>;
23
+ moreRef: import("react").RefObject<HTMLLIElement | null>;
24
+ };
25
+ export {};
@@ -0,0 +1,61 @@
1
+ import { useRef, useState } from 'react';
2
+ import { useIsomorphicLayoutEffect } from './helpers.js';
3
+ import { splitItems, isSameSplit } from './splitItems.js';
4
+
5
+ const getWidth = element => element ? element.getBoundingClientRect().width : 0;
6
+ /**
7
+ * Measures the items and splits them into the row and "More".
8
+ *
9
+ * Widths come from a hidden measurer that always renders every item, so the
10
+ * items inside "More" are measured too, for example after a web font loads.
11
+ * ResizeObserver watches the container, the measurer and the "More" trigger.
12
+ * Before the first measurement, and on the server, `split` is `null`.
13
+ */
14
+ const useOverflowSplit = ({
15
+ itemCount,
16
+ pinnedCount,
17
+ activeIndex,
18
+ forceMore,
19
+ contentKey
20
+ }) => {
21
+ const containerRef = useRef(null);
22
+ const listRef = useRef(null);
23
+ const measurerRef = useRef(null);
24
+ const moreRef = useRef(null);
25
+ const [split, setSplit] = useState(null);
26
+ useIsomorphicLayoutEffect(() => {
27
+ const container = containerRef.current;
28
+ const measurer = measurerRef.current;
29
+ if (!container || !measurer) return undefined;
30
+ const recalculate = () => {
31
+ const widths = Array.from(measurer.children, getWidth);
32
+ const gap = listRef.current ? parseFloat(getComputedStyle(listRef.current).columnGap) || 0 : 0;
33
+ const next = splitItems({
34
+ itemWidths: widths.slice(0, itemCount),
35
+ pinnedWidths: widths.slice(itemCount, itemCount + pinnedCount),
36
+ moreWidth: getWidth(moreRef.current),
37
+ containerWidth: getWidth(container),
38
+ gap,
39
+ activeIndex,
40
+ forceMore
41
+ });
42
+ setSplit(prev => prev && isSameSplit(prev, next) ? prev : next);
43
+ };
44
+ recalculate();
45
+ if (typeof ResizeObserver === "undefined") return undefined;
46
+ const observer = new ResizeObserver(recalculate);
47
+ observer.observe(container);
48
+ observer.observe(measurer);
49
+ if (moreRef.current) observer.observe(moreRef.current);
50
+ return () => observer.disconnect();
51
+ }, [itemCount, pinnedCount, activeIndex, forceMore, contentKey]);
52
+ return {
53
+ split,
54
+ containerRef,
55
+ listRef,
56
+ measurerRef,
57
+ moreRef
58
+ };
59
+ };
60
+
61
+ export { useOverflowSplit };
@@ -692,7 +692,11 @@ export declare const THEMES: {
692
692
  "component-pagination-bg-current": string;
693
693
  "component-pagination-bg-hover": string;
694
694
  "component-pagination-focus-ring": string;
695
+ "component-navigation-item-text": string;
696
+ "component-navigation-item-text-selected": string;
697
+ "component-navigation-item-bg-hover": string;
695
698
  "component-navigation-item-bg-selected": string;
699
+ "component-navigation-item-focus-ring": string;
696
700
  "component-chip-bg-selected": string;
697
701
  "component-chip-bg-selected-strong": string;
698
702
  "palette-black": string;
@@ -1536,7 +1540,11 @@ export declare const THEMES: {
1536
1540
  "component-pagination-bg-current": string;
1537
1541
  "component-pagination-bg-hover": string;
1538
1542
  "component-pagination-focus-ring": string;
1543
+ "component-navigation-item-text": string;
1544
+ "component-navigation-item-text-selected": string;
1545
+ "component-navigation-item-bg-hover": string;
1539
1546
  "component-navigation-item-bg-selected": string;
1547
+ "component-navigation-item-focus-ring": string;
1540
1548
  "component-chip-bg-selected": string;
1541
1549
  "component-chip-bg-selected-strong": string;
1542
1550
  "palette-black": string;
@@ -613,7 +613,11 @@ declare const _default: {
613
613
  "component-pagination-bg-current": string;
614
614
  "component-pagination-bg-hover": string;
615
615
  "component-pagination-focus-ring": string;
616
+ "component-navigation-item-text": string;
617
+ "component-navigation-item-text-selected": string;
618
+ "component-navigation-item-bg-hover": string;
616
619
  "component-navigation-item-bg-selected": string;
620
+ "component-navigation-item-focus-ring": string;
617
621
  "component-chip-bg-selected": string;
618
622
  "component-chip-bg-selected-strong": string;
619
623
  "palette-black": string;
@@ -615,7 +615,11 @@ var THEME_BA = {
615
615
  "component-pagination-bg-current": Color.BRAND_BA_FOREST,
616
616
  "component-pagination-bg-hover": Color.NEUTRAL_BA_100,
617
617
  "component-pagination-focus-ring": Color.BRAND_BA_LIME,
618
+ "component-navigation-item-text": Color.BRAND_BA_FOREST,
619
+ "component-navigation-item-text-selected": Color.BRAND_BA_LIME,
620
+ "component-navigation-item-bg-hover": Color.NEUTRAL_BA_100,
618
621
  "component-navigation-item-bg-selected": Color.BRAND_BA_FOREST,
622
+ "component-navigation-item-focus-ring": Color.BRAND_BA_LIME,
619
623
  "component-chip-bg-selected": Color.BRAND_BA_FOREST,
620
624
  "component-chip-bg-selected-strong": Color.BRAND_BA_LIME,
621
625
  "palette-black": Color.BRAND_BA_FOREST,